Home | History | Annotate | Download | only in ExtraTests
      1 #
      2 # Build extra tests.
      3 #
      4 # Requires CATCH_BUILD_EXTRA_TESTS to be defined 'true', see ../CMakeLists.txt.
      5 #
      6 
      7 cmake_minimum_required( VERSION 3.5 )
      8 
      9 project( Catch2ExtraTests LANGUAGES CXX )
     10 
     11 message( STATUS "Extra tests included" )
     12 
     13 # define folders used:
     14 
     15 set( TESTS_DIR   ${CATCH_DIR}/projects/ExtraTests )
     16 set( SINGLE_INCLUDE_PATH ${CATCH_DIR}/single_include )
     17 
     18 
     19 add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp)
     20 target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL )
     21 
     22 add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
     23 set_tests_properties(
     24     CATCH_CONFIG_PREFIX_ALL
     25   PROPERTIES
     26     PASS_REGULAR_EXPRESSION "CATCH_"
     27     FAIL_REGULAR_EXPRESSION
     28     # The spaces are important -> They disambiguate between CATCH_REQUIRE
     29     # and REQUIRE without prefix.
     30     " 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"
     31 )
     32 
     33 add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp)
     34 target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE )
     35 
     36 add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s)
     37 set_tests_properties(
     38     CATCH_CONFIG_DISABLE-1
     39   PROPERTIES
     40     PASS_REGULAR_EXPRESSION "No tests ran"
     41     FAIL_REGULAR_EXPRESSION "This should not happen"
     42 )
     43 add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests)
     44 set_tests_properties(
     45     CATCH_CONFIG_DISABLE-2
     46   PROPERTIES
     47     PASS_REGULAR_EXPRESSION "0 test cases"
     48 )
     49 
     50 
     51 add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp )
     52 add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp )
     53 
     54 foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler)
     55 target_compile_options( ${target}
     56   PRIVATE
     57     $<$<CXX_COMPILER_ID:MSVC>:/EHs-c-;/D_HAS_EXCEPTIONS=0>
     58     $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>>:-fno-exceptions>
     59 #    $<$<CXX_COMPILER_ID:Clang>:-fno-exceptions>
     60 #    $<$<CXX_COMPILER_ID:GNU>:-fno-exceptions>
     61 )
     62 endforeach()
     63 
     64 
     65 add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run")
     66 set_tests_properties(
     67     CATCH_CONFIG_DISABLE_EXCEPTIONS-1
     68   PROPERTIES
     69     PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
     70     FAIL_REGULAR_EXPRESSION "abort;terminate;fatal"
     71 )
     72 
     73 add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort")
     74 set_tests_properties(
     75     CATCH_CONFIG_DISABLE_EXCEPTIONS-2
     76   PROPERTIES
     77     PASS_REGULAR_EXPRESSION "Catch will terminate"
     78 )
     79 
     80 add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run")
     81 set_tests_properties(
     82     CATCH_CONFIG_DISABLE_EXCEPTIONS-3
     83   PROPERTIES
     84     PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed"
     85     FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
     86 )
     87 
     88 add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort")
     89 set_tests_properties(
     90     CATCH_CONFIG_DISABLE_EXCEPTIONS-4
     91   PROPERTIES
     92     PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======"
     93 )
     94 
     95 
     96 
     97 add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp)
     98 target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier )
     99 
    100 add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s)
    101 set_tests_properties(
    102     FallbackStringifier
    103   PROPERTIES
    104     PASS_REGULAR_EXPRESSION "foo{} for: { !!! }"
    105 )
    106 
    107 
    108 add_executable(DisableStringification ${TESTS_DIR}/X11-DisableStringification.cpp)
    109 target_compile_definitions( DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION )
    110 add_test(NAME CATCH_CONFIG_DISABLE_STRINGIFICATION COMMAND DisableStringification -r compact -s)
    111 set_tests_properties(
    112     CATCH_CONFIG_DISABLE_STRINGIFICATION
    113   PROPERTIES
    114     PASS_REGULAR_EXPRESSION "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
    115     FAIL_REGULAR_EXPRESSION  "Hidden{} == Hidden{}"
    116 )
    117 
    118 
    119 set( EXTRA_TEST_BINARIES
    120     PrefixedMacros
    121     DisabledMacros
    122     DisabledExceptions-DefaultHandler
    123     DisabledExceptions-CustomHandler
    124     FallbackStringifier
    125     DisableStringification
    126 )
    127 
    128 # Shared config
    129 foreach( test ${EXTRA_TEST_BINARIES} )
    130     set_property( TARGET ${test} PROPERTY CXX_STANDARD 11 )
    131     set_property( TARGET ${test} PROPERTY CXX_STANDARD_REQUIRED ON )
    132     set_property( TARGET ${test} PROPERTY CXX_EXTENSIONS OFF )
    133     target_include_directories( ${test} PRIVATE ${SINGLE_INCLUDE_PATH} )
    134 endforeach()
    135 
    136