From 134e45b3ade922e5cbdb2df6b81830fbd93fe448 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sun, 28 Oct 2012 20:57:21 +0000 Subject: [PATCH] Fixed #132 --- include/internal/catch_expression_lhs.hpp | 19 ++++++++----------- projects/SelfTest/TestMain.cpp | 2 +- projects/SelfTest/TrickyTests.cpp | 21 +++++++++++++++++++++ single_include/catch.hpp | 21 +++++++++------------ 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp index f7c4fb14..572c8c37 100644 --- a/include/internal/catch_expression_lhs.hpp +++ b/include/internal/catch_expression_lhs.hpp @@ -13,13 +13,7 @@ namespace Catch { - struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - - template - 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 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( m_lhs, rhs ) ) + .setLhs( Catch::toString( m_lhs ) ) .setRhs( Catch::toString( rhs ) ) .setOp( Internal::OperatorTraits::getName() ); } diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp index b0fe11f5..6e38d44c 100644 --- a/projects/SelfTest/TestMain.cpp +++ b/projects/SelfTest/TestMain.cpp @@ -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 ); } diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 50e6a394..f15d236c 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -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 ); +} diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 96e87228..c3413227 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -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 - 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 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( m_lhs, rhs ) ) + .setLhs( Catch::toString( m_lhs ) ) .setRhs( Catch::toString( rhs ) ) .setOp( Internal::OperatorTraits::getName() ); }