CMakeLists.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. include(MiscFunctions)
  2. ####
  3. # Temporary workaround for VS toolset changes in 2017
  4. # We need to disable <UseFullPaths> property, but CMake doesn't support it
  5. # until 3.13 (not yet released)
  6. ####
  7. if (MSVC)
  8. configure_file(${CATCH_DIR}/misc/SelfTest.vcxproj.user
  9. ${CMAKE_BINARY_DIR}/projects
  10. COPYONLY)
  11. endif(MSVC) #Temporary workaround
  12. # define the sources of the self test
  13. # Please keep these ordered alphabetically
  14. set(TEST_SOURCES
  15. ${SELF_TEST_DIR}/TestMain.cpp
  16. ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp
  17. ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp
  18. ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp
  19. ${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp
  20. ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp
  21. ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp
  22. ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp
  23. ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp
  24. ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp
  25. ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp
  26. ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp
  27. ${SELF_TEST_DIR}/TimingTests/Sleep.tests.cpp
  28. ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp
  29. ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp
  30. ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp
  31. ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp
  32. ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp
  33. ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp
  34. ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp
  35. ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp
  36. ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp
  37. ${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp
  38. ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp
  39. ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp
  40. ${SELF_TEST_DIR}/UsageTests/ToStringByte.tests.cpp
  41. ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp
  42. ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp
  43. ${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp
  44. ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp
  45. ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp
  46. ${SELF_TEST_DIR}/UsageTests/ToStringVariant.tests.cpp
  47. ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp
  48. ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp
  49. ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp
  50. ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp
  51. ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp
  52. )
  53. CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
  54. # A set of impl files that just #include a single header
  55. # Please keep these ordered alphabetically
  56. set(SURROGATE_SOURCES
  57. ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
  58. ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
  59. ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
  60. ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
  61. ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
  62. ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
  63. ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
  64. ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
  65. )
  66. CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
  67. # Please keep these ordered alphabetically
  68. set(TOP_LEVEL_HEADERS
  69. ${HEADER_DIR}/catch.hpp
  70. ${HEADER_DIR}/catch_with_main.hpp
  71. )
  72. CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
  73. # Please keep these ordered alphabetically
  74. set(EXTERNAL_HEADERS
  75. ${HEADER_DIR}/external/clara.hpp
  76. )
  77. CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
  78. # Please keep these ordered alphabetically
  79. set(BENCHMARK_HEADERS
  80. ${HEADER_DIR}/internal/benchmark/catch_benchmark.hpp
  81. ${HEADER_DIR}/internal/benchmark/catch_chronometer.hpp
  82. ${HEADER_DIR}/internal/benchmark/catch_clock.hpp
  83. ${HEADER_DIR}/internal/benchmark/catch_constructor.hpp
  84. ${HEADER_DIR}/internal/benchmark/catch_environment.hpp
  85. ${HEADER_DIR}/internal/benchmark/catch_estimate.hpp
  86. ${HEADER_DIR}/internal/benchmark/catch_execution_plan.hpp
  87. ${HEADER_DIR}/internal/benchmark/catch_optimizer.hpp
  88. ${HEADER_DIR}/internal/benchmark/catch_outlier_classification.hpp
  89. ${HEADER_DIR}/internal/benchmark/catch_sample_analysis.hpp
  90. ${HEADER_DIR}/internal/benchmark/detail/catch_analyse.hpp
  91. ${HEADER_DIR}/internal/benchmark/detail/catch_benchmark_function.hpp
  92. ${HEADER_DIR}/internal/benchmark/detail/catch_complete_invoke.hpp
  93. ${HEADER_DIR}/internal/benchmark/detail/catch_estimate_clock.hpp
  94. ${HEADER_DIR}/internal/benchmark/detail/catch_measure.hpp
  95. ${HEADER_DIR}/internal/benchmark/detail/catch_repeat.hpp
  96. ${HEADER_DIR}/internal/benchmark/detail/catch_run_for_at_least.hpp
  97. ${HEADER_DIR}/internal/benchmark/detail/catch_stats.hpp
  98. ${HEADER_DIR}/internal/benchmark/detail/catch_timing.hpp
  99. )
  100. set(BENCHMARK_SOURCES
  101. ${HEADER_DIR}/internal/benchmark/detail/catch_stats.cpp
  102. )
  103. SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES})
  104. set(INTERNAL_HEADERS
  105. ${HEADER_DIR}/internal/catch_approx.h
  106. ${HEADER_DIR}/internal/catch_assertionhandler.h
  107. ${HEADER_DIR}/internal/catch_assertioninfo.h
  108. ${HEADER_DIR}/internal/catch_assertionresult.h
  109. ${HEADER_DIR}/internal/catch_capture.hpp
  110. ${HEADER_DIR}/internal/catch_capture_matchers.h
  111. ${HEADER_DIR}/internal/catch_clara.h
  112. ${HEADER_DIR}/internal/catch_commandline.h
  113. ${HEADER_DIR}/internal/catch_common.h
  114. ${HEADER_DIR}/internal/catch_compiler_capabilities.h
  115. ${HEADER_DIR}/internal/catch_config.hpp
  116. ${HEADER_DIR}/internal/catch_config_uncaught_exceptions.hpp
  117. ${HEADER_DIR}/internal/catch_console_colour.h
  118. ${HEADER_DIR}/internal/catch_context.h
  119. ${HEADER_DIR}/internal/catch_debug_console.h
  120. ${HEADER_DIR}/internal/catch_debugger.h
  121. ${HEADER_DIR}/internal/catch_decomposer.h
  122. ${HEADER_DIR}/internal/catch_default_main.hpp
  123. ${HEADER_DIR}/internal/catch_enforce.h
  124. ${HEADER_DIR}/internal/catch_enum_values_registry.h
  125. ${HEADER_DIR}/internal/catch_errno_guard.h
  126. ${HEADER_DIR}/internal/catch_exception_translator_registry.h
  127. ${HEADER_DIR}/internal/catch_external_interfaces.h
  128. ${HEADER_DIR}/internal/catch_fatal_condition.h
  129. ${HEADER_DIR}/internal/catch_generators.hpp
  130. ${HEADER_DIR}/internal/catch_generators_generic.hpp
  131. ${HEADER_DIR}/internal/catch_generators_specific.hpp
  132. ${HEADER_DIR}/internal/catch_impl.hpp
  133. ${HEADER_DIR}/internal/catch_interfaces_capture.h
  134. ${HEADER_DIR}/internal/catch_interfaces_config.h
  135. ${HEADER_DIR}/internal/catch_interfaces_enum_values_registry.h
  136. ${HEADER_DIR}/internal/catch_interfaces_exception.h
  137. ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
  138. ${HEADER_DIR}/internal/catch_interfaces_reporter.h
  139. ${HEADER_DIR}/internal/catch_interfaces_runner.h
  140. ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
  141. ${HEADER_DIR}/internal/catch_interfaces_testcase.h
  142. ${HEADER_DIR}/internal/catch_leak_detector.h
  143. ${HEADER_DIR}/internal/catch_list.h
  144. ${HEADER_DIR}/internal/catch_matchers.h
  145. ${HEADER_DIR}/internal/catch_matchers_exception.hpp
  146. ${HEADER_DIR}/internal/catch_matchers_floating.h
  147. ${HEADER_DIR}/internal/catch_matchers_generic.hpp
  148. ${HEADER_DIR}/internal/catch_matchers_string.h
  149. ${HEADER_DIR}/internal/catch_matchers_vector.h
  150. ${HEADER_DIR}/internal/catch_message.h
  151. ${HEADER_DIR}/internal/catch_meta.hpp
  152. ${HEADER_DIR}/internal/catch_objc.hpp
  153. ${HEADER_DIR}/internal/catch_objc_arc.hpp
  154. ${HEADER_DIR}/internal/catch_option.hpp
  155. ${HEADER_DIR}/internal/catch_output_redirect.h
  156. ${HEADER_DIR}/internal/catch_platform.h
  157. ${HEADER_DIR}/internal/catch_polyfills.hpp
  158. ${HEADER_DIR}/internal/catch_preprocessor.hpp
  159. ${HEADER_DIR}/internal/catch_random_number_generator.h
  160. ${HEADER_DIR}/internal/catch_reenable_warnings.h
  161. ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
  162. ${HEADER_DIR}/internal/catch_reporter_registry.h
  163. ${HEADER_DIR}/internal/catch_result_type.h
  164. ${HEADER_DIR}/internal/catch_run_context.h
  165. ${HEADER_DIR}/internal/catch_section.h
  166. ${HEADER_DIR}/internal/catch_section_info.h
  167. ${HEADER_DIR}/internal/catch_session.h
  168. ${HEADER_DIR}/internal/catch_singletons.hpp
  169. ${HEADER_DIR}/internal/catch_startup_exception_registry.h
  170. ${HEADER_DIR}/internal/catch_stream.h
  171. ${HEADER_DIR}/internal/catch_stringref.h
  172. ${HEADER_DIR}/internal/catch_string_manip.h
  173. ${HEADER_DIR}/internal/catch_suppress_warnings.h
  174. ${HEADER_DIR}/internal/catch_tag_alias.h
  175. ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h
  176. ${HEADER_DIR}/internal/catch_tag_alias_registry.h
  177. ${HEADER_DIR}/internal/catch_test_case_info.h
  178. ${HEADER_DIR}/internal/catch_test_case_registry_impl.h
  179. ${HEADER_DIR}/internal/catch_test_case_tracker.h
  180. ${HEADER_DIR}/internal/catch_test_registry.h
  181. ${HEADER_DIR}/internal/catch_test_spec.h
  182. ${HEADER_DIR}/internal/catch_test_spec_parser.h
  183. ${HEADER_DIR}/internal/catch_text.h
  184. ${HEADER_DIR}/internal/catch_timer.h
  185. ${HEADER_DIR}/internal/catch_to_string.hpp
  186. ${HEADER_DIR}/internal/catch_tostring.h
  187. ${HEADER_DIR}/internal/catch_totals.h
  188. ${HEADER_DIR}/internal/catch_uncaught_exceptions.h
  189. ${HEADER_DIR}/internal/catch_user_interfaces.h
  190. ${HEADER_DIR}/internal/catch_version.h
  191. ${HEADER_DIR}/internal/catch_wildcard_pattern.h
  192. ${HEADER_DIR}/internal/catch_windows_h_proxy.h
  193. ${HEADER_DIR}/internal/catch_xmlwriter.h
  194. )
  195. set(IMPL_SOURCES
  196. ${HEADER_DIR}/internal/catch_approx.cpp
  197. ${HEADER_DIR}/internal/catch_assertionhandler.cpp
  198. ${HEADER_DIR}/internal/catch_assertionresult.cpp
  199. ${HEADER_DIR}/internal/catch_capture_matchers.cpp
  200. ${HEADER_DIR}/internal/catch_commandline.cpp
  201. ${HEADER_DIR}/internal/catch_common.cpp
  202. ${HEADER_DIR}/internal/catch_config.cpp
  203. ${HEADER_DIR}/internal/catch_console_colour.cpp
  204. ${HEADER_DIR}/internal/catch_context.cpp
  205. ${HEADER_DIR}/internal/catch_debug_console.cpp
  206. ${HEADER_DIR}/internal/catch_debugger.cpp
  207. ${HEADER_DIR}/internal/catch_decomposer.cpp
  208. ${HEADER_DIR}/internal/catch_enforce.cpp
  209. ${HEADER_DIR}/internal/catch_enum_values_registry.cpp
  210. ${HEADER_DIR}/internal/catch_errno_guard.cpp
  211. ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp
  212. ${HEADER_DIR}/internal/catch_fatal_condition.cpp
  213. ${HEADER_DIR}/internal/catch_generators.cpp
  214. ${HEADER_DIR}/internal/catch_interfaces_capture.cpp
  215. ${HEADER_DIR}/internal/catch_interfaces_config.cpp
  216. ${HEADER_DIR}/internal/catch_interfaces_exception.cpp
  217. ${HEADER_DIR}/internal/catch_interfaces_generatortracker.h
  218. ${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp
  219. ${HEADER_DIR}/internal/catch_interfaces_runner.cpp
  220. ${HEADER_DIR}/internal/catch_interfaces_testcase.cpp
  221. ${HEADER_DIR}/internal/catch_list.cpp
  222. ${HEADER_DIR}/internal/catch_leak_detector.cpp
  223. ${HEADER_DIR}/internal/catch_matchers.cpp
  224. ${HEADER_DIR}/internal/catch_matchers_exception.cpp
  225. ${HEADER_DIR}/internal/catch_matchers_floating.cpp
  226. ${HEADER_DIR}/internal/catch_matchers_generic.cpp
  227. ${HEADER_DIR}/internal/catch_matchers_string.cpp
  228. ${HEADER_DIR}/internal/catch_message.cpp
  229. ${HEADER_DIR}/internal/catch_output_redirect.cpp
  230. ${HEADER_DIR}/internal/catch_registry_hub.cpp
  231. ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
  232. ${HEADER_DIR}/internal/catch_polyfills.cpp
  233. ${HEADER_DIR}/internal/catch_random_number_generator.cpp
  234. ${HEADER_DIR}/internal/catch_reporter_registry.cpp
  235. ${HEADER_DIR}/internal/catch_result_type.cpp
  236. ${HEADER_DIR}/internal/catch_run_context.cpp
  237. ${HEADER_DIR}/internal/catch_section.cpp
  238. ${HEADER_DIR}/internal/catch_section_info.cpp
  239. ${HEADER_DIR}/internal/catch_session.cpp
  240. ${HEADER_DIR}/internal/catch_singletons.cpp
  241. ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp
  242. ${HEADER_DIR}/internal/catch_stream.cpp
  243. ${HEADER_DIR}/internal/catch_stringref.cpp
  244. ${HEADER_DIR}/internal/catch_string_manip.cpp
  245. ${HEADER_DIR}/internal/catch_tag_alias.cpp
  246. ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp
  247. ${HEADER_DIR}/internal/catch_tag_alias_registry.cpp
  248. ${HEADER_DIR}/internal/catch_test_case_info.cpp
  249. ${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp
  250. ${HEADER_DIR}/internal/catch_test_case_tracker.cpp
  251. ${HEADER_DIR}/internal/catch_test_registry.cpp
  252. ${HEADER_DIR}/internal/catch_test_spec.cpp
  253. ${HEADER_DIR}/internal/catch_test_spec_parser.cpp
  254. ${HEADER_DIR}/internal/catch_timer.cpp
  255. ${HEADER_DIR}/internal/catch_tostring.cpp
  256. ${HEADER_DIR}/internal/catch_totals.cpp
  257. ${HEADER_DIR}/internal/catch_uncaught_exceptions.cpp
  258. ${HEADER_DIR}/internal/catch_version.cpp
  259. ${HEADER_DIR}/internal/catch_wildcard_pattern.cpp
  260. ${HEADER_DIR}/internal/catch_xmlwriter.cpp
  261. )
  262. set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS})
  263. CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal)
  264. # Please keep these ordered alphabetically
  265. set(REPORTER_HEADERS
  266. ${HEADER_DIR}/reporters/catch_reporter_automake.hpp
  267. ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
  268. ${HEADER_DIR}/reporters/catch_reporter_compact.h
  269. ${HEADER_DIR}/reporters/catch_reporter_console.h
  270. ${HEADER_DIR}/reporters/catch_reporter_junit.h
  271. ${HEADER_DIR}/reporters/catch_reporter_listening.h
  272. ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
  273. ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
  274. ${HEADER_DIR}/reporters/catch_reporter_xml.h
  275. ${HEADER_DIR}/reporters/catch_reporter_sonarqube.hpp
  276. )
  277. set(REPORTER_SOURCES
  278. ${HEADER_DIR}/reporters/catch_reporter_bases.cpp
  279. ${HEADER_DIR}/reporters/catch_reporter_compact.cpp
  280. ${HEADER_DIR}/reporters/catch_reporter_console.cpp
  281. ${HEADER_DIR}/reporters/catch_reporter_junit.cpp
  282. ${HEADER_DIR}/reporters/catch_reporter_listening.cpp
  283. ${HEADER_DIR}/reporters/catch_reporter_xml.cpp
  284. )
  285. set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES})
  286. CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters)
  287. # Specify the headers, too, so CLion recognises them as project files
  288. set(HEADERS
  289. ${TOP_LEVEL_HEADERS}
  290. ${EXTERNAL_HEADERS}
  291. ${INTERNAL_HEADERS}
  292. ${REPORTER_HEADERS}
  293. ${BENCHMARK_HEADERS}
  294. ${BENCHMARK_SOURCES}
  295. )
  296. # Provide some groupings for IDEs
  297. SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
  298. SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES})
  299. include(CTest)
  300. add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS})
  301. target_include_directories(SelfTest PRIVATE ${HEADER_DIR})
  302. # It took CMake until 3.8 to abandon the doomed approach of enumerating
  303. # required features so we just list C++11 features to support older ones.
  304. target_compile_features(SelfTest
  305. PRIVATE
  306. cxx_alignas
  307. cxx_alignof
  308. cxx_attributes
  309. cxx_auto_type
  310. cxx_constexpr
  311. cxx_defaulted_functions
  312. cxx_deleted_functions
  313. cxx_final
  314. cxx_lambdas
  315. cxx_noexcept
  316. cxx_override
  317. cxx_range_for
  318. cxx_rvalue_references
  319. cxx_static_assert
  320. cxx_strong_enums
  321. cxx_trailing_return_types
  322. cxx_unicode_literals
  323. cxx_user_literals
  324. cxx_variadic_macros
  325. )
  326. if (CATCH_ENABLE_COVERAGE)
  327. set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
  328. find_package(codecov)
  329. add_coverage(SelfTest)
  330. list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
  331. coverage_evaluate()
  332. endif()
  333. # Add per compiler options
  334. if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
  335. target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic -Wmissing-declarations )
  336. if (CATCH_ENABLE_WERROR)
  337. target_compile_options( SelfTest PRIVATE -Werror )
  338. endif()
  339. endif()
  340. # Clang specific options go here
  341. if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  342. target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
  343. endif()
  344. if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
  345. STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
  346. target_compile_options( SelfTest PRIVATE /w44265 /w44061 /w44062 /w45038 )
  347. if (CATCH_ENABLE_WERROR)
  348. target_compile_options( SelfTest PRIVATE /WX)
  349. endif()
  350. # Force MSVC to consider everything as encoded in utf-8
  351. target_compile_options( SelfTest PRIVATE /utf-8 )
  352. endif()
  353. # configure unit tests via CTest
  354. add_test(NAME RunTests COMMAND $<TARGET_FILE:SelfTest>)
  355. set_tests_properties(RunTests PROPERTIES
  356. FAIL_REGULAR_EXPRESSION "Filters:"
  357. )
  358. add_test(NAME ListTests COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
  359. set_tests_properties(ListTests PROPERTIES
  360. PASS_REGULAR_EXPRESSION "[0-9]+ test cases"
  361. FAIL_REGULAR_EXPRESSION "Hidden Test"
  362. )
  363. add_test(NAME ListTags COMMAND $<TARGET_FILE:SelfTest> --list-tags)
  364. set_tests_properties(ListTags PROPERTIES
  365. PASS_REGULAR_EXPRESSION "[0-9]+ tags"
  366. FAIL_REGULAR_EXPRESSION "\\[\\.\\]")
  367. add_test(NAME ListReporters COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
  368. set_tests_properties(ListReporters PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:")
  369. add_test(NAME ListTestNamesOnly COMMAND $<TARGET_FILE:SelfTest> --list-test-names-only)
  370. set_tests_properties(ListTestNamesOnly PROPERTIES
  371. PASS_REGULAR_EXPRESSION "Regex string matcher"
  372. FAIL_REGULAR_EXPRESSION "Hidden Test")
  373. add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions)
  374. set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")
  375. add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___")
  376. set_tests_properties(NoTest PROPERTIES
  377. PASS_REGULAR_EXPRESSION "No test cases matched '___nonexistent_test___'"
  378. FAIL_REGULAR_EXPRESSION "No tests ran"
  379. )
  380. add_test(NAME WarnAboutNoTests COMMAND ${CMAKE_COMMAND} -P ${CATCH_DIR}/projects/SelfTest/WarnAboutNoTests.cmake $<TARGET_FILE:SelfTest>)
  381. add_test(NAME UnmatchedOutputFilter COMMAND $<TARGET_FILE:SelfTest> [this-tag-does-not-exist] -w NoTests)
  382. set_tests_properties(UnmatchedOutputFilter
  383. PROPERTIES
  384. PASS_REGULAR_EXPRESSION "No test cases matched '\\[this-tag-does-not-exist\\]'"
  385. )
  386. add_test(NAME FilteredSection-1 COMMAND $<TARGET_FILE:SelfTest> \#1394 -c RunSection)
  387. set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
  388. add_test(NAME FilteredSection-2 COMMAND $<TARGET_FILE:SelfTest> \#1394\ nested -c NestedRunSection -c s1)
  389. set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
  390. add_test(
  391. NAME
  392. FilteredSection::GeneratorsDontCauseInfiniteLoop-1
  393. COMMAND
  394. $<TARGET_FILE:SelfTest> "#2025: original repro" -c "fov_0"
  395. )
  396. set_tests_properties(FilteredSection::GeneratorsDontCauseInfiniteLoop-1
  397. PROPERTIES
  398. PASS_REGULAR_EXPRESSION "inside with fov: 0" # This should happen
  399. FAIL_REGULAR_EXPRESSION "inside with fov: 1" # This would mean there was no filtering
  400. )
  401. # GENERATE between filtered sections (both are selected)
  402. add_test(
  403. NAME
  404. FilteredSection::GeneratorsDontCauseInfiniteLoop-2
  405. COMMAND
  406. $<TARGET_FILE:SelfTest> "#2025: same-level sections"
  407. -c "A"
  408. -c "B"
  409. )
  410. set_tests_properties(FilteredSection::GeneratorsDontCauseInfiniteLoop-2
  411. PROPERTIES
  412. PASS_REGULAR_EXPRESSION "All tests passed \\(4 assertions in 1 test case\\)"
  413. )
  414. # AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
  415. add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
  416. set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
  417. add_test(NAME RegressionCheck-1670 COMMAND $<TARGET_FILE:SelfTest> "#1670 regression check" -c A -r compact)
  418. set_tests_properties(RegressionCheck-1670 PROPERTIES PASS_REGULAR_EXPRESSION "Passed 1 test case with 2 assertions.")
  419. add_test(NAME VersionCheck COMMAND $<TARGET_FILE:SelfTest> -h)
  420. set_tests_properties(VersionCheck PROPERTIES PASS_REGULAR_EXPRESSION "Catch v${PROJECT_VERSION}")
  421. add_test(NAME LibIdentityTest COMMAND $<TARGET_FILE:SelfTest> --libidentify)
  422. set_tests_properties(LibIdentityTest PROPERTIES PASS_REGULAR_EXPRESSION "description: A Catch2 test executable")
  423. add_test(NAME FilenameAsTagsTest COMMAND $<TARGET_FILE:SelfTest> -\# --list-tags)
  424. set_tests_properties(FilenameAsTagsTest PROPERTIES PASS_REGULAR_EXPRESSION "\\[#Approx.tests\\]")
  425. add_test(NAME EscapeSpecialCharactersInTestNames COMMAND $<TARGET_FILE:SelfTest> "Test with special\\, characters \"in name")
  426. set_tests_properties(EscapeSpecialCharactersInTestNames PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
  427. add_test(NAME TestsInFile::SimpleSpecs COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/plain-old-tests.input")
  428. set_tests_properties(TestsInFile::SimpleSpecs PROPERTIES PASS_REGULAR_EXPRESSION "6 assertions in 2 test cases")
  429. add_test(NAME TestsInFile::EscapeSpecialCharacters COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/special-characters-in-file.input")
  430. set_tests_properties(TestsInFile::EscapeSpecialCharacters PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
  431. # CTest does not allow us to create an AND of required regular expressions,
  432. # so we have to split the test into 2 parts and look for parts of the expected
  433. # output separately.
  434. add_test(NAME TestsInFile::InvalidTestNames-1 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input")
  435. set_tests_properties(TestsInFile::InvalidTestNames-1 PROPERTIES PASS_REGULAR_EXPRESSION "Invalid Filter: \"Test with special, characters in \\\\\" name\"")
  436. add_test(NAME TestsInFile::InvalidTestNames-2 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input")
  437. set_tests_properties(TestsInFile::InvalidTestNames-2 PROPERTIES PASS_REGULAR_EXPRESSION "No tests ran")
  438. add_test(NAME RandomTestOrdering COMMAND ${PYTHON_EXECUTABLE}
  439. ${CATCH_DIR}/projects/TestScripts/testRandomOrder.py $<TARGET_FILE:SelfTest>)
  440. if (CATCH_USE_VALGRIND)
  441. add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)
  442. add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
  443. set_tests_properties(ValgrindListTests PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks")
  444. add_test(NAME ValgrindListTags COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tags)
  445. set_tests_properties(ValgrindListTags PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks")
  446. endif()