mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Add ExtraTest for CATCH_CONFIG_DISABLE
This commit is contained in:
parent
8b01883854
commit
a5c900d077
@ -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
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/EHs-c-;/D_HAS_EXCEPTIONS=0>
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>>:-fno-exceptions>
|
||||
# $<$<CXX_COMPILER_ID:Clang>:-fno-exceptions>
|
||||
# $<$<CXX_COMPILER_ID:GNU>:-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
|
||||
)
|
||||
|
@ -0,0 +1,23 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
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);
|
||||
}
|
33
projects/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp
Normal file
33
projects/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#define CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user