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

Always debug-break non-inline

Commit
9329d97a43b36aa2499ac1bc1e7ed78815ca2584
Author
Phil Nash ·
Parents
8141a7836fb2

Files · Download .tar.gz

Changes

 include/internal/catch_assertionhandler.cpp | 24 ++++++++++++------------
 include/internal/catch_assertionhandler.h   |  8 +++-----
 include/internal/catch_capture.hpp          | 22 +++-------------------
 include/internal/catch_run_context.cpp      |  6 ++++--
 4 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp
index 8aa7573d..0fe8e3e9 100644
--- a/include/internal/catch_assertionhandler.cpp
+++ b/include/internal/catch_assertionhandler.cpp
@@ -61,7 +61,7 @@ namespace Catch {
         getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo );
     }
     AssertionHandler::~AssertionHandler() {
-        if ( !m_handled ) {
+        if ( !m_completed ) {
             handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" );
             getCurrentContext().getResultCapture()->exceptionEarlyReported();
         }
@@ -76,7 +76,6 @@ namespace Catch {
         {
             getCurrentContext().getResultCapture()->assertionRun();
             getCurrentContext().getResultCapture()->assertionPassed();
-            m_handled = true;
             return;
         }
 
@@ -96,7 +95,6 @@ namespace Catch {
     }
     void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) {
 
-        m_handled = true;
         getResultCapture().assertionRun();
 
         AssertionResult assertionResult{ m_assertionInfo, resultData };
@@ -116,20 +114,22 @@ namespace Catch {
         return getCurrentContext().getConfig()->allowThrows();
     }
 
-    void AssertionHandler::reactWithDebugBreak() const {
-        if (m_shouldDebugBreak) {
-            ///////////////////////////////////////////////////////////////////
-            // To inspect the state during test, you need to go one level up the callstack
-            // To go back to the test and change execution, jump over the reactWithoutDebugBreak() call
-            ///////////////////////////////////////////////////////////////////
+    void AssertionHandler::complete() {
+        setCompleted();
+        if( m_shouldDebugBreak ) {
+
+            // If you find your debugger stopping you here then go one level up on the
+            // call-stack for the code that caused it (typically a failed assertion)
+
+            // (To go back to the test and change execution, jump over the throw, next)
             CATCH_BREAK_INTO_DEBUGGER();
         }
-        reactWithoutDebugBreak();
-    }
-    void AssertionHandler::reactWithoutDebugBreak() const {
         if( m_shouldThrow )
             throw Catch::TestFailureException();
     }
+    void AssertionHandler::setCompleted() {
+        m_completed = true;
+    }
 
     void AssertionHandler::useActiveException() {
         handle( ResultWas::ThrewException, Catch::translateActiveException() );
diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h
index 7903cefe..fb936506 100644
--- a/include/internal/catch_assertionhandler.h
+++ b/include/internal/catch_assertionhandler.h
@@ -36,7 +36,7 @@ namespace Catch {
         AssertionInfo m_assertionInfo;
         bool m_shouldDebugBreak = false;
         bool m_shouldThrow = false;
-        bool m_handled = false;
+        bool m_completed = false;
 
     public:
         AssertionHandler
@@ -57,11 +57,9 @@ namespace Catch {
         void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
         void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
 
-        auto shouldDebugBreak() const -> bool { return m_shouldDebugBreak; }
-
         auto allowThrows() const -> bool;
-        void reactWithDebugBreak() const;
-        void reactWithoutDebugBreak() const;
+        void complete();
+        void setCompleted();
         void useActiveException();
     };
 
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index d7c322ba..69e47ed1 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -11,7 +11,6 @@
 #include "catch_assertionhandler.h"
 #include "catch_message.h"
 #include "catch_interfaces_capture.h"
-#include "catch_debugger.h"
 
 #if !defined(CATCH_CONFIG_DISABLE)
 
@@ -22,37 +21,22 @@
 #endif
 
 #if defined(CATCH_CONFIG_FAST_COMPILE)
-///////////////////////////////////////////////////////////////////////////////
-// We can speedup compilation significantly by breaking into debugger lower in
-// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
-// macro in each assertion
-#define INTERNAL_CATCH_REACT( handler ) \
-    handler.reactWithDebugBreak();
 
 ///////////////////////////////////////////////////////////////////////////////
 // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
 // macros.
-// This can potentially cause false negative, if the test code catches
-// the exception before it propagates back up to the runner.
 #define INTERNAL_CATCH_TRY
 #define INTERNAL_CATCH_CATCH( capturer )
 
 #else // CATCH_CONFIG_FAST_COMPILE
 
-///////////////////////////////////////////////////////////////////////////////
-// In the event of a failure works out if the debugger needs to be invoked
-// and/or an exception thrown and takes appropriate action.
-// This needs to be done as a macro so the debugger will stop in the user
-// source code rather than in Catch library code
-#define INTERNAL_CATCH_REACT( handler ) \
-    if( handler.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
-    handler.reactWithoutDebugBreak();
-
 #define INTERNAL_CATCH_TRY try
-#define INTERNAL_CATCH_CATCH( capturer ) catch(...) { capturer.useActiveException(); }
+#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.useActiveException(); }
 
 #endif
 
+#define INTERNAL_CATCH_REACT( handler ) handler.complete();
+
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
     do { \
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index d6ab1576..1122885e 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -297,11 +297,13 @@ namespace Catch {
             // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
             // are reported without translation at the point of origin.
             if (m_shouldReportUnexpected) {
-                AssertionHandler
+                AssertionHandler handler
                     ( m_lastAssertionInfo.macroName,
                       m_lastAssertionInfo.lineInfo,
                       m_lastAssertionInfo.capturedExpression,
-                      m_lastAssertionInfo.resultDisposition ).useActiveException();
+                      m_lastAssertionInfo.resultDisposition );
+                handler.useActiveException();
+                handler.setCompleted();
             }
         }
         m_testCaseTracker->close();