diff --git a/include/internal/catch_assertionresult_builder.h b/include/internal/catch_assertionresult_builder.h index 3ef2f5fd..986e2079 100644 --- a/include/internal/catch_assertionresult_builder.h +++ b/include/internal/catch_assertionresult_builder.h @@ -21,7 +21,7 @@ struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; class AssertionResultBuilder { public: - AssertionResultBuilder(); + AssertionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown ); AssertionResultBuilder( const AssertionResultBuilder& other ); AssertionResultBuilder& operator=(const AssertionResultBuilder& other ); diff --git a/include/internal/catch_assertionresult_builder.hpp b/include/internal/catch_assertionresult_builder.hpp index dce5af7e..f8d91e0d 100644 --- a/include/internal/catch_assertionresult_builder.hpp +++ b/include/internal/catch_assertionresult_builder.hpp @@ -10,16 +10,19 @@ #include "catch_assertionresult_builder.h" +#include + namespace Catch { - AssertionResultBuilder::AssertionResultBuilder() {} + AssertionResultBuilder::AssertionResultBuilder( ResultWas::OfType resultType ) { + m_data.resultType = resultType; + } AssertionResultBuilder::AssertionResultBuilder( const AssertionResultBuilder& other ) : m_data( other.m_data ), m_exprComponents( other.m_exprComponents ) { m_stream << other.m_stream.str(); } - AssertionResultBuilder& AssertionResultBuilder::operator=(const AssertionResultBuilder& other ) { m_data = other.m_data; m_exprComponents = other.m_exprComponents; @@ -27,15 +30,8 @@ namespace Catch { m_stream << other.m_stream.str(); return *this; } - AssertionResultBuilder& AssertionResultBuilder::setResultType( ResultWas::OfType result ) { - // Flip bool results if isFalse is set - if( m_exprComponents.isFalse && result == ResultWas::Ok ) - m_data.resultType = ResultWas::ExpressionFailed; - else if( m_exprComponents.isFalse && result == ResultWas::ExpressionFailed ) - m_data.resultType = ResultWas::Ok; - else - m_data.resultType = result; + m_data.resultType = result; return *this; } AssertionResultBuilder& AssertionResultBuilder::setCapturedExpression( const std::string& capturedExpression ) { @@ -46,35 +42,38 @@ namespace Catch { m_exprComponents.isFalse = isFalse; return *this; } - AssertionResultBuilder& AssertionResultBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { m_data.lineInfo = lineInfo; return *this; } - AssertionResultBuilder& AssertionResultBuilder::setMacroName( const std::string& macroName ) { m_data.macroName = macroName; return *this; } - AssertionResultBuilder& AssertionResultBuilder::setLhs( const std::string& lhs ) { m_exprComponents.lhs = lhs; return *this; } - AssertionResultBuilder& AssertionResultBuilder::setRhs( const std::string& rhs ) { m_exprComponents.rhs = rhs; return *this; } - AssertionResultBuilder& AssertionResultBuilder::setOp( const std::string& op ) { m_exprComponents.op = op; return *this; } - AssertionResult AssertionResultBuilder::build() const { + assert( m_data.resultType != ResultWas::Unknown ); + AssertionResultData data = m_data; + + // Flip bool results if isFalse is set + if( m_exprComponents.isFalse && data.resultType == ResultWas::Ok ) + data.resultType = ResultWas::ExpressionFailed; + else if( m_exprComponents.isFalse && data.resultType == ResultWas::ExpressionFailed ) + data.resultType = ResultWas::Ok; + data.message = m_stream.str(); data.reconstructedExpression = reconstructExpression(); if( m_exprComponents.isFalse ) { @@ -89,7 +88,6 @@ namespace Catch { } return AssertionResult( data ); } - std::string AssertionResultBuilder::reconstructExpression() const { if( m_exprComponents.op == "" ) return m_exprComponents.lhs.empty() ? m_data.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 7c731727..c3a1c535 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -101,11 +101,11 @@ inline bool isTrue( bool value ){ return value; } #define INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ) \ do { try { \ Catch::getResultCapture().acceptAssertionInfo( Catch::AssertionInfo( macroName, CATCH_INTERNAL_LINEINFO, #expr ) ); \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( isFalse )->*expr ), stopOnFailure, expr ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder()->*expr ).setIsFalse( isFalse ), stopOnFailure, expr ); \ } catch( Catch::TestFailureException& ) { \ throw; \ } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), false, expr ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), false, expr ); \ throw; \ } } while( Catch::isTrue( false ) ) @@ -124,10 +124,10 @@ inline bool isTrue( bool value ){ return value; } try { \ Catch::getResultCapture().acceptAssertionInfo( Catch::AssertionInfo( macroName, CATCH_INTERNAL_LINEINFO, #expr ) ); \ expr; \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \ } \ catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -136,26 +136,26 @@ inline bool isTrue( bool value ){ return value; } Catch::getResultCapture().acceptAssertionInfo( Catch::AssertionInfo( macroName, CATCH_INTERNAL_LINEINFO, #expr ) ); \ if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \ expr; \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \ } \ } \ catch( Catch::TestFailureException& ) { \ throw; \ } \ catch( exceptionType ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( Catch::ResultWas::Ok ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \ INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::AssertionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \ - INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder().setResultType( resultType ) << reason, stopOnFailure, true ); + INTERNAL_CATCH_ACCEPT_EXPR( Catch::AssertionResultBuilder( resultType ) << reason, stopOnFailure, true ); /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_SCOPED_INFO( log ) \ @@ -170,7 +170,7 @@ inline bool isTrue( bool value ){ return value; } } catch( Catch::TestFailureException& ) { \ throw; \ } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::AssertionResultBuilder().setResultType( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), false, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::AssertionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), false, false ); \ throw; \ }}while( Catch::isTrue( false ) )