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

integrated AssertionHandler into INTERNAL_CATCH_NO_THROW

Commit
f033f4f1842cb3859b97855261d3119488783b20
Author
Phil Nash ·
Parents
f247ce5bff02

Files · Download .tar.gz

Changes

 include/internal/catch_assertionhandler.cpp | 46 +++++++++++------------------
 include/internal/catch_assertionhandler.h   |  4 +++
 include/internal/catch_capture.hpp          | 11 +++----
 3 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp
index a71a2dc2..1b7e1346 100644
--- a/include/internal/catch_assertionhandler.cpp
+++ b/include/internal/catch_assertionhandler.cpp
@@ -59,24 +59,17 @@ namespace Catch {
         getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo );
     }
 
-    void AssertionHandler::handle( ITransientExpression const& expr ) {
-
-        bool negated = isFalseTest( m_assertionInfo.resultDisposition );
-        bool result = expr.getResult() != negated;
-
-        AssertionResultData data( result ? ResultWas::Ok : ResultWas::ExpressionFailed, LazyExpression( negated ) );
-
-        // Deprecated
-//        data.negated = negated;
-//        data.parenthesized = negated && expr.isBinaryExpression(); // !TBD: needed?
-//        data.decomposedExpression = nullptr; // !TBD
-//        data.reconstructedExpression = ""; // !TBD
+    void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) {
 
+        AssertionResultData data( resultType, LazyExpression( negated ) );
+        handle( data, expr );
+    }
+    void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) {
 
         getResultCapture().assertionRun();
 
-        AssertionResult assertionResult{ m_assertionInfo, data };
-        assertionResult.m_resultData.lazyExpression.m_transientExpression = &expr;
+        AssertionResult assertionResult{ m_assertionInfo, resultData };
+        assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
 
         getResultCapture().assertionEnded( assertionResult );
 
@@ -87,6 +80,16 @@ namespace Catch {
                     (m_assertionInfo.resultDisposition & ResultDisposition::Normal);
         }
     }
+    void AssertionHandler::handle( ITransientExpression const& expr ) {
+
+        bool negated = isFalseTest( m_assertionInfo.resultDisposition );
+        bool result = expr.getResult() != negated;
+
+        handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated );
+    }
+    void AssertionHandler::handle( ResultWas::OfType resultType ) {
+        handle( resultType, nullptr, false );
+    }
 
     auto AssertionHandler::shouldDebugBreak() const -> bool {
         return m_shouldDebugBreak;
@@ -116,20 +119,7 @@ namespace Catch {
         AssertionResultData data( ResultWas::ThrewException, LazyExpression( negated ) );
         data.message = Catch::translateActiveException();
 
-        //data.decomposedExpression = &expr; // for lazy reconstruction
-
-        AssertionResult result( m_assertionInfo, data );
-
-        getResultCapture().assertionEnded( result );
-
-        // !TBD: factor this out? handleResult()?
-        if( !result.isOk() ) {
-            if( getCurrentContext().getConfig()->shouldDebugBreak() )
-                m_shouldDebugBreak = true;
-            if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
-                m_shouldThrow = true;
-        }
-
+        handle( data, nullptr );
     }
 
 } // namespace Catch
diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h
index 8c8dff67..0c8b020b 100644
--- a/include/internal/catch_assertionhandler.h
+++ b/include/internal/catch_assertionhandler.h
@@ -14,6 +14,7 @@
 namespace Catch {
 
     struct TestFailureException{};
+    struct AssertionResultData;
 
     class LazyExpression {
         friend class AssertionHandler;
@@ -48,6 +49,9 @@ namespace Catch {
         void handle( ExprLhs<T> const& expr ) {
             handle( expr.makeUnaryExpr() );
         }
+        void handle( ResultWas::OfType resultType );
+        void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
+        void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
 
         auto shouldDebugBreak() const -> bool;
         void reactWithDebugBreak() const;
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index aafafeef..9510d7a5 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -51,6 +51,7 @@
 
 #define INTERNAL_CATCH_TRY try
 #define INTERNAL_CATCH_CATCH( capturer, disposition ) catch(...) { capturer.useActiveException( disposition ); }
+#define INTERNAL_CATCH_CATCH2( capturer ) catch(...) { capturer.useActiveException(); }
 
 #endif
 
@@ -62,7 +63,7 @@
             CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
             catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \
             CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
-        } INTERNAL_CATCH_CATCH( catchAssertionHandler, resultDisposition ) \
+        } INTERNAL_CATCH_CATCH2( catchAssertionHandler ) \
         INTERNAL_CATCH_REACT2( catchAssertionHandler ) \
     } while( Catch::isTrue( false && static_cast<bool>( !!(__VA_ARGS__) ) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
     // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
@@ -80,15 +81,15 @@
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
     do { \
-        Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition ); \
+        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition ); \
         try { \
             static_cast<void>(__VA_ARGS__); \
-            __catchResult.captureResult( Catch::ResultWas::Ok ); \
+            catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
         } \
         catch( ... ) { \
-            __catchResult.useActiveException( resultDisposition ); \
+            catchAssertionHandler.useActiveException(); \
         } \
-        INTERNAL_CATCH_REACT( __catchResult ) \
+        INTERNAL_CATCH_REACT2( catchAssertionHandler ) \
     } while( Catch::alwaysFalse() )
 
 ///////////////////////////////////////////////////////////////////////////////