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

Reorganize base headers for matchers

Commit
40e35d43182c69f56ab892f92e079af5d2b94dc5
Author
Martin Hořeňovský ·
Parents
b83a12b12cf0

Files · Download .tar.gz

Changes

 src/catch2/catch_capture_matchers.cpp |   4 +-
 src/catch2/catch_capture_matchers.h   |  10 ++--
 src/catch2/catch_matchers.cpp         |  10 ++--
 src/catch2/catch_matchers.h           | 100 ++++++++++++++++++++++++----------
 src/catch2/catch_test_macros.hpp      |  33 -----------
 5 files changed, 84 insertions(+), 73 deletions(-)

diff --git a/src/catch2/catch_capture_matchers.cpp b/src/catch2/catch_capture_matchers.cpp
index 2b455a93..809da66d 100644
--- a/src/catch2/catch_capture_matchers.cpp
+++ b/src/catch2/catch_capture_matchers.cpp
@@ -1,11 +1,9 @@
 /*
- *  Created by Phil on 9/8/2017.
- *  Copyright 2017 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)
  */
 #include <catch2/catch_capture_matchers.h>
+#include <catch2/catch_matchers.h>
 #include <catch2/catch_interfaces_registry_hub.h>
 
 namespace Catch {
diff --git a/src/catch2/catch_capture_matchers.h b/src/catch2/catch_capture_matchers.h
index b567b8e8..1b622413 100644
--- a/src/catch2/catch_capture_matchers.h
+++ b/src/catch2/catch_capture_matchers.h
@@ -1,7 +1,4 @@
 /*
- *  Created by Phil on 9/8/2017
- *  Copyright 2017 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)
  */
@@ -9,7 +6,6 @@
 #define TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
 
 #include <catch2/catch_capture.hpp>
-#include <catch2/catch_matchers.h>
 #include <catch2/catch_stringref.h>
 
 namespace Catch {
@@ -37,6 +33,11 @@ namespace Catch {
         }
     };
 
+    namespace Matchers {
+    template <typename ArgT>
+    struct MatcherBase;
+    }
+
     using StringMatcher = Matchers::MatcherBase<std::string>;
 
     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString  );
@@ -80,4 +81,5 @@ namespace Catch {
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
 
+
 #endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
diff --git a/src/catch2/catch_matchers.cpp b/src/catch2/catch_matchers.cpp
index 7793ed06..af32b6cb 100644
--- a/src/catch2/catch_matchers.cpp
+++ b/src/catch2/catch_matchers.cpp
@@ -1,6 +1,4 @@
 /*
- *  Created by Phil Nash on 19/07/2017.
- *
  * 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)
  */
@@ -8,15 +6,17 @@
 #include <catch2/catch_matchers.h>
 
 namespace Catch {
-namespace Matchers {
+
+    namespace Matchers {
 
         std::string MatcherUntypedBase::toString() const {
-            if( m_cachedToString.empty() )
+            if (m_cachedToString.empty())
                 m_cachedToString = describe();
             return m_cachedToString;
         }
 
         MatcherUntypedBase::~MatcherUntypedBase() = default;
 
-} // namespace Matchers
+    } // namespace Matchers
+
 } // namespace Catch
diff --git a/src/catch2/catch_matchers.h b/src/catch2/catch_matchers.h
index 2d43cb8a..102917a3 100644
--- a/src/catch2/catch_matchers.h
+++ b/src/catch2/catch_matchers.h
@@ -1,7 +1,4 @@
 /*
- *  Created by Phil Nash on 04/03/2012.
- *  Copyright (c) 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)
  */
@@ -9,6 +6,7 @@
 #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
 
 #include <catch2/catch_common.h>
+#include <catch2/catch_capture_matchers.h>
 
 #include <string>
 #include <vector>
@@ -16,44 +14,44 @@
 namespace Catch {
 namespace Matchers {
 
+    class MatcherUntypedBase {
+    public:
+        MatcherUntypedBase() = default;
+        MatcherUntypedBase(MatcherUntypedBase const&) = default;
+        MatcherUntypedBase& operator = (MatcherUntypedBase const&) = delete;
+        std::string toString() const;
+
+    protected:
+        virtual ~MatcherUntypedBase(); // = default;
+        virtual std::string describe() const = 0;
+        mutable std::string m_cachedToString;
+    };
+
 #ifdef __clang__
 #    pragma clang diagnostic push
 #    pragma clang diagnostic ignored "-Wnon-virtual-dtor"
 #endif
 
-        class MatcherUntypedBase {
-        public:
-            MatcherUntypedBase() = default;
-            MatcherUntypedBase ( MatcherUntypedBase const& ) = default;
-            MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete;
-            std::string toString() const;
-
-        protected:
-            virtual ~MatcherUntypedBase(); // = default;
-            virtual std::string describe() const = 0;
-            mutable std::string m_cachedToString;
-        };
-
-        template<typename ObjectT>
-        struct MatcherMethod {
-            virtual bool match( ObjectT const& arg ) const = 0;
-        };
+    template<typename ObjectT>
+    struct MatcherMethod {
+        virtual bool match(ObjectT const& arg) const = 0;
+    };
 
 #if defined(__OBJC__)
-        // Hack to fix Catch GH issue #1661. Could use id for generic Object support.
-        // use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
-        template<>
-        struct MatcherMethod<NSString*> {
-            virtual bool match( NSString* arg ) const = 0;
-        };
+    // Hack to fix Catch GH issue #1661. Could use id for generic Object support.
+    // use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
+    template<>
+    struct MatcherMethod<NSString*> {
+        virtual bool match(NSString* arg) const = 0;
+    };
 #endif
 
 #ifdef __clang__
 #    pragma clang diagnostic pop
 #endif
 
-        template<typename T>
-        struct MatcherBase : MatcherUntypedBase, MatcherMethod<T> {};
+    template<typename T>
+    struct MatcherBase : MatcherUntypedBase, MatcherMethod<T> {};
 
     namespace Detail {
 
@@ -203,4 +201,50 @@ namespace Matchers {
 } // namespace Matchers
 } // namespace Catch
 
+
+#if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
+  #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
+  #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
+
+  #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+  #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+
+  #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
+  #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
+
+#elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
+
+  #define CATCH_REQUIRE_THROWS_WITH( expr, matcher )                   (void)(0)
+  #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+
+  #define CATCH_CHECK_THROWS_WITH( expr, matcher )                     (void)(0)
+  #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher )   (void)(0)
+
+  #define CATCH_CHECK_THAT( arg, matcher )                             (void)(0)
+  #define CATCH_REQUIRE_THAT( arg, matcher )                           (void)(0)
+
+#elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
+
+  #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
+  #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
+
+  #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+  #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
+
+  #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
+  #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
+
+#elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
+
+  #define REQUIRE_THROWS_WITH( expr, matcher )                   (void)(0)
+  #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
+
+  #define CHECK_THROWS_WITH( expr, matcher )                     (void)(0)
+  #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher )   (void)(0)
+
+  #define CHECK_THAT( arg, matcher )                             (void)(0)
+  #define REQUIRE_THAT( arg, matcher )                           (void)(0)
+
+#endif // end of user facing macro declarations
+
 #endif // TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
diff --git a/src/catch2/catch_test_macros.hpp b/src/catch2/catch_test_macros.hpp
index 0dd41bf5..a5b2d0c3 100644
--- a/src/catch2/catch_test_macros.hpp
+++ b/src/catch2/catch_test_macros.hpp
@@ -7,7 +7,6 @@
 #define TWOBLUECUBES_CATCH_TEST_MACROS_HPP_INCLUDED
 
 #include <catch2/catch_capture.hpp>
-#include <catch2/catch_capture_matchers.h>
 #include <catch2/catch_interfaces_exception.h>
 #include <catch2/catch_preprocessor.hpp>
 #include <catch2/catch_section.h>
@@ -23,8 +22,6 @@
 
 #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
 #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
-#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
-#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
 #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
 
 #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
@@ -35,14 +32,8 @@
 
 #define CATCH_CHECK_THROWS( ... )  INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
 #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
-#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
-#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
 #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
 
-#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
-
-#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
-
 #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
 #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
 #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
@@ -111,8 +102,6 @@
 
 #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
 #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
-#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
-#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
 #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
 
 #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
@@ -123,15 +112,9 @@
 
 #define CHECK_THROWS( ... )  INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
 #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
-#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
-#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
 #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
 
 
-#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
-
-#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
-
 #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
 #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
 #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
@@ -211,8 +194,6 @@
 
 #define CATCH_REQUIRE_THROWS( ... ) (void)(0)
 #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
-#define CATCH_REQUIRE_THROWS_WITH( expr, matcher )     (void)(0)
-#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
 #define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
 
 #define CATCH_CHECK( ... )         (void)(0)
@@ -223,14 +204,8 @@
 
 #define CATCH_CHECK_THROWS( ... )  (void)(0)
 #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
-#define CATCH_CHECK_THROWS_WITH( expr, matcher )     (void)(0)
-#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
 #define CATCH_CHECK_NOTHROW( ... ) (void)(0)
 
-#define CATCH_CHECK_THAT( arg, matcher )   (void)(0)
-
-#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
-
 #define CATCH_INFO( msg )          (void)(0)
 #define CATCH_UNSCOPED_INFO( msg ) (void)(0)
 #define CATCH_WARN( msg )          (void)(0)
@@ -287,8 +262,6 @@
 
 #define REQUIRE_THROWS( ... ) (void)(0)
 #define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
-#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
-#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
 #define REQUIRE_NOTHROW( ... ) (void)(0)
 
 #define CHECK( ... ) (void)(0)
@@ -299,14 +272,8 @@
 
 #define CHECK_THROWS( ... )  (void)(0)
 #define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
-#define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
-#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
 #define CHECK_NOTHROW( ... ) (void)(0)
 
-#define CHECK_THAT( arg, matcher ) (void)(0)
-
-#define REQUIRE_THAT( arg, matcher ) (void)(0)
-
 #define INFO( msg ) (void)(0)
 #define UNSCOPED_INFO( msg ) (void)(0)
 #define WARN( msg ) (void)(0)