mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Cleaned up ResultInfoBuilder a bit
This commit is contained in:
parent
71edf8b727
commit
9902ac9f1a
@ -19,53 +19,50 @@ class Expression {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Expression( ResultInfoBuilder& result, T lhs )
|
Expression( ResultInfoBuilder& result, T lhs )
|
||||||
: m_result( result ),
|
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
|
||||||
m_lhs( lhs )
|
m_lhs( lhs )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsNotEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsLessThan>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsLessThan>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsGreaterThan>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsGreaterThan>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsLessThanOrEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsGreaterThanOrEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultInfoBuilder& operator == ( bool rhs ) {
|
ResultInfoBuilder& operator == ( bool rhs ) {
|
||||||
return captureExpression<Internal::IsEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultInfoBuilder& operator != ( bool rhs ) {
|
ResultInfoBuilder& operator != ( bool rhs ) {
|
||||||
return captureExpression<Internal::IsNotEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
operator ResultInfoBuilder& () {
|
operator ResultInfoBuilder& () {
|
||||||
return m_result
|
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||||
.setLhs( Catch::toString( m_lhs ) )
|
|
||||||
.setOp( "" )
|
|
||||||
.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
@ -74,6 +71,15 @@ public:
|
|||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<Internal::Operator Op, typename RhsT>
|
||||||
|
ResultInfoBuilder& captureExpression( const RhsT& rhs ) {
|
||||||
|
return m_result
|
||||||
|
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
||||||
|
.setRhs( Catch::toString( rhs ) )
|
||||||
|
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResultInfoBuilder& m_result;
|
ResultInfoBuilder& m_result;
|
||||||
T m_lhs;
|
T m_lhs;
|
||||||
|
@ -53,21 +53,6 @@ private:
|
|||||||
bool m_isFalse;
|
bool m_isFalse;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<Internal::Operator Op, typename T1, typename T2>
|
|
||||||
ResultInfoBuilder& captureExpression( ResultInfoBuilder& builder, const T1& lhs, const T2& rhs ) {
|
|
||||||
return builder
|
|
||||||
.setResultType( Internal::compare<Op>( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
|
||||||
.setLhs( Catch::toString( lhs ) )
|
|
||||||
.setRhs( Catch::toString( rhs ) )
|
|
||||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Internal::Operator Op, typename T>
|
|
||||||
ResultInfoBuilder& captureExpression( ResultInfoBuilder& builder, const T* lhs, int rhs ) {
|
|
||||||
return captureExpression<Op>( builder, lhs, reinterpret_cast<const T*>( rhs ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated: 2012-10-09 11:46:45.335978
|
* Generated: 2012-10-09 20:58:02.234458
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -913,29 +913,15 @@ public:
|
|||||||
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& );
|
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( const RhsT& );
|
||||||
|
|
||||||
bool getIsFalse() const {
|
bool getIsFalse() const {
|
||||||
return m_isNot;
|
return m_isFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResultData m_data;
|
ResultData m_data;
|
||||||
std::string m_lhs, m_rhs, m_op;
|
std::string m_lhs, m_rhs, m_op;
|
||||||
bool m_isNot;
|
bool m_isFalse;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<Internal::Operator Op, typename T1, typename T2>
|
|
||||||
ResultInfoBuilder& captureExpression( ResultInfoBuilder& builder, const T1& lhs, const T2& rhs ) {
|
|
||||||
return builder
|
|
||||||
.setResultType( Internal::compare<Op>( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
|
||||||
.setLhs( Catch::toString( lhs ) )
|
|
||||||
.setRhs( Catch::toString( rhs ) )
|
|
||||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Internal::Operator Op, typename T>
|
|
||||||
ResultInfoBuilder& captureExpression( ResultInfoBuilder& builder, const T* lhs, int rhs ) {
|
|
||||||
return captureExpression<Op>( builder, lhs, reinterpret_cast<const T*>( rhs ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
@ -946,53 +932,50 @@ class Expression {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Expression( ResultInfoBuilder& result, T lhs )
|
Expression( ResultInfoBuilder& result, T lhs )
|
||||||
: m_result( result ),
|
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
|
||||||
m_lhs( lhs )
|
m_lhs( lhs )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsNotEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsLessThan>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsLessThan>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsGreaterThan>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsGreaterThan>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsLessThanOrEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
||||||
return captureExpression<Internal::IsGreaterThanOrEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultInfoBuilder& operator == ( bool rhs ) {
|
ResultInfoBuilder& operator == ( bool rhs ) {
|
||||||
return captureExpression<Internal::IsEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultInfoBuilder& operator != ( bool rhs ) {
|
ResultInfoBuilder& operator != ( bool rhs ) {
|
||||||
return captureExpression<Internal::IsNotEqualTo>( m_result, m_lhs, rhs );
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
operator ResultInfoBuilder& () {
|
operator ResultInfoBuilder& () {
|
||||||
return m_result
|
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
||||||
.setLhs( Catch::toString( m_lhs ) )
|
|
||||||
.setOp( "" )
|
|
||||||
.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
@ -1001,6 +984,15 @@ public:
|
|||||||
template<typename RhsT>
|
template<typename RhsT>
|
||||||
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<Internal::Operator Op, typename RhsT>
|
||||||
|
ResultInfoBuilder& captureExpression( const RhsT& rhs ) {
|
||||||
|
return m_result
|
||||||
|
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
||||||
|
.setRhs( Catch::toString( rhs ) )
|
||||||
|
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResultInfoBuilder& m_result;
|
ResultInfoBuilder& m_result;
|
||||||
T m_lhs;
|
T m_lhs;
|
||||||
@ -1018,12 +1010,12 @@ public:
|
|||||||
ExpressionBuilder( const SourceLineInfo& lineInfo,
|
ExpressionBuilder( const SourceLineInfo& lineInfo,
|
||||||
const char* macroName,
|
const char* macroName,
|
||||||
const char* expr = "",
|
const char* expr = "",
|
||||||
bool isNot = false )
|
bool isFalse = false )
|
||||||
: m_messageStream()
|
: m_messageStream()
|
||||||
{
|
{
|
||||||
m_result
|
m_result
|
||||||
.setCapturedExpression( expr )
|
.setCapturedExpression( expr )
|
||||||
.setIsFalse( isNot )
|
.setIsFalse( isFalse )
|
||||||
.setLineInfo( lineInfo )
|
.setLineInfo( lineInfo )
|
||||||
.setMacroName( macroName );
|
.setMacroName( macroName );
|
||||||
}
|
}
|
||||||
@ -1342,9 +1334,9 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ) \
|
||||||
do { try { \
|
do { try { \
|
||||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure, expr ); \
|
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isFalse )->*expr ), stopOnFailure, expr ); \
|
||||||
} catch( Catch::TestFailureException& ) { \
|
} catch( Catch::TestFailureException& ) { \
|
||||||
throw; \
|
throw; \
|
||||||
} catch( ... ) { \
|
} catch( ... ) { \
|
||||||
@ -1353,13 +1345,13 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
} } while( Catch::isTrue( false ) )
|
} } while( Catch::isTrue( false ) )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_IF( expr, isNot, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_IF( expr, isFalse, stopOnFailure, macroName ) \
|
||||||
INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ); \
|
INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \
|
||||||
if( Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
if( Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_ELSE( expr, isNot, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_ELSE( expr, isFalse, stopOnFailure, macroName ) \
|
||||||
INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ); \
|
INTERNAL_CATCH_TEST( expr, isFalse, stopOnFailure, macroName ); \
|
||||||
if( !Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
if( !Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -4945,10 +4937,10 @@ namespace Catch {
|
|||||||
ResultInfoBuilder::ResultInfoBuilder() {}
|
ResultInfoBuilder::ResultInfoBuilder() {}
|
||||||
|
|
||||||
ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
|
ResultInfoBuilder& ResultInfoBuilder::setResultType( ResultWas::OfType result ) {
|
||||||
// Flip bool results if isNot is set
|
// Flip bool results if isFalse is set
|
||||||
if( m_isNot && result == ResultWas::Ok )
|
if( m_isFalse && result == ResultWas::Ok )
|
||||||
m_data.resultType = ResultWas::ExpressionFailed;
|
m_data.resultType = ResultWas::ExpressionFailed;
|
||||||
else if( m_isNot && result == ResultWas::ExpressionFailed )
|
else if( m_isFalse && result == ResultWas::ExpressionFailed )
|
||||||
m_data.resultType = ResultWas::Ok;
|
m_data.resultType = ResultWas::Ok;
|
||||||
else
|
else
|
||||||
m_data.resultType = result;
|
m_data.resultType = result;
|
||||||
@ -4959,7 +4951,7 @@ namespace Catch {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
ResultInfoBuilder& ResultInfoBuilder::setIsFalse( bool isFalse ) {
|
ResultInfoBuilder& ResultInfoBuilder::setIsFalse( bool isFalse ) {
|
||||||
m_isNot = isFalse;
|
m_isFalse = isFalse;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4997,7 +4989,7 @@ namespace Catch {
|
|||||||
{
|
{
|
||||||
ResultData data = m_data;
|
ResultData data = m_data;
|
||||||
data.reconstructedExpression = reconstructExpression();
|
data.reconstructedExpression = reconstructExpression();
|
||||||
if( m_isNot ) {
|
if( m_isFalse ) {
|
||||||
if( m_op == "" ) {
|
if( m_op == "" ) {
|
||||||
data.capturedExpression = "!" + data.capturedExpression;
|
data.capturedExpression = "!" + data.capturedExpression;
|
||||||
data.reconstructedExpression = "!" + data.reconstructedExpression;
|
data.reconstructedExpression = "!" + data.reconstructedExpression;
|
||||||
|
Loading…
Reference in New Issue
Block a user