diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp index fe8e32a0..d53b09fa 100644 --- a/include/internal/catch_assertionhandler.cpp +++ b/include/internal/catch_assertionhandler.cpp @@ -59,8 +59,22 @@ namespace Catch { getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo ); } - void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) { + void AssertionHandler::handle( ITransientExpression const& expr ) { + bool negated = isFalseTest( m_assertionInfo.resultDisposition ); + bool result = expr.getResult() != negated; + + handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated ); + } + void AssertionHandler::handle( ResultWas::OfType resultType ) { + handle( resultType, nullptr, false ); + } + void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) { + AssertionResultData data( resultType, LazyExpression( false ) ); + data.message = message.c_str(); + handle( data, nullptr ); + } + void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) { AssertionResultData data( resultType, LazyExpression( negated ) ); handle( data, expr ); } @@ -80,16 +94,7 @@ namespace Catch { (m_assertionInfo.resultDisposition & ResultDisposition::Normal); } } - void AssertionHandler::handle( ITransientExpression const& expr ) { - bool negated = isFalseTest( m_assertionInfo.resultDisposition ); - bool result = expr.getResult() != negated; - - handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated ); - } - void AssertionHandler::handle( ResultWas::OfType resultType ) { - handle( resultType, nullptr, false ); - } auto AssertionHandler::allowThrows() const -> bool { return getCurrentContext().getConfig()->allowThrows(); } @@ -117,12 +122,7 @@ namespace Catch { useActiveException(); } void AssertionHandler::useActiveException() { - bool negated = isFalseTest( m_assertionInfo.resultDisposition ); - - AssertionResultData data( ResultWas::ThrewException, LazyExpression( negated ) ); - data.message = Catch::translateActiveException(); - - handle( data, nullptr ); + handle( ResultWas::ThrewException, Catch::translateActiveException().c_str() ); } } // namespace Catch diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h index 6e140e44..18137448 100644 --- a/include/internal/catch_assertionhandler.h +++ b/include/internal/catch_assertionhandler.h @@ -50,6 +50,7 @@ namespace Catch { handle( expr.makeUnaryExpr() ); } void handle( ResultWas::OfType resultType ); + void handle( ResultWas::OfType resultType, StringRef const& message ); void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ); void handle( AssertionResultData const& resultData, ITransientExpression const* expr ); diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 68859412..13101ec6 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -133,10 +133,9 @@ /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ - __catchResult.captureResult( messageType ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ + catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str().c_str() ); \ + INTERNAL_CATCH_REACT2( catchAssertionHandler ) \ } while( Catch::alwaysFalse() ) /////////////////////////////////////////////////////////////////////////////// diff --git a/include/internal/catch_message.h b/include/internal/catch_message.h index 2550fb41..553882b7 100644 --- a/include/internal/catch_message.h +++ b/include/internal/catch_message.h @@ -32,7 +32,19 @@ namespace Catch { static unsigned int globalCount; }; - struct MessageBuilder { + struct MessageStream { + + template + MessageStream& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + // !TBD reuse a global/ thread-local stream + std::ostringstream m_stream; + }; + + struct MessageBuilder : MessageStream { MessageBuilder( std::string const& macroName, SourceLineInfo const& lineInfo, ResultWas::OfType type ); @@ -44,7 +56,6 @@ namespace Catch { } MessageInfo m_info; - std::ostringstream m_stream; }; class ScopedMessage {