diff --git a/.gitignore b/.gitignore index 065011c..28dc407 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tests/approval_tests/data/actual tests/approval_tests/data/blanked install/ .sublime-tests/ +.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e20f47f..33aa453 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,9 +33,10 @@ set(SNITCH_WITH_TEAMCITY_REPORTER OFF CACHE BOOL "Allow the TeamCity re set(SNITCH_WITH_CATCH2_XML_REPORTER OFF CACHE BOOL "Allow the Catch2 XML reporter to be selected from the command line -- enable if needed.") # Building and packaging options; not part of the library API. -set(SNITCH_HEADER_ONLY OFF CACHE BOOL "Create a single-header header-only version of snitch.") -set(SNITCH_UNITY_BUILD ON CACHE BOOL "Build sources as single file instead of separate files (faster full build).") -set(SNITCH_DO_TEST OFF CACHE BOOL "Build tests.") +set(SNITCH_HEADER_ONLY OFF CACHE BOOL "Create a single-header header-only version of snitch.") +set(SNITCH_UNITY_BUILD ON CACHE BOOL "Build sources as single file instead of separate files (faster full build).") +set(SNITCH_DO_TEST OFF CACHE BOOL "Build tests.") +set(SNITCH_USE_SYSTEM_DOCTEST OFF CACHE BOOL "Assume doctest is already installed, do not download it (used in tests only).") # Figure out git hash, if any execute_process( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e305022..55d165f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -69,7 +69,7 @@ set(APPROVAL_TEST_FILES ${PROJECT_SOURCE_DIR}/tests/approval_tests/reporter_console.cpp ${PROJECT_SOURCE_DIR}/tests/approval_tests/reporter_teamcity.cpp) -if(CMAKE_SYSTEM_NAME MATCHES "Emscripten") +if (CMAKE_SYSTEM_NAME MATCHES "Emscripten") # For Emcripten, we need the working directory to be where the binaries are created, # because Emscripten will generate *.data files there that we need to load. # We don't have access to the filesystem otherwise. @@ -87,15 +87,18 @@ function(copy_shared_library TARGET) endif() endfunction() -include(FetchContent) +if (SNITCH_USE_SYSTEM_DOCTEST) + find_package(doctest REQUIRED) +else() + include(FetchContent) -set(DOCTEST_WITH_MAIN_IN_STATIC_LIB ON) -set(DOCTEST_NO_INSTALL ON) + set(DOCTEST_NO_INSTALL ON) -FetchContent_Declare(doctest - GIT_REPOSITORY https://github.com/doctest/doctest.git - GIT_TAG v2.4.9) -FetchContent_MakeAvailable(doctest) + FetchContent_Declare(doctest + GIT_REPOSITORY https://github.com/doctest/doctest.git + GIT_TAG v2.4.9) + FetchContent_MakeAvailable(doctest) +endif() # Test snitch with doctest. add_executable(snitch_runtime_tests @@ -106,8 +109,7 @@ target_include_directories(snitch_runtime_tests PRIVATE ${PROJECT_SOURCE_DIR}/tests) target_link_libraries(snitch_runtime_tests PRIVATE snitch-testlib - doctest::doctest - doctest::doctest_with_main) + doctest::doctest) add_platform_definitions(snitch_runtime_tests) target_compile_features(snitch_runtime_tests PUBLIC cxx_std_20) target_compile_definitions(snitch_runtime_tests PUBLIC @@ -129,15 +131,14 @@ target_include_directories(snitch_approval_tests PRIVATE ${PROJECT_SOURCE_DIR}/tests) target_link_libraries(snitch_approval_tests PRIVATE snitch-testlib - doctest::doctest - doctest::doctest_with_main) + doctest::doctest) add_platform_definitions(snitch_approval_tests) target_compile_features(snitch_approval_tests PUBLIC cxx_std_20) target_compile_definitions(snitch_approval_tests PUBLIC SNITCH_WITH_SHORTHAND_MACROS=0) copy_shared_library(snitch_approval_tests) -if(CMAKE_SYSTEM_NAME MATCHES "Emscripten") +if (CMAKE_SYSTEM_NAME MATCHES "Emscripten") # Add approval test data to the preload-file list target_link_options(snitch_approval_tests PUBLIC "SHELL:--preload-file ${PROJECT_SOURCE_DIR}/tests/approval_tests/data@data") diff --git a/tests/testing.cpp b/tests/testing.cpp index ca43c54..8a1cf92 100644 --- a/tests/testing.cpp +++ b/tests/testing.cpp @@ -3,6 +3,9 @@ #if defined(SNITCH_TEST_WITH_SNITCH) # undef SNITCH_DEFINE_MAIN # define SNITCH_DEFINE_MAIN 1 +#else +# define DOCTEST_CONFIG_IMPLEMENT +# define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #endif #include "testing.hpp"