mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 13:25:41 +02:00

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
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
|
|
// Copyright Catch2 Authors
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE.txt or copy at
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
TEST_CASE( "Incomplete AssertionHandler", "[assertion-handler][!shouldfail]" ) {
|
|
Catch::AssertionHandler catchAssertionHandler(
|
|
"REQUIRE"_catch_sr,
|
|
CATCH_INTERNAL_LINEINFO,
|
|
"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() );
|
|
}
|