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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-09-23 11:01:27 +0200
committerMartin Hořeňovský2025-09-23 11:46:26 +0200
commit434bf55d4727ab1d1aef244ef16823a0ed1e6b4a (patch)
treee891786493ba589f694459bc85f246e5a6d3e862 /src/catch2/internal
parent9048c24fa7c6b568d52f76cbf06bbd62b7f83556 (diff)
downloadcatch3-434bf55d4727ab1d1aef244ef16823a0ed1e6b4a.tar.gz
Make message push/pop static
Since the change to make the message macros thread-safe, and thus thread-local, there is no need to handle messages through instance of `RunContext`.
Diffstat (limited to 'src/catch2/internal')
-rw-r--r--src/catch2/internal/catch_run_context.cpp44
-rw-r--r--src/catch2/internal/catch_run_context.hpp5
2 files changed, 22 insertions, 27 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 3ca15fd0..fc521f8b 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -483,28 +483,6 @@ namespace Catch {
m_reporter->benchmarkFailed( error );
}
- void RunContext::pushScopedMessage( MessageInfo&& message ) {
- Detail::g_messages.push_back( CATCH_MOVE(message) );
- }
-
- void RunContext::popScopedMessage( unsigned int messageId ) {
- // Note: On average, it would probably be better to look for the message
- // backwards. However, we do not expect to have to deal with more
- // messages than low single digits, so the optimization is tiny,
- // and we would have to hand-write the loop to avoid terrible
- // codegen of reverse iterators in debug mode.
- Detail::g_messages.erase(
- std::find_if( Detail::g_messages.begin(),
- Detail::g_messages.end(),
- [=]( MessageInfo const& msg ) {
- return msg.sequence == messageId;
- } ) );
- }
-
- void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) {
- Detail::g_messageScopes.emplace_back( CATCH_MOVE(builder) );
- }
-
std::string RunContext::getCurrentTestName() const {
return m_activeTestCase
? m_activeTestCase->getTestCaseInfo().name
@@ -838,6 +816,28 @@ namespace Catch {
CATCH_INTERNAL_ERROR("No result capture instance");
}
+ void IResultCapture::pushScopedMessage( MessageInfo&& message ) {
+ Detail::g_messages.push_back( CATCH_MOVE( message ) );
+ }
+
+ void IResultCapture::popScopedMessage( unsigned int messageId ) {
+ // Note: On average, it would probably be better to look for the message
+ // backwards. However, we do not expect to have to deal with more
+ // messages than low single digits, so the optimization is tiny,
+ // and we would have to hand-write the loop to avoid terrible
+ // codegen of reverse iterators in debug mode.
+ Detail::g_messages.erase( std::find_if( Detail::g_messages.begin(),
+ Detail::g_messages.end(),
+ [=]( MessageInfo const& msg ) {
+ return msg.sequence ==
+ messageId;
+ } ) );
+ }
+
+ void IResultCapture::emplaceUnscopedMessage( MessageBuilder&& builder ) {
+ Detail::g_messageScopes.emplace_back( CATCH_MOVE( builder ) );
+ }
+
void seedRng(IConfig const& config) {
sharedRng().seed(config.rngSeed());
}
diff --git a/src/catch2/internal/catch_run_context.hpp b/src/catch2/internal/catch_run_context.hpp
index 1ff9caf6..dee851e0 100644
--- a/src/catch2/internal/catch_run_context.hpp
+++ b/src/catch2/internal/catch_run_context.hpp
@@ -94,11 +94,6 @@ namespace Catch {
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
void benchmarkFailed( StringRef error ) override;
- void pushScopedMessage( MessageInfo&& message ) override;
- void popScopedMessage( unsigned int messageId ) override;
-
- void emplaceUnscopedMessage( MessageBuilder&& builder ) override;
-
std::string getCurrentTestName() const override;
const AssertionResult* getLastResult() const override;