diff options
| author | Martin Hořeňovský | 2025-07-27 20:28:51 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-07-27 21:41:02 +0200 |
| commit | d547cae549f484dda3c6a2b3cc5f71b9db40e842 (patch) | |
| tree | fb947c6dd70b9eb5e8d7fd792bd85684b454d0fd /tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp | |
| parent | fee81626d2a4811095c3a39d20fb355eeb954101 (diff) | |
| download | catch3-d547cae549f484dda3c6a2b3cc5f71b9db40e842.tar.gz | |
Fix bad error reporting for nested exceptions in default configuration
Bad handling of `TestFailureException` when translating unexpected
exceptions inside assertion macros led to the unexpected exceptions
handling erroring out through throwing the same exception again.
This was then backstopped by the machinery for handling uncaught
exceptions from assertions, which is normally used by the
`CATCH_CONFIG_FAST_COMPILE` machinery, where we assume that it can
only be invoked because the assertion macros are not configured to
catch assertions.
Closes #1292
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp b/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp index ab096074..15966a07 100644 --- a/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp @@ -15,3 +15,28 @@ TEST_CASE( "Incomplete AssertionHandler", "[assertion-handler][!shouldfail]" ) { "Dummy", Catch::ResultDisposition::Normal ); } + + +static int foo( int i ) { + REQUIRE( i > 10 ); + return 42; +} + +TEST_CASE( "Assertions can be nested - CHECK", "[assertions][!shouldfail]" ) { + CHECK( foo( 2 ) == 2 ); + // We should hit this, because CHECK continues on failure + CHECK( true ); +} + +TEST_CASE( "Assertions can be nested - REQUIRE", "[assertions][!shouldfail]" ) { + REQUIRE( foo( 2 ) == 2 ); + // We should not hit this, because REQUIRE does not continue on failure + CHECK( true ); +} + +static void do_fail() { FAIL( "Throw a Catch::TestFailureException" ); } + +TEST_CASE( "FAIL can be nested in assertion", "[assertions][!shouldfail]" ) { + // Fails, but the error message makes sense. + CHECK_NOTHROW( do_fail() ); +} |