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

Remove special handling of default stream for reporters

This fixes an issue where reporter with default-output to stdout
would think that it was given a stream _not_ backed by console,
thus not using colour.
Commit
06092f727d271d2128b026db99dc0d5736434481
Author
Martin Hořeňovský ·
Parents
4acc520f763f

Files · Download .tar.gz

Changes

 src/catch2/catch_config.cpp                       | 16 ++++++++++------
 src/catch2/catch_config.hpp                       |  2 --
 src/catch2/interfaces/catch_interfaces_config.hpp |  1 -
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index 6d6e0831..8541d223 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -45,8 +45,7 @@ namespace Catch {
     }
 
     Config::Config( ConfigData const& data ):
-        m_data( data ),
-        m_defaultStream( openStream( data.defaultOutputFilename ) ) {
+        m_data( data ) {
         // We need to trim filter specs to avoid trouble with superfluous
         // whitespace (esp. important for bdd macros, as those are manually
         // aligned with whitespace).
@@ -81,13 +80,19 @@ namespace Catch {
             } );
         }
 
+        bool defaultOutputUsed = false;
         m_reporterStreams.reserve( m_data.reporterSpecifications.size() );
         for ( auto const& reporterAndFile : m_data.reporterSpecifications ) {
             if ( reporterAndFile.outputFileName.none() ) {
-                m_reporterStreams.emplace_back( new Detail::RDBufStream(
-                    m_defaultStream->stream().rdbuf() ) );
+                CATCH_ENFORCE( !defaultOutputUsed,
+                               "Internal error: cannot use default output for "
+                               "multiple reporters" );
+                defaultOutputUsed = true;
+
+                m_reporterStreams.push_back(
+                    openStream( data.defaultOutputFilename ) );
             } else {
-                m_reporterStreams.emplace_back(
+                m_reporterStreams.push_back(
                     openStream( *reporterAndFile.outputFileName ) );
             }
         }
@@ -118,7 +123,6 @@ namespace Catch {
 
     // IConfig interface
     bool Config::allowThrows() const                   { return !m_data.noThrow; }
-    IStream const* Config::defaultStream() const       { return m_defaultStream.get(); }
     StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
     bool Config::includeSuccessfulResults() const      { return m_data.showSuccessfulTests; }
     bool Config::warnAboutMissingAssertions() const {
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index 7b33fa71..2a71537d 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -103,7 +103,6 @@ namespace Catch {
 
         // IConfig interface
         bool allowThrows() const override;
-        IStream const* defaultStream() const override;
         StringRef name() const override;
         bool includeSuccessfulResults() const override;
         bool warnAboutMissingAssertions() const override;
@@ -130,7 +129,6 @@ namespace Catch {
         Detail::unique_ptr<IStream const> openStream(std::string const& outputFileName);
         ConfigData m_data;
 
-        Detail::unique_ptr<IStream const> m_defaultStream;
         std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams;
         TestSpec m_testSpec;
         bool m_hasTestFilters = false;
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index 6c17081a..d98f7b44 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -62,7 +62,6 @@ namespace Catch {
         virtual ~IConfig();
 
         virtual bool allowThrows() const = 0;
-        virtual IStream const* defaultStream() const = 0;
         virtual StringRef name() const = 0;
         virtual bool includeSuccessfulResults() const = 0;
         virtual bool shouldDebugBreak() const = 0;