Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-02-23 23:46:45 +0100
committerMartin Hořeňovský2022-03-06 16:34:13 +0100
commit61d0f7a9afb88c12f8931f80321e58f2cfbc62db (patch)
treecdb5f8f3a86c99dd56c5dcb14a05b3f5751b1e9b /src
parent9b01c404f514782383ec064c57a0a8e7d326f476 (diff)
downloadcatch3-61d0f7a9afb88c12f8931f80321e58f2cfbc62db.tar.gz
Pass the whole IStream wrapper into reporter
This will become useful when reworking colour support, because Win32 colour support requires checking whether the output is stdout, which is done through the `IStream` wrapper.
Diffstat (limited to 'src')
-rw-r--r--src/catch2/catch_config.cpp6
-rw-r--r--src/catch2/catch_config.hpp6
-rw-r--r--src/catch2/catch_session.cpp4
-rw-r--r--src/catch2/interfaces/catch_interfaces_config.hpp3
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter.cpp6
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter.hpp7
-rw-r--r--src/catch2/internal/catch_console_colour.cpp2
-rw-r--r--src/catch2/internal/catch_stream.hpp3
-rw-r--r--src/catch2/reporters/catch_reporter_common_base.hpp11
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp2
-rw-r--r--src/catch2/reporters/catch_reporter_xml.cpp2
11 files changed, 31 insertions, 21 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index e6a5b2ed..6d6e0831 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -107,8 +107,8 @@ namespace Catch {
return m_data.reporterSpecifications;
}
- std::ostream& Config::getReporterOutputStream(std::size_t reporterIdx) const {
- return m_reporterStreams.at(reporterIdx)->stream();
+ IStream const* Config::getReporterOutputStream(std::size_t reporterIdx) const {
+ return m_reporterStreams.at(reporterIdx).get();
}
TestSpec const& Config::testSpec() const { return m_testSpec; }
@@ -118,7 +118,7 @@ namespace Catch {
// IConfig interface
bool Config::allowThrows() const { return !m_data.noThrow; }
- std::ostream& Config::defaultStream() const { return m_defaultStream->stream(); }
+ 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 2795d42e..7b33fa71 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -21,7 +21,7 @@
namespace Catch {
- struct IStream;
+ class IStream;
struct ConfigData {
struct ReporterAndFile {
@@ -91,7 +91,7 @@ namespace Catch {
bool listReporters() const;
std::vector<ConfigData::ReporterAndFile> const& getReportersAndOutputFiles() const;
- std::ostream& getReporterOutputStream(std::size_t reporterIdx) const;
+ IStream const* getReporterOutputStream(std::size_t reporterIdx) const;
std::vector<std::string> const& getTestsOrTags() const override;
std::vector<std::string> const& getSectionsToRun() const override;
@@ -103,7 +103,7 @@ namespace Catch {
// IConfig interface
bool allowThrows() const override;
- std::ostream& defaultStream() const override;
+ IStream const* defaultStream() const override;
StringRef name() const override;
bool includeSuccessfulResults() const override;
bool warnAboutMissingAssertions() const override;
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index a4a78bb6..f20531e3 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -44,7 +44,7 @@ namespace Catch {
IStreamingReporterPtr makeReporter(Config const* config) {
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()
&& config->getReportersAndOutputFiles().size() == 1) {
- auto& stream = config->getReporterOutputStream(0);
+ auto stream = config->getReporterOutputStream(0);
return createReporter(config->getReportersAndOutputFiles()[0].reporterName, ReporterConfig(config, stream));
}
@@ -57,7 +57,7 @@ namespace Catch {
std::size_t reporterIdx = 0;
for (auto const& reporterAndFile : config->getReportersAndOutputFiles()) {
- auto& stream = config->getReporterOutputStream(reporterIdx);
+ auto stream = config->getReporterOutputStream(reporterIdx);
multi->addReporter(createReporter(reporterAndFile.reporterName, ReporterConfig(config, stream)));
reporterIdx++;
}
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index 4b2bd365..6c17081a 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -55,13 +55,14 @@ namespace Catch {
}; };
class TestSpec;
+ class IStream;
struct IConfig : Detail::NonCopyable {
virtual ~IConfig();
virtual bool allowThrows() const = 0;
- virtual std::ostream& defaultStream() const = 0;
+ virtual IStream const* defaultStream() const = 0;
virtual StringRef name() const = 0;
virtual bool includeSuccessfulResults() const = 0;
virtual bool shouldDebugBreak() const = 0;
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.cpp b/src/catch2/interfaces/catch_interfaces_reporter.cpp
index e5d3921f..5f5d274a 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.cpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.cpp
@@ -20,10 +20,10 @@
namespace Catch {
- ReporterConfig::ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream )
- : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
+ ReporterConfig::ReporterConfig( IConfig const* _fullConfig, IStream const* _stream )
+ : m_stream( _stream ), m_fullConfig( _fullConfig ) {}
- std::ostream& ReporterConfig::stream() const { return *m_stream; }
+ IStream const* ReporterConfig::stream() const { return m_stream; }
IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; }
AssertionStats::AssertionStats( AssertionResult const& _assertionResult,
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp
index c05648b7..41cf426b 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp
@@ -30,15 +30,16 @@ namespace Catch {
struct TestCaseInfo;
class TestCaseHandle;
struct IConfig;
+ class IStream;
struct ReporterConfig {
- ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream );
+ ReporterConfig( IConfig const* _fullConfig, IStream const* _stream );
- std::ostream& stream() const;
+ IStream const* stream() const;
IConfig const* fullConfig() const;
private:
- std::ostream* m_stream;
+ IStream const* m_stream;
IConfig const* m_fullConfig;
};
diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp
index b3e4934e..b3d583d2 100644
--- a/src/catch2/internal/catch_console_colour.cpp
+++ b/src/catch2/internal/catch_console_colour.cpp
@@ -160,7 +160,7 @@ namespace {
void setColour( const char* _escapeCode ) {
// The escape sequence must be flushed to console, otherwise if
// stdin and stderr are intermixed, we'd get accidentally coloured output.
- getCurrentContext().getConfig()->defaultStream()
+ getCurrentContext().getConfig()->defaultStream()->stream()
<< '\033' << _escapeCode << std::flush;
}
};
diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp
index 77a35760..1b92b4dc 100644
--- a/src/catch2/internal/catch_stream.hpp
+++ b/src/catch2/internal/catch_stream.hpp
@@ -22,7 +22,8 @@ namespace Catch {
std::ostream& cerr();
std::ostream& clog();
- struct IStream {
+ class IStream {
+ public:
virtual ~IStream(); // = default
virtual std::ostream& stream() const = 0;
// Win32 colour supports requires us to identify whether a stream
diff --git a/src/catch2/reporters/catch_reporter_common_base.hpp b/src/catch2/reporters/catch_reporter_common_base.hpp
index 235c2606..b7610a93 100644
--- a/src/catch2/reporters/catch_reporter_common_base.hpp
+++ b/src/catch2/reporters/catch_reporter_common_base.hpp
@@ -9,6 +9,7 @@
#define CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+#include <catch2/internal/catch_stream.hpp>
namespace Catch {
/**
@@ -23,13 +24,19 @@ namespace Catch {
*/
class ReporterBase : public IEventListener {
protected:
- //! Stream to write the output to
+ //! The stream wrapper as passed to us by outside code
+ IStream const* m_wrapped_stream;
+ //! Cached output stream from `m_wrapped_stream` to reduce
+ //! number of indirect calls needed to write output.
std::ostream& m_stream;
+
+
public:
ReporterBase( ReporterConfig const& config ):
IEventListener( config.fullConfig() ),
- m_stream( config.stream() ) {}
+ m_wrapped_stream( config.stream() ),
+ m_stream( m_wrapped_stream->stream() ) {}
/**
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index d5dd89c5..e79d6a63 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -355,7 +355,7 @@ public:
ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
: StreamingReporterBase(config),
- m_tablePrinter(Detail::make_unique<TablePrinter>(config.stream(),
+ m_tablePrinter(Detail::make_unique<TablePrinter>(m_stream,
[&config]() -> std::vector<ColumnInfo> {
if (config.fullConfig()->benchmarkNoAnalysis())
{
diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp
index 8c3338cb..78fa8647 100644
--- a/src/catch2/reporters/catch_reporter_xml.cpp
+++ b/src/catch2/reporters/catch_reporter_xml.cpp
@@ -24,7 +24,7 @@
namespace Catch {
XmlReporter::XmlReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
- m_xml(_config.stream())
+ m_xml(m_stream)
{
m_preferences.shouldRedirectStdOut = true;
m_preferences.shouldReportAllAssertions = true;