Skip to content

Commit 3ab0d7c

Browse files
committed
Turn IResultCapture::{push,pop}*Message into free functions
The thread-safety changes in assertions & messages turned the message stacks into thread-local state, instead of it being member of `RunContext`. The relevant {push,pop}(Un)ScopedMessage functions were turned from member functions into static functions, but this left `catch_message.hpp` with dependency on `IResultCapture`'s definition for the functions, and thus it still had to include `catch_interfaces_capture.hpp`. With this change, `catch_message.hpp` no longer needs `catch_interfaces_capture.hpp`.
1 parent e83218c commit 3ab0d7c

4 files changed

Lines changed: 36 additions & 30 deletions

File tree

src/catch2/catch_message.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// https://www.boost.org/LICENSE_1_0.txt)
66

77
// SPDX-License-Identifier: BSL-1.0
8+
89
#include <catch2/catch_message.hpp>
9-
#include <catch2/interfaces/catch_interfaces_capture.hpp>
1010
#include <catch2/internal/catch_enforce.hpp>
1111
#include <catch2/internal/catch_move_and_forward.hpp>
1212

@@ -22,7 +22,7 @@ namespace Catch {
2222
m_messageId( builder.m_info.sequence ) {
2323
MessageInfo info( CATCH_MOVE( builder.m_info ) );
2424
info.message = builder.m_stream.str();
25-
IResultCapture::pushScopedMessage( CATCH_MOVE( info ) );
25+
Detail::pushScopedMessage( CATCH_MOVE( info ) );
2626
}
2727

2828
ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
@@ -31,7 +31,7 @@ namespace Catch {
3131
}
3232

3333
ScopedMessage::~ScopedMessage() {
34-
if ( !m_moved ) { IResultCapture::popScopedMessage( m_messageId ); }
34+
if ( !m_moved ) { Detail::popScopedMessage( m_messageId ); }
3535
}
3636

3737

@@ -103,7 +103,7 @@ namespace Catch {
103103
assert( m_captured == m_messages.size() );
104104
if ( m_isScoped ) {
105105
for ( auto const& message : m_messages ) {
106-
IResultCapture::popScopedMessage( message.sequence );
106+
Detail::popScopedMessage( message.sequence );
107107
}
108108
}
109109
}
@@ -112,9 +112,9 @@ namespace Catch {
112112
assert( index < m_messages.size() );
113113
m_messages[index].message += value;
114114
if ( m_isScoped ) {
115-
IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) );
115+
Detail::pushScopedMessage( CATCH_MOVE( m_messages[index] ) );
116116
} else {
117-
IResultCapture::addUnscopedMessage( CATCH_MOVE( m_messages[index] ) );
117+
Detail::addUnscopedMessage( CATCH_MOVE( m_messages[index] ) );
118118
}
119119
m_captured++;
120120
}

src/catch2/catch_message.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@
1414
#include <catch2/internal/catch_stream_end_stop.hpp>
1515
#include <catch2/internal/catch_message_info.hpp>
1616
#include <catch2/catch_tostring.hpp>
17-
#include <catch2/interfaces/catch_interfaces_capture.hpp>
1817

1918
#include <string>
2019
#include <vector>
2120

2221
namespace Catch {
22+
struct MessageInfo;
23+
struct MessageBuilder;
24+
25+
namespace Detail {
26+
// The message state affecting functions have to be defined in
27+
// the TU where the thread-local message holders are defined.
28+
// Currently this is catch_run_context.cpp
29+
30+
void pushScopedMessage( MessageInfo&& message );
31+
void popScopedMessage( unsigned int messageId );
32+
void addUnscopedMessage( MessageInfo&& message );
33+
void emplaceUnscopedMessage( MessageBuilder&& builder );
34+
} // namespace Detail
2335

2436
struct SourceLineInfo;
25-
class IResultCapture;
2637

2738
struct MessageStream {
2839

@@ -112,7 +123,7 @@ namespace Catch {
112123

113124
///////////////////////////////////////////////////////////////////////////////
114125
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
115-
Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
126+
Catch::Detail::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
116127

117128

118129
#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)

src/catch2/interfaces/catch_interfaces_capture.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace Catch {
2222
struct AssertionInfo;
2323
struct SectionInfo;
2424
struct SectionEndInfo;
25-
struct MessageInfo;
26-
struct MessageBuilder;
2725
struct Counts;
2826
struct AssertionReaction;
2927
struct SourceLineInfo;
@@ -63,10 +61,6 @@ namespace Catch {
6361
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
6462
virtual void benchmarkFailed( StringRef error ) = 0;
6563

66-
static void pushScopedMessage( MessageInfo&& message );
67-
static void popScopedMessage( unsigned int messageId );
68-
static void addUnscopedMessage( MessageInfo&& message );
69-
static void emplaceUnscopedMessage( MessageBuilder&& builder );
7064

7165
virtual void handleFatalErrorCondition( StringRef message ) = 0;
7266

src/catch2/internal/catch_run_context.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,22 @@ namespace Catch {
308308
}
309309
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
310310

311+
312+
void pushScopedMessage( MessageInfo&& message ) {
313+
Detail::g_messageHolder().addScopedMessage( CATCH_MOVE( message ) );
314+
}
315+
316+
void popScopedMessage( unsigned int messageId ) {
317+
Detail::g_messageHolder().removeMessage( messageId );
318+
}
319+
320+
void emplaceUnscopedMessage( MessageBuilder&& builder ) {
321+
Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( builder ) );
322+
}
323+
324+
void addUnscopedMessage( MessageInfo&& message ) {
325+
Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) );
326+
}
311327
} // namespace Detail
312328

313329
RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter)
@@ -937,21 +953,6 @@ namespace Catch {
937953
}
938954
}
939955

940-
void IResultCapture::pushScopedMessage( MessageInfo&& message ) {
941-
Detail::g_messageHolder().addScopedMessage( CATCH_MOVE( message ) );
942-
}
943-
944-
void IResultCapture::popScopedMessage( unsigned int messageId ) {
945-
Detail::g_messageHolder().removeMessage( messageId );
946-
}
947-
948-
void IResultCapture::emplaceUnscopedMessage( MessageBuilder&& builder ) {
949-
Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( builder ) );
950-
}
951-
952-
void IResultCapture::addUnscopedMessage( MessageInfo&& message ) {
953-
Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) );
954-
}
955956

956957
void seedRng(IConfig const& config) {
957958
sharedRng().seed(config.rngSeed());

0 commit comments

Comments
 (0)