CMakeLists.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #
  2. # Build extra tests.
  3. #
  4. # Requires CATCH_BUILD_EXTRA_TESTS to be defined 'true', see ../CMakeLists.txt.
  5. #
  6. cmake_minimum_required( VERSION 3.5 )
  7. project( Catch2ExtraTests LANGUAGES CXX )
  8. message( STATUS "Extra tests included" )
  9. # The MinDuration reporting tests do not need separate compilation, but
  10. # they have non-trivial execution time, so they are categorized as
  11. # extra tests, so that they are run less.
  12. add_test(NAME MinDuration::SimpleThreshold COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.22 [min_duration_test])
  13. set_tests_properties(
  14. MinDuration::SimpleThreshold
  15. PROPERTIES
  16. PASS_REGULAR_EXPRESSION "s: sleep_for_250ms"
  17. FAIL_REGULAR_EXPRESSION "sleep_for_100ms"
  18. RUN_SERIAL ON # The test is timing sensitive, so we want to run it
  19. # serially to avoid false positives on oversubscribed machines
  20. )
  21. # -d yes overrides the threshold, so we should see the faster test even
  22. # with a ridiculous high min duration threshold
  23. add_test(NAME MinDuration::DurationOverrideYes COMMAND $<TARGET_FILE:SelfTest> --min-duration 1.0 -d yes [min_duration_test])
  24. set_tests_properties(
  25. MinDuration::DurationOverrideYes
  26. PROPERTIES
  27. PASS_REGULAR_EXPRESSION "s: sleep_for_100ms"
  28. )
  29. # -d no overrides the threshold, so we should never see any tests even
  30. # with ridiculously low min duration threshold
  31. add_test(NAME MinDuration::DurationOverrideNo COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.0001 -d no [min_duration_test])
  32. set_tests_properties(
  33. MinDuration::DurationOverrideNo
  34. PROPERTIES
  35. FAIL_REGULAR_EXPRESSION "sleep_for_250ms"
  36. )
  37. # ------------ end of duration reporting tests
  38. # define folders used:
  39. set( TESTS_DIR ${CATCH_DIR}/projects/ExtraTests )
  40. set( SINGLE_INCLUDE_PATH ${CATCH_DIR}/single_include )
  41. add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp)
  42. target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL )
  43. add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
  44. set_tests_properties(
  45. CATCH_CONFIG_PREFIX_ALL
  46. PROPERTIES
  47. PASS_REGULAR_EXPRESSION "CATCH_"
  48. FAIL_REGULAR_EXPRESSION
  49. # The spaces are important -> They disambiguate between CATCH_REQUIRE
  50. # and REQUIRE without prefix.
  51. " 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"
  52. )
  53. add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp)
  54. target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE )
  55. add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s)
  56. set_tests_properties(
  57. CATCH_CONFIG_DISABLE-1
  58. PROPERTIES
  59. PASS_REGULAR_EXPRESSION "No tests ran"
  60. FAIL_REGULAR_EXPRESSION "This should not happen"
  61. )
  62. add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests)
  63. set_tests_properties(
  64. CATCH_CONFIG_DISABLE-2
  65. PROPERTIES
  66. PASS_REGULAR_EXPRESSION "0 test cases"
  67. )
  68. add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp )
  69. add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp )
  70. foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler)
  71. target_compile_options( ${target}
  72. PRIVATE
  73. $<$<CXX_COMPILER_ID:MSVC>:/EHs-c-;/D_HAS_EXCEPTIONS=0>
  74. $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>>:-fno-exceptions>
  75. # $<$<CXX_COMPILER_ID:Clang>:-fno-exceptions>
  76. # $<$<CXX_COMPILER_ID:GNU>:-fno-exceptions>
  77. )
  78. endforeach()
  79. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run")
  80. set_tests_properties(
  81. CATCH_CONFIG_DISABLE_EXCEPTIONS-1
  82. PROPERTIES
  83. PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
  84. FAIL_REGULAR_EXPRESSION "abort;terminate;fatal"
  85. )
  86. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort")
  87. set_tests_properties(
  88. CATCH_CONFIG_DISABLE_EXCEPTIONS-2
  89. PROPERTIES
  90. PASS_REGULAR_EXPRESSION "Catch will terminate"
  91. )
  92. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run")
  93. set_tests_properties(
  94. CATCH_CONFIG_DISABLE_EXCEPTIONS-3
  95. PROPERTIES
  96. PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
  97. FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
  98. )
  99. add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort")
  100. set_tests_properties(
  101. CATCH_CONFIG_DISABLE_EXCEPTIONS-4
  102. PROPERTIES
  103. PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
  104. )
  105. add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp)
  106. target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier )
  107. add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s)
  108. set_tests_properties(
  109. FallbackStringifier
  110. PROPERTIES
  111. PASS_REGULAR_EXPRESSION "foo{} for: { !!! }"
  112. )
  113. add_executable(DisableStringification ${TESTS_DIR}/X11-DisableStringification.cpp)
  114. target_compile_definitions( DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION )
  115. add_test(NAME CATCH_CONFIG_DISABLE_STRINGIFICATION COMMAND DisableStringification -r compact -s)
  116. set_tests_properties(
  117. CATCH_CONFIG_DISABLE_STRINGIFICATION
  118. PROPERTIES
  119. PASS_REGULAR_EXPRESSION "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  120. FAIL_REGULAR_EXPRESSION "Hidden{} == Hidden{}"
  121. )
  122. add_executable(BenchmarkingMacros ${TESTS_DIR}/X20-BenchmarkingMacros.cpp)
  123. target_compile_definitions( BenchmarkingMacros PRIVATE CATCH_CONFIG_ENABLE_BENCHMARKING )
  124. add_test(NAME BenchmarkingMacros COMMAND BenchmarkingMacros -r console -s)
  125. set_tests_properties(
  126. BenchmarkingMacros
  127. PROPERTIES
  128. PASS_REGULAR_EXPRESSION "benchmark name[\\r\\n\\t ]+samples[\\r\\n\\t ]+iterations[\\r\\n\\t ]+estimated"
  129. )
  130. # This test touches windows.h, so it should only be compiled under msvc
  131. if (MSVC)
  132. # This test fails if it does not compile and succeeds otherwise
  133. add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp)
  134. set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD 11 )
  135. set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD_REQUIRED ON )
  136. set_property( TARGET WindowsHeader PROPERTY CXX_EXTENSIONS OFF )
  137. target_include_directories( WindowsHeader PRIVATE ${SINGLE_INCLUDE_PATH} )
  138. add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact)
  139. endif()
  140. add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp)
  141. add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break)
  142. set_tests_properties(
  143. DebugBreakMacros
  144. PROPERTIES
  145. PASS_REGULAR_EXPRESSION "Pretty please, break into debugger"
  146. )
  147. set( EXTRA_TEST_BINARIES
  148. PrefixedMacros
  149. DisabledMacros
  150. DisabledExceptions-DefaultHandler
  151. DisabledExceptions-CustomHandler
  152. FallbackStringifier
  153. DisableStringification
  154. BenchmarkingMacros
  155. DebugBreakMacros
  156. )
  157. # Shared config
  158. foreach( test ${EXTRA_TEST_BINARIES} )
  159. set_property( TARGET ${test} PROPERTY CXX_STANDARD 11 )
  160. set_property( TARGET ${test} PROPERTY CXX_STANDARD_REQUIRED ON )
  161. set_property( TARGET ${test} PROPERTY CXX_EXTENSIONS OFF )
  162. target_include_directories( ${test} PRIVATE ${SINGLE_INCLUDE_PATH} )
  163. endforeach()