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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-01-16 15:27:47 +0100
committerMartin Hořeňovský2021-01-16 15:27:56 +0100
commit74f2f4ba5e84355e4f123ec807c1ec3b29a0daa7 (patch)
treedfd00fd5eb5da2d638b1ddfebce1d5c89fc0ca8d /src/catch2
parentba8150516800dd5e18f818346a2a12c45b6ec542 (diff)
downloadcatch3-74f2f4ba5e84355e4f123ec807c1ec3b29a0daa7.tar.gz
Hold reporter's IConfig instance in the interface
Previously, every base derived from the IStreamingReporter had its own `IConfig const* m_config` member, so this just centralizes the handling thereof. Part of #2061
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_session.cpp2
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter.hpp5
-rw-r--r--src/catch2/reporters/catch_reporter_cumulative_base.hpp4
-rw-r--r--src/catch2/reporters/catch_reporter_event_listener.hpp4
-rw-r--r--src/catch2/reporters/catch_reporter_listening.cpp5
-rw-r--r--src/catch2/reporters/catch_reporter_listening.hpp7
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.hpp5
7 files changed, 17 insertions, 15 deletions
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index a9519e75..5b1a50a9 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -48,7 +48,7 @@ namespace Catch {
// doesn't compile without a std::move call. However, this causes
// a warning on newer platforms. Thus, we have to work around
// it a bit and downcast the pointer manually.
- auto ret = Detail::unique_ptr<IStreamingReporter>(new ListeningReporter);
+ auto ret = Detail::unique_ptr<IStreamingReporter>(new ListeningReporter(config));
auto& multi = static_cast<ListeningReporter&>(*ret);
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
for (auto const& listener : listeners) {
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp
index 791cc992..9dbd1847 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp
@@ -176,7 +176,12 @@ namespace Catch {
protected:
//! Derived classes can set up their preferences here
ReporterPreferences m_preferences;
+ //! The test run's config as filled in from CLI and defaults
+ IConfig const* m_config;
+
public:
+ IStreamingReporter( IConfig const* config ): m_config( config ) {}
+
virtual ~IStreamingReporter() = default;
// Implementing class must also provide the following static methods:
diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.hpp b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
index 0b643ff1..0729567c 100644
--- a/src/catch2/reporters/catch_reporter_cumulative_base.hpp
+++ b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
@@ -46,7 +46,8 @@ namespace Catch {
using TestRunNode = Node<TestRunStats, TestGroupNode>;
CumulativeReporterBase( ReporterConfig const& _config ):
- m_config( _config.fullConfig() ), stream( _config.stream() ) {}
+ IStreamingReporter( _config.fullConfig() ),
+ stream( _config.stream() ) {}
~CumulativeReporterBase() override;
void testRunStarting( TestRunInfo const& ) override {}
@@ -68,7 +69,6 @@ namespace Catch {
void skipTest(TestCaseInfo const&) override {}
- IConfig const* m_config;
std::ostream& stream;
// Note: We rely on pointer identity being stable, which is why
// which is why we store around pointers rather than values.
diff --git a/src/catch2/reporters/catch_reporter_event_listener.hpp b/src/catch2/reporters/catch_reporter_event_listener.hpp
index 816e42f6..df089c08 100644
--- a/src/catch2/reporters/catch_reporter_event_listener.hpp
+++ b/src/catch2/reporters/catch_reporter_event_listener.hpp
@@ -20,11 +20,9 @@ namespace Catch {
* member functions it actually cares about.
*/
class EventListenerBase : public IStreamingReporter {
- IConfig const* m_config;
-
public:
EventListenerBase( ReporterConfig const& config ):
- m_config( config.fullConfig() ) {}
+ IStreamingReporter( config.fullConfig() ) {}
void assertionStarting( AssertionInfo const& assertionInfo ) override;
bool assertionEnded( AssertionStats const& assertionStats ) override;
diff --git a/src/catch2/reporters/catch_reporter_listening.cpp b/src/catch2/reporters/catch_reporter_listening.cpp
index f1978424..60059c84 100644
--- a/src/catch2/reporters/catch_reporter_listening.cpp
+++ b/src/catch2/reporters/catch_reporter_listening.cpp
@@ -11,11 +11,6 @@
namespace Catch {
- ListeningReporter::ListeningReporter() {
- // We will assume that listeners will always want all assertions
- m_preferences.shouldReportAllAssertions = true;
- }
-
void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
m_listeners.push_back( std::move( listener ) );
}
diff --git a/src/catch2/reporters/catch_reporter_listening.hpp b/src/catch2/reporters/catch_reporter_listening.hpp
index 8ac52839..c6485300 100644
--- a/src/catch2/reporters/catch_reporter_listening.hpp
+++ b/src/catch2/reporters/catch_reporter_listening.hpp
@@ -18,7 +18,12 @@ namespace Catch {
IStreamingReporterPtr m_reporter = nullptr;
public:
- ListeningReporter();
+ ListeningReporter( IConfig const* config ):
+ IStreamingReporter( config ) {
+ // We will assume that listeners will always want all assertions
+ m_preferences.shouldReportAllAssertions = true;
+ }
+
void addListener( IStreamingReporterPtr&& listener );
void addReporter( IStreamingReporterPtr&& reporter );
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.hpp b/src/catch2/reporters/catch_reporter_streaming_base.hpp
index 5826f63b..ebf06385 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.hpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp
@@ -36,8 +36,8 @@ namespace Catch {
struct StreamingReporterBase : IStreamingReporter {
StreamingReporterBase( ReporterConfig const& _config ):
- m_config( _config.fullConfig() ), stream( _config.stream() ) {
- }
+ IStreamingReporter( _config.fullConfig() ),
+ stream( _config.stream() ) {}
~StreamingReporterBase() override;
@@ -71,7 +71,6 @@ namespace Catch {
// It can optionally be overridden in the derived class.
}
- IConfig const* m_config;
std::ostream& stream;
LazyStat<TestRunInfo> currentTestRunInfo;