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

Move expression classes into own file

Commit
a6855f7eab47512d866914fae9f714a60d184585
Author
Phil Nash ·
Parents
d10d2d34855e

Files · Download .tar.gz

Changes

 include/internal/catch_capture.hpp                 | 193 +------------------
 include/internal/catch_expression.hpp              | 208 +++++++++++++++++++++
 .../CatchSelfTest.xcodeproj/project.pbxproj        |   2 +
 3 files changed, 212 insertions(+), 191 deletions(-)

diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 91bfa6bd..14426d01 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -8,6 +8,7 @@
 #ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
 #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
 
+#include "catch_expression.hpp"
 #include "catch_resultinfo_builder.hpp"
 #include "catch_tostring.hpp"
 #include "catch_resultinfo.hpp"
@@ -24,197 +25,7 @@ namespace Catch
     
 struct TestFailureException{};
 struct DummyExceptionType_DontUse{};
-
-template<typename T>
-class Expression
-{
-	void operator = ( const Expression& );
-
-public:
-    ///////////////////////////////////////////////////////////////////////////
-    Expression
-    (
-        ResultInfoBuilder& result, 
-        T lhs 
-    )
-    :   m_result( result ),
-        m_lhs( lhs )
-    {
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator == 
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator != 
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator <
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator >
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator <= 
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator >= 
-    (
-        const RhsT& rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    ResultInfoBuilder& operator == 
-    (
-        bool rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    ResultInfoBuilder& operator != 
-    (
-        bool rhs
-    )
-    {
-        return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    operator ResultInfoBuilder&
-    ()
-    {
-        return m_result.captureBoolExpression( m_lhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator +
-    (
-        const RhsT&
-    );
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator -
-    (
-        const RhsT&
-    );
-
-private:
-    ResultInfoBuilder& m_result;
-    T m_lhs;
-};
-    
-template<typename LhsT> 
-class PtrExpression
-{
-public:
-
-    ///////////////////////////////////////////////////////////////////////////
-    PtrExpression
-    (
-        ResultInfoBuilder& result, 
-        const LhsT* lhs 
-    )
-    :   m_result( &result ),
-        m_lhs( lhs )
-    {}
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator == 
-    (
-        const RhsT* rhs
-    )
-    {
-        return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    // This catches NULL
-    ResultInfoBuilder& operator == 
-    (
-        LhsT* rhs
-    )
-    {
-        return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    template<typename RhsT>
-    ResultInfoBuilder& operator != 
-    (
-        const RhsT* rhs
-    )
-    {
-        return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
-    }
-    
-    ///////////////////////////////////////////////////////////////////////////
-    // This catches NULL
-    ResultInfoBuilder& operator != 
-    (
-        LhsT* rhs
-    )
-    {
-        return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    operator ResultInfoBuilder&
-    ()
-    {
-        return m_result->captureBoolExpression( m_lhs );
-    }
-    
-    
-private:
-    ResultInfoBuilder* m_result;
-    const LhsT* m_lhs;
-};
-
-    
+ 
 class ResultBuilder
 {
 public:
diff --git a/include/internal/catch_expression.hpp b/include/internal/catch_expression.hpp
new file mode 100644
index 00000000..d1502195
--- /dev/null
+++ b/include/internal/catch_expression.hpp
@@ -0,0 +1,208 @@
+/*
+ *  Created by Phil on 11/5/2012.
+ *  Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
+ *
+ *  Distributed under the Boost Software License, Version 1.0. (See accompanying
+ *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+#ifndef TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
+#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
+
+#include "catch_resultinfo_builder.hpp"
+#include "catch_evaluate.hpp"
+
+namespace Catch
+{
+
+template<typename T>
+class Expression
+{
+	void operator = ( const Expression& );
+
+public:
+    ///////////////////////////////////////////////////////////////////////////
+    Expression
+    (
+        ResultInfoBuilder& result, 
+        T lhs 
+    )
+    :   m_result( result ),
+        m_lhs( lhs )
+    {
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator == 
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator != 
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator <
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator >
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator <= 
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator >= 
+    (
+        const RhsT& rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    ResultInfoBuilder& operator == 
+    (
+        bool rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    ResultInfoBuilder& operator != 
+    (
+        bool rhs
+    )
+    {
+        return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    operator ResultInfoBuilder&
+    ()
+    {
+        return m_result.captureBoolExpression( m_lhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator +
+    (
+        const RhsT&
+    );
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator -
+    (
+        const RhsT&
+    );
+
+private:
+    ResultInfoBuilder& m_result;
+    T m_lhs;
+};
+    
+template<typename LhsT> 
+class PtrExpression
+{
+public:
+
+    ///////////////////////////////////////////////////////////////////////////
+    PtrExpression
+    (
+        ResultInfoBuilder& result, 
+        const LhsT* lhs 
+    )
+    :   m_result( &result ),
+        m_lhs( lhs )
+    {}
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator == 
+    (
+        const RhsT* rhs
+    )
+    {
+        return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // This catches NULL
+    ResultInfoBuilder& operator == 
+    (
+        LhsT* rhs
+    )
+    {
+        return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    template<typename RhsT>
+    ResultInfoBuilder& operator != 
+    (
+        const RhsT* rhs
+    )
+    {
+        return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////
+    // This catches NULL
+    ResultInfoBuilder& operator != 
+    (
+        LhsT* rhs
+    )
+    {
+        return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    operator ResultInfoBuilder&
+    ()
+    {
+        return m_result->captureBoolExpression( m_lhs );
+    }
+    
+    
+private:
+    ResultInfoBuilder* m_result;
+    const LhsT* m_lhs;
+};
+
+} // end namespace Catch
+
+#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
index 0ae06273..db8a0a84 100644
--- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
+++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
@@ -92,6 +92,7 @@
 		4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = "<group>"; };
 		4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_section_info.hpp; sourceTree = "<group>"; };
 		4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_running_test.hpp; sourceTree = "<group>"; };
+		4AC91CCE155CF02800DC5117 /* catch_expression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression.hpp; sourceTree = "<group>"; };
 		4AE1840A14EE4F230066340D /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -214,6 +215,7 @@
 				4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
 				4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */,
 				4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */,
+				4AC91CCE155CF02800DC5117 /* catch_expression.hpp */,
 			);
 			name = Assertions;
 			sourceTree = "<group>";