CMakeLists.txt (7948B)
1 ################################################################################ 2 ## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE 3 ################################################################################ 4 5 set(files_with_output 6 main.cpp 7 doctest_proxy.h 8 header.h 9 alternative_macros.cpp 10 assertion_macros.cpp 11 stringification.cpp 12 double_stringification.cpp 13 reporters_and_listeners.cpp 14 subcases.cpp 15 logging.cpp 16 templated_test_cases.cpp 17 test_cases_and_suites.cpp 18 asserts_used_outside_of_tests.cpp 19 enums.cpp 20 decomposition.cpp 21 ) 22 23 set(files_all 24 ${files_with_output} 25 concurrency.cpp 26 coverage_maxout.cpp 27 namespace1.cpp 28 namespace2.cpp 29 namespace3.cpp 30 namespace4.cpp 31 namespace5.cpp 32 namespace6.cpp 33 namespace7.cpp 34 namespace8.cpp 35 namespace9.cpp 36 no_failures.cpp 37 ) 38 39 # add the executable 40 add_executable(all_features ${files_all}) 41 target_link_libraries(all_features doctest ${CMAKE_THREAD_LIBS_INIT}) 42 43 # easy way to fix test coverage - disable colors and crash handling 44 target_compile_definitions(all_features PRIVATE 45 DOCTEST_CONFIG_COLORS_NONE 46 DOCTEST_CONFIG_NO_POSIX_SIGNALS 47 DOCTEST_CONFIG_NO_WINDOWS_SEH) 48 49 # omit the version and the num test cases skipped from the summary - this way the output will change less often 50 set(common_args COMMAND $<TARGET_FILE:all_features> --no-skipped-summary --no-version) 51 52 # add per-file tests 53 foreach(f ${files_with_output}) 54 doctest_add_test(NAME ${f} ${common_args} -sf=*${f}) 55 endforeach() 56 57 # add this separately since it shouldn't have output compared to reference output - due to concurrency 58 # not adding it for MinGW since it crashes when using mingw-w64-x86_64-8.1.0-release-posix-seh-rt_v6-rev0 59 # (also disabled for old XCode builds where there is no thread_local support and this is defined in the build matrix) 60 if(NOT MINGW AND NOT DEFINED DOCTEST_THREAD_LOCAL) 61 doctest_add_test(NO_OUTPUT NAME concurrency.cpp ${common_args} -sf=*concurrency.cpp -d) # duration: there is no output anyway 62 endif() 63 64 doctest_add_test(NO_OUTPUT NAME namespace1.cpp ${common_args} -sf=*namespace1.cpp ) 65 doctest_add_test(NO_OUTPUT NAME namespace2.cpp ${common_args} -sf=*namespace2.cpp ) 66 doctest_add_test(NO_OUTPUT NAME namespace3.cpp ${common_args} -sf=*namespace3.cpp ) 67 doctest_add_test(NO_OUTPUT NAME namespace4.cpp ${common_args} -sf=*namespace4.cpp ) 68 doctest_add_test(NO_OUTPUT NAME namespace5.cpp ${common_args} -sf=*namespace5.cpp ) 69 doctest_add_test(NO_OUTPUT NAME namespace6.cpp ${common_args} -sf=*namespace6.cpp ) 70 doctest_add_test(NO_OUTPUT NAME namespace7.cpp ${common_args} -sf=*namespace7.cpp ) 71 doctest_add_test(NO_OUTPUT NAME namespace8.cpp ${common_args} -sf=*namespace8.cpp ) 72 doctest_add_test(NO_OUTPUT NAME namespace9.cpp ${common_args} -sf=*namespace9.cpp ) 73 74 # add this separately since the file has a non-straightforward path 75 doctest_add_test(NAME coverage_maxout.cpp ${common_args} -sf=*coverage_maxout.cpp) 76 77 # queries 78 doctest_add_test(NAME version COMMAND $<TARGET_FILE:all_features> -v) 79 doctest_add_test(NAME help ${common_args} -h) 80 doctest_add_test(NO_OUTPUT NAME outfile ${common_args} -c -out=temp) # just to exercise the output option 81 doctest_add_test(NAME count ${common_args} -c -sf=*coverage*) 82 doctest_add_test(NAME list_test_cases ${common_args} -ltc -sf=*coverage*) 83 doctest_add_test(NAME list_test_suites ${common_args} -lts -sf=*coverage*) 84 doctest_add_test(NAME list_reporters ${common_args} -lr -sf=*coverage*) 85 86 # options 87 doctest_add_test(NAME all_binary ${common_args} -tc=all?binary* -s) # print all binary asserts - for getAssertString() 88 doctest_add_test(NAME abort_after ${common_args} -aa=2 -e=off -sf=*coverage*) # abort after 2 assert fails and parse a negative 89 doctest_add_test(NAME first_last ${common_args} -f=2 -l=4 -sf=*coverage*) # run a range 90 doctest_add_test(NAME filter_1 ${common_args} -ts=none) # should filter out all 91 # -order-by=name to avoid different output depending on the compiler used. See https://github.com/doctest/doctest/issues/287 92 doctest_add_test(NAME filter_2 COMMAND $<TARGET_FILE:all_features> -tse=* -nv -order-by=name) # should filter out all + print skipped 93 doctest_add_test(NAME filter_3 ${common_args} -sc=from*,sc* -sce=sc2 -sf=*subcases*) # enter a specific subcase - sc1 94 doctest_add_test(NAME filter_4 ${common_args} -ts=*\\, -tc=*\\: -sc=*\\\\\\,,*:) # escape stuff 95 doctest_add_test(NAME order_1 ${common_args} -ob=suite -ns -sf=*test_cases_and_suites*) 96 doctest_add_test(NAME order_2 ${common_args} -ob=name -sf=*test_cases_and_suites*) 97 doctest_add_test(NAME order_3 ${common_args} -ob=rand -sfe=*) # exclude everything for no output 98 doctest_add_test(NO_OUTPUT NAME quiet ${common_args} -q -sf=*test_cases_and_suites*) # quiet 99 doctest_add_test(NAME minimal ${common_args} -m -sf=*test_cases_and_suites*) # minimal with summary 100 doctest_add_test(NAME minimal_no_fail ${common_args} -m -sf=*no_failures.cpp) # minimal 101 102 add_executable(disabled_but_evaluated assert_returns_disabled.cpp assert_returns_disabled_evaluate.cpp) 103 target_compile_definitions(disabled_but_evaluated PRIVATE DOCTEST_CONFIG_DISABLE) 104 target_link_libraries(disabled_but_evaluated doctest ${CMAKE_THREAD_LIBS_INIT}) 105 106 doctest_add_test_impl(NO_OUTPUT NAME disabled_but_evaluated COMMAND $<TARGET_FILE:disabled_but_evaluated>) 107 108 if(MSVC) 109 target_compile_options(disabled_but_evaluated PRIVATE /wd4702) # unreachable code 110 endif() 111 112 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 113 target_compile_options(disabled_but_evaluated PRIVATE -Wno-global-constructors) 114 target_compile_options(disabled_but_evaluated PRIVATE -Wno-unused-variable) 115 elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") 116 target_compile_options(disabled_but_evaluated PRIVATE -Wno-unused-variable) 117 endif() 118 119 ################################################################################ 120 ## CONFIG TESTS - TESTS WITH VARIOUS CONFIGURATION OPTIONS 121 ################################################################################ 122 123 function(add_test_all_features test_name flags) 124 add_executable(${test_name} ${files_with_output}) 125 target_compile_definitions(${test_name} PRIVATE ${flags}) 126 target_link_libraries(${test_name} doctest ${CMAKE_THREAD_LIBS_INIT}) 127 128 doctest_add_test_impl(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}> --no-skipped-summary --no-version -ob=name) 129 endfunction() 130 131 add_test_all_features(no_multithreading DOCTEST_CONFIG_NO_MULTITHREADING) 132 add_test_all_features(no_multi_lane_atomics DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS) 133 add_test_all_features(disabled DOCTEST_CONFIG_DISABLE) 134 add_test_all_features(std_headers DOCTEST_CONFIG_USE_STD_HEADERS) 135 136 # TODO: think about fixing these in a different way! - see issue #61 or commit 6b61e8aa3818c5ea100cedc1bb48a60ea10df6e8 137 if(MSVC) 138 target_compile_options(disabled PRIVATE /wd4505) # unreferenced local function has been removed 139 target_compile_options(disabled PRIVATE /wd4100) # unreferenced formal parameter 140 target_compile_options(disabled PRIVATE /wd4189) # local variable is initialized but not referenced 141 endif() 142 143 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 144 target_compile_options(disabled PRIVATE -Wno-unknown-warning-option) 145 target_compile_options(disabled PRIVATE -Wno-unneeded-internal-declaration) 146 target_compile_options(disabled PRIVATE -Wno-unused-function) 147 target_compile_options(disabled PRIVATE -Wno-unused-parameter) 148 target_compile_options(disabled PRIVATE -Wno-unused-variable) 149 target_compile_options(disabled PRIVATE -Wno-unused-template) 150 elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") 151 target_compile_options(disabled PRIVATE -Wno-unused-function) 152 target_compile_options(disabled PRIVATE -Wno-unused-parameter) 153 target_compile_options(disabled PRIVATE -Wno-unused-variable) 154 endif()