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 ):
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 {

View File

@ -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;

View File

@ -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;