From defca58566653fd088f615c2979d7e7a681bf107 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 10 Nov 2012 18:43:23 +0000 Subject: [PATCH] negate() -> endExpression(), takes ResultDisposition --- include/internal/catch_capture.hpp | 38 +++------- include/internal/catch_expression_lhs.hpp | 4 +- .../internal/catch_expressionresult_builder.h | 2 +- .../catch_expressionresult_builder.hpp | 4 +- include/internal/catch_result_type.h | 75 ++++++++++++------- 5 files changed, 63 insertions(+), 60 deletions(-) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index f2a6ad55..805d8179 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -75,24 +75,8 @@ private: ExpressionResultBuilder m_resultBuilder; }; -struct ResultDisposition { - enum Flags { - Normal = 0x00, - - ContinueOnFailure = 0x01, - NegateResult = 0x02, - SuppressFail = 0x04 - }; -}; -inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast( static_cast( lhs ) | static_cast( rhs ) ); -} - // This is just here to avoid compiler warnings with macro constants and boolean literals inline bool isTrue( bool value ){ return value; } -inline bool testFlag( int flags, int bitOrBitsToTest ) { return ( flags & bitOrBitsToTest ) == bitOrBitsToTest; } -inline bool setFlag( int flags, int bitOrBitsToSet ) { return static_cast( flags | bitOrBitsToSet ); } -inline bool resetFlag( int flags, int bitOrBitsToReset ) { return static_cast( flags & ~bitOrBitsToReset ); } } // end namespace Catch @@ -104,20 +88,20 @@ inline bool resetFlag( int flags, int bitOrBitsToReset ) { return static_cast*expr ).negate( testFlag( resultDisposition, Catch::ResultDisposition::NegateResult ) ), resultDisposition, expr ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionDecomposer()->*expr ).endExpression( resultDisposition ), resultDisposition, expr ); \ } catch( Catch::TestFailureException& ) { \ throw; \ } catch( ... ) { \ @@ -140,7 +124,7 @@ inline bool resetFlag( int flags, int bitOrBitsToReset ) { return static_cast( rhs ); } - ExpressionResultBuilder& negate( bool shouldNegate ) { + ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition ) { bool value = m_lhs ? true : false; return m_result .setLhs( Catch::toString( value ) ) .setResultType( value ) - .negate( shouldNegate ); + .endExpression( resultDisposition ); } // Only simple binary expressions are allowed on the LHS. diff --git a/include/internal/catch_expressionresult_builder.h b/include/internal/catch_expressionresult_builder.h index 23b84646..eb9109f9 100644 --- a/include/internal/catch_expressionresult_builder.h +++ b/include/internal/catch_expressionresult_builder.h @@ -31,7 +31,7 @@ public: ExpressionResultBuilder& setRhs( const std::string& rhs ); ExpressionResultBuilder& setOp( const std::string& op ); - ExpressionResultBuilder& negate( bool shouldNegate ); + ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition ); template ExpressionResultBuilder& operator << ( const T& value ) { diff --git a/include/internal/catch_expressionresult_builder.hpp b/include/internal/catch_expressionresult_builder.hpp index 0c0a28a8..1ecccad5 100644 --- a/include/internal/catch_expressionresult_builder.hpp +++ b/include/internal/catch_expressionresult_builder.hpp @@ -38,8 +38,8 @@ namespace Catch { m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; return *this; } - ExpressionResultBuilder& ExpressionResultBuilder::negate( bool shouldNegate ) { - m_exprComponents.shouldNegate = shouldNegate; + ExpressionResultBuilder& ExpressionResultBuilder::endExpression( ResultDisposition::Flags resultDisposition ) { + m_exprComponents.shouldNegate = testFlag( resultDisposition, ResultDisposition::NegateResult ); return *this; } ExpressionResultBuilder& ExpressionResultBuilder::setLhs( const std::string& lhs ) { diff --git a/include/internal/catch_result_type.h b/include/internal/catch_result_type.h index e151f070..60678e27 100644 --- a/include/internal/catch_result_type.h +++ b/include/internal/catch_result_type.h @@ -10,35 +10,54 @@ namespace Catch { -struct ResultWas { enum OfType { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x100 | FailureBit, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2 - -}; }; + struct ResultWas { enum OfType { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, + + FailureBit = 0x10, + + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, + + Exception = 0x100 | FailureBit, + + ThrewException = Exception | 1, + DidntThrowException = Exception | 2 + + }; }; -inline bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; -} + inline bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } -struct ResultAction { enum Value { - None, - Failed = 1, // Failure - but no debug break if Debug bit not set - Debug = 2, // If this bit is set, invoke the debugger - Abort = 4 // Test run should abort -}; }; - -} + struct ResultAction { enum Value { + None, + Failed = 1, // Failure - but no debug break if Debug bit not set + Debug = 2, // If this bit is set, invoke the debugger + Abort = 4 // Test run should abort + }; }; + + struct ResultDisposition { + enum Flags { + Normal = 0x00, + + ContinueOnFailure = 0x01, + NegateResult = 0x02, + SuppressFail = 0x04 + }; + }; + inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast( static_cast( lhs ) | static_cast( rhs ) ); + } + + inline bool testFlag( int flags, int bitOrBitsToTest ) { return ( flags & bitOrBitsToTest ) == bitOrBitsToTest; } + inline bool setFlag( int flags, int bitOrBitsToSet ) { return static_cast( flags | bitOrBitsToSet ); } + inline bool resetFlag( int flags, int bitOrBitsToReset ) { return static_cast( flags & ~bitOrBitsToReset ); } + + inline bool shouldContinueOnFailure( int flags ) { return testFlag( flags, ResultDisposition::ContinueOnFailure ); } + +} // end namespace Catch #endif // TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED