mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
INFO and CAPTURE are now scoped
- SCOPED_INFO and SCOPED_CAPTURE are now just aliases
This commit is contained in:
@@ -74,9 +74,9 @@
|
||||
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN" )
|
||||
#define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL" )
|
||||
#define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED" )
|
||||
#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "CATCH_SCOPED_INFO" )
|
||||
#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
|
||||
#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
|
||||
#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "CATCH_SCOPED_CAPTURE" )
|
||||
#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
|
||||
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||
@@ -135,9 +135,9 @@
|
||||
#define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN" )
|
||||
#define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL" )
|
||||
#define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED" )
|
||||
#define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "SCOPED_INFO" )
|
||||
#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
|
||||
#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
|
||||
#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "SCOPED_CAPTURE" )
|
||||
#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
|
||||
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||
|
@@ -145,11 +145,6 @@ struct TestFailureException{};
|
||||
} \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_INFO( log, macroName ) \
|
||||
do { \
|
||||
Catch::getResultCapture().acceptMessage( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); \
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_MSG( log, messageType, resultDisposition, macroName ) \
|
||||
@@ -159,10 +154,8 @@ struct TestFailureException{};
|
||||
} while( Catch::isTrue( false ) )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \
|
||||
Catch::ScopedMessageBuilder INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ); \
|
||||
INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) << log; \
|
||||
Catch::getResultCapture().pushScopedMessage( INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) )
|
||||
#define INTERNAL_CATCH_INFO( log, macroName ) \
|
||||
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -20,7 +20,7 @@ namespace Catch {
|
||||
class AssertionResult;
|
||||
struct AssertionInfo;
|
||||
struct SectionInfo;
|
||||
class MessageBuilder;
|
||||
struct MessageInfo;
|
||||
class ScopedMessageBuilder;
|
||||
|
||||
struct IResultCapture {
|
||||
@@ -31,12 +31,11 @@ namespace Catch {
|
||||
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
||||
Counts& assertions ) = 0;
|
||||
virtual void sectionEnded( SectionInfo const& name, Counts const& assertions ) = 0;
|
||||
virtual void pushScopedMessage( ScopedMessageBuilder const& _builder ) = 0;
|
||||
virtual void popScopedMessage( ScopedMessageBuilder const& _builder ) = 0;
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
||||
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
||||
|
||||
virtual bool shouldDebugBreak() const = 0;
|
||||
|
||||
virtual void acceptMessage( MessageBuilder const& messageBuilder ) = 0;
|
||||
virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) = 0;
|
||||
|
||||
virtual std::string getCurrentTestName() const = 0;
|
||||
|
@@ -102,7 +102,9 @@ namespace Catch
|
||||
// !TBD This should have been done earlier, somewhere
|
||||
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
||||
builder << assertionResult.getMessage();
|
||||
infoMessages.push_back( builder.build() );
|
||||
builder.m_info.message = builder.m_stream.str();
|
||||
|
||||
infoMessages.push_back( builder.m_info );
|
||||
}
|
||||
}
|
||||
virtual ~AssertionStats();
|
||||
|
@@ -35,30 +35,29 @@ namespace Catch {
|
||||
static unsigned int globalCount;
|
||||
};
|
||||
|
||||
|
||||
class MessageBuilder : public MessageInfo {
|
||||
public:
|
||||
MessageBuilder( std::string const& _macroName,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
ResultWas::OfType _type );
|
||||
|
||||
MessageInfo build() const;
|
||||
struct MessageBuilder {
|
||||
MessageBuilder( std::string const& macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
ResultWas::OfType type )
|
||||
: m_info( macroName, lineInfo, type )
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
MessageBuilder& operator << ( T const& _value ) {
|
||||
stream << _value;
|
||||
MessageBuilder& operator << ( T const& value ) {
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
std::ostringstream stream;
|
||||
|
||||
MessageInfo m_info;
|
||||
std::ostringstream m_stream;
|
||||
};
|
||||
|
||||
class ScopedMessageBuilder : public MessageBuilder {
|
||||
|
||||
class ScopedMessage {
|
||||
public:
|
||||
ScopedMessageBuilder( std::string const& _macroName,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
ResultWas::OfType _type );
|
||||
~ScopedMessageBuilder();
|
||||
ScopedMessage( MessageBuilder const& builder );
|
||||
~ScopedMessage();
|
||||
|
||||
MessageInfo m_info;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@@ -24,31 +24,17 @@ namespace Catch {
|
||||
// This may need protecting if threading support is added
|
||||
unsigned int MessageInfo::globalCount = 0;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MessageBuilder::MessageBuilder( std::string const& _macroName,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
ResultWas::OfType _type )
|
||||
: MessageInfo( _macroName, _lineInfo, _type )
|
||||
{}
|
||||
|
||||
MessageInfo MessageBuilder::build() const {
|
||||
MessageInfo message = *this;
|
||||
message.message = stream.str();
|
||||
return message;
|
||||
ScopedMessage::ScopedMessage( MessageBuilder const& builder )
|
||||
: m_info( builder.m_info )
|
||||
{
|
||||
m_info.message = builder.m_stream.str();
|
||||
getResultCapture().pushScopedMessage( m_info );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ScopedMessageBuilder::ScopedMessageBuilder
|
||||
( std::string const& _macroName,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
ResultWas::OfType _type )
|
||||
: MessageBuilder( _macroName, _lineInfo, _type )
|
||||
{}
|
||||
|
||||
ScopedMessageBuilder::~ScopedMessageBuilder() {
|
||||
getResultCapture().popScopedMessage( *this );
|
||||
ScopedMessage::~ScopedMessage() {
|
||||
getResultCapture().popScopedMessage( m_info );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -154,10 +154,6 @@ namespace Catch {
|
||||
|
||||
private: // IResultCapture
|
||||
|
||||
virtual void acceptMessage( MessageBuilder const& messageBuilder ) {
|
||||
m_messages.push_back( messageBuilder.build() );
|
||||
}
|
||||
|
||||
virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) {
|
||||
m_lastAssertionInfo = assertionInfo;
|
||||
return actOnCurrentResult( assertionResult.buildResult( assertionInfo ) );
|
||||
@@ -221,12 +217,12 @@ namespace Catch {
|
||||
m_messages.clear();
|
||||
}
|
||||
|
||||
virtual void pushScopedMessage( ScopedMessageBuilder const& _builder ) {
|
||||
m_messages.push_back( _builder.build() );
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) {
|
||||
m_messages.push_back( message );
|
||||
}
|
||||
|
||||
virtual void popScopedMessage( ScopedMessageBuilder const& _builder ) {
|
||||
m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), _builder ), m_messages.end() );
|
||||
virtual void popScopedMessage( MessageInfo const& message ) {
|
||||
m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
|
||||
}
|
||||
|
||||
virtual bool shouldDebugBreak() const {
|
||||
|
Reference in New Issue
Block a user