mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
integrated AssertionHandler into INTERNAL_CATCH_MSG
This commit is contained in:
parent
8a97beece2
commit
5f91724368
@ -59,8 +59,22 @@ namespace Catch {
|
|||||||
getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo );
|
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 ) );
|
AssertionResultData data( resultType, LazyExpression( negated ) );
|
||||||
handle( data, expr );
|
handle( data, expr );
|
||||||
}
|
}
|
||||||
@ -80,16 +94,7 @@ namespace Catch {
|
|||||||
(m_assertionInfo.resultDisposition & ResultDisposition::Normal);
|
(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 {
|
auto AssertionHandler::allowThrows() const -> bool {
|
||||||
return getCurrentContext().getConfig()->allowThrows();
|
return getCurrentContext().getConfig()->allowThrows();
|
||||||
}
|
}
|
||||||
@ -117,12 +122,7 @@ namespace Catch {
|
|||||||
useActiveException();
|
useActiveException();
|
||||||
}
|
}
|
||||||
void AssertionHandler::useActiveException() {
|
void AssertionHandler::useActiveException() {
|
||||||
bool negated = isFalseTest( m_assertionInfo.resultDisposition );
|
handle( ResultWas::ThrewException, Catch::translateActiveException().c_str() );
|
||||||
|
|
||||||
AssertionResultData data( ResultWas::ThrewException, LazyExpression( negated ) );
|
|
||||||
data.message = Catch::translateActiveException();
|
|
||||||
|
|
||||||
handle( data, nullptr );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
@ -50,6 +50,7 @@ namespace Catch {
|
|||||||
handle( expr.makeUnaryExpr() );
|
handle( expr.makeUnaryExpr() );
|
||||||
}
|
}
|
||||||
void handle( ResultWas::OfType resultType );
|
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( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
|
||||||
void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
|
void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
|
||||||
|
|
||||||
|
@ -133,10 +133,9 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||||
__catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
|
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str().c_str() ); \
|
||||||
__catchResult.captureResult( messageType ); \
|
INTERNAL_CATCH_REACT2( catchAssertionHandler ) \
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -32,7 +32,19 @@ namespace Catch {
|
|||||||
static unsigned int globalCount;
|
static unsigned int globalCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MessageBuilder {
|
struct MessageStream {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
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,
|
MessageBuilder( std::string const& macroName,
|
||||||
SourceLineInfo const& lineInfo,
|
SourceLineInfo const& lineInfo,
|
||||||
ResultWas::OfType type );
|
ResultWas::OfType type );
|
||||||
@ -44,7 +56,6 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageInfo m_info;
|
MessageInfo m_info;
|
||||||
std::ostringstream m_stream;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScopedMessage {
|
class ScopedMessage {
|
||||||
|
Loading…
Reference in New Issue
Block a user