CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. #
  2. # Build extra tests.
  3. #
  4. cmake_minimum_required( VERSION 3.10 )
  5. project( Catch2ExtraTests LANGUAGES CXX )
  6. message( STATUS "Extra tests included" )
  7. add_test(
  8. NAME TestShardingIntegration
  9. COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testSharding.py $<TARGET_FILE:SelfTest>
  10. )
  11. set_tests_properties(TestShardingIntegration
  12. PROPERTIES
  13. LABELS "uses-python"
  14. )
  15. add_test(
  16. NAME TestSharding::OverlyLargeShardIndex
  17. COMMAND $<TARGET_FILE:SelfTest> --shard-index 5 --shard-count 5
  18. )
  19. set_tests_properties(
  20. TestSharding::OverlyLargeShardIndex
  21. PROPERTIES
  22. PASS_REGULAR_EXPRESSION "The shard count \\(5\\) must be greater than the shard index \\(5\\)"
  23. )
  24. # The MinDuration reporting tests do not need separate compilation, but
  25. # they have non-trivial execution time, so they are categorized as
  26. # extra tests, so that they are run less.
  27. add_test(NAME MinDuration::SimpleThreshold COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.950 [min_duration_test])
  28. set_tests_properties(
  29. MinDuration::SimpleThreshold
  30. PROPERTIES
  31. PASS_REGULAR_EXPRESSION "s: sleep_for_1000ms"
  32. FAIL_REGULAR_EXPRESSION "sleep_for_100ms"
  33. RUN_SERIAL ON # The test is timing sensitive, so we want to run it
  34. # serially to avoid false positives on oversubscribed machines
  35. )
  36. # -d yes overrides the threshold, so we should see the faster test even
  37. # with a ridiculous high min duration threshold
  38. add_test(NAME MinDuration::DurationOverrideYes COMMAND $<TARGET_FILE:SelfTest> --min-duration 1.0 -d yes [min_duration_test])
  39. set_tests_properties(
  40. MinDuration::DurationOverrideYes
  41. PROPERTIES
  42. PASS_REGULAR_EXPRESSION "s: sleep_for_100ms"
  43. )
  44. # -d no overrides the threshold, so we should never see any tests even
  45. # with ridiculously low min duration threshold
  46. add_test(NAME MinDuration::DurationOverrideNo COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.0001 -d no [min_duration_test])
  47. set_tests_properties(
  48. MinDuration::DurationOverrideNo
  49. PROPERTIES
  50. FAIL_REGULAR_EXPRESSION "sleep_for_250ms"
  51. )
  52. # ------------ end of duration reporting tests
  53. # define folders used:
  54. set( TESTS_DIR ${CATCH_DIR}/tests/ExtraTests )
  55. add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp)
  56. target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE )
  57. # Macro configuration does not touch the compiled parts, so we can link
  58. # it against the main library
  59. target_link_libraries( PrefixedMacros Catch2WithMain )
  60. add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
  61. set_tests_properties(
  62. CATCH_CONFIG_PREFIX_ALL
  63. PROPERTIES
  64. PASS_REGULAR_EXPRESSION "CATCH_"
  65. FAIL_REGULAR_EXPRESSION
  66. # The spaces are important -> They disambiguate between CATCH_REQUIRE
  67. # and REQUIRE without prefix.
  68. " REQUIRE; REQUIRE_FALSE; REQUIRE_THROWS; REQUIRE_THROWS_AS; REQUIRE_THROWS_WITH; REQUIRE_THROWS_MATCHES; REQUIRE_NOTHROW; CHECK; CHECK_FALSE; CHECKED_IF; CHECKED_ELSE; CHECK_NOFAIL; CHECK_THROWS; CHECK_THROWS_AS; CHECK_THROWS_WITH; CHECK_THROWS_MATCHES; CHECK_NOTHROW; REQUIRE_THAT; CHECK_THAT"
  69. )
  70. add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp)
  71. target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE )
  72. # Macro configuration does not touch the compiled parts, so we can link
  73. # it against the main library
  74. target_link_libraries( DisabledMacros Catch2WithMain )
  75. add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s)
  76. set_tests_properties(
  77. CATCH_CONFIG_DISABLE-1
  78. PROPERTIES
  79. PASS_REGULAR_EXPRESSION "No tests ran"
  80. FAIL_REGULAR_EXPRESSION "This should not happen"
  81. )
  82. add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests)
  83. set_tests_properties(
  84. CATCH_CONFIG_DISABLE-2
  85. PROPERTIES
  86. PASS_REGULAR_EXPRESSION "0 test cases"
  87. )
  88. add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp )
  89. add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp )
  90. foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler)
  91. target_compile_options( ${target}
  92. PUBLIC
  93. $<$<CXX_COMPILER_ID:MSVC>:/EHs-c-;/D_HAS_EXCEPTIONS=0>
  94. $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>>:-fno-exceptions>
  95. )
  96. target_link_libraries(${target} Catch2_buildall_interface)
  97. endforeach()
  98. target_compile_definitions( DisabledExceptions-CustomHandler PUBLIC CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER )
  99. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run")
  100. set_tests_properties(
  101. CATCH_CONFIG_DISABLE_EXCEPTIONS-1
  102. PROPERTIES
  103. PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
  104. FAIL_REGULAR_EXPRESSION "abort;terminate;fatal"
  105. )
  106. add_executable( BazelReporter ${TESTS_DIR}/X30-BazelReporter.cpp )
  107. target_compile_definitions( BazelReporter PRIVATE CATCH_CONFIG_BAZEL_SUPPORT )
  108. target_link_libraries(BazelReporter Catch2_buildall_interface)
  109. add_test(NAME CATCH_CONFIG_BAZEL_REPORTER-1
  110. COMMAND
  111. "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $<TARGET_FILE:BazelReporter> "${CMAKE_CURRENT_BINARY_DIR}"
  112. )
  113. set_tests_properties(CATCH_CONFIG_BAZEL_REPORTER-1
  114. PROPERTIES
  115. LABELS "uses-python"
  116. )
  117. # We must now test this works without the build flag.
  118. add_executable( BazelReporterNoCatchConfig ${TESTS_DIR}/X30-BazelReporter.cpp )
  119. target_link_libraries(BazelReporterNoCatchConfig Catch2WithMain)
  120. add_test(NAME NO_CATCH_CONFIG_BAZEL_REPORTER-1
  121. COMMAND
  122. "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $<TARGET_FILE:BazelReporterNoCatchConfig> "${CMAKE_CURRENT_BINARY_DIR}"
  123. )
  124. set_tests_properties(NO_CATCH_CONFIG_BAZEL_REPORTER-1
  125. PROPERTIES
  126. LABELS "uses-python"
  127. ENVIRONMENT "BAZEL_TEST=1"
  128. )
  129. # The default handler on Windows leads to the just-in-time debugger firing,
  130. # which makes this test unsuitable for CI and headless runs, as it opens
  131. # up an interactive dialog.
  132. if (NOT WIN32)
  133. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort")
  134. set_tests_properties(
  135. CATCH_CONFIG_DISABLE_EXCEPTIONS-2
  136. PROPERTIES
  137. PASS_REGULAR_EXPRESSION "Catch will terminate"
  138. )
  139. endif(NOT WIN32)
  140. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run")
  141. set_tests_properties(
  142. CATCH_CONFIG_DISABLE_EXCEPTIONS-3
  143. PROPERTIES
  144. PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
  145. FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
  146. )
  147. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort")
  148. set_tests_properties(
  149. CATCH_CONFIG_DISABLE_EXCEPTIONS-4
  150. PROPERTIES
  151. PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
  152. )
  153. add_executable(DeferredStaticChecks ${TESTS_DIR}/X05-DeferredStaticChecks.cpp)
  154. target_link_libraries(DeferredStaticChecks PRIVATE Catch2WithMain)
  155. target_compile_definitions(DeferredStaticChecks PRIVATE "CATCH_CONFIG_RUNTIME_STATIC_REQUIRE")
  156. add_test(NAME DeferredStaticChecks COMMAND DeferredStaticChecks -r compact)
  157. set_tests_properties(
  158. DeferredStaticChecks
  159. PROPERTIES
  160. PASS_REGULAR_EXPRESSION "Failed 1 test case, failed all 3 assertions."
  161. )
  162. add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp)
  163. target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier )
  164. target_link_libraries( FallbackStringifier Catch2WithMain )
  165. add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s)
  166. set_tests_properties(
  167. FallbackStringifier
  168. PROPERTIES
  169. PASS_REGULAR_EXPRESSION "foo{} for: { !!! }"
  170. )
  171. add_executable(DisableStringification ${TESTS_DIR}/X11-DisableStringification.cpp)
  172. target_compile_definitions( DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION )
  173. target_link_libraries(DisableStringification Catch2WithMain)
  174. add_test(NAME CATCH_CONFIG_DISABLE_STRINGIFICATION COMMAND DisableStringification -r compact -s)
  175. set_tests_properties(
  176. CATCH_CONFIG_DISABLE_STRINGIFICATION
  177. PROPERTIES
  178. PASS_REGULAR_EXPRESSION "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  179. FAIL_REGULAR_EXPRESSION "Hidden{} == Hidden{}"
  180. )
  181. # This test touches windows.h, so it should only be compiled under msvc
  182. if (MSVC)
  183. # This test fails if it does not compile and succeeds otherwise
  184. add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp)
  185. set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD 14 )
  186. set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD_REQUIRED ON )
  187. set_property( TARGET WindowsHeader PROPERTY CXX_EXTENSIONS OFF )
  188. target_link_libraries( WindowsHeader Catch2WithMain )
  189. add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact)
  190. list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES} WindowsHeader)
  191. endif()
  192. add_executable(PartialTestCaseEvents ${TESTS_DIR}/X21-PartialTestCaseEvents.cpp)
  193. target_link_libraries(PartialTestCaseEvents PRIVATE Catch2WithMain)
  194. add_test(
  195. NAME PartialTestCaseEvents
  196. COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $<TARGET_FILE:PartialTestCaseEvents>
  197. )
  198. set_tests_properties(PartialTestCaseEvents
  199. PROPERTIES
  200. LABELS "uses-python"
  201. )
  202. add_executable(BenchmarksInCumulativeReporter ${TESTS_DIR}/X22-BenchmarksInCumulativeReporter.cpp)
  203. target_link_libraries(BenchmarksInCumulativeReporter PRIVATE Catch2::Catch2WithMain)
  204. add_test(
  205. NAME BenchmarksInCumulativeReporter
  206. COMMAND BenchmarksInCumulativeReporter --reporter testReporter
  207. )
  208. set_tests_properties(
  209. BenchmarksInCumulativeReporter
  210. PROPERTIES
  211. PASS_REGULAR_EXPRESSION "1\n2\n3\n4\n5\n"
  212. )
  213. add_executable(CasingInReporterNames ${TESTS_DIR}/X23-CasingInReporterNames.cpp)
  214. target_link_libraries(CasingInReporterNames PRIVATE Catch2::Catch2WithMain)
  215. add_test(
  216. NAME Reporters::registration-is-case-preserving
  217. COMMAND CasingInReporterNames --list-reporters
  218. )
  219. set_tests_properties(
  220. Reporters::registration-is-case-preserving
  221. PROPERTIES
  222. PASS_REGULAR_EXPRESSION "testReporterCASED"
  223. )
  224. add_test(
  225. NAME Reporters::selection-is-case-insensitive
  226. COMMAND CasingInReporterNames -r testReportercased
  227. )
  228. set_tests_properties(
  229. Reporters::selection-is-case-insensitive
  230. PROPERTIES
  231. PASS_REGULAR_EXPRESSION "TestReporter constructed"
  232. )
  233. add_executable(CapturedStdoutInTestCaseEvents ${TESTS_DIR}/X27-CapturedStdoutInTestCaseEvents.cpp)
  234. target_link_libraries(CapturedStdoutInTestCaseEvents PRIVATE Catch2::Catch2WithMain)
  235. add_test(
  236. NAME Reporters::CapturedStdOutInEvents
  237. COMMAND CapturedStdoutInTestCaseEvents
  238. --reporter test-reporter
  239. )
  240. set_tests_properties(
  241. Reporters::CapturedStdOutInEvents
  242. PROPERTIES
  243. PASS_REGULAR_EXPRESSION "X27 - TestReporter constructed"
  244. FAIL_REGULAR_EXPRESSION "X27 ERROR"
  245. )
  246. if (MSVC)
  247. set(_NullFile "NUL")
  248. else()
  249. set(_NullFile "/dev/null")
  250. endif()
  251. add_executable(ListenerStdoutCaptureInMultireporter ${TESTS_DIR}/X24-ListenerStdoutCaptureInMultireporter.cpp)
  252. target_link_libraries(ListenerStdoutCaptureInMultireporter PRIVATE Catch2::Catch2WithMain)
  253. # This test checks that there is nothing written out from the process,
  254. # but if CMake is running the tests under Valgrind or similar tool, then
  255. # that will write its own output to stdout and the test would fail.
  256. if (NOT MEMORYCHECK_COMMAND)
  257. add_test(
  258. NAME MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough
  259. COMMAND ListenerStdoutCaptureInMultireporter
  260. --reporter xml::out=${_NullFile}
  261. --reporter junit::out=${_NullFile}
  262. )
  263. set_tests_properties(
  264. MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough
  265. PROPERTIES
  266. PASS_REGULAR_EXPRESSION "X24 - NonCapturingListener initialized"
  267. FAIL_REGULAR_EXPRESSION "X24 - FooBarBaz"
  268. )
  269. endif()
  270. add_executable(ListenerCanAskForCapturedStdout ${TESTS_DIR}/X25-ListenerCanAskForCapturedStdout.cpp)
  271. target_link_libraries(ListenerCanAskForCapturedStdout PRIVATE Catch2::Catch2WithMain)
  272. add_test(
  273. NAME MultiReporter::CapturingListenerCausesStdoutCapture
  274. COMMAND ListenerCanAskForCapturedStdout
  275. --reporter compact::out=${_NullFile}
  276. --reporter console::out=${_NullFile}
  277. )
  278. set_tests_properties(
  279. MultiReporter::CapturingListenerCausesStdoutCapture
  280. PROPERTIES
  281. PASS_REGULAR_EXPRESSION "CapturingListener initialized"
  282. FAIL_REGULAR_EXPRESSION "X25 - ERROR"
  283. )
  284. add_executable(ReporterPreferencesForPassingAssertionsIsRespected ${TESTS_DIR}/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp)
  285. target_link_libraries(ReporterPreferencesForPassingAssertionsIsRespected PRIVATE Catch2::Catch2WithMain)
  286. add_test(
  287. NAME Reporters::PreferencesForPassingAssertionsIsRespected
  288. COMMAND ReporterPreferencesForPassingAssertionsIsRespected
  289. --reporter test-reporter
  290. )
  291. set_tests_properties(
  292. Reporters::PreferencesForPassingAssertionsIsRespected
  293. PROPERTIES
  294. PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed"
  295. FAIL_REGULAR_EXPRESSION "X26 - assertionEnded"
  296. )
  297. add_test(
  298. NAME MultiReporter::PreferencesForPassingAssertionsIsRespected
  299. COMMAND ReporterPreferencesForPassingAssertionsIsRespected
  300. --reporter test-reporter
  301. --reporter console::out=${_NullFile}
  302. )
  303. set_tests_properties(
  304. MultiReporter::PreferencesForPassingAssertionsIsRespected
  305. PROPERTIES
  306. PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed"
  307. FAIL_REGULAR_EXPRESSION "X26 - assertionEnded"
  308. )
  309. add_executable(ListenersGetEventsBeforeReporters ${TESTS_DIR}/X28-ListenersGetEventsBeforeReporters.cpp)
  310. target_link_libraries(ListenersGetEventsBeforeReporters PRIVATE Catch2::Catch2WithMain)
  311. add_test(
  312. NAME ListenersGetEventsBeforeReporters
  313. COMMAND ListenersGetEventsBeforeReporters --reporter test-reporter
  314. )
  315. set_tests_properties(
  316. ListenersGetEventsBeforeReporters
  317. PROPERTIES
  318. PASS_REGULAR_EXPRESSION "X28 - TestReporter constructed"
  319. FAIL_REGULAR_EXPRESSION "X28 - ERROR"
  320. )
  321. add_executable(CustomArgumentsForReporters ${TESTS_DIR}/X29-CustomArgumentsForReporters.cpp)
  322. target_link_libraries(CustomArgumentsForReporters PRIVATE Catch2::Catch2WithMain)
  323. add_test(
  324. NAME CustomArgumentsForReporters
  325. COMMAND CustomArgumentsForReporters
  326. --reporter "test-reporter::Xa b=c 1::Xz:e = 1234"
  327. )
  328. set_tests_properties(
  329. CustomArgumentsForReporters
  330. PROPERTIES
  331. PASS_REGULAR_EXPRESSION "Xa b=c 1::Xz:e = 1234"
  332. )
  333. add_executable(DuplicatedTestCases-SameNameAndTags ${TESTS_DIR}/X31-DuplicatedTestCases.cpp)
  334. target_link_libraries(DuplicatedTestCases-SameNameAndTags PRIVATE Catch2::Catch2WithMain)
  335. add_test(
  336. NAME DuplicatedTestCases::SameNameAndTags
  337. COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameAndTags>
  338. )
  339. set_tests_properties(
  340. DuplicatedTestCases::SameNameAndTags
  341. PROPERTIES
  342. PASS_REGULAR_EXPRESSION "error: .* already defined\\."
  343. )
  344. add_executable(DuplicatedTestCases-SameNameDifferentTags ${TESTS_DIR}/X32-DuplicatedTestCasesDifferentTags.cpp)
  345. target_link_libraries(DuplicatedTestCases-SameNameDifferentTags PRIVATE Catch2::Catch2WithMain)
  346. add_test(
  347. NAME DuplicatedTestCases::SameNameDifferentTags
  348. COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameDifferentTags>
  349. )
  350. set_tests_properties(
  351. DuplicatedTestCases::SameNameDifferentTags
  352. PROPERTIES
  353. FAIL_REGULAR_EXPRESSION "error: .* already defined\\."
  354. )
  355. add_executable(DuplicatedTestCases-DuplicatedTestCaseMethods ${TESTS_DIR}/X33-DuplicatedTestCaseMethods.cpp)
  356. target_link_libraries(DuplicatedTestCases-DuplicatedTestCaseMethods PRIVATE Catch2::Catch2WithMain)
  357. add_test(
  358. NAME DuplicatedTestCases::DuplicatedTestCaseMethods
  359. COMMAND $<TARGET_FILE:DuplicatedTestCases-DuplicatedTestCaseMethods>
  360. )
  361. set_tests_properties(
  362. DuplicatedTestCases::DuplicatedTestCaseMethods
  363. PROPERTIES
  364. PASS_REGULAR_EXPRESSION "error: .* already defined\\."
  365. )
  366. add_executable(DuplicatedTestCases-DifferentFixtures ${TESTS_DIR}/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp)
  367. target_link_libraries(DuplicatedTestCases-DifferentFixtures PRIVATE Catch2::Catch2WithMain)
  368. add_test(
  369. NAME DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures
  370. COMMAND $<TARGET_FILE:DuplicatedTestCases-DifferentFixtures>
  371. )
  372. set_tests_properties(
  373. DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures
  374. PROPERTIES
  375. FAIL_REGULAR_EXPRESSION "error: .* already defined\\."
  376. )
  377. add_executable(DuplicatedReporters ${TESTS_DIR}/X35-DuplicatedReporterNames.cpp)
  378. target_link_libraries(DuplicatedReporters PRIVATE Catch2::Catch2WithMain)
  379. add_test(
  380. NAME Reporters::RegistrationErrorsAreCaught
  381. COMMAND $<TARGET_FILE:DuplicatedReporters>
  382. )
  383. set_tests_properties(
  384. Reporters::RegistrationErrorsAreCaught
  385. PROPERTIES
  386. PASS_REGULAR_EXPRESSION "Errors occurred during startup!"
  387. )
  388. #add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp)
  389. #target_link_libraries(DebugBreakMacros Catch2)
  390. #add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break)
  391. #set_tests_properties(
  392. # DebugBreakMacros
  393. # PROPERTIES
  394. # PASS_REGULAR_EXPRESSION "Pretty please, break into debugger"
  395. #)
  396. add_executable(NoTests ${TESTS_DIR}/X92-NoTests.cpp)
  397. target_link_libraries(NoTests PRIVATE Catch2::Catch2WithMain)
  398. add_test(
  399. NAME TestSpecs::EmptySpecWithNoTestsFails
  400. COMMAND $<TARGET_FILE:NoTests>
  401. )
  402. set_tests_properties(TestSpecs::EmptySpecWithNoTestsFails
  403. PROPERTIES
  404. WILL_FAIL ON
  405. )
  406. add_test(
  407. NAME TestSpecs::OverrideFailureWithEmptySpec
  408. COMMAND $<TARGET_FILE:NoTests> --allow-running-no-tests
  409. )
  410. add_test(
  411. NAME List::Listeners::WorksWithoutRegisteredListeners
  412. COMMAND $<TARGET_FILE:NoTests> --list-listeners
  413. )
  414. set( EXTRA_TEST_BINARIES
  415. PrefixedMacros
  416. DisabledMacros
  417. DisabledExceptions-DefaultHandler
  418. DisabledExceptions-CustomHandler
  419. FallbackStringifier
  420. DisableStringification
  421. PartialTestCaseEvents
  422. DuplicatedTestCases-SameNameAndTags
  423. DuplicatedTestCases-SameNameDifferentTags
  424. DuplicatedTestCases-DuplicatedTestCaseMethods
  425. NoTests
  426. ListenersGetEventsBeforeReporters
  427. # DebugBreakMacros
  428. )
  429. # Shared config
  430. foreach( test ${EXTRA_TEST_BINARIES} )
  431. set_property( TARGET ${test} PROPERTY CXX_STANDARD 14 )
  432. set_property( TARGET ${test} PROPERTY CXX_STANDARD_REQUIRED ON )
  433. set_property( TARGET ${test} PROPERTY CXX_EXTENSIONS OFF )
  434. endforeach()
  435. # Notice that we are modifying EXTRA_TEST_BINARIES destructively, do not
  436. # use it after this point!
  437. list(FILTER EXTRA_TEST_BINARIES EXCLUDE REGEX "DisabledExceptions.*")
  438. list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES})
  439. set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
  440. # This sets up a one-off executable that compiles against the amalgamated
  441. # files, and then runs it for a super simple check that the amalgamated
  442. # files are usable.
  443. add_executable(AmalgamatedTestCompilation
  444. ${TESTS_DIR}/X91-AmalgamatedCatch.cpp
  445. ${CATCH_DIR}/extras/catch_amalgamated.hpp
  446. ${CATCH_DIR}/extras/catch_amalgamated.cpp
  447. )
  448. target_include_directories(AmalgamatedTestCompilation PRIVATE ${CATCH_DIR}/extras)
  449. set_property( TARGET AmalgamatedTestCompilation PROPERTY CXX_STANDARD 14 )
  450. set_property( TARGET AmalgamatedTestCompilation PROPERTY CXX_STANDARD_REQUIRED ON )
  451. set_property( TARGET AmalgamatedTestCompilation PROPERTY CXX_EXTENSIONS OFF )
  452. add_test(NAME AmalgamatedFileTest COMMAND AmalgamatedTestCompilation)
  453. set_tests_properties(
  454. AmalgamatedFileTest
  455. PROPERTIES
  456. PASS_REGULAR_EXPRESSION "All tests passed \\(14 assertions in 3 test cases\\)"
  457. )