First cut of single-evaluation fix

This commit is contained in:
Phil Nash 2011-03-09 19:45:05 +00:00
parent c57ff75cdb
commit b708789ee9
7 changed files with 181 additions and 6 deletions

View File

@ -153,6 +153,33 @@ TEST_CASE( "./failing/conditions/ordered", "Ordering comparison checks that shou
CHECK( data.str_hello <= "a" );
}
// Comparisons with int literals
TEST_CASE( "./succeeding/conditions/int literals", "Comparisons with int literals don't warn when mixing signed/ unsigned" )
{
int i = 1;
unsigned int ui = 2;
long l = 3;
unsigned long ul = 4;
char c = 5;
unsigned char uc = 6;
REQUIRE( i == 1 );
REQUIRE( ui == 2 );
REQUIRE( l == 3 );
REQUIRE( ul == 4 );
REQUIRE( c == 5 );
REQUIRE( uc == 6 );
REQUIRE( 1 == i );
REQUIRE( 2 == ui );
REQUIRE( 3 == l );
REQUIRE( 4 == ul );
REQUIRE( 5 == c );
REQUIRE( 6 == uc );
REQUIRE( 62270208023445 > ul );
}
// Not (!) tests
// The problem with the ! operator is that it has right-to-left associativity.
// This means we can't isolate it when we decompose. The simple REQUIRE( !false ) form, therefore,

View File

@ -113,3 +113,11 @@ TEST_CASE( "./succeeding/Misc/null strings", "" )
REQUIRE( makeString( false ) != static_cast<char*>(NULL));
REQUIRE( makeString( true ) == static_cast<char*>(NULL));
}
TEST_CASE( "./failing/info", "sends information to INFO" )
{
INFO( "hi" );
int i = 7;
CAPTURE( i );
REQUIRE( false );
}

View File

@ -42,6 +42,7 @@
4A3BFFB8128DCF06005609E3 /* TestMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestMain.cpp; sourceTree = "<group>"; };
4A3BFFF0128DD23C005609E3 /* catch_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_config.hpp; path = ../internal/catch_config.hpp; sourceTree = SOURCE_ROOT; };
4A6D514B12C8A547008F0415 /* catch_debugger.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_debugger.hpp; path = ../internal/catch_debugger.hpp; sourceTree = SOURCE_ROOT; };
4A72A6FE13217CB70008EC53 /* catch_evaluate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_evaluate.hpp; path = ../internal/catch_evaluate.hpp; sourceTree = SOURCE_ROOT; };
4A8A68FF12F1F75100ACED26 /* catch_generators.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_generators.hpp; path = ../internal/catch_generators.hpp; sourceTree = SOURCE_ROOT; };
4A8A698812F2CDA100ACED26 /* catch_generators_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_generators_impl.hpp; path = ../internal/catch_generators_impl.hpp; sourceTree = SOURCE_ROOT; };
4A8A69C512F2D1C600ACED26 /* GeneratorTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeneratorTests.cpp; sourceTree = "<group>"; };
@ -171,6 +172,7 @@
4AFC341612809A36003A0C29 /* catch_common.h */,
4A992A6512B2156C002B7B66 /* catch_xmlwriter.hpp */,
4A15D4A812E4DF0D0005EB03 /* catch_stream.hpp */,
4A72A6FE13217CB70008EC53 /* catch_evaluate.hpp */,
);
name = support;
sourceTree = "<group>";

View File

@ -20,13 +20,13 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
runner.runMatching( "./succeeding/*" );
INFO( runner.getOutput() );
CHECK( runner.getSuccessCount() == 199 );
CHECK( runner.getSuccessCount() == 212 );
CHECK( runner.getFailureCount() == 0 );
runner.runMatching( "./failing/*" );
INFO( runner.getOutput() );
CHECK( runner.getSuccessCount() == 0 );
CHECK( runner.getFailureCount() == 53 );
CHECK( runner.getFailureCount() == 54 );
}
TEST_CASE( "meta/Misc/Sections", "looped tests" )

View File

@ -16,6 +16,7 @@
#include "catch_result_type.h"
#include "catch_interfaces_capture.h"
#include "catch_debugger.hpp"
#include "catch_evaluate.hpp"
#include <sstream>
#include <cmath>
@ -211,6 +212,8 @@ public:
private:
friend class ResultBuilder;
template<typename T>
friend class Expression;
///////////////////////////////////////////////////////////////////////////
void setLhs
@ -232,8 +235,109 @@ private:
m_rhs = rhs;
return *this;
}
///////////////////////////////////////////////////////////////////////////
template<Operator Op, typename T1, typename T2>
MutableResultInfo& setExpressionComponents
(
const T1& lhs,
const T2& rhs
)
{
setResultType( compare<Op>( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
m_rhs = toString( rhs );
m_op = OperatorTraits<Op>::getName();
return *this;
}
};
template<typename T>
class Expression
{
public:
///////////////////////////////////////////////////////////////////////////
Expression
(
MutableResultInfo& result,
const T& lhs
)
: m_result( result ),
m_lhs( lhs )
{
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator ==
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsEqualTo>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator !=
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsEqualTo>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator <
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsLessThan>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator >
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsGreaterThan>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator <=
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsLessThanOrEqualTo>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator >=
(
const RhsT& rhs
)
{
return m_result.setExpressionComponents<IsGreaterThanOrEqualTo>( m_lhs, rhs );
}
///////////////////////////////////////////////////////////////////////////
operator MutableResultInfo&
()
{
return m_result;
}
private:
MutableResultInfo& m_result;
const T& m_lhs;
};
class ResultBuilder
{
public:
@ -252,15 +356,28 @@ public:
///////////////////////////////////////////////////////////////////////////
template<typename T>
ResultBuilder& operator->*
Expression<T> operator->*
(
const T & operand
)
{
Expression<T> expr( m_result, operand );
m_result.setLhs( toString( operand ) );
return expr;
}
/*
///////////////////////////////////////////////////////////////////////////
template<typename T>
ResultBuilder& operator->*
(
const T & operand
)
{
m_result.setLhs( toString( operand ) );
return *this;
}
*/
///////////////////////////////////////////////////////////////////////////
template<typename RhsT>
MutableResultInfo& operator ==

View File

@ -25,6 +25,27 @@ namespace Catch
IsGreaterThanOrEqualTo
};
template<Operator Op>
struct OperatorTraits{ static const char* getName(){ return "*error - unknown operator*"; } };
template<>
struct OperatorTraits<IsEqualTo>{ static const char* getName(){ return "=="; } };
template<>
struct OperatorTraits<IsNotEqualTo>{ static const char* getName(){ return "!="; } };
template<>
struct OperatorTraits<IsLessThan>{ static const char* getName(){ return "<"; } };
template<>
struct OperatorTraits<IsGreaterThan>{ static const char* getName(){ return ">"; } };
template<>
struct OperatorTraits<IsLessThanOrEqualTo>{ static const char* getName(){ return "<="; } };
template<>
struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
template<typename T1, typename T2, Operator Op>
class Evaluator{};

View File

@ -60,7 +60,7 @@ public:
)
const
{
return m_from+index;
return m_from+static_cast<T>( index );
}
///////////////////////////////////////////////////////////////////////////