Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-11-05 00:22:45 +0100
committerMartin Hořeňovský2022-11-05 00:22:45 +0100
commit5f9d4ef3319f2b13011161662ca2b02d0feb4667 (patch)
tree8d64bc6b62fb4ec1c12078cc8cef53aa9fb55a5c /src
parentec59cd8736b7ee8fcd69c76c71c2a0b72293b00c (diff)
downloadcatch3-5f9d4ef3319f2b13011161662ca2b02d0feb4667.tar.gz
Move throwing test failure exceptions into a helper
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/catch2/internal/catch_assertion_handler.cpp6
-rw-r--r--src/catch2/internal/catch_test_failure_exception.cpp23
-rw-r--r--src/catch2/internal/catch_test_failure_exception.hpp7
-rw-r--r--src/catch2/meson.build1
5 files changed, 33 insertions, 5 deletions
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 <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
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',