Fixed some issues caused by single evaluation work

This commit is contained in:
Phil Nash 2011-03-10 19:18:14 +00:00
parent e0e74774e2
commit 2e444861c9
4 changed files with 52 additions and 18 deletions

View File

@ -41,15 +41,32 @@ TEST_CASE
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
TEST_CASE TEST_CASE
( (
"./inprogress/succeeding/Tricky/complex lhs", "./inprogress/failing/Tricky/complex lhs",
"Where the LHS is not a simple value" "Where the LHS is not a simple value"
) )
{ {
/*
int a = 1; int a = 1;
int b = 2; int b = 2;
// This only captures part of the expression, but issues a warning about the rest // This only captures part of the expression, but issues a warning about the rest
REQUIRE( a == 2 || b == 2 ); REQUIRE( a == 2 || b == 2 );
*/
}
///////////////////////////////////////////////////////////////////////////////
TEST_CASE
(
"./inprogress/failing/Tricky/complex 2",
"Where the LHS is not a simple value"
)
{
/*
int a = 1;
int b = 2;
// This only captures part of the expression, but issues a warning about the rest
REQUIRE( a+1 == b-1 );
*/
} }
struct Opaque struct Opaque

View File

@ -155,12 +155,13 @@ inline std::string toString
return value ? "true" : "false"; return value ? "true" : "false";
} }
class TestFailureException struct TestFailureException
{ {
}; };
class DummyExceptionType_DontUse struct DummyExceptionType_DontUse
{ {
}; };
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
class MutableResultInfo : public ResultInfo class MutableResultInfo : public ResultInfo
{ {
@ -208,18 +209,21 @@ public:
{ {
m_message = message; m_message = message;
} }
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator ||
(
const RhsT&
);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template<typename RhsT> template<typename RhsT>
MutableResultInfo& operator || STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator &&
( (
const RhsT& const RhsT&
) );
{
m_expressionIncomplete = true;
return *this;
}
private: private:
friend class ResultBuilder; friend class ResultBuilder;
template<typename T> template<typename T>
@ -250,7 +254,8 @@ private:
m_rhs = toString( rhs ); m_rhs = toString( rhs );
m_op = OperatorTraits<Op>::getName(); m_op = OperatorTraits<Op>::getName();
return *this; return *this;
} }
}; };
template<typename T> template<typename T>
@ -335,6 +340,20 @@ public:
return m_result.captureBoolExpression( m_lhs ); return m_result.captureBoolExpression( m_lhs );
} }
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator +
(
const RhsT&
);
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator -
(
const RhsT&
);
private: private:
MutableResultInfo& m_result; MutableResultInfo& m_result;
const T& m_lhs; const T& m_lhs;

View File

@ -27,6 +27,7 @@ struct ResultWas{ enum OfType
ExpressionFailed = FailureBit | 1, ExpressionFailed = FailureBit | 1,
ExplicitFailure = FailureBit | 2, ExplicitFailure = FailureBit | 2,
ExpressionTooComplex = FailureBit | 3,
Exception = 0x110, Exception = 0x110,

View File

@ -26,8 +26,7 @@ namespace Catch
() ()
: m_line( 0 ), : m_line( 0 ),
m_result( ResultWas::Unknown ), m_result( ResultWas::Unknown ),
m_isNot( false ), m_isNot( false )
m_expressionIncomplete( false )
{} {}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -48,8 +47,7 @@ namespace Catch
m_op( isNotExpression( expr ) ? "!" : "" ), m_op( isNotExpression( expr ) ? "!" : "" ),
m_message( message ), m_message( message ),
m_result( result ), m_result( result ),
m_isNot( isNot ), m_isNot( isNot )
m_expressionIncomplete( false )
{ {
if( isNot ) if( isNot )
m_expr = "!" + m_expr; m_expr = "!" + m_expr;
@ -103,8 +101,8 @@ namespace Catch
if( !hasExpression() ) if( !hasExpression() )
return ""; return "";
return m_expressionIncomplete return m_result == ResultWas::ExpressionTooComplex
? getExpandedExpressionInternal() + " {can't expand the rest of the expression - consider rewriting it}" ? getExpandedExpressionInternal() + " {couldn't fully decompose the expression to evaluate it - please rewrite as a binary comparison}"
: getExpandedExpressionInternal(); : getExpandedExpressionInternal();
} }
@ -172,7 +170,6 @@ namespace Catch
std::string m_message; std::string m_message;
ResultWas::OfType m_result; ResultWas::OfType m_result;
bool m_isNot; bool m_isNot;
bool m_expressionIncomplete;
}; };
} // end namespace Catch } // end namespace Catch