catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Inline the `getResultCapture` helper into header.
- Commit
756ae05d307168eaa27bd904dbd8e591a6406889- Author
- Martin Hořeňovský ·
- Parents
a2e41916f2cc
Changes
src/catch2/interfaces/catch_interfaces_capture.cpp | 9 ++++++++- src/catch2/interfaces/catch_interfaces_capture.hpp | 13 ++++++++++++- src/catch2/internal/catch_context.hpp | 1 - src/catch2/internal/catch_run_context.cpp | 7 ------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/catch2/interfaces/catch_interfaces_capture.cpp b/src/catch2/interfaces/catch_interfaces_capture.cpp index 9b40ee5d..492c5bd9 100644 --- a/src/catch2/interfaces/catch_interfaces_capture.cpp +++ b/src/catch2/interfaces/catch_interfaces_capture.cpp @@ -7,7 +7,14 @@ // SPDX-License-Identifier: BSL-1.0 #include <catch2/interfaces/catch_interfaces_capture.hpp> +#include <catch2/internal/catch_enforce.hpp> namespace Catch { + namespace Detail { + void missingCaptureInstance() { + CATCH_INTERNAL_ERROR( "No result capture instance" ); + } + } // namespace Detail + IResultCapture::~IResultCapture() = default; -} +} // namespace Catch diff --git a/src/catch2/interfaces/catch_interfaces_capture.hpp b/src/catch2/interfaces/catch_interfaces_capture.hpp index 702ccb4d..4e27a985 100644 --- a/src/catch2/interfaces/catch_interfaces_capture.hpp +++ b/src/catch2/interfaces/catch_interfaces_capture.hpp @@ -10,6 +10,7 @@ #include <string> +#include <catch2/internal/catch_context.hpp> #include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_result_type.hpp> #include <catch2/internal/catch_unique_ptr.hpp> @@ -100,7 +101,17 @@ namespace Catch { virtual void exceptionEarlyReported() = 0; }; - IResultCapture& getResultCapture(); + namespace Detail { + [[noreturn]] + void missingCaptureInstance(); + } + inline IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) { + return *capture; + } else { + Detail::missingCaptureInstance(); + } + } } diff --git a/src/catch2/internal/catch_context.hpp b/src/catch2/internal/catch_context.hpp index e35de4b4..0b89632c 100644 --- a/src/catch2/internal/catch_context.hpp +++ b/src/catch2/internal/catch_context.hpp @@ -32,7 +32,6 @@ namespace Catch { m_resultCapture = resultCapture; } constexpr void setConfig( IConfig const* config ) { m_config = config; } - }; Context& getCurrentMutableContext(); diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index fc521f8b..0029bf56 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -809,13 +809,6 @@ namespace Catch { } } - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); - } - void IResultCapture::pushScopedMessage( MessageInfo&& message ) { Detail::g_messages.push_back( CATCH_MOVE( message ) ); }