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

Turn IResultCapture::{push,pop}*Message into free functions

The thread-safety changes in assertions & messages turned the message
stacks into thread-local state, instead of it being member of `RunContext`.
The relevant {push,pop}(Un)ScopedMessage functions were turned from member
functions into static functions, but this left `catch_message.hpp` with
dependency on `IResultCapture`'s definition for the functions, and thus
it still had to include `catch_interfaces_capture.hpp`.

With this change, `catch_message.hpp` no longer needs
`catch_interfaces_capture.hpp`.
Commit
3ab0d7cef3313d91e652a89870c89b0c42760f9e
Author
Martin Hořeňovský ·
Parents
e83218c2dfdf

Files · Download .tar.gz

Changes

 src/catch2/catch_message.cpp                       | 12 ++++-----
 src/catch2/catch_message.hpp                       | 17 +++++++++---
 src/catch2/interfaces/catch_interfaces_capture.hpp |  6 -----
 src/catch2/internal/catch_run_context.cpp          | 31 +++++++++++-----------
 4 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/src/catch2/catch_message.cpp b/src/catch2/catch_message.cpp
index 870651e3..3a83e34e 100644
--- a/src/catch2/catch_message.cpp
+++ b/src/catch2/catch_message.cpp
@@ -5,8 +5,8 @@
 //        https://www.boost.org/LICENSE_1_0.txt)
 
 // SPDX-License-Identifier: BSL-1.0
+
 #include <catch2/catch_message.hpp>
-#include <catch2/interfaces/catch_interfaces_capture.hpp>
 #include <catch2/internal/catch_enforce.hpp>
 #include <catch2/internal/catch_move_and_forward.hpp>
 
@@ -22,7 +22,7 @@ namespace Catch {
         m_messageId( builder.m_info.sequence ) {
         MessageInfo info( CATCH_MOVE( builder.m_info ) );
         info.message = builder.m_stream.str();
-        IResultCapture::pushScopedMessage( CATCH_MOVE( info ) );
+        Detail::pushScopedMessage( CATCH_MOVE( info ) );
     }
 
     ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
@@ -31,7 +31,7 @@ namespace Catch {
     }
 
     ScopedMessage::~ScopedMessage() {
-        if ( !m_moved ) { IResultCapture::popScopedMessage( m_messageId ); }
+        if ( !m_moved ) { Detail::popScopedMessage( m_messageId ); }
     }
 
 
@@ -103,7 +103,7 @@ namespace Catch {
         assert( m_captured == m_messages.size() );
         if ( m_isScoped ) {
             for ( auto const& message : m_messages ) {
-                IResultCapture::popScopedMessage( message.sequence );
+                Detail::popScopedMessage( message.sequence );
             }
         }
     }
@@ -112,9 +112,9 @@ namespace Catch {
         assert( index < m_messages.size() );
         m_messages[index].message += value;
         if ( m_isScoped ) {
-            IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) );
+            Detail::pushScopedMessage( CATCH_MOVE( m_messages[index] ) );
         } else {
-            IResultCapture::addUnscopedMessage( CATCH_MOVE( m_messages[index] ) );
+            Detail::addUnscopedMessage( CATCH_MOVE( m_messages[index] ) );
         }
         m_captured++;
     }
diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp
index 9e868516..4958716d 100644
--- a/src/catch2/catch_message.hpp
+++ b/src/catch2/catch_message.hpp
@@ -14,15 +14,26 @@
 #include <catch2/internal/catch_stream_end_stop.hpp>
 #include <catch2/internal/catch_message_info.hpp>
 #include <catch2/catch_tostring.hpp>
-#include <catch2/interfaces/catch_interfaces_capture.hpp>
 
 #include <string>
 #include <vector>
 
 namespace Catch {
+    struct MessageInfo;
+    struct MessageBuilder;
+
+    namespace Detail {
+        // The message state affecting functions have to be defined in
+        // the TU where the thread-local message holders are defined.
+        // Currently this is catch_run_context.cpp
+
+        void pushScopedMessage( MessageInfo&& message );
+        void popScopedMessage( unsigned int messageId );
+        void addUnscopedMessage( MessageInfo&& message );
+        void emplaceUnscopedMessage( MessageBuilder&& builder );
+    } // namespace Detail
 
     struct SourceLineInfo;
-    class IResultCapture;
 
     struct MessageStream {
 
@@ -112,7 +123,7 @@ namespace Catch {
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
-    Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
+    Catch::Detail::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
 
 
 #if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
diff --git a/src/catch2/interfaces/catch_interfaces_capture.hpp b/src/catch2/interfaces/catch_interfaces_capture.hpp
index 79062cad..b67437b1 100644
--- a/src/catch2/interfaces/catch_interfaces_capture.hpp
+++ b/src/catch2/interfaces/catch_interfaces_capture.hpp
@@ -22,8 +22,6 @@ namespace Catch {
     struct AssertionInfo;
     struct SectionInfo;
     struct SectionEndInfo;
-    struct MessageInfo;
-    struct MessageBuilder;
     struct Counts;
     struct AssertionReaction;
     struct SourceLineInfo;
@@ -63,10 +61,6 @@ namespace Catch {
         virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
         virtual void benchmarkFailed( StringRef error ) = 0;
 
-        static void pushScopedMessage( MessageInfo&& message );
-        static void popScopedMessage( unsigned int messageId );
-        static void addUnscopedMessage( MessageInfo&& message );
-        static void emplaceUnscopedMessage( MessageBuilder&& builder );
 
         virtual void handleFatalErrorCondition( StringRef message ) = 0;
 
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index fd4b7a38..125ffc7b 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -308,6 +308,22 @@ namespace Catch {
         }
         CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
 
+
+        void pushScopedMessage( MessageInfo&& message ) {
+            Detail::g_messageHolder().addScopedMessage(  CATCH_MOVE( message ) );
+        }
+
+        void popScopedMessage( unsigned int messageId ) {
+            Detail::g_messageHolder().removeMessage( messageId );
+        }
+
+        void emplaceUnscopedMessage( MessageBuilder&& builder ) {
+            Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( builder ) );
+        }
+
+        void addUnscopedMessage( MessageInfo&& message ) {
+            Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) );
+        }
     } // namespace Detail
 
     RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter)
@@ -937,21 +953,6 @@ namespace Catch {
         }
     }
 
-    void IResultCapture::pushScopedMessage( MessageInfo&& message ) {
-        Detail::g_messageHolder().addScopedMessage(  CATCH_MOVE( message ) );
-    }
-
-    void IResultCapture::popScopedMessage( unsigned int messageId ) {
-        Detail::g_messageHolder().removeMessage( messageId );
-    }
-
-    void IResultCapture::emplaceUnscopedMessage( MessageBuilder&& builder ) {
-        Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( builder ) );
-    }
-
-    void IResultCapture::addUnscopedMessage( MessageInfo&& message ) {
-        Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) );
-    }
 
     void seedRng(IConfig const& config) {
         sharedRng().seed(config.rngSeed());