WIP: allow inlining context retrieval

This commit is contained in:
Martin Hořeňovský
2025-09-23 15:23:58 +02:00
parent bbc5134e3a
commit b8a217fbcc
2 changed files with 21 additions and 8 deletions

View File

@@ -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,19 @@ 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();
}
}
}

View File

@@ -21,6 +21,7 @@
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp>
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
#include <cassert>
#include <algorithm>
@@ -809,13 +810,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 ) );
}
@@ -846,4 +840,10 @@ namespace Catch {
return getCurrentContext().getConfig()->rngSeed();
}
namespace Detail {
void missingCaptureInstance() {
CATCH_INTERNAL_ERROR( "No result capture instance" );
}
} // namespace Detail
}