mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 23:06:10 +01:00
Detect and warn about overly complex expressions
This commit is contained in:
parent
3d0fed768a
commit
48a70220a3
@ -38,6 +38,6 @@ TEST_CASE( "succeeding/Tricky/complex lhs", "Where the LHS is not a simple value
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
|
||||
// !TBD: This only captures part of the expression
|
||||
EXPECT( a == 2 || b == 2 );
|
||||
// This only captures part of the expression, but issues a warning about the rest
|
||||
EXPECT( a == 2 || b == 1 );
|
||||
}
|
@ -63,7 +63,7 @@ public:
|
||||
template<typename RhsT>
|
||||
MutableResultInfo& operator ||( const RhsT& rhs )
|
||||
{
|
||||
// !TBD: set message to say we haven't captured all parts
|
||||
m_expressionIncomplete = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,8 @@ namespace Catch
|
||||
ResultInfo()
|
||||
: m_result( ResultWas::Unknown ),
|
||||
m_isNot( false ),
|
||||
m_line( 0 )
|
||||
m_line( 0 ),
|
||||
m_expressionIncomplete( false )
|
||||
{}
|
||||
|
||||
ResultInfo( const std::string& expr, ResultWas::OfType result, bool isNot, const std::string& filename, size_t line, const std::string& macroName )
|
||||
@ -50,7 +51,8 @@ namespace Catch
|
||||
m_op( m_expr[0] == '!' ? "!" : "" ),
|
||||
m_filename( filename ),
|
||||
m_line( line ),
|
||||
m_macroName( macroName )
|
||||
m_macroName( macroName ),
|
||||
m_expressionIncomplete( false )
|
||||
{
|
||||
}
|
||||
|
||||
@ -78,12 +80,9 @@ namespace Catch
|
||||
}
|
||||
std::string getExpandedExpression() const
|
||||
{
|
||||
if( m_op == "" || m_isNot )
|
||||
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
||||
else if( m_op != "!" )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else
|
||||
return "{can't expand - use " + m_macroName + "_NOT( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
return m_expressionIncomplete
|
||||
? getExpandedExpressionInternal() + " {can't expand the rest of the expression - consider rewriting it}"
|
||||
: getExpandedExpressionInternal();
|
||||
}
|
||||
|
||||
std::string getMessage() const
|
||||
@ -105,6 +104,17 @@ namespace Catch
|
||||
{
|
||||
return m_macroName;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string getExpandedExpressionInternal() const
|
||||
{
|
||||
if( m_op == "" || m_isNot )
|
||||
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
||||
else if( m_op != "!" )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else
|
||||
return "{can't expand - use " + m_macroName + "_NOT( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_macroName;
|
||||
@ -114,6 +124,7 @@ namespace Catch
|
||||
std::string m_message;
|
||||
ResultWas::OfType m_result;
|
||||
bool m_isNot;
|
||||
bool m_expressionIncomplete;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
Loading…
Reference in New Issue
Block a user