blob: 3b33a89ca6b87682adfbf562fbddf9b6c677db22 [file] [log] [blame]
onqtam98e12af2017-04-16 22:11:21 +03001get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
2project(${PROJECT_NAME})
3
onqtam7cc0e962017-04-17 23:30:36 +03004################################################################################
5## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE
6################################################################################
7
onqtam98e12af2017-04-16 22:11:21 +03008set(files
9 main.cpp
onqtam12d55982017-04-16 22:35:27 +030010 doctest_proxy.h
onqtam7cc0e962017-04-17 23:30:36 +030011 header.h
onqtam98e12af2017-04-16 22:11:21 +030012 coverage_maxout.cpp
13 alternative_macros.cpp
14 assertion_macros.cpp
15 stringification.cpp
16 subcases.cpp
onqtam119cfb62017-04-17 10:46:55 +030017 logging.cpp
18 templated_test_cases.cpp
onqtam378d6702017-04-19 11:30:03 +030019 test_cases_and_suites.cpp
onqtam98e12af2017-04-16 22:11:21 +030020)
21
onqtam12d55982017-04-16 22:35:27 +030022doctest_add_executable(${PROJECT_NAME} ${files})
onqtamf0f899b2017-05-02 21:40:41 +030023# easy way to fix test coverage - disable colors and crash handling
24target_compile_definitions(${PROJECT_NAME} PRIVATE
25 DOCTEST_CONFIG_COLORS_NONE
26 DOCTEST_CONFIG_NO_POSIX_SIGNALS
27 DOCTEST_CONFIG_NO_WINDOWS_SEH)
onqtam98e12af2017-04-16 22:11:21 +030028
onqtam5dbcb1e2017-05-02 23:07:56 +030029set(common_args COMMAND $<TARGET_FILE:${PROJECT_NAME}> --no-skipped-summary --no-version)
onqtam76305352017-05-01 20:25:09 +030030
onqtam98e12af2017-04-16 22:11:21 +030031# add per-file tests
32foreach(f ${files})
onqtam5dbcb1e2017-05-02 23:07:56 +030033 doctest_add_test(NAME ${f} ${common_args} -sf=*${f})
onqtam98e12af2017-04-16 22:11:21 +030034endforeach()
35
onqtam76305352017-05-01 20:25:09 +030036# queries
onqtamf6370e22017-05-03 06:38:27 +030037doctest_add_test(NAME version COMMAND $<TARGET_FILE:${PROJECT_NAME}> -v)
onqtam5dbcb1e2017-05-02 23:07:56 +030038doctest_add_test(NAME help ${common_args} -h)
39doctest_add_test(NAME count ${common_args} -c -sf=*coverage*)
40doctest_add_test(NAME list_test_cases ${common_args} -ltc -sf=*coverage*)
41doctest_add_test(NAME list_test_suites ${common_args} -lts -sf=*coverage*)
onqtam321f2702017-05-01 19:14:58 +030042
onqtam89da6542017-05-02 21:10:42 +030043# options
onqtam5dbcb1e2017-05-02 23:07:56 +030044doctest_add_test(NAME all_binary ${common_args} -tc=all?binary* -s) # print all binary asserts - for getAssertString()
45doctest_add_test(NAME abort_after ${common_args} -aa=2 -e=off -sf=*coverage*) # abort after 2 assert fails and parse a negative
46doctest_add_test(NAME first_last ${common_args} -f=2 -l=4 -sf=*coverage*) # run a range
onqtam14ddb1e2017-05-02 23:19:09 +030047doctest_add_test(NAME filter_1 ${common_args} -ts=none) # should filter out all
onqtamf6370e22017-05-03 06:38:27 +030048doctest_add_test(NAME filter_2 COMMAND $<TARGET_FILE:${PROJECT_NAME}> -tse=* -nv) # should filter out all + print skipped
onqtam14ddb1e2017-05-02 23:19:09 +030049doctest_add_test(NAME filter_3 ${common_args} -sc=from*,sc* -sce=sc2 -sf=*subcases*) # enter a specific subcase - sc1
onqtame6412e12017-05-07 16:21:36 +030050doctest_add_test(NAME order_1 ${common_args} -ob=suite -ns -sf=*test_cases_and_suites*)
onqtam14ddb1e2017-05-02 23:19:09 +030051doctest_add_test(NAME order_2 ${common_args} -ob=name -sf=*test_cases_and_suites*)
52doctest_add_test(NAME order_3 ${common_args} -ob=rand -sfe=*) # exclude everything for no output
onqtame0f18802017-04-16 23:38:33 +030053
onqtam7cc0e962017-04-17 23:30:36 +030054################################################################################
55## VARIATION OF THE BUILD WITH DOCTEST DISABLED - SHOULD STILL COMPILE
56################################################################################
57
onqtamaec53d22017-05-03 06:29:47 +030058if(DEFINED ENV{CODE_COVERAGE})
59 return() # do not continue with the disabled example
60endif()
onqtamf6d1a512017-05-01 13:56:12 +030061
onqtame0f18802017-04-16 23:38:33 +030062doctest_add_executable(disabled ${files})
onqtame0f18802017-04-16 23:38:33 +030063target_compile_definitions(disabled PRIVATE DOCTEST_CONFIG_DISABLE)
onqtam7cc0e962017-04-17 23:30:36 +030064
onqtame0f18802017-04-16 23:38:33 +030065doctest_add_test(NAME disabled COMMAND $<TARGET_FILE:disabled>)
onqtam7cc0e962017-04-17 23:30:36 +030066
onqtamd320ac22017-04-17 11:44:32 +030067# TODO: think about fixing these in a different way! - see issue #61 or commit 6b61e8aa3818c5ea100cedc1bb48a60ea10df6e8
68if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
69 target_compile_options(disabled PRIVATE /wd4505) # unreferenced local function has been removed
onqtamcb7bad62017-04-19 11:19:57 +030070 target_compile_options(disabled PRIVATE /wd4100) # unreferenced formal parameter
onqtamaf07cbb2017-04-19 19:40:43 +030071 target_compile_options(disabled PRIVATE /wd4189) # local variable is initialized but not referenced
onqtamd320ac22017-04-17 11:44:32 +030072elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
onqtam135a50e2017-04-18 11:48:20 +030073 target_compile_options(disabled PRIVATE -Wno-unknown-warning-option)
onqtamd320ac22017-04-17 11:44:32 +030074 target_compile_options(disabled PRIVATE -Wno-unneeded-internal-declaration)
onqtamcb7bad62017-04-19 11:19:57 +030075 target_compile_options(disabled PRIVATE -Wno-unused-parameter)
onqtamc79b7542017-04-19 20:47:13 +030076 target_compile_options(disabled PRIVATE -Wno-unused-variable)
77elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
onqtamcb7bad62017-04-19 11:19:57 +030078 target_compile_options(disabled PRIVATE -Wno-unused-function)
onqtamc79b7542017-04-19 20:47:13 +030079 target_compile_options(disabled PRIVATE -Wno-unused-parameter)
onqtamaf07cbb2017-04-19 19:40:43 +030080 target_compile_options(disabled PRIVATE -Wno-unused-variable)
onqtamd320ac22017-04-17 11:44:32 +030081endif()