Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

First cut of single-evaluation fix

Commit
b708789ee9aa5888e104adbcaa7048b2432eaf9b
Author
Phil Nash ·
Parents
c57ff75cdb98

Files · Download .tar.gz

Changes

 Test/ConditionTests.cpp             |  27 ++++++++
 Test/MiscTests.cpp                  |   8 +++
 Test/Test.xcodeproj/project.pbxproj |   2 +
 Test/TestMain.cpp                   |   4 +-
 internal/catch_capture.hpp          | 123 +++++++++++++++++++++++++++++++++++-
 internal/catch_evaluate.hpp         |  21 ++++++
 internal/catch_generators.hpp       |   2 +-
 7 files changed, 181 insertions(+), 6 deletions(-)

diff --git a/Test/ConditionTests.cpp b/Test/ConditionTests.cpp
index f7247f89..b1010169 100644
--- a/Test/ConditionTests.cpp
+++ b/Test/ConditionTests.cpp
@@ -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,
diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp
index ab380dc2..cae910d6 100644
--- a/Test/MiscTests.cpp
+++ b/Test/MiscTests.cpp
@@ -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 );
+}
diff --git a/Test/Test.xcodeproj/project.pbxproj b/Test/Test.xcodeproj/project.pbxproj
index 68a12f74..9767a657 100644
--- a/Test/Test.xcodeproj/project.pbxproj
+++ b/Test/Test.xcodeproj/project.pbxproj
@@ -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>";
diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp
index 04855fc8..78b978fa 100644
--- a/Test/TestMain.cpp
+++ b/Test/TestMain.cpp
@@ -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" )
diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp
index 213c609f..10da8901 100644
--- a/internal/catch_capture.hpp
+++ b/internal/catch_capture.hpp
@@ -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,7 +235,108 @@ 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
 {
@@ -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 == 
@@ -329,7 +446,7 @@ public:
     }
     
 private:
-    MutableResultInfo m_result;
+    MutableResultInfo m_result;    
     
 };
 
diff --git a/internal/catch_evaluate.hpp b/internal/catch_evaluate.hpp
index 69441001..46c6f8a0 100644
--- a/internal/catch_evaluate.hpp
+++ b/internal/catch_evaluate.hpp
@@ -24,7 +24,28 @@ namespace Catch
         IsLessThanOrEqualTo,
         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{};
     
diff --git a/internal/catch_generators.hpp b/internal/catch_generators.hpp
index 6623cb2d..3ab69ac1 100644
--- a/internal/catch_generators.hpp
+++ b/internal/catch_generators.hpp
@@ -60,7 +60,7 @@ public:
     )
     const
     {
-        return m_from+index;
+        return m_from+static_cast<T>( index );
     }
     
     ///////////////////////////////////////////////////////////////////////////