Skip to content

Commit

Permalink
support Catch2 v3
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
drew-parsons committed Jan 5, 2025
1 parent 63cb566 commit cb1e8d1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/../.. )

Expand Down
8 changes: 8 additions & 0 deletions tests/catch/archive.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
#include <../core/ngcore.hpp>
#include <core/register_archive.hpp>
#include <core/logging.hpp>
Expand Down Expand Up @@ -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")
{
Expand Down
4 changes: 4 additions & 0 deletions tests/catch/array.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
#include <core/array.hpp>
using namespace ngcore;
using namespace std;
Expand Down
4 changes: 4 additions & 0 deletions tests/catch/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#define CATCH_CONFIG_MAIN
#define DO_NOT_USE_WMAIN
#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
4 changes: 4 additions & 0 deletions tests/catch/ranges.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif

#include <core/array.hpp>
#include <core/ranges.hpp>
Expand Down
4 changes: 4 additions & 0 deletions tests/catch/symboltable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
#include <../core/ngcore.hpp>
using namespace ngcore;
using namespace std;
Expand Down
4 changes: 4 additions & 0 deletions tests/catch/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
#include <core/ngcore.hpp>
using namespace ngcore;
using namespace std;
Expand Down
4 changes: 4 additions & 0 deletions tests/catch/version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#ifdef CATCH2_v3
#include "catch2/catch_all.hpp"
#else
#include <catch2/catch.hpp>
#endif
#include <../core/ngcore.hpp>
using namespace ngcore;
using namespace std;
Expand Down

0 comments on commit cb1e8d1

Please sign in to comment.