Restructure build targets of CMake configuration

* Rename the library under test from src to GildedRoseLib.
* Move the lib folder to test/third_party and handle ApprovalTests.hpp as header-only dependency.
* Remove the superfluous googletest_approval_main.cpp (in the same sense as there is only one GildedRoseCatch2ApprovalTests.cc)
* Set USE_FOLDERS property such that target ALL_BUILD, RUN_TESTS and ZERO_CHECK are grouped for Visual Studio.
* Set WORKING_DIRECTORY such that the RUN_TESTS target works successfully.
* Fix C++ language standard for Catch2 v3 to C++14.
* Bump third-party dependencies
  * Update ApprovalTests.hpp to v10.13.0
  * Update Catch2 to v3.8.0
  * Update GTest to v1.16.0
This commit is contained in:
tbeu committed 2025-02-11 23:04:23 +01:00
1 parent a9fe49d2b6
commit 3bf108ef0e
17 files changed
+6968 -3004

No files matched your search

+27
View File
@@ -1,3 +1,30 @@
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.16.0
GIT_SHALLOW TRUE
)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(googletest catch2)
# Force Google Test to link the C/C++ runtimes dynamically
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Disable building GMock
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
# Do not install GTest
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
add_subdirectory(cpp_catch2_approvaltest)
add_subdirectory(cpp_catch2_unittest)
add_subdirectory(cpp_googletest_approvaltest)
@@ -1,9 +1,14 @@
set(TEST_NAME GildedRoseCatch2ApprovalTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
target_link_libraries(${TEST_NAME} lib src Catch2::Catch2 Catch2::Catch2WithMain)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
@@ -1,5 +1,5 @@
#define APPROVALS_CATCH
#include "ApprovalTests.hpp"
#define APPROVALS_CATCH2_V3
#include <ApprovalTests.hpp>
#include "GildedRose.h"
std::ostream& operator<<(std::ostream& os, const Item& obj)
+7 -3
View File
@@ -1,9 +1,13 @@
set(TEST_NAME GildedRoseCatch2UnitTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
target_link_libraries(${TEST_NAME} lib src Catch2::Catch2 Catch2::Catch2WithMain )
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain )
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
@@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch2/catch_all.hpp"
#include <catch2/catch_all.hpp>
#include "GildedRose.h"
TEST_CASE("GildedRoseUnitTest", "Foo")
@@ -1,9 +1,14 @@
set(TEST_NAME GildedRoseGoogletestApprovalTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE googletest_approval_main.cc GildedRoseGoogletestApprovalTests.cc)
target_link_libraries(${TEST_NAME} lib src gtest)
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestApprovalTests.cc)
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
target_link_libraries(${TEST_NAME} GildedRoseLib gtest)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro can be used to get the path to current test file.
@@ -1,8 +1,5 @@
// Include header files for test frameworks
#include <gtest/gtest.h>
#define APPROVALS_GOOGLETEST
#include <ApprovalTests.hpp>
// Include code to be tested
#include "GildedRose.h"
std::ostream& operator<<(std::ostream& os, const Item& obj)
@@ -1,2 +0,0 @@
#define APPROVALS_GOOGLETEST // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"
@@ -1,9 +1,13 @@
set(TEST_NAME GildedRoseGoogletestUnitTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestUnitTests.cc)
target_link_libraries(${TEST_NAME} src gtest gtest_main)
target_link_libraries(${TEST_NAME} GildedRoseLib gtest gtest_main)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro can be used to get the path to current test file.
+6 -2
View File
@@ -1,9 +1,13 @@
set(TEST_NAME GildedRoseTextTests)
add_executable(${TEST_NAME} GildedRoseTextTests.cc)
target_sources(${TEST_NAME} PRIVATE GildedRoseTextTests.cc)
target_link_libraries(${TEST_NAME} lib src)
target_link_libraries(${TEST_NAME} GildedRoseLib)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
File diff suppressed because it is too large. Load diff