Skip to content

Commit

Permalink
Merge pull request #202 from snitch-org/system-doctest
Browse files Browse the repository at this point in the history
Allow using doctest installed on system
  • Loading branch information
cschreib authored Dec 7, 2024
2 parents 2a59433 + 806fc44 commit 5143f38
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tests/approval_tests/data/actual
tests/approval_tests/data/blanked
install/
.sublime-tests/
.cache/
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 14 additions & 13 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5143f38

Please sign in to comment.