Merge pull request #445 from shelling21/main

CPP: Updated googletest to v1.12.1 & Catch2 to v3.3.2
This commit is contained in:
Emily Bache 2023-06-09 14:29:30 +02:00 committed by GitHub
commit a674623c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 17613 deletions

View File

@ -8,13 +8,16 @@ include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
googletest googletest
GIT_REPOSITORY https://github.com/google/googletest.git GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1 GIT_TAG release-1.12.1
) )
# Fetch GoogleTest amd make build scripts available FetchContent_Declare(
if (NOT googletest_POPULATED) catch2
FetchContent_Populate(googletest) GIT_REPOSITORY https://github.com/catchorg/Catch2.git
endif() GIT_TAG v3.3.2
)
FetchContent_MakeAvailable(googletest catch2)
#set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE) #set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
# Force Google Test to link the C/C++ runtimes dynamically when # Force Google Test to link the C/C++ runtimes dynamically when
@ -25,9 +28,6 @@ if (MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif() endif()
# Bring the populated content into the build
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
# uncomment this line to enable coverage measurements using gcov # uncomment this line to enable coverage measurements using gcov
# set(CMAKE_CXX_FLAGS "--coverage") # set(CMAKE_CXX_FLAGS "--coverage")

View File

@ -2419,12 +2419,12 @@ verifyAllCombinations(Converter&& converter, const Containers&... inputs)
#ifdef APPROVALS_CATCH #ifdef APPROVALS_CATCH
#include <Catch.hpp> #include <catch2/catch_all.hpp>
//namespace ApprovalTests { //namespace ApprovalTests {
struct Catch2ApprovalListener : Catch::TestEventListenerBase { struct Catch2ApprovalListener : Catch::EventListenerBase {
ApprovalTests::TestName currentTest; ApprovalTests::TestName currentTest;
using TestEventListenerBase::TestEventListenerBase; // This using allows us to use all base-class constructors using EventListenerBase::EventListenerBase; // This using allows us to use all base-class constructors
virtual void testCaseStarting(Catch::TestCaseInfo const &testInfo) override { virtual void testCaseStarting(Catch::TestCaseInfo const &testInfo) override {
currentTest.setFileName(testInfo.lineInfo.file); currentTest.setFileName(testInfo.lineInfo.file);
@ -2452,8 +2452,8 @@ CATCH_REGISTER_LISTENER(Catch2ApprovalListener)
#ifdef TEST_COMMIT_REVERT_CATCH #ifdef TEST_COMMIT_REVERT_CATCH
//namespace ApprovalTests { //namespace ApprovalTests {
struct Catch2TestCommitRevert : Catch::TestEventListenerBase { struct Catch2TestCommitRevert : Catch::EventListenerBase {
using TestEventListenerBase::TestEventListenerBase; // This using allows us to use all base-class constructors using EventListenerBase::EventListenerBase; // This using allows us to use all base-class constructors
virtual void testRunEnded( Catch::TestRunStats const& testRunStats )override{ virtual void testRunEnded( Catch::TestRunStats const& testRunStats )override{
bool commit = testRunStats.totals.testCases.allOk(); bool commit = testRunStats.totals.testCases.allOk();
std::string message = "r "; std::string message = "r ";

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
set(TEST_NAME GildedRoseCatch2ApprovalTests) set(TEST_NAME GildedRoseCatch2ApprovalTests)
add_executable(${TEST_NAME}) add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc) target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
target_link_libraries(${TEST_NAME} lib src) target_link_libraries(${TEST_NAME} lib src Catch2::Catch2 Catch2::Catch2WithMain)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11) 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})

View File

@ -1,7 +1,7 @@
set(TEST_NAME GildedRoseCatch2UnitTests) set(TEST_NAME GildedRoseCatch2UnitTests)
add_executable(${TEST_NAME}) add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc) target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
target_link_libraries(${TEST_NAME} lib src) target_link_libraries(${TEST_NAME} lib src Catch2::Catch2 Catch2::Catch2WithMain )
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11) 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})

View File

@ -1,5 +1,5 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "Catch.hpp" #include "catch2/catch_all.hpp"
#include "GildedRose.h" #include "GildedRose.h"
TEST_CASE("GildedRoseUnitTest", "Foo") TEST_CASE("GildedRoseUnitTest", "Foo")