CMakeLists.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. include(CatchMiscFunctions)
  2. if (CATCH_BUILD_SURROGATES)
  3. message(STATUS "Configuring targets for surrogate TUs")
  4. # If the folder does not exist before we ask for output redirect to
  5. # a file, it won't work.
  6. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/surrogates)
  7. # Creates target to generate the surrogate TU for provided header.
  8. # Returns the path to the generated file.
  9. function(createSurrogateFileTarget sourceHeader pathToFile)
  10. set(pathPrefix ${PROJECT_SOURCE_DIR}/src)
  11. file(RELATIVE_PATH includePath ${pathPrefix} ${sourceHeader})
  12. get_filename_component(basicFileName "${sourceHeader}" NAME_WE)
  13. set(surrogateFilePath ${CMAKE_CURRENT_BINARY_DIR}/surrogates/surrogate_${basicFileName}.cpp)
  14. add_custom_command(
  15. OUTPUT ${surrogateFilePath}
  16. COMMAND cmake -E echo "\#include <${includePath}>" > "${surrogateFilePath}"
  17. VERBATIM
  18. )
  19. set(${pathToFile} ${surrogateFilePath} PARENT_SCOPE)
  20. endfunction()
  21. # Extracts all non-helper (e.g. catch_all.hpp) headers from the
  22. # Catch2 target, and returns them through the argument.
  23. function(ExtractCatch2Headers OutArg)
  24. get_target_property(targetSources Catch2 SOURCES)
  25. foreach(Source ${targetSources})
  26. string(REGEX MATCH "^.*\\.hpp$" isHeader ${Source})
  27. string(REGEX MATCH "_all.hpp" isAllHeader ${Source})
  28. if(isHeader AND NOT isAllHeader)
  29. list(APPEND AllHeaders ${Source})
  30. endif()
  31. endforeach()
  32. set(${OutArg} ${AllHeaders} PARENT_SCOPE)
  33. endfunction()
  34. ExtractCatch2Headers(mainHeaders)
  35. if (NOT mainHeaders)
  36. message(FATAL_ERROR "No headers in the main target were detected. Something is broken.")
  37. endif()
  38. foreach(header ${mainHeaders})
  39. createSurrogateFileTarget(${header} pathToGeneratedFile)
  40. list(APPEND surrogateFiles ${pathToGeneratedFile})
  41. endforeach()
  42. add_executable(Catch2SurrogateTarget
  43. ${surrogateFiles}
  44. )
  45. target_link_libraries(Catch2SurrogateTarget PRIVATE Catch2WithMain)
  46. endif(CATCH_BUILD_SURROGATES)
  47. ####
  48. # Temporary workaround for VS toolset changes in 2017
  49. # We need to disable <UseFullPaths> property, but CMake doesn't support it
  50. # until 3.13 (not yet released)
  51. ####
  52. if (MSVC)
  53. configure_file(${CATCH_DIR}/tools/misc/SelfTest.vcxproj.user
  54. ${CMAKE_BINARY_DIR}/tests
  55. COPYONLY)
  56. endif(MSVC) #Temporary workaround
  57. # define the sources of the self test
  58. # Please keep these ordered alphabetically
  59. set(TEST_SOURCES
  60. ${SELF_TEST_DIR}/TestRegistrations.cpp
  61. ${SELF_TEST_DIR}/IntrospectiveTests/Clara.tests.cpp
  62. ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp
  63. ${SELF_TEST_DIR}/IntrospectiveTests/CmdLineHelpers.tests.cpp
  64. ${SELF_TEST_DIR}/IntrospectiveTests/ColourImpl.tests.cpp
  65. ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp
  66. ${SELF_TEST_DIR}/IntrospectiveTests/FloatingPoint.tests.cpp
  67. ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp
  68. ${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp
  69. ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp
  70. ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp
  71. ${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp
  72. ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp
  73. ${SELF_TEST_DIR}/IntrospectiveTests/TestCaseInfoHasher.tests.cpp
  74. ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp
  75. ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp
  76. ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp
  77. ${SELF_TEST_DIR}/IntrospectiveTests/Stream.tests.cpp
  78. ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp
  79. ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp
  80. ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp
  81. ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp
  82. ${SELF_TEST_DIR}/IntrospectiveTests/UniquePtr.tests.cpp
  83. ${SELF_TEST_DIR}/TimingTests/Sleep.tests.cpp
  84. ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp
  85. ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp
  86. ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp
  87. ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp
  88. ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp
  89. ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp
  90. ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp
  91. ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp
  92. ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp
  93. ${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp
  94. ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp
  95. ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp
  96. ${SELF_TEST_DIR}/UsageTests/ToStringByte.tests.cpp
  97. ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp
  98. ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp
  99. ${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp
  100. ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp
  101. ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp
  102. ${SELF_TEST_DIR}/UsageTests/ToStringVariant.tests.cpp
  103. ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp
  104. ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp
  105. ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp
  106. ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp
  107. ${SELF_TEST_DIR}/UsageTests/MatchersRanges.tests.cpp
  108. ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp
  109. )
  110. # Specify the headers, too, so CLion recognises them as project files
  111. set(HEADERS
  112. ${TOP_LEVEL_HEADERS}
  113. ${EXTERNAL_HEADERS}
  114. ${INTERNAL_HEADERS}
  115. ${REPORTER_HEADERS}
  116. ${BENCHMARK_HEADERS}
  117. ${BENCHMARK_SOURCES}
  118. )
  119. # Provide some groupings for IDEs
  120. #SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES})
  121. #SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
  122. include(CTest)
  123. add_executable(SelfTest ${TEST_SOURCES})
  124. target_link_libraries(SelfTest PRIVATE Catch2WithMain)
  125. if (BUILD_SHARED_LIBS AND WIN32)
  126. add_custom_command(TARGET SelfTest PRE_LINK
  127. COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Catch2>
  128. $<TARGET_FILE:Catch2WithMain> $<TARGET_FILE_DIR:SelfTest>
  129. )
  130. endif()
  131. if (CATCH_ENABLE_COVERAGE)
  132. set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
  133. find_package(codecov)
  134. add_coverage(SelfTest)
  135. list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
  136. coverage_evaluate()
  137. endif()
  138. # configure unit tests via CTest
  139. add_test(NAME RunTests COMMAND $<TARGET_FILE:SelfTest> --order rand --rng-seed time)
  140. set_tests_properties(RunTests PROPERTIES
  141. FAIL_REGULAR_EXPRESSION "Filters:"
  142. COST 60
  143. )
  144. # Because CTest does not allow us to check both return code _and_ expected
  145. # output in one test, we run these commands twice. First time we check
  146. # the output, the second time we check the exit code.
  147. add_test(NAME List::Tests::Output COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
  148. set_tests_properties(List::Tests::Output PROPERTIES
  149. PASS_REGULAR_EXPRESSION "[0-9]+ test cases"
  150. FAIL_REGULAR_EXPRESSION "Hidden Test"
  151. )
  152. # This should be equivalent to the old --list-test-names-only and be usable
  153. # with --input-file.
  154. add_test(NAME List::Tests::Quiet COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity quiet)
  155. # Sadly we cannot ask for start-of-line and end-of-line in a ctest regex,
  156. # so we fail if we see space/tab at the start...
  157. set_tests_properties(List::Tests::Quiet PROPERTIES
  158. PASS_REGULAR_EXPRESSION "\"#1905 -- test spec parser properly clears internal state between compound tests\"[\r\n]"
  159. FAIL_REGULAR_EXPRESSION "[ \t]\"#1905 -- test spec parser properly clears internal state between compound tests\""
  160. )
  161. add_test(NAME List::Tests::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
  162. add_test(NAME List::Tests::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high -r xml)
  163. set_tests_properties(List::Tests::XmlOutput PROPERTIES
  164. PASS_REGULAR_EXPRESSION "<Line>[0-9]+</Line>"
  165. FAIL_REGULAR_EXPRESSION "[0-9]+ test cases"
  166. )
  167. add_test(NAME List::Tags::Output COMMAND $<TARGET_FILE:SelfTest> --list-tags)
  168. set_tests_properties(List::Tags::Output PROPERTIES
  169. PASS_REGULAR_EXPRESSION "[0-9]+ tags"
  170. FAIL_REGULAR_EXPRESSION "\\[\\.\\]")
  171. add_test(NAME List::Tags::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-tags)
  172. add_test(NAME List::Tags::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-tags -r xml)
  173. set_tests_properties(List::Tags::XmlOutput PROPERTIES
  174. PASS_REGULAR_EXPRESSION "<Count>18</Count>"
  175. FAIL_REGULAR_EXPRESSION "[0-9]+ tags"
  176. )
  177. add_test(NAME List::Reporters::Output COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
  178. set_tests_properties(List::Reporters::Output PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:")
  179. add_test(NAME List::Reporters::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
  180. add_test(NAME List::Reporters::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-reporters -r xml)
  181. set_tests_properties(List::Reporters::XmlOutput PROPERTIES
  182. PASS_REGULAR_EXPRESSION "<Name>compact</Name>"
  183. FAIL_REGULAR_EXPRESSION "Available reporters:"
  184. )
  185. add_test(NAME List::Listeners::Output
  186. COMMAND
  187. $<TARGET_FILE:SelfTest> --list-listeners
  188. )
  189. set_tests_properties(List::Listeners::Output
  190. PROPERTIES
  191. PASS_REGULAR_EXPRESSION "Registered listeners:"
  192. )
  193. add_test(NAME List::Listeners::ExitCode
  194. COMMAND
  195. $<TARGET_FILE:SelfTest> --list-listeners
  196. )
  197. add_test(NAME List::Listeners::XmlOutput
  198. COMMAND
  199. $<TARGET_FILE:SelfTest>
  200. --list-listeners
  201. --reporter xml
  202. )
  203. set_tests_properties(List::Listeners::XmlOutput
  204. PROPERTIES
  205. PASS_REGULAR_EXPRESSION "<RegisteredListeners>"
  206. FAIL_REGULAR_EXPRESSION "Registered listeners:"
  207. )
  208. add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions "An empty test with no assertions")
  209. set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")
  210. # We cannot combine a regular expression on output with return code check
  211. # in one test, so we register two instead of making a checking script because
  212. # the runtime overhead is small enough.
  213. add_test(NAME TestSpecs::CombiningMatchingAndNonMatchingIsOk-1 COMMAND $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___")
  214. add_test(NAME TestSpecs::CombiningMatchingAndNonMatchingIsOk-2 COMMAND $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___")
  215. set_tests_properties(TestSpecs::CombiningMatchingAndNonMatchingIsOk-2 PROPERTIES
  216. PASS_REGULAR_EXPRESSION "No test cases matched '___nonexistent_test___'"
  217. FAIL_REGULAR_EXPRESSION "No tests ran"
  218. )
  219. add_test(NAME TestSpecs::NoMatchedTestsFail
  220. COMMAND $<TARGET_FILE:SelfTest> "___nonexistent_test___"
  221. )
  222. set_tests_properties(TestSpecs::NoMatchedTestsFail
  223. PROPERTIES
  224. WILL_FAIL ON
  225. )
  226. add_test(NAME TestSpecs::OverrideFailureWithNoMatchedTests
  227. COMMAND $<TARGET_FILE:SelfTest> "___nonexistent_test___" --allow-running-no-tests
  228. )
  229. add_test(NAME Warnings::UnmatchedTestSpecIsAccepted
  230. COMMAND $<TARGET_FILE:SelfTest> Tracker --warn UnmatchedTestSpec
  231. )
  232. set_tests_properties(Warnings::UnmatchedTestSpecIsAccepted
  233. PROPERTIES
  234. FAIL_REGULAR_EXPRESSION "Unrecognised warning option: "
  235. )
  236. add_test(NAME Warnings::MultipleWarningsCanBeSpecified
  237. COMMAND
  238. $<TARGET_FILE:SelfTest> Tracker
  239. --warn NoAssertions
  240. --warn UnmatchedTestSpec
  241. )
  242. add_test(NAME TestSpecs::WarnUnmatchedTestSpecFailsWithUnmatchedTestSpec
  243. COMMAND
  244. $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___" --warn UnmatchedTestSpec
  245. )
  246. set_tests_properties(TestSpecs::WarnUnmatchedTestSpecFailsWithUnmatchedTestSpec
  247. PROPERTIES
  248. WILL_FAIL ON
  249. )
  250. add_test(NAME UnmatchedOutputFilter COMMAND $<TARGET_FILE:SelfTest> [this-tag-does-not-exist])
  251. set_tests_properties(UnmatchedOutputFilter
  252. PROPERTIES
  253. PASS_REGULAR_EXPRESSION "No test cases matched '\\[this-tag-does-not-exist\\]'"
  254. )
  255. add_test(NAME FilteredSection-1 COMMAND $<TARGET_FILE:SelfTest> \#1394 -c RunSection)
  256. set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
  257. add_test(NAME FilteredSection-2 COMMAND $<TARGET_FILE:SelfTest> \#1394\ nested -c NestedRunSection -c s1)
  258. set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
  259. add_test(
  260. NAME
  261. FilteredSection::GeneratorsDontCauseInfiniteLoop-1
  262. COMMAND
  263. $<TARGET_FILE:SelfTest> "#2025: original repro" -c "fov_0"
  264. )
  265. set_tests_properties(FilteredSection::GeneratorsDontCauseInfiniteLoop-1
  266. PROPERTIES
  267. PASS_REGULAR_EXPRESSION "inside with fov: 0" # This should happen
  268. FAIL_REGULAR_EXPRESSION "inside with fov: 1" # This would mean there was no filtering
  269. )
  270. # GENERATE between filtered sections (both are selected)
  271. add_test(
  272. NAME
  273. FilteredSection::GeneratorsDontCauseInfiniteLoop-2
  274. COMMAND
  275. $<TARGET_FILE:SelfTest> "#2025: same-level sections"
  276. -c "A"
  277. -c "B"
  278. --colour-mode none
  279. )
  280. set_tests_properties(FilteredSection::GeneratorsDontCauseInfiniteLoop-2
  281. PROPERTIES
  282. PASS_REGULAR_EXPRESSION "All tests passed \\(4 assertions in 1 test case\\)"
  283. )
  284. # AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
  285. add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tools/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
  286. set_tests_properties(ApprovalTests
  287. PROPERTIES
  288. FAIL_REGULAR_EXPRESSION "Results differed"
  289. COST 120 # We know that this is either the most, or second most,
  290. # expensive test in the test suite, so we give it high estimate for CI runs
  291. LABELS "uses-python"
  292. )
  293. add_test(NAME RegressionCheck-1670 COMMAND $<TARGET_FILE:SelfTest> "#1670 regression check" -c A -r compact)
  294. set_tests_properties(RegressionCheck-1670 PROPERTIES PASS_REGULAR_EXPRESSION "Passed 1 test case with 2 assertions.")
  295. add_test(NAME VersionCheck COMMAND $<TARGET_FILE:SelfTest> -h)
  296. set_tests_properties(VersionCheck PROPERTIES PASS_REGULAR_EXPRESSION "Catch2 v${PROJECT_VERSION}")
  297. add_test(NAME LibIdentityTest COMMAND $<TARGET_FILE:SelfTest> --libidentify)
  298. set_tests_properties(LibIdentityTest PROPERTIES PASS_REGULAR_EXPRESSION "description: A Catch2 test executable")
  299. add_test(NAME FilenameAsTagsTest COMMAND $<TARGET_FILE:SelfTest> -\# --list-tags)
  300. set_tests_properties(FilenameAsTagsTest PROPERTIES PASS_REGULAR_EXPRESSION "\\[#Approx.tests\\]")
  301. # Check that the filename tags can also be matched against (#2064)
  302. add_test(NAME FilenameAsTagsMatching COMMAND $<TARGET_FILE:SelfTest> -\# --list-tags [\#Approx.tests])
  303. set_tests_properties(FilenameAsTagsMatching
  304. PROPERTIES
  305. PASS_REGULAR_EXPRESSION "\\[#Approx.tests\\]"
  306. # Avoids false positives by looking for start of line (newline) before the 0
  307. FAIL_REGULAR_EXPRESSION "[\r\n]0 tag"
  308. )
  309. add_test(NAME EscapeSpecialCharactersInTestNames COMMAND $<TARGET_FILE:SelfTest> "Test with special\\, characters \"in name")
  310. set_tests_properties(EscapeSpecialCharactersInTestNames PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
  311. add_test(NAME NegativeSpecNoHiddenTests COMMAND $<TARGET_FILE:SelfTest> --list-tests ~[approval])
  312. set_tests_properties(NegativeSpecNoHiddenTests PROPERTIES FAIL_REGULAR_EXPRESSION "\\[\\.\\]")
  313. add_test(NAME TestsInFile::SimpleSpecs COMMAND $<TARGET_FILE:SelfTest> "-f ${SELF_TEST_DIR}/Misc/plain-old-tests.input")
  314. set_tests_properties(TestsInFile::SimpleSpecs PROPERTIES PASS_REGULAR_EXPRESSION "6 assertions in 2 test cases")
  315. add_test(NAME TestsInFile::EscapeSpecialCharacters COMMAND $<TARGET_FILE:SelfTest> "-f ${SELF_TEST_DIR}/Misc/special-characters-in-file.input")
  316. set_tests_properties(TestsInFile::EscapeSpecialCharacters PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
  317. add_test(NAME TestsInFile::InvalidTestNames-1 COMMAND $<TARGET_FILE:SelfTest> "-f ${SELF_TEST_DIR}/Misc/invalid-test-names.input")
  318. set_tests_properties(TestsInFile::InvalidTestNames-1
  319. PROPERTIES
  320. PASS_REGULAR_EXPRESSION "Invalid Filter: \"Test with special, characters in \\\\\" name\""
  321. FAIL_REGULAR_EXPRESSION "No tests ran"
  322. )
  323. add_test(NAME TagAlias COMMAND $<TARGET_FILE:SelfTest> [@tricky] --list-tests)
  324. set_tests_properties(TagAlias PROPERTIES
  325. PASS_REGULAR_EXPRESSION "[0-9]+ matching test cases"
  326. FAIL_REGULAR_EXPRESSION "0 matching test cases"
  327. )
  328. add_test(NAME RandomTestOrdering COMMAND ${PYTHON_EXECUTABLE}
  329. ${CATCH_DIR}/tests/TestScripts/testRandomOrder.py $<TARGET_FILE:SelfTest>)
  330. set_tests_properties(RandomTestOrdering
  331. PROPERTIES
  332. LABELS "uses-python"
  333. )
  334. add_test(NAME CheckConvenienceHeaders
  335. COMMAND
  336. ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tools/scripts/checkConvenienceHeaders.py
  337. )
  338. set_tests_properties(CheckConvenienceHeaders
  339. PROPERTIES
  340. LABELS "uses-python"
  341. )
  342. add_test(NAME "Benchmarking::SkipBenchmarkMacros"
  343. COMMAND
  344. $<TARGET_FILE:SelfTest> "Skip benchmark macros"
  345. --reporter console
  346. --skip-benchmarks
  347. --colour-mode none
  348. )
  349. set_tests_properties("Benchmarking::SkipBenchmarkMacros"
  350. PROPERTIES
  351. PASS_REGULAR_EXPRESSION "All tests passed \\(2 assertions in 1 test case\\)"
  352. FAIL_REGULAR_EXPRESSION "benchmark name"
  353. )
  354. add_test(NAME "Benchmarking::FailureReporting::OptimizedOut"
  355. COMMAND
  356. $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "empty" -r xml
  357. # This test only makes sense with the optimizer being enabled when
  358. # the tests are being compiled.
  359. CONFIGURATIONS Release
  360. )
  361. set_tests_properties("Benchmarking::FailureReporting::OptimizedOut"
  362. PROPERTIES
  363. PASS_REGULAR_EXPRESSION "could not measure benchmark\, maybe it was optimized away"
  364. FAIL_REGULAR_EXPRESSION "successes=\"1\""
  365. )
  366. add_test(NAME "Benchmarking::FailureReporting::ThrowingBenchmark"
  367. COMMAND
  368. $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "throw" -r xml
  369. )
  370. set_tests_properties("Benchmarking::FailureReporting::ThrowingBenchmark"
  371. PROPERTIES
  372. PASS_REGULAR_EXPRESSION "<failed message=\"just a plain literal"
  373. FAIL_REGULAR_EXPRESSION "successes=\"1\""
  374. )
  375. add_test(NAME "Benchmarking::FailureReporting::FailedAssertion"
  376. COMMAND
  377. $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "assert" -r xml
  378. )
  379. set_tests_properties("Benchmarking::FailureReporting::FailedAssertion"
  380. PROPERTIES
  381. PASS_REGULAR_EXPRESSION "<Expression success=\"false\""
  382. FAIL_REGULAR_EXPRESSION "successes=\"1\""
  383. )
  384. add_test(NAME "Benchmarking::FailureReporting::FailMacro"
  385. COMMAND
  386. $<TARGET_FILE:SelfTest> "Failing benchmarks" -c "fail" -r xml
  387. )
  388. set_tests_properties("Benchmarking::FailureReporting::FailMacro"
  389. PROPERTIES
  390. PASS_REGULAR_EXPRESSION "This benchmark only fails\, nothing else"
  391. FAIL_REGULAR_EXPRESSION "successes=\"1\""
  392. )
  393. add_test(NAME "Benchmarking::FailureReporting::ShouldFailIsRespected"
  394. COMMAND
  395. $<TARGET_FILE:SelfTest> "Failing benchmark respects should-fail"
  396. )
  397. set_tests_properties("Benchmarking::FailureReporting::ShouldFailIsRespected"
  398. PROPERTIES
  399. PASS_REGULAR_EXPRESSION "1 failed as expected"
  400. )
  401. add_test(NAME "ErrorHandling::InvalidTestSpecExitsEarly"
  402. COMMAND
  403. $<TARGET_FILE:SelfTest> "[aa,a]"
  404. )
  405. set_tests_properties("ErrorHandling::InvalidTestSpecExitsEarly"
  406. PROPERTIES
  407. PASS_REGULAR_EXPRESSION "Invalid Filter: \\[aa\,a\\]"
  408. FAIL_REGULAR_EXPRESSION "No tests ran"
  409. )
  410. if (MSVC)
  411. set(_NullFile "NUL")
  412. else()
  413. set(_NullFile "/dev/null")
  414. endif()
  415. # This test checks that there is nothing written out from the process,
  416. # but if CMake is running the tests under Valgrind or similar tool, then
  417. # that will write its own output to stdout and the test would fail.
  418. if (NOT MEMORYCHECK_COMMAND)
  419. add_test(NAME "MultiReporter::CapturingReportersDontPropagateStdOut"
  420. COMMAND
  421. $<TARGET_FILE:SelfTest> "Sends stuff to stdout and stderr"
  422. --reporter xml::out=${_NullFile}
  423. --reporter junit::out=${_NullFile}
  424. )
  425. set_tests_properties("MultiReporter::CapturingReportersDontPropagateStdOut"
  426. PROPERTIES
  427. FAIL_REGULAR_EXPRESSION ".+"
  428. )
  429. endif()
  430. add_test(NAME "MultiReporter::NonCapturingReportersPropagateStdout"
  431. COMMAND
  432. $<TARGET_FILE:SelfTest> "Sends stuff to stdout and stderr"
  433. --reporter xml::out=${_NullFile}
  434. --reporter console::out=${_NullFile}
  435. )
  436. set_tests_properties("MultiReporter::NonCapturingReportersPropagateStdout"
  437. PROPERTIES
  438. PASS_REGULAR_EXPRESSION "A string sent to stderr via clog"
  439. )
  440. add_test(NAME "Outputs::DashAsOutLocationSendsOutputToStdout"
  441. COMMAND
  442. $<TARGET_FILE:SelfTest> "Factorials are computed"
  443. --out=-
  444. --colour-mode none
  445. )
  446. set_tests_properties("Outputs::DashAsOutLocationSendsOutputToStdout"
  447. PROPERTIES
  448. PASS_REGULAR_EXPRESSION "All tests passed \\(5 assertions in 1 test case\\)"
  449. )
  450. add_test(NAME "Reporters::DashAsLocationInReporterSpecSendsOutputToStdout"
  451. COMMAND
  452. $<TARGET_FILE:SelfTest> "Factorials are computed"
  453. --reporter console::out=-
  454. --colour-mode none
  455. )
  456. set_tests_properties("Reporters::DashAsLocationInReporterSpecSendsOutputToStdout"
  457. PROPERTIES
  458. PASS_REGULAR_EXPRESSION "All tests passed \\(5 assertions in 1 test case\\)"
  459. )
  460. add_test(NAME "Reporters::ReporterSpecificColourOverridesDefaultColour"
  461. COMMAND
  462. $<TARGET_FILE:SelfTest> "Factorials are computed"
  463. --reporter console::colour-mode=ansi
  464. --colour-mode none
  465. )
  466. set_tests_properties("Reporters::ReporterSpecificColourOverridesDefaultColour"
  467. PROPERTIES
  468. PASS_REGULAR_EXPRESSION "\\[1\;32mAll tests passed"
  469. )
  470. add_test(NAME "Reporters::UnrecognizedOptionInSpecCausesError"
  471. COMMAND
  472. $<TARGET_FILE:SelfTest> "Factorials are computed"
  473. --reporter console::bad-option=ansi
  474. )
  475. set_tests_properties("Reporters::UnrecognizedOptionInSpecCausesError"
  476. PROPERTIES
  477. WILL_FAIL ON
  478. )
  479. add_test(NAME "Colours::ColourModeCanBeExplicitlySetToAnsi"
  480. COMMAND
  481. $<TARGET_FILE:SelfTest> "Factorials are computed"
  482. --reporter console
  483. --colour-mode ansi
  484. )
  485. set_tests_properties("Colours::ColourModeCanBeExplicitlySetToAnsi"
  486. PROPERTIES
  487. PASS_REGULAR_EXPRESSION "\\[1\;32mAll tests passed"
  488. )
  489. add_test(NAME "Reporters::JUnit::NamespacesAreNormalized"
  490. COMMAND
  491. $<TARGET_FILE:SelfTest>
  492. --reporter junit
  493. "A TEST_CASE_METHOD testing junit classname normalization"
  494. )
  495. set_tests_properties("Reporters::JUnit::NamespacesAreNormalized"
  496. PROPERTIES
  497. PASS_REGULAR_EXPRESSION "testcase classname=\"SelfTest(\.exe)?\\.A\\.B\\.TestClass\""
  498. )
  499. if (CATCH_ENABLE_CONFIGURE_TESTS)
  500. foreach(testName "DefaultReporter" "Disable" "DisableStringification"
  501. "ExperimentalRedirect")
  502. add_test(NAME "CMakeConfig::${testName}"
  503. COMMAND
  504. "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/TestScripts/testConfigure${testName}.py" "${CATCH_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
  505. )
  506. set_tests_properties("CMakeConfig::${testName}"
  507. PROPERTIES
  508. COST 240
  509. LABELS "uses-python"
  510. )
  511. endforeach()
  512. endif()
  513. foreach (reporterName # "Automake" - the simple .trs format does not support any kind of comments/metadata
  514. "compact"
  515. "console"
  516. "JUnit"
  517. "SonarQube"
  518. "TAP"
  519. # "TeamCity" - does not seem to support test suite-level metadata/comments
  520. "XML")
  521. add_test(NAME "Reporters:RngSeed:${reporterName}"
  522. COMMAND
  523. $<TARGET_FILE:SelfTest> "Factorials are computed"
  524. --reporter ${reporterName}
  525. --rng-seed 18181818
  526. )
  527. set_tests_properties("Reporters:RngSeed:${reporterName}"
  528. PROPERTIES
  529. PASS_REGULAR_EXPRESSION "18181818"
  530. )
  531. endforeach()
  532. list(APPEND CATCH_WARNING_TARGETS SelfTest)
  533. set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)