Support version 3 of Catch2

This commit is contained in:
Marius Kittler 2023-01-22 23:07:15 +01:00
parent 27252986a8
commit f015a9444d
3 changed files with 15 additions and 2 deletions

View File

@ -67,6 +67,10 @@ use_package(
# find catch2 (required by tests)
use_package(TARGET_NAME Catch2::Catch2 PACKAGE_NAME Catch2 LIBRARIES_VARIABLE "TEST_LIBRARIES")
if (Catch2_VERSION VERSION_GREATER_EQUAL 3)
list(APPEND CATCH2_DEFINITIONS CATCH2_SPLIT_HEADERS)
list(APPEND TEST_LIBRARIES Catch2::Catch2WithMain)
endif ()
# find threading library (required by examples)
use_package(TARGET_NAME Threads::Threads PACKAGE_NAME Threads LIBRARIES_VARIABLE "TEST_LIBRARIES")
@ -100,6 +104,7 @@ include(TestUtilities)
list(APPEND TEST_LIBRARIES ${META_TARGET_NAME})
foreach (TEST ${TESTS})
configure_test_target(TEST_NAME "${TEST}_tests" SRC_FILES "tests/${TEST}.cc" LIBRARIES "${TEST_LIBRARIES}")
target_compile_definitions("${META_TARGET_NAME}_${TEST}_tests" PRIVATE "${CATCH2_DEFINITIONS}")
endforeach ()
foreach (EXAMPLE ${EXAMPLES})
configure_test_target(TEST_NAME "${EXAMPLE}_example" SRC_FILES "examples/${EXAMPLE}.cc" LIBRARIES "${TEST_LIBRARIES}")

View File

@ -1,7 +1,11 @@
#include "../lmdb-safe.hh"
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN // for catch2 < 3
#ifdef CATCH2_SPLIT_HEADERS
#include <catch2/catch_all.hpp>
#else
#include <catch2/catch.hpp>
#endif
#include <c++utilities/application/global.h>

View File

@ -1,8 +1,12 @@
#include "../lmdb-boost-serialization.hh"
#include "../lmdb-typed.hh"
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN // for catch2 < 3
#ifdef CATCH2_SPLIT_HEADERS
#include <catch2/catch_all.hpp>
#else
#include <catch2/catch.hpp>
#endif
#include <c++utilities/application/global.h>