diff --git a/tests/catch/CMakeLists.txt b/tests/catch/CMakeLists.txt index fce02cdc..e89dc00f 100644 --- a/tests/catch/CMakeLists.txt +++ b/tests/catch/CMakeLists.txt @@ -3,12 +3,18 @@ if(ENABLE_UNIT_TESTS) add_custom_target(unit_tests) # Build catch_main test object +find_package(Catch2 REQUIRED) include_directories(${CATCH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../libsrc/include ${SPDLOG_INCLUDE_DIR}) add_library(catch_main STATIC main.cpp) set_target_properties(catch_main PROPERTIES CXX_STANDARD 17) add_dependencies(unit_tests catch_main) add_dependencies(catch_main project_catch) +if (Catch2_VERSION VERSION_GREATER_EQUAL 3) + target_compile_options(catch_main PUBLIC -DCATCH2_v3) + target_link_libraries(catch_main Catch2::Catch2WithMain) +endif() + # ensure the test targets are built before testing add_test(NAME unit_tests_built COMMAND ${CMAKE_COMMAND} --build . --target unit_tests --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../.. ) diff --git a/tests/catch/archive.cpp b/tests/catch/archive.cpp index 62f6df46..1d1b55f7 100644 --- a/tests/catch/archive.cpp +++ b/tests/catch/archive.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include <../core/ngcore.hpp> #include #include @@ -354,7 +358,11 @@ void testArchive(Archive& in, Archive& out) SECTION("Not registered") { SharedPtrAndPtrHolder* p = new NotRegisteredForArchive; +#ifdef CATCH2_v3 + REQUIRE_THROWS(out & p, Catch::Matchers::ContainsSubstring("not registered for archive")); +#else REQUIRE_THROWS(out & p, Catch::Contains("not registered for archive")); +#endif } SECTION("Non-default constructor") { diff --git a/tests/catch/array.cpp b/tests/catch/array.cpp index 63011533..2c0eee79 100644 --- a/tests/catch/array.cpp +++ b/tests/catch/array.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include using namespace ngcore; using namespace std; diff --git a/tests/catch/main.cpp b/tests/catch/main.cpp index ad4c8431..6e8f9a3a 100644 --- a/tests/catch/main.cpp +++ b/tests/catch/main.cpp @@ -1,3 +1,7 @@ #define CATCH_CONFIG_MAIN #define DO_NOT_USE_WMAIN +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif \ No newline at end of file diff --git a/tests/catch/ranges.cpp b/tests/catch/ranges.cpp index aeca69b8..b37dbb37 100644 --- a/tests/catch/ranges.cpp +++ b/tests/catch/ranges.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include #include diff --git a/tests/catch/symboltable.cpp b/tests/catch/symboltable.cpp index 10bdff12..88dbc806 100644 --- a/tests/catch/symboltable.cpp +++ b/tests/catch/symboltable.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include <../core/ngcore.hpp> using namespace ngcore; using namespace std; diff --git a/tests/catch/utils.cpp b/tests/catch/utils.cpp index 74b6dd37..50f754d4 100644 --- a/tests/catch/utils.cpp +++ b/tests/catch/utils.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include using namespace ngcore; using namespace std; diff --git a/tests/catch/version.cpp b/tests/catch/version.cpp index 873636c2..ec79ecca 100644 --- a/tests/catch/version.cpp +++ b/tests/catch/version.cpp @@ -1,5 +1,9 @@ +#ifdef CATCH2_v3 +#include "catch2/catch_all.hpp" +#else #include +#endif #include <../core/ngcore.hpp> using namespace ngcore; using namespace std;