mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Fixed #132
This commit is contained in:
parent
2f92db9898
commit
134e45b3ad
@ -13,13 +13,7 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
template<typename T>
|
||||
inline void setResultIfBoolean( ExpressionResultBuilder&, const T& ) {}
|
||||
inline void setResultIfBoolean( ExpressionResultBuilder& result, bool value ) {
|
||||
result.setResultType( value );
|
||||
}
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
|
||||
// in an ExpressionResultBuilder object
|
||||
@ -28,9 +22,7 @@ class ExpressionLhs {
|
||||
void operator = ( const ExpressionLhs& );
|
||||
|
||||
public:
|
||||
ExpressionLhs( T lhs ) : m_lhs( lhs ) {
|
||||
setResultIfBoolean( m_result.setLhs( Catch::toString( lhs ) ), lhs );
|
||||
}
|
||||
ExpressionLhs( T lhs ) : m_lhs( lhs ) {}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator == ( const RhsT& rhs ) {
|
||||
@ -71,7 +63,11 @@ public:
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& negate( bool shouldNegate ) {
|
||||
return m_result.negate( shouldNegate );
|
||||
bool value = m_lhs ? true : false;
|
||||
return m_result
|
||||
.setLhs( Catch::toString( value ) )
|
||||
.setResultType( value )
|
||||
.negate( shouldNegate );
|
||||
}
|
||||
|
||||
// Only simple binary expressions are allowed on the LHS.
|
||||
@ -86,6 +82,7 @@ private:
|
||||
ExpressionResultBuilder& captureExpression( const RhsT& rhs ) {
|
||||
return m_result
|
||||
.setResultType( Internal::compare<Op>( m_lhs, rhs ) )
|
||||
.setLhs( Catch::toString( m_lhs ) )
|
||||
.setRhs( Catch::toString( rhs ) )
|
||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
||||
SECTION( "selftest/test counts/succeeding tests",
|
||||
"Number of 'succeeding' tests is fixed" ) {
|
||||
Totals totals = runner.runMatching( "./succeeding/*" );
|
||||
CHECK( totals.assertions.passed == 285 );
|
||||
CHECK( totals.assertions.passed == 288 );
|
||||
CHECK( totals.assertions.failed == 0 );
|
||||
}
|
||||
|
||||
|
@ -293,3 +293,24 @@ TEST_CASE( "./sameName", "Tests with the same name are not allowed" )
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
struct Boolable
|
||||
{
|
||||
explicit Boolable( bool value ) : m_value( value ) {}
|
||||
|
||||
operator Catch::SafeBool::type() const {
|
||||
return Catch::SafeBool::makeSafe( m_value );
|
||||
}
|
||||
|
||||
bool m_value;
|
||||
};
|
||||
|
||||
TEST_CASE( "./succeeding/SafeBool", "Objects that evaluated in boolean contexts can be checked")
|
||||
{
|
||||
Boolable True( true );
|
||||
Boolable False( false );
|
||||
|
||||
CHECK( True );
|
||||
CHECK( !False );
|
||||
CHECK_FALSE( False );
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Generated: 2012-10-28 12:06:53.944416
|
||||
* Generated: 2012-10-28 20:56:33.944771
|
||||
* ----------------------------------------------------------
|
||||
* This file has been merged from multiple headers. Please don't edit it directly
|
||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
@ -943,13 +943,7 @@ private:
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
template<typename T>
|
||||
inline void setResultIfBoolean( ExpressionResultBuilder&, const T& ) {}
|
||||
inline void setResultIfBoolean( ExpressionResultBuilder& result, bool value ) {
|
||||
result.setResultType( value );
|
||||
}
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
|
||||
// in an ExpressionResultBuilder object
|
||||
@ -958,9 +952,7 @@ class ExpressionLhs {
|
||||
void operator = ( const ExpressionLhs& );
|
||||
|
||||
public:
|
||||
ExpressionLhs( T lhs ) : m_lhs( lhs ) {
|
||||
setResultIfBoolean( m_result.setLhs( Catch::toString( lhs ) ), lhs );
|
||||
}
|
||||
ExpressionLhs( T lhs ) : m_lhs( lhs ) {}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator == ( const RhsT& rhs ) {
|
||||
@ -1001,7 +993,11 @@ public:
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& negate( bool shouldNegate ) {
|
||||
return m_result.negate( shouldNegate );
|
||||
bool value = m_lhs ? true : false;
|
||||
return m_result
|
||||
.setLhs( Catch::toString( value ) )
|
||||
.setResultType( value )
|
||||
.negate( shouldNegate );
|
||||
}
|
||||
|
||||
// Only simple binary expressions are allowed on the LHS.
|
||||
@ -1016,6 +1012,7 @@ private:
|
||||
ExpressionResultBuilder& captureExpression( const RhsT& rhs ) {
|
||||
return m_result
|
||||
.setResultType( Internal::compare<Op>( m_lhs, rhs ) )
|
||||
.setLhs( Catch::toString( m_lhs ) )
|
||||
.setRhs( Catch::toString( rhs ) )
|
||||
.setOp( Internal::OperatorTraits<Op>::getName() );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user