Move throwing test failure exceptions into a helper

This commit is contained in:
Martin Hořeňovský 2022-11-05 00:22:45 +01:00
parent ec59cd8736
commit 5f9d4ef331
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
5 changed files with 33 additions and 5 deletions

View File

@ -176,6 +176,7 @@ set(IMPL_SOURCES
${SOURCES_DIR}/internal/catch_commandline.cpp
${SOURCES_DIR}/internal/catch_source_line_info.cpp
${SOURCES_DIR}/catch_config.cpp
${SOURCES_DIR}/internal/catch_test_failure_exception.cpp
${SOURCES_DIR}/internal/catch_case_insensitive_comparisons.cpp
${SOURCES_DIR}/internal/catch_console_colour.cpp
${SOURCES_DIR}/internal/catch_context.cpp

View File

@ -48,11 +48,7 @@ namespace Catch {
CATCH_BREAK_INTO_DEBUGGER();
}
if (m_reaction.shouldThrow) {
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
throw Catch::TestFailureException();
#else
CATCH_ERROR( "Test failure requires aborting test!" );
#endif
throw_test_failure_exception();
}
}
void AssertionHandler::setCompleted() {

View File

@ -0,0 +1,23 @@
// 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/internal/catch_test_failure_exception.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/catch_user_config.hpp>
namespace Catch {
void throw_test_failure_exception() {
#if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS )
throw TestFailureException{};
#else
CATCH_ERROR( "Test failure requires aborting test!" );
#endif
}
} // namespace Catch

View File

@ -13,6 +13,13 @@ namespace Catch {
//! Used to signal that an assertion macro failed
struct TestFailureException{};
/**
* Outlines throwing of `TestFailureException` into a single TU
*
* Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers.
*/
[[noreturn]] void throw_test_failure_exception();
} // namespace Catch
#endif // CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED

View File

@ -231,6 +231,7 @@ internal_sources = files(
'internal/catch_test_case_info_hasher.cpp',
'internal/catch_test_case_registry_impl.cpp',
'internal/catch_test_case_tracker.cpp',
'internal/catch_test_failure_exception.cpp',
'internal/catch_test_registry.cpp',
'internal/catch_test_spec_parser.cpp',
'internal/catch_textflow.cpp',