blob: 5b752e0e0094548d1bb812e2029cb739905f1cf5 [file] [log] [blame]
onqtam7cc0e962017-04-17 23:30:36 +03001################################################################################
2## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE
3################################################################################
4
onqtamc9b4e1f2018-08-17 14:20:59 +03005set(files_with_output
onqtam98e12af2017-04-16 22:11:21 +03006 main.cpp
onqtam12d55982017-04-16 22:35:27 +03007 doctest_proxy.h
onqtam7cc0e962017-04-17 23:30:36 +03008 header.h
onqtam98e12af2017-04-16 22:11:21 +03009 alternative_macros.cpp
10 assertion_macros.cpp
11 stringification.cpp
Stefan4e111002022-04-30 18:22:49 +020012 double_stringification.cpp
onqtama1a38de2019-03-16 19:11:36 +020013 reporters_and_listeners.cpp
onqtam98e12af2017-04-16 22:11:21 +030014 subcases.cpp
onqtam119cfb62017-04-17 10:46:55 +030015 logging.cpp
16 templated_test_cases.cpp
onqtam378d6702017-04-19 11:30:03 +030017 test_cases_and_suites.cpp
onqtam8171c482018-07-03 20:31:18 +030018 asserts_used_outside_of_tests.cpp
jkriegshauser961a5422020-11-04 08:13:29 -080019 enums.cpp
Stefance13bc42022-04-18 17:45:33 +020020 decomposition.cpp
onqtam98e12af2017-04-16 22:11:21 +030021)
22
onqtamc9b4e1f2018-08-17 14:20:59 +030023set(files_all
24 ${files_with_output}
25 concurrency.cpp
26 ../../scripts/coverage_maxout.cpp
Navin P318e1df2021-03-21 19:15:46 +053027 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
Stefan8f63ba42021-12-09 16:01:47 +010036 no_failures.cpp
onqtamc9b4e1f2018-08-17 14:20:59 +030037)
38
onqtam3ac4c3f2018-06-01 15:31:06 +030039# add the executable
onqtam36e37452019-03-02 20:10:05 +020040add_executable(all_features ${files_all})
41target_link_libraries(all_features doctest ${CMAKE_THREAD_LIBS_INIT})
onqtam3ac4c3f2018-06-01 15:31:06 +030042
onqtamf0f899b2017-05-02 21:40:41 +030043# easy way to fix test coverage - disable colors and crash handling
onqtam36e37452019-03-02 20:10:05 +020044target_compile_definitions(all_features PRIVATE
onqtamf0f899b2017-05-02 21:40:41 +030045 DOCTEST_CONFIG_COLORS_NONE
46 DOCTEST_CONFIG_NO_POSIX_SIGNALS
47 DOCTEST_CONFIG_NO_WINDOWS_SEH)
onqtam98e12af2017-04-16 22:11:21 +030048
onqtam3ac4c3f2018-06-01 15:31:06 +030049# omit the version and the num test cases skipped from the summary - this way the output will change less often
onqtam585bb712019-03-16 17:46:58 +020050set(common_args COMMAND $<TARGET_FILE:all_features> --no-skipped-summary --no-version)
onqtam76305352017-05-01 20:25:09 +030051
onqtam98e12af2017-04-16 22:11:21 +030052# add per-file tests
onqtamc9b4e1f2018-08-17 14:20:59 +030053foreach(f ${files_with_output})
onqtam5dbcb1e2017-05-02 23:07:56 +030054 doctest_add_test(NAME ${f} ${common_args} -sf=*${f})
onqtam98e12af2017-04-16 22:11:21 +030055endforeach()
56
onqtamc9b4e1f2018-08-17 14:20:59 +030057# add this separately since it shouldn't have output compared to reference output - due to concurrency
onqtam7b7bb8a2018-08-17 16:20:16 +030058# not adding it for MinGW since it crashes when using mingw-w64-x86_64-8.1.0-release-posix-seh-rt_v6-rev0
onqtam443c7072022-01-10 14:40:50 +020059# (also disabled for old XCode builds where there is no thread_local support and this is defined in the build matrix)
onqtameb89a022019-01-14 00:16:11 +020060if(NOT MINGW AND NOT DEFINED DOCTEST_THREAD_LOCAL)
onqtamacbcd122019-03-02 21:24:18 +020061 doctest_add_test(NO_OUTPUT NAME concurrency.cpp ${common_args} -sf=*concurrency.cpp -d) # duration: there is no output anyway
onqtam7b7bb8a2018-08-17 16:20:16 +030062endif()
onqtamc9b4e1f2018-08-17 14:20:59 +030063
Navin P318e1df2021-03-21 19:15:46 +053064doctest_add_test(NO_OUTPUT NAME namespace1.cpp ${common_args} -sf=*namespace1.cpp )
65doctest_add_test(NO_OUTPUT NAME namespace2.cpp ${common_args} -sf=*namespace2.cpp )
66doctest_add_test(NO_OUTPUT NAME namespace3.cpp ${common_args} -sf=*namespace3.cpp )
67doctest_add_test(NO_OUTPUT NAME namespace4.cpp ${common_args} -sf=*namespace4.cpp )
68doctest_add_test(NO_OUTPUT NAME namespace5.cpp ${common_args} -sf=*namespace5.cpp )
69doctest_add_test(NO_OUTPUT NAME namespace6.cpp ${common_args} -sf=*namespace6.cpp )
70doctest_add_test(NO_OUTPUT NAME namespace7.cpp ${common_args} -sf=*namespace7.cpp )
71doctest_add_test(NO_OUTPUT NAME namespace8.cpp ${common_args} -sf=*namespace8.cpp )
72doctest_add_test(NO_OUTPUT NAME namespace9.cpp ${common_args} -sf=*namespace9.cpp )
73
onqtam3ac4c3f2018-06-01 15:31:06 +030074# add this separately since the file has a non-straightforward path
75doctest_add_test(NAME coverage_maxout.cpp ${common_args} -sf=*coverage_maxout.cpp)
76
onqtam76305352017-05-01 20:25:09 +030077# queries
onqtam36e37452019-03-02 20:10:05 +020078doctest_add_test(NAME version COMMAND $<TARGET_FILE:all_features> -v)
onqtam5dbcb1e2017-05-02 23:07:56 +030079doctest_add_test(NAME help ${common_args} -h)
onqtam2377a0c2019-03-20 21:04:24 +020080doctest_add_test(NO_OUTPUT NAME outfile ${common_args} -c -out=temp) # just to exercise the output option
onqtam5dbcb1e2017-05-02 23:07:56 +030081doctest_add_test(NAME count ${common_args} -c -sf=*coverage*)
82doctest_add_test(NAME list_test_cases ${common_args} -ltc -sf=*coverage*)
83doctest_add_test(NAME list_test_suites ${common_args} -lts -sf=*coverage*)
onqtam3ac4c3f2018-06-01 15:31:06 +030084doctest_add_test(NAME list_reporters ${common_args} -lr -sf=*coverage*)
onqtam321f2702017-05-01 19:14:58 +030085
onqtam89da6542017-05-02 21:10:42 +030086# options
onqtam5dbcb1e2017-05-02 23:07:56 +030087doctest_add_test(NAME all_binary ${common_args} -tc=all?binary* -s) # print all binary asserts - for getAssertString()
88doctest_add_test(NAME abort_after ${common_args} -aa=2 -e=off -sf=*coverage*) # abort after 2 assert fails and parse a negative
89doctest_add_test(NAME first_last ${common_args} -f=2 -l=4 -sf=*coverage*) # run a range
onqtam14ddb1e2017-05-02 23:19:09 +030090doctest_add_test(NAME filter_1 ${common_args} -ts=none) # should filter out all
onqtam8ee35452021-12-15 15:42:40 +020091# -order-by=name to avoid different output depending on the compiler used. See https://github.com/doctest/doctest/issues/287
Stefan8f63ba42021-12-09 16:01:47 +010092doctest_add_test(NAME filter_2 COMMAND $<TARGET_FILE:all_features> -tse=* -nv -order-by=name) # should filter out all + print skipped
93doctest_add_test(NAME filter_3 ${common_args} -sc=from*,sc* -sce=sc2 -sf=*subcases*) # enter a specific subcase - sc1
Egor Suvorovbef19652022-03-05 15:36:58 +030094doctest_add_test(NAME filter_4 ${common_args} -ts=*\\, -tc=*\\: -sc=*\\\\\\,,*:) # escape stuff
Stefan8f63ba42021-12-09 16:01:47 +010095doctest_add_test(NAME order_1 ${common_args} -ob=suite -ns -sf=*test_cases_and_suites*)
96doctest_add_test(NAME order_2 ${common_args} -ob=name -sf=*test_cases_and_suites*)
97doctest_add_test(NAME order_3 ${common_args} -ob=rand -sfe=*) # exclude everything for no output
98doctest_add_test(NO_OUTPUT NAME quiet ${common_args} -q -sf=*test_cases_and_suites*) # quiet
99doctest_add_test(NAME minimal ${common_args} -m -sf=*test_cases_and_suites*) # minimal with summary
100doctest_add_test(NAME minimal_no_fail ${common_args} -m -sf=*no_failures.cpp) # minimal
onqtame0f18802017-04-16 23:38:33 +0300101
Salvage860904d2022-01-12 00:52:38 +0100102add_executable(disabled_but_evaluated assert_returns_disabled.cpp assert_returns_disabled_evaluate.cpp)
103target_compile_definitions(disabled_but_evaluated PRIVATE DOCTEST_CONFIG_DISABLE)
104target_link_libraries(disabled_but_evaluated doctest ${CMAKE_THREAD_LIBS_INIT})
105
Stefan0fc371e2022-03-19 17:50:37 +0100106doctest_add_test_impl(NO_OUTPUT NAME disabled_but_evaluated COMMAND $<TARGET_FILE:disabled_but_evaluated>)
Salvage860904d2022-01-12 00:52:38 +0100107
Salvagee798deb2022-01-12 02:44:57 +0100108if(MSVC)
109 target_compile_options(disabled_but_evaluated PRIVATE /wd4702) # unreachable code
110endif()
111
112if(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)
115elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
116 target_compile_options(disabled_but_evaluated PRIVATE -Wno-unused-variable)
117endif()
118
Salvage860904d2022-01-12 00:52:38 +0100119################################################################################
Stefan0fc371e2022-03-19 17:50:37 +0100120## CONFIG TESTS - TESTS WITH VARIOUS CONFIGURATION OPTIONS
onqtam7cc0e962017-04-17 23:30:36 +0300121################################################################################
122
Stefan0fc371e2022-03-19 17:50:37 +0100123function(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})
onqtam7cc0e962017-04-17 23:30:36 +0300127
Stefan0fc371e2022-03-19 17:50:37 +0100128 doctest_add_test_impl(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}> --no-skipped-summary --no-version -ob=name)
129endfunction()
130
131add_test_all_features(no_multithreading DOCTEST_CONFIG_NO_MULTITHREADING)
132add_test_all_features(no_multi_lane_atomics DOCTEST_CONFIG_NO_MULTI_LANE_ATOMICS)
133add_test_all_features(disabled DOCTEST_CONFIG_DISABLE)
Stefan94b52bb2022-05-02 05:19:20 +0200134add_test_all_features(std_headers DOCTEST_CONFIG_USE_STD_HEADERS)
onqtam7cc0e962017-04-17 23:30:36 +0300135
onqtamd320ac22017-04-17 11:44:32 +0300136# TODO: think about fixing these in a different way! - see issue #61 or commit 6b61e8aa3818c5ea100cedc1bb48a60ea10df6e8
Martin Moened8a7edc2017-08-01 17:08:08 +0200137if(MSVC)
onqtamd320ac22017-04-17 11:44:32 +0300138 target_compile_options(disabled PRIVATE /wd4505) # unreferenced local function has been removed
onqtamcb7bad62017-04-19 11:19:57 +0300139 target_compile_options(disabled PRIVATE /wd4100) # unreferenced formal parameter
onqtamaf07cbb2017-04-19 19:40:43 +0300140 target_compile_options(disabled PRIVATE /wd4189) # local variable is initialized but not referenced
Daan De Meyer3c6834b2019-09-10 15:40:53 +0200141endif()
142
143if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
onqtam135a50e2017-04-18 11:48:20 +0300144 target_compile_options(disabled PRIVATE -Wno-unknown-warning-option)
onqtamd320ac22017-04-17 11:44:32 +0300145 target_compile_options(disabled PRIVATE -Wno-unneeded-internal-declaration)
onqtama82c1e42017-05-07 17:36:41 +0300146 target_compile_options(disabled PRIVATE -Wno-unused-function)
onqtamcb7bad62017-04-19 11:19:57 +0300147 target_compile_options(disabled PRIVATE -Wno-unused-parameter)
onqtamc79b7542017-04-19 20:47:13 +0300148 target_compile_options(disabled PRIVATE -Wno-unused-variable)
onqtameb96d162017-09-11 14:26:32 +0300149 target_compile_options(disabled PRIVATE -Wno-unused-template)
onqtamc79b7542017-04-19 20:47:13 +0300150elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
onqtamcb7bad62017-04-19 11:19:57 +0300151 target_compile_options(disabled PRIVATE -Wno-unused-function)
onqtamc79b7542017-04-19 20:47:13 +0300152 target_compile_options(disabled PRIVATE -Wno-unused-parameter)
onqtamaf07cbb2017-04-19 19:40:43 +0300153 target_compile_options(disabled PRIVATE -Wno-unused-variable)
onqtamd320ac22017-04-17 11:44:32 +0300154endif()