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
This commit is contained in:
Martin Hořeňovský
2025-07-27 20:28:51 +02:00
parent fee81626d2
commit d547cae549
21 changed files with 595 additions and 23 deletions

View File

@@ -347,6 +347,38 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
unexpected exception
-------------------------------------------------------------------------------
Assertions can be nested - CHECK
-------------------------------------------------------------------------------
AssertionHandler.tests.cpp:<line number>
...............................................................................
AssertionHandler.tests.cpp:<line number>: FAILED:
REQUIRE( i > 10 )
with expansion:
2 > 10
AssertionHandler.tests.cpp:<line number>: FAILED:
CHECK( foo( 2 ) == 2 )
due to unexpected exception with message:
{ nested assertion failed }
-------------------------------------------------------------------------------
Assertions can be nested - REQUIRE
-------------------------------------------------------------------------------
AssertionHandler.tests.cpp:<line number>
...............................................................................
AssertionHandler.tests.cpp:<line number>: FAILED:
REQUIRE( i > 10 )
with expansion:
2 > 10
AssertionHandler.tests.cpp:<line number>: FAILED:
REQUIRE( foo( 2 ) == 2 )
due to unexpected exception with message:
{ nested assertion failed }
-------------------------------------------------------------------------------
Captures do not leave block with an exception
-------------------------------------------------------------------------------
@@ -619,6 +651,21 @@ Message.tests.cpp:<line number>: FAILED:
explicitly with message:
This is a failure
-------------------------------------------------------------------------------
FAIL can be nested in assertion
-------------------------------------------------------------------------------
AssertionHandler.tests.cpp:<line number>
...............................................................................
AssertionHandler.tests.cpp:<line number>: FAILED:
explicitly with message:
Throw a Catch::TestFailureException
AssertionHandler.tests.cpp:<line number>: FAILED:
CHECK_NOTHROW( do_fail() )
due to unexpected exception with message:
{ nested assertion failed }
-------------------------------------------------------------------------------
FAIL does not require an argument
-------------------------------------------------------------------------------
@@ -1672,6 +1719,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 428 | 331 passed | 76 failed | 7 skipped | 14 failed as expected
assertions: 2260 | 2089 passed | 136 failed | 35 failed as expected
test cases: 431 | 331 passed | 76 failed | 7 skipped | 17 failed as expected
assertions: 2267 | 2090 passed | 136 failed | 41 failed as expected