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

Refactored most handle() calls to more specific/ descriptive calls

Commit
db44964e27cb9dc4e4ff115e0ba29c9038824bcc
Author
Phil Nash ·
Parents
2800adba2518

Files · Download .tar.gz

Changes

 include/internal/catch_assertionhandler.cpp | 20 ++++++++++++++++++--
 include/internal/catch_assertionhandler.h   | 23 ++++++++++++++++-------
 include/internal/catch_capture.hpp          | 26 +++++++++++++-------------
 include/internal/catch_capture_matchers.cpp |  2 +-
 include/internal/catch_capture_matchers.h   | 10 +++++-----
 include/internal/catch_run_context.cpp      |  2 +-
 6 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp
index 34540e94..a5a2e2c1 100644
--- a/include/internal/catch_assertionhandler.cpp
+++ b/include/internal/catch_assertionhandler.cpp
@@ -68,7 +68,7 @@ namespace Catch {
         }
     }
 
-    void AssertionHandler::handle( ITransientExpression const& expr ) {
+    void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
 
         bool negated = isFalseTest( m_assertionInfo.resultDisposition );
         bool result = expr.getResult() != negated;
@@ -132,10 +132,26 @@ namespace Catch {
         m_completed = true;
     }
 
-    void AssertionHandler::useActiveException() {
+    void AssertionHandler::handleUnexpectedInflightException() {
         handle( ResultWas::ThrewException, Catch::translateActiveException() );
     }
 
+    void AssertionHandler::handleExceptionThrownAsExpected() {
+        handle( Catch::ResultWas::Ok );
+    }
+    void AssertionHandler::handleExceptionNotThrownAsExpected() {
+        handle( Catch::ResultWas::Ok );
+    }
+
+    void AssertionHandler::handleUnexpectedExceptionNotThrown() {
+        handle( Catch::ResultWas::DidntThrowException );
+    }
+
+    void AssertionHandler::handleThrowingCallSkipped() {
+        handle( Catch::ResultWas::Ok );
+    }
+
+
     // This is the overload that takes a string and infers the Equals matcher from it
     // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString  ) {
diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h
index 02d89221..7eee7f2d 100644
--- a/include/internal/catch_assertionhandler.h
+++ b/include/internal/catch_assertionhandler.h
@@ -48,21 +48,30 @@ namespace Catch {
                 ResultDisposition::Flags resultDisposition );
         ~AssertionHandler();
 
-        void handle( ITransientExpression const& expr );
-
         template<typename T>
-        void handle( ExprLhs<T> const& expr ) {
-            handle( expr.makeUnaryExpr() );
+        void handleExpr( ExprLhs<T> const& expr ) {
+            handleExpr( expr.makeUnaryExpr() );
         }
-        void handle( ResultWas::OfType resultType );
+        void handleExpr( ITransientExpression const& expr );
+
         void handle( ResultWas::OfType resultType, StringRef const& message );
         void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
         void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
 
-        auto allowThrows() const -> bool;
+        void handleExceptionThrownAsExpected();
+        void handleUnexpectedExceptionNotThrown();
+        void handleExceptionNotThrownAsExpected();
+        void handleThrowingCallSkipped();
+        void handleUnexpectedInflightException();
+
         void complete();
         void setCompleted();
-        void useActiveException();
+
+        // query
+        auto allowThrows() const -> bool;
+
+    private:
+        void handle( ResultWas::OfType resultType );
     };
 
     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 44368e5a..fcdeabf9 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -31,7 +31,7 @@
 #else // CATCH_CONFIG_FAST_COMPILE
 
 #define INTERNAL_CATCH_TRY try
-#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.useActiveException(); }
+#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
 
 #endif
 
@@ -43,7 +43,7 @@
         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
         INTERNAL_CATCH_TRY { \
             CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
-            catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \
+            catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
             CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
@@ -66,10 +66,10 @@
         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
         try { \
             static_cast<void>(__VA_ARGS__); \
-            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
         } \
         catch( ... ) { \
-            catchAssertionHandler.useActiveException(); \
+            catchAssertionHandler.handleUnexpectedInflightException(); \
         } \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
@@ -81,13 +81,13 @@
         if( catchAssertionHandler.allowThrows() ) \
             try { \
                 static_cast<void>(__VA_ARGS__); \
-                catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
+                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
             } \
             catch( ... ) { \
-                catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+                catchAssertionHandler.handleExceptionThrownAsExpected(); \
             } \
         else \
-            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handleThrowingCallSkipped(); \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
 
@@ -98,16 +98,16 @@
         if( catchAssertionHandler.allowThrows() ) \
             try { \
                 static_cast<void>(expr); \
-                catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
+                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
             } \
             catch( exceptionType const& ) { \
-                catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+                catchAssertionHandler.handleExceptionThrownAsExpected(); \
             } \
             catch( ... ) { \
-                catchAssertionHandler.useActiveException(); \
+                catchAssertionHandler.handleUnexpectedInflightException(); \
             } \
         else \
-            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handleThrowingCallSkipped(); \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
 
@@ -132,13 +132,13 @@
         if( catchAssertionHandler.allowThrows() ) \
             try { \
                 static_cast<void>(__VA_ARGS__); \
-                catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
+                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
             } \
             catch( ... ) { \
                 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \
             } \
         else \
-            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handleThrowingCallSkipped(); \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
 
diff --git a/include/internal/catch_capture_matchers.cpp b/include/internal/catch_capture_matchers.cpp
index 758177e9..7ef1597d 100644
--- a/include/internal/catch_capture_matchers.cpp
+++ b/include/internal/catch_capture_matchers.cpp
@@ -18,7 +18,7 @@ namespace Catch {
     void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString  ) {
         std::string exceptionMessage = Catch::translateActiveException();
         MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
-        handler.handle( expr );
+        handler.handleExpr( expr );
     }
 
 } // namespace Catch
diff --git a/include/internal/catch_capture_matchers.h b/include/internal/catch_capture_matchers.h
index 9cbcb21d..afd95801 100644
--- a/include/internal/catch_capture_matchers.h
+++ b/include/internal/catch_capture_matchers.h
@@ -60,7 +60,7 @@ namespace Catch {
     do { \
         Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
         INTERNAL_CATCH_TRY { \
-            catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
+            catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
@@ -73,16 +73,16 @@ namespace Catch {
         if( catchAssertionHandler.allowThrows() ) \
             try { \
                 static_cast<void>(__VA_ARGS__ ); \
-                catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
+                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
             } \
             catch( exceptionType const& ex ) { \
-                catchAssertionHandler.handle( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
+                catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
             } \
             catch( ... ) { \
-                catchAssertionHandler.useActiveException(); \
+                catchAssertionHandler.handleUnexpectedInflightException(); \
             } \
         else \
-            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handleThrowingCallSkipped(); \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
     } while( false )
 
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index 1122885e..d334275e 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -302,7 +302,7 @@ namespace Catch {
                       m_lastAssertionInfo.lineInfo,
                       m_lastAssertionInfo.capturedExpression,
                       m_lastAssertionInfo.resultDisposition );
-                handler.useActiveException();
+                handler.handleUnexpectedInflightException();
                 handler.setCompleted();
             }
         }