From e0fc9bd75e43761a37125406fde631d2ba5ce1d6 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sat, 7 Dec 2024 14:48:38 +0000 Subject: [PATCH 1/3] Add .cache to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 065011c4..28dc407b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tests/approval_tests/data/actual tests/approval_tests/data/blanked install/ .sublime-tests/ +.cache/ From c00ecec5dba209dd3c09c44c9efba0d34b614576 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sat, 7 Dec 2024 14:49:50 +0000 Subject: [PATCH 2/3] Add SNITCH_USE_SYSTEM_DOCTEST --- CMakeLists.txt | 7 ++++--- tests/CMakeLists.txt | 23 ++++++++++++----------- tests/testing.cpp | 3 +++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e20f47f0..33aa4539 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 e305022b..1bb46105 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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,8 +131,7 @@ 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 diff --git a/tests/testing.cpp b/tests/testing.cpp index ca43c54f..8a1cf92f 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" From 806fc44020569fd46ad10bcca192696418c3e6b3 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sat, 7 Dec 2024 14:50:05 +0000 Subject: [PATCH 3/3] Fix CMake if() formatting --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1bb46105..55d165f1 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. @@ -138,7 +138,7 @@ 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")