diff --git a/projects/ExtraTests/CMakeLists.txt b/projects/ExtraTests/CMakeLists.txt index 27556c82..c0dd82d8 100644 --- a/projects/ExtraTests/CMakeLists.txt +++ b/projects/ExtraTests/CMakeLists.txt @@ -48,6 +48,52 @@ set_tests_properties( ) +add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp ) +add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp ) + +foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler) +target_compile_options( ${target} + PRIVATE + $<$:/EHs-c-;/D_HAS_EXCEPTIONS=0> + $<$,$,$>:-fno-exceptions> +# $<$:-fno-exceptions> +# $<$:-fno-exceptions> +) +endforeach() + + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-1 + PROPERTIES + PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" + FAIL_REGULAR_EXPRESSION "abort;terminate;fatal" +) + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-2 + PROPERTIES + PASS_REGULAR_EXPRESSION "Catch will terminate" +) + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-3 + PROPERTIES + PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" + FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" +) + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-4 + PROPERTIES + PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" +) + + + add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp) target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier ) @@ -73,6 +119,8 @@ set_tests_properties( set( EXTRA_TEST_BINARIES PrefixedMacros DisabledMacros + DisabledExceptions-DefaultHandler + DisabledExceptions-CustomHandler FallbackStringifier DisableStringification ) diff --git a/projects/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp b/projects/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp new file mode 100644 index 00000000..846c9b0f --- /dev/null +++ b/projects/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp @@ -0,0 +1,23 @@ +#define CATCH_CONFIG_MAIN +#include + +TEST_CASE("Tests that run") { + // All of these should be run and be reported + CHECK(1 == 2); + CHECK(1 == 1); + CHECK(1 != 3); + CHECK(1 == 4); +} + + + +TEST_CASE("Tests that abort") { + // Avoid abort and other exceptional exits -- there is no way + // to tell CMake that abort is the desired outcome of a test. + std::set_terminate([](){exit(1);}); + REQUIRE(1 == 1); + REQUIRE(1 != 2); + REQUIRE(1 == 3); + // We should not get here, because the test above aborts + REQUIRE(1 != 4); +} diff --git a/projects/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp b/projects/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp new file mode 100644 index 00000000..96f3ceb8 --- /dev/null +++ b/projects/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp @@ -0,0 +1,33 @@ +#define CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER + +#define CATCH_CONFIG_MAIN +#include + +namespace Catch { + [[noreturn]] + void throw_exception(std::exception const& e) { + Catch::cerr() << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n" + << "The message was: " << e.what() << '\n'; + // Avoid abort and other exceptional exits -- there is no way + // to tell CMake that abort is the desired outcome of a test. + exit(1); + } +} + +TEST_CASE("Tests that run") { + // All of these should be run and be reported + CHECK(1 == 2); + CHECK(1 == 1); + CHECK(1 != 3); + CHECK(1 == 4); +} + + + +TEST_CASE("Tests that abort") { + REQUIRE(1 == 1); + REQUIRE(1 != 2); + REQUIRE(1 == 3); + // We should not get here, because the test above aborts + REQUIRE(1 != 4); +}