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

Fixed a potential ordering issue with output streambufs

Commit
48112c2700cff97b2c078a59b2d8e7094702ae12
Author
Phil Nash ·
Parents
6b6143ccd4a5

Files · Download .tar.gz

Changes

 include/catch.hpp                 |  1 -
 include/internal/catch_config.hpp | 17 ++++++++---------
 single_include/catch.hpp          | 18 ++++++++----------
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/include/catch.hpp b/include/catch.hpp
index 49109da6..4925e334 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -16,7 +16,6 @@
 
  Later:
     Finish command line parser (list as xml, specify FP tolerance)
-    Revisit Approx()
     Tags?
     Finish macros, listed here, later (just CHECK_NOFAIL now)
  */
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index e577cacb..e23f40b8 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -60,15 +60,16 @@ namespace Catch
             m_listSpec( List::None ),
             m_shouldDebugBreak( false ),
             m_showHelp( false ),
-            m_streambuf( std::cout.rdbuf() ),
-            m_os( m_streambuf ),
+            m_streambuf( NULL ),
+            m_os( std::cout.rdbuf() ),
             m_includeWhat( Include::FailedOnly )
         {}
         
         ///////////////////////////////////////////////////////////////////////////
         ~Config()
         {
-            setStreamBuf( NULL );
+            m_os.rdbuf( std::cout.rdbuf() );
+            delete m_streambuf;
         }
         
         ///////////////////////////////////////////////////////////////////////////
@@ -210,18 +211,16 @@ namespace Catch
         ///////////////////////////////////////////////////////////////////////////
         void setStreamBuf( std::streambuf* buf )
         {
-            // Delete previous stream buf if we own it
-            if( m_streambuf && dynamic_cast<StreamBufBase*>( m_streambuf ) )
-                delete m_streambuf;
-
-            m_streambuf = buf;
             m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
         }        
 
         ///////////////////////////////////////////////////////////////////////////
         void useStream( const std::string& streamName )
         {
-            setStreamBuf( Hub::createStreamBuf( streamName ) );
+            std::streambuf* newBuf = Hub::createStreamBuf( streamName );
+            setStreamBuf( newBuf );
+            delete m_streambuf;
+            m_streambuf = newBuf;
         }        
         
         ///////////////////////////////////////////////////////////////////////////
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index 09e5d0c8..2b6c7aad 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -20,7 +20,6 @@
 
  Later:
     Finish command line parser (list as xml, specify FP tolerance)
-    Revisit Approx()
     Tags?
     Finish macros, listed here, later (just CHECK_NOFAIL now)
  */
@@ -3163,15 +3162,16 @@ namespace Catch
             m_listSpec( List::None ),
             m_shouldDebugBreak( false ),
             m_showHelp( false ),
-            m_streambuf( std::cout.rdbuf() ),
-            m_os( m_streambuf ),
+            m_streambuf( NULL ),
+            m_os( std::cout.rdbuf() ),
             m_includeWhat( Include::FailedOnly )
         {}
 
         ///////////////////////////////////////////////////////////////////////////
         ~Config()
         {
-            setStreamBuf( NULL );
+            m_os.rdbuf( std::cout.rdbuf() );
+            delete m_streambuf;
         }
 
         ///////////////////////////////////////////////////////////////////////////
@@ -3313,18 +3313,16 @@ namespace Catch
         ///////////////////////////////////////////////////////////////////////////
         void setStreamBuf( std::streambuf* buf )
         {
-            // Delete previous stream buf if we own it
-            if( m_streambuf && dynamic_cast<StreamBufBase*>( m_streambuf ) )
-                delete m_streambuf;
-
-            m_streambuf = buf;
             m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
         }
 
         ///////////////////////////////////////////////////////////////////////////
         void useStream( const std::string& streamName )
         {
-            setStreamBuf( Hub::createStreamBuf( streamName ) );
+            std::streambuf* newBuf = Hub::createStreamBuf( streamName );
+            setStreamBuf( newBuf );
+            delete m_streambuf;
+            m_streambuf = newBuf;
         }
 
         ///////////////////////////////////////////////////////////////////////////