mirror of
https://github.com/NGSolve/netgen.git
synced 2025-02-11 12:53:08 +05:00
![Drew Parsons](/assets/img/avatar_default.png)
- 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
d7ca1c564d/debian/patches/catch2_v3.patch
44 lines
1.6 KiB
CMake
44 lines
1.6 KiB
CMake
|
|
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}/../.. )
|
|
|
|
macro(add_unit_test name sources)
|
|
add_executable(test_${name} ${sources} )
|
|
target_link_libraries(test_${name} ngcore catch_main nglib)
|
|
|
|
add_dependencies(unit_tests test_${name})
|
|
add_test(NAME unit_${name} COMMAND test_${name})
|
|
set_tests_properties(unit_${name} PROPERTIES DEPENDS unit_tests_built)
|
|
|
|
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
|
set_target_properties(test_${name} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
|
endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
|
endmacro()
|
|
|
|
add_unit_test(archive archive.cpp)
|
|
# RegisterForArchive needs Python.h if built with Python
|
|
target_link_libraries(test_archive netgen_python)
|
|
add_unit_test(array array.cpp)
|
|
add_unit_test(ranges ranges.cpp)
|
|
add_unit_test(symboltable symboltable.cpp)
|
|
add_unit_test(utils utils.cpp)
|
|
add_unit_test(version version.cpp)
|
|
|
|
endif(ENABLE_UNIT_TESTS)
|