Skip to content

Commit cb1e8d1

Browse files
committed
support Catch2 v3
- uses Cmake config files for Catch2 - supports both v2 and v3 of Catch2 - Catch2 v3 includes <catch2/catch_all.hpp> instead of <catch2/catch.hpp> - v3 moves Catch::Contains to Catch::Matchers::ContainsSubstring see https://github.com/catchorg/Catch2/blob/devel/docs/migrate-v2-to-v3.md Patch adapted from debian patch catch2_v3.patch https://salsa.debian.org/science-team/netgen/-/blob/d7ca1c564d90d00ce3d83e0b63c36fbec11cf1ce/debian/patches/catch2_v3.patch
1 parent 63cb566 commit cb1e8d1

File tree

8 files changed

+38
-0
lines changed

8 files changed

+38
-0
lines changed

tests/catch/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ if(ENABLE_UNIT_TESTS)
33
add_custom_target(unit_tests)
44

55
# Build catch_main test object
6+
find_package(Catch2 REQUIRED)
67
include_directories(${CATCH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../libsrc/include ${SPDLOG_INCLUDE_DIR})
78
add_library(catch_main STATIC main.cpp)
89
set_target_properties(catch_main PROPERTIES CXX_STANDARD 17)
910
add_dependencies(unit_tests catch_main)
1011
add_dependencies(catch_main project_catch)
1112

13+
if (Catch2_VERSION VERSION_GREATER_EQUAL 3)
14+
target_compile_options(catch_main PUBLIC -DCATCH2_v3)
15+
target_link_libraries(catch_main Catch2::Catch2WithMain)
16+
endif()
17+
1218
# ensure the test targets are built before testing
1319
add_test(NAME unit_tests_built COMMAND ${CMAKE_COMMAND} --build . --target unit_tests --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../.. )
1420

tests/catch/archive.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37
#include <../core/ngcore.hpp>
48
#include <core/register_archive.hpp>
59
#include <core/logging.hpp>
@@ -354,7 +358,11 @@ void testArchive(Archive& in, Archive& out)
354358
SECTION("Not registered")
355359
{
356360
SharedPtrAndPtrHolder* p = new NotRegisteredForArchive;
361+
#ifdef CATCH2_v3
362+
REQUIRE_THROWS(out & p, Catch::Matchers::ContainsSubstring("not registered for archive"));
363+
#else
357364
REQUIRE_THROWS(out & p, Catch::Contains("not registered for archive"));
365+
#endif
358366
}
359367
SECTION("Non-default constructor")
360368
{

tests/catch/array.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37
#include <core/array.hpp>
48
using namespace ngcore;
59
using namespace std;

tests/catch/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#define CATCH_CONFIG_MAIN
22
#define DO_NOT_USE_WMAIN
3+
#ifdef CATCH2_v3
4+
#include "catch2/catch_all.hpp"
5+
#else
36
#include <catch2/catch.hpp>
7+
#endif

tests/catch/ranges.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37

48
#include <core/array.hpp>
59
#include <core/ranges.hpp>

tests/catch/symboltable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37
#include <../core/ngcore.hpp>
48
using namespace ngcore;
59
using namespace std;

tests/catch/utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37
#include <core/ngcore.hpp>
48
using namespace ngcore;
59
using namespace std;

tests/catch/version.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2+
#ifdef CATCH2_v3
3+
#include "catch2/catch_all.hpp"
4+
#else
25
#include <catch2/catch.hpp>
6+
#endif
37
#include <../core/ngcore.hpp>
48
using namespace ngcore;
59
using namespace std;

0 commit comments

Comments
 (0)