diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 98f2ffd8..25a5e1ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/catch2/internal/catch_assertion_handler.cpp b/src/catch2/internal/catch_assertion_handler.cpp index 96e5c8b3..bfa0897d 100644 --- a/src/catch2/internal/catch_assertion_handler.cpp +++ b/src/catch2/internal/catch_assertion_handler.cpp @@ -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() { diff --git a/src/catch2/internal/catch_test_failure_exception.cpp b/src/catch2/internal/catch_test_failure_exception.cpp new file mode 100644 index 00000000..c1edff3c --- /dev/null +++ b/src/catch2/internal/catch_test_failure_exception.cpp @@ -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 +#include +#include + +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 diff --git a/src/catch2/internal/catch_test_failure_exception.hpp b/src/catch2/internal/catch_test_failure_exception.hpp index 8dc32b46..810a81c9 100644 --- a/src/catch2/internal/catch_test_failure_exception.hpp +++ b/src/catch2/internal/catch_test_failure_exception.hpp @@ -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 diff --git a/src/catch2/meson.build b/src/catch2/meson.build index 1083897d..9cdaf9d9 100644 --- a/src/catch2/meson.build +++ b/src/catch2/meson.build @@ -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',