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

Fixed issue with evaluating static bools

Commit
4d0a8d96e63663a36a212ee51ff3011c03fda718
Author
Phil Nash ·
Parents
4021d65f6401

Files · Download .tar.gz

Changes

 include/internal/catch_capture.hpp | 28 +++++++++++++++++++++++++
 projects/SelfTest/TrickyTests.cpp  | 43 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 6ae888c5..e049d7f5 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -434,6 +434,24 @@ public:
         return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
     }
 
+    ///////////////////////////////////////////////////////////////////////////
+    MutableResultInfo& operator == 
+    (
+        bool rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    MutableResultInfo& operator != 
+    (
+        bool rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////
     operator MutableResultInfo&
     ()
@@ -591,6 +609,16 @@ public:
         return expr;
     }
     
+    ///////////////////////////////////////////////////////////////////////////
+    Expression<bool> operator->*
+    (
+        bool value
+    )
+    {
+        Expression<bool> expr( m_result, value );
+        return expr;
+    }
+    
     ///////////////////////////////////////////////////////////////////////////
     template<typename T>
     ResultBuilder& operator <<
diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp
index ab388d1f..dbc4a646 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -235,3 +235,46 @@ TEST_CASE("./succeeding/boolean member", "")
     Obj obj;
     REQUIRE( obj.prop != NULL );
 }
+
+// Tests for a problem submitted by Ralph McArdell
+//
+// The static bool value should not need to be defined outside the
+// struct it is declared in - but when evaluating it in a deduced
+// context it appears to require the extra definition.
+// The issue was fixed by adding bool overloads to bypass the
+// templates that were deduce it.
+template <bool B>
+struct is_true
+{
+    static const bool value = B;
+};
+
+TEST_CASE( "./succeeding/unimplemented static bool", "static bools can be evaluated" )
+{
+    SECTION("compare to true","")
+    {
+        REQUIRE( is_true<true>::value == true );
+        REQUIRE( true == is_true<true>::value );
+    }
+    SECTION("compare to false","")
+    {
+        REQUIRE( is_true<false>::value == false );
+        REQUIRE( false == is_true<false>::value );
+    }
+
+    SECTION("negation", "")
+    {
+        REQUIRE( !is_true<false>::value );
+    }
+
+    SECTION("double negation","")
+    {
+        REQUIRE( !!is_true<true>::value );
+    }
+
+    SECTION("direct","")
+    {
+        REQUIRE( is_true<true>::value );
+        REQUIRE_FALSE( is_true<false>::value );
+    }
+}