onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 1 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) |
| 2 | project(${PROJECT_NAME}) |
| 3 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 4 | ################################################################################ |
| 5 | ## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE |
| 6 | ################################################################################ |
| 7 | |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 8 | set(files |
| 9 | main.cpp |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 10 | doctest_proxy.h |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 11 | header.h |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 12 | coverage_maxout.cpp |
| 13 | alternative_macros.cpp |
| 14 | assertion_macros.cpp |
| 15 | stringification.cpp |
| 16 | subcases.cpp |
onqtam | 119cfb6 | 2017-04-17 10:46:55 +0300 | [diff] [blame] | 17 | logging.cpp |
| 18 | templated_test_cases.cpp |
onqtam | 378d670 | 2017-04-19 11:30:03 +0300 | [diff] [blame] | 19 | test_cases_and_suites.cpp |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 20 | ) |
| 21 | |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 22 | doctest_add_executable(${PROJECT_NAME} ${files}) |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame^] | 23 | # easy way to fix test coverage - disable colors and signals |
| 24 | target_compile_definitions(${PROJECT_NAME} PRIVATE DOCTEST_CONFIG_COLORS_NONE DOCTEST_CONFIG_NO_POSIX_SIGNALS) |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 25 | |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame^] | 26 | set(common_test_args COMMAND $<TARGET_FILE:${PROJECT_NAME}> --no-skipped-summary --no-version) |
onqtam | 7630535 | 2017-05-01 20:25:09 +0300 | [diff] [blame] | 27 | |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 28 | # add per-file tests |
| 29 | foreach(f ${files}) |
onqtam | 7630535 | 2017-05-01 20:25:09 +0300 | [diff] [blame] | 30 | doctest_add_test(NAME ${f} ${common_test_args} -sf=*${f}) |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 31 | endforeach() |
| 32 | |
onqtam | 7630535 | 2017-05-01 20:25:09 +0300 | [diff] [blame] | 33 | set(common_cov_args ${common_test_args} -sf=*coverage*) |
onqtam | 321f270 | 2017-05-01 19:14:58 +0300 | [diff] [blame] | 34 | |
onqtam | 7630535 | 2017-05-01 20:25:09 +0300 | [diff] [blame] | 35 | # queries |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame^] | 36 | doctest_add_test(NAME version COMMAND $<TARGET_FILE:${PROJECT_NAME}> -v) |
| 37 | doctest_add_test(NAME help ${common_cov_args} -h) |
| 38 | doctest_add_test(NAME count ${common_cov_args} -c) |
| 39 | doctest_add_test(NAME list_test_cases ${common_cov_args} -ltc) |
| 40 | doctest_add_test(NAME list_test_suites ${common_cov_args} -lts) |
onqtam | 7630535 | 2017-05-01 20:25:09 +0300 | [diff] [blame] | 41 | |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame^] | 42 | # get all the binary asserts to be printed - to exercise all cases in getAssertString() |
| 43 | doctest_add_test(NAME all_binary_success ${common_test_args} -tc=all?binary* -s) |
onqtam | 321f270 | 2017-05-01 19:14:58 +0300 | [diff] [blame] | 44 | |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame^] | 45 | # options |
| 46 | doctest_add_test(NAME abort_after ${common_cov_args} -aa=2 -e=off) # abort after 2 failed asserts (and parse negative) |
| 47 | doctest_add_test(NAME first_last ${common_cov_args} -f=2 -l=4) # run a range |
| 48 | doctest_add_test(NAME filter_1 ${common_cov_args} -ts=nonexistent) # should filter out all |
| 49 | doctest_add_test(NAME filter_2 ${common_cov_args} -tse=*) # should filter out all |
| 50 | doctest_add_test(NAME order_1 ${common_test_args} -ob=suite -sf=*test_cases_and_suites*) |
| 51 | doctest_add_test(NAME order_2 ${common_test_args} -ob=name -sf=*test_cases_and_suites*) |
| 52 | doctest_add_test(NAME order_3 ${common_test_args} -ob=rand -sfe=*) # exclude everything for no output |
onqtam | e0f1880 | 2017-04-16 23:38:33 +0300 | [diff] [blame] | 53 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 54 | ################################################################################ |
| 55 | ## VARIATION OF THE BUILD WITH DOCTEST DISABLED - SHOULD STILL COMPILE |
| 56 | ################################################################################ |
| 57 | |
onqtam | f6d1a51 | 2017-05-01 13:56:12 +0300 | [diff] [blame] | 58 | return() # temp hack |
| 59 | |
onqtam | e0f1880 | 2017-04-16 23:38:33 +0300 | [diff] [blame] | 60 | doctest_add_executable(disabled ${files}) |
onqtam | e0f1880 | 2017-04-16 23:38:33 +0300 | [diff] [blame] | 61 | target_compile_definitions(disabled PRIVATE DOCTEST_CONFIG_DISABLE) |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 62 | |
onqtam | e0f1880 | 2017-04-16 23:38:33 +0300 | [diff] [blame] | 63 | doctest_add_test(NAME disabled COMMAND $<TARGET_FILE:disabled>) |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 64 | |
onqtam | d320ac2 | 2017-04-17 11:44:32 +0300 | [diff] [blame] | 65 | # TODO: think about fixing these in a different way! - see issue #61 or commit 6b61e8aa3818c5ea100cedc1bb48a60ea10df6e8 |
| 66 | if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 67 | target_compile_options(disabled PRIVATE /wd4505) # unreferenced local function has been removed |
onqtam | cb7bad6 | 2017-04-19 11:19:57 +0300 | [diff] [blame] | 68 | target_compile_options(disabled PRIVATE /wd4100) # unreferenced formal parameter |
onqtam | af07cbb | 2017-04-19 19:40:43 +0300 | [diff] [blame] | 69 | target_compile_options(disabled PRIVATE /wd4189) # local variable is initialized but not referenced |
onqtam | d320ac2 | 2017-04-17 11:44:32 +0300 | [diff] [blame] | 70 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
onqtam | 135a50e | 2017-04-18 11:48:20 +0300 | [diff] [blame] | 71 | target_compile_options(disabled PRIVATE -Wno-unknown-warning-option) |
onqtam | d320ac2 | 2017-04-17 11:44:32 +0300 | [diff] [blame] | 72 | target_compile_options(disabled PRIVATE -Wno-unneeded-internal-declaration) |
onqtam | cb7bad6 | 2017-04-19 11:19:57 +0300 | [diff] [blame] | 73 | target_compile_options(disabled PRIVATE -Wno-unused-parameter) |
onqtam | c79b754 | 2017-04-19 20:47:13 +0300 | [diff] [blame] | 74 | target_compile_options(disabled PRIVATE -Wno-unused-variable) |
| 75 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
onqtam | cb7bad6 | 2017-04-19 11:19:57 +0300 | [diff] [blame] | 76 | target_compile_options(disabled PRIVATE -Wno-unused-function) |
onqtam | c79b754 | 2017-04-19 20:47:13 +0300 | [diff] [blame] | 77 | target_compile_options(disabled PRIVATE -Wno-unused-parameter) |
onqtam | af07cbb | 2017-04-19 19:40:43 +0300 | [diff] [blame] | 78 | target_compile_options(disabled PRIVATE -Wno-unused-variable) |
onqtam | d320ac2 | 2017-04-17 11:44:32 +0300 | [diff] [blame] | 79 | endif() |