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.
This commit is contained in:
Martin Hořeňovský 2022-03-18 00:14:09 +01:00
parent 4acc520f76
commit 06092f727d
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
3 changed files with 10 additions and 9 deletions

View File

@ -45,8 +45,7 @@ namespace Catch {
} }
Config::Config( ConfigData const& data ): Config::Config( ConfigData const& data ):
m_data( data ), m_data( data ) {
m_defaultStream( openStream( data.defaultOutputFilename ) ) {
// We need to trim filter specs to avoid trouble with superfluous // We need to trim filter specs to avoid trouble with superfluous
// whitespace (esp. important for bdd macros, as those are manually // whitespace (esp. important for bdd macros, as those are manually
// aligned with whitespace). // aligned with whitespace).
@ -81,13 +80,19 @@ namespace Catch {
} ); } );
} }
bool defaultOutputUsed = false;
m_reporterStreams.reserve( m_data.reporterSpecifications.size() ); m_reporterStreams.reserve( m_data.reporterSpecifications.size() );
for ( auto const& reporterAndFile : m_data.reporterSpecifications ) { for ( auto const& reporterAndFile : m_data.reporterSpecifications ) {
if ( reporterAndFile.outputFileName.none() ) { if ( reporterAndFile.outputFileName.none() ) {
m_reporterStreams.emplace_back( new Detail::RDBufStream( CATCH_ENFORCE( !defaultOutputUsed,
m_defaultStream->stream().rdbuf() ) ); "Internal error: cannot use default output for "
"multiple reporters" );
defaultOutputUsed = true;
m_reporterStreams.push_back(
openStream( data.defaultOutputFilename ) );
} else { } else {
m_reporterStreams.emplace_back( m_reporterStreams.push_back(
openStream( *reporterAndFile.outputFileName ) ); openStream( *reporterAndFile.outputFileName ) );
} }
} }
@ -118,7 +123,6 @@ namespace Catch {
// IConfig interface // IConfig interface
bool Config::allowThrows() const { return !m_data.noThrow; } 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; } 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::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
bool Config::warnAboutMissingAssertions() const { bool Config::warnAboutMissingAssertions() const {

View File

@ -103,7 +103,6 @@ namespace Catch {
// IConfig interface // IConfig interface
bool allowThrows() const override; bool allowThrows() const override;
IStream const* defaultStream() const override;
StringRef name() const override; StringRef name() const override;
bool includeSuccessfulResults() const override; bool includeSuccessfulResults() const override;
bool warnAboutMissingAssertions() const override; bool warnAboutMissingAssertions() const override;
@ -130,7 +129,6 @@ namespace Catch {
Detail::unique_ptr<IStream const> openStream(std::string const& outputFileName); Detail::unique_ptr<IStream const> openStream(std::string const& outputFileName);
ConfigData m_data; ConfigData m_data;
Detail::unique_ptr<IStream const> m_defaultStream;
std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams; std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams;
TestSpec m_testSpec; TestSpec m_testSpec;
bool m_hasTestFilters = false; bool m_hasTestFilters = false;

View File

@ -62,7 +62,6 @@ namespace Catch {
virtual ~IConfig(); virtual ~IConfig();
virtual bool allowThrows() const = 0; virtual bool allowThrows() const = 0;
virtual IStream const* defaultStream() const = 0;
virtual StringRef name() const = 0; virtual StringRef name() const = 0;
virtual bool includeSuccessfulResults() const = 0; virtual bool includeSuccessfulResults() const = 0;
virtual bool shouldDebugBreak() const = 0; virtual bool shouldDebugBreak() const = 0;