mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-25 06:31:07 +02:00
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`.
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Catch {
|
|||||||
m_messageId( builder.m_info.sequence ) {
|
m_messageId( builder.m_info.sequence ) {
|
||||||
MessageInfo info( CATCH_MOVE( builder.m_info ) );
|
MessageInfo info( CATCH_MOVE( builder.m_info ) );
|
||||||
info.message = builder.m_stream.str();
|
info.message = builder.m_stream.str();
|
||||||
getResultCapture().pushScopedMessage( CATCH_MOVE(info) );
|
IResultCapture::pushScopedMessage( CATCH_MOVE( info ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
|
ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
|
||||||
@@ -31,15 +31,14 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScopedMessage::~ScopedMessage() {
|
ScopedMessage::~ScopedMessage() {
|
||||||
if ( !m_moved ) { getResultCapture().popScopedMessage( m_messageId ); }
|
if ( !m_moved ) { IResultCapture::popScopedMessage( m_messageId ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Capturer::Capturer( StringRef macroName,
|
Capturer::Capturer( StringRef macroName,
|
||||||
SourceLineInfo const& lineInfo,
|
SourceLineInfo const& lineInfo,
|
||||||
ResultWas::OfType resultType,
|
ResultWas::OfType resultType,
|
||||||
StringRef names ):
|
StringRef names ) {
|
||||||
m_resultCapture( getResultCapture() ) {
|
|
||||||
auto trimmed = [&] (size_t start, size_t end) {
|
auto trimmed = [&] (size_t start, size_t end) {
|
||||||
while (names[start] == ',' || isspace(static_cast<unsigned char>(names[start]))) {
|
while (names[start] == ',' || isspace(static_cast<unsigned char>(names[start]))) {
|
||||||
++start;
|
++start;
|
||||||
@@ -101,14 +100,14 @@ namespace Catch {
|
|||||||
Capturer::~Capturer() {
|
Capturer::~Capturer() {
|
||||||
assert( m_captured == m_messages.size() );
|
assert( m_captured == m_messages.size() );
|
||||||
for (auto const& message : m_messages) {
|
for (auto const& message : m_messages) {
|
||||||
m_resultCapture.popScopedMessage( message.sequence );
|
IResultCapture::popScopedMessage( message.sequence );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Capturer::captureValue( size_t index, std::string const& value ) {
|
void Capturer::captureValue( size_t index, std::string const& value ) {
|
||||||
assert( index < m_messages.size() );
|
assert( index < m_messages.size() );
|
||||||
m_messages[index].message += value;
|
m_messages[index].message += value;
|
||||||
m_resultCapture.pushScopedMessage( CATCH_MOVE(m_messages[index]) );
|
IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) );
|
||||||
m_captured++;
|
m_captured++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,7 +63,6 @@ namespace Catch {
|
|||||||
|
|
||||||
class Capturer {
|
class Capturer {
|
||||||
std::vector<MessageInfo> m_messages;
|
std::vector<MessageInfo> m_messages;
|
||||||
IResultCapture& m_resultCapture;
|
|
||||||
size_t m_captured = 0;
|
size_t m_captured = 0;
|
||||||
public:
|
public:
|
||||||
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
|
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
|
||||||
@@ -111,7 +110,7 @@ namespace Catch {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
|
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
|
||||||
Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
|
Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
|
||||||
|
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
|
#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
|
||||||
|
@@ -62,10 +62,9 @@ namespace Catch {
|
|||||||
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
|
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
|
||||||
virtual void benchmarkFailed( StringRef error ) = 0;
|
virtual void benchmarkFailed( StringRef error ) = 0;
|
||||||
|
|
||||||
virtual void pushScopedMessage( MessageInfo&& message ) = 0;
|
static void pushScopedMessage( MessageInfo&& message );
|
||||||
virtual void popScopedMessage( unsigned int messageId ) = 0;
|
static void popScopedMessage( unsigned int messageId );
|
||||||
|
static void emplaceUnscopedMessage( MessageBuilder&& builder );
|
||||||
virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0;
|
|
||||||
|
|
||||||
virtual void handleFatalErrorCondition( StringRef message ) = 0;
|
virtual void handleFatalErrorCondition( StringRef message ) = 0;
|
||||||
|
|
||||||
@@ -102,6 +101,7 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
IResultCapture& getResultCapture();
|
IResultCapture& getResultCapture();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
|
#endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
|
||||||
|
@@ -483,28 +483,6 @@ namespace Catch {
|
|||||||
m_reporter->benchmarkFailed( error );
|
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 {
|
std::string RunContext::getCurrentTestName() const {
|
||||||
return m_activeTestCase
|
return m_activeTestCase
|
||||||
? m_activeTestCase->getTestCaseInfo().name
|
? m_activeTestCase->getTestCaseInfo().name
|
||||||
@@ -838,6 +816,28 @@ namespace Catch {
|
|||||||
CATCH_INTERNAL_ERROR("No result capture instance");
|
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) {
|
void seedRng(IConfig const& config) {
|
||||||
sharedRng().seed(config.rngSeed());
|
sharedRng().seed(config.rngSeed());
|
||||||
}
|
}
|
||||||
|
@@ -94,11 +94,6 @@ namespace Catch {
|
|||||||
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
|
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
|
||||||
void benchmarkFailed( StringRef error ) 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;
|
std::string getCurrentTestName() const override;
|
||||||
|
|
||||||
const AssertionResult* getLastResult() const override;
|
const AssertionResult* getLastResult() const override;
|
||||||
|
Reference in New Issue
Block a user