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
This commit is contained in:
Martin Hořeňovský 2021-01-16 15:27:47 +01:00
parent ba81505168
commit 74f2f4ba5e
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 17 additions and 15 deletions

View File

@ -48,7 +48,7 @@ namespace Catch {
// doesn't compile without a std::move call. However, this causes // doesn't compile without a std::move call. However, this causes
// a warning on newer platforms. Thus, we have to work around // a warning on newer platforms. Thus, we have to work around
// it a bit and downcast the pointer manually. // 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& multi = static_cast<ListeningReporter&>(*ret);
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
for (auto const& listener : listeners) { for (auto const& listener : listeners) {

View File

@ -176,7 +176,12 @@ namespace Catch {
protected: protected:
//! Derived classes can set up their preferences here //! Derived classes can set up their preferences here
ReporterPreferences m_preferences; ReporterPreferences m_preferences;
//! The test run's config as filled in from CLI and defaults
IConfig const* m_config;
public: public:
IStreamingReporter( IConfig const* config ): m_config( config ) {}
virtual ~IStreamingReporter() = default; virtual ~IStreamingReporter() = default;
// Implementing class must also provide the following static methods: // Implementing class must also provide the following static methods:

View File

@ -46,7 +46,8 @@ namespace Catch {
using TestRunNode = Node<TestRunStats, TestGroupNode>; using TestRunNode = Node<TestRunStats, TestGroupNode>;
CumulativeReporterBase( ReporterConfig const& _config ): CumulativeReporterBase( ReporterConfig const& _config ):
m_config( _config.fullConfig() ), stream( _config.stream() ) {} IStreamingReporter( _config.fullConfig() ),
stream( _config.stream() ) {}
~CumulativeReporterBase() override; ~CumulativeReporterBase() override;
void testRunStarting( TestRunInfo const& ) override {} void testRunStarting( TestRunInfo const& ) override {}
@ -68,7 +69,6 @@ namespace Catch {
void skipTest(TestCaseInfo const&) override {} void skipTest(TestCaseInfo const&) override {}
IConfig const* m_config;
std::ostream& stream; std::ostream& stream;
// Note: We rely on pointer identity being stable, which is why // Note: We rely on pointer identity being stable, which is why
// which is why we store around pointers rather than values. // which is why we store around pointers rather than values.

View File

@ -20,11 +20,9 @@ namespace Catch {
* member functions it actually cares about. * member functions it actually cares about.
*/ */
class EventListenerBase : public IStreamingReporter { class EventListenerBase : public IStreamingReporter {
IConfig const* m_config;
public: public:
EventListenerBase( ReporterConfig const& config ): EventListenerBase( ReporterConfig const& config ):
m_config( config.fullConfig() ) {} IStreamingReporter( config.fullConfig() ) {}
void assertionStarting( AssertionInfo const& assertionInfo ) override; void assertionStarting( AssertionInfo const& assertionInfo ) override;
bool assertionEnded( AssertionStats const& assertionStats ) override; bool assertionEnded( AssertionStats const& assertionStats ) override;

View File

@ -11,11 +11,6 @@
namespace Catch { namespace Catch {
ListeningReporter::ListeningReporter() {
// We will assume that listeners will always want all assertions
m_preferences.shouldReportAllAssertions = true;
}
void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) { void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
m_listeners.push_back( std::move( listener ) ); m_listeners.push_back( std::move( listener ) );
} }

View File

@ -18,7 +18,12 @@ namespace Catch {
IStreamingReporterPtr m_reporter = nullptr; IStreamingReporterPtr m_reporter = nullptr;
public: 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 addListener( IStreamingReporterPtr&& listener );
void addReporter( IStreamingReporterPtr&& reporter ); void addReporter( IStreamingReporterPtr&& reporter );

View File

@ -36,8 +36,8 @@ namespace Catch {
struct StreamingReporterBase : IStreamingReporter { struct StreamingReporterBase : IStreamingReporter {
StreamingReporterBase( ReporterConfig const& _config ): StreamingReporterBase( ReporterConfig const& _config ):
m_config( _config.fullConfig() ), stream( _config.stream() ) { IStreamingReporter( _config.fullConfig() ),
} stream( _config.stream() ) {}
~StreamingReporterBase() override; ~StreamingReporterBase() override;
@ -71,7 +71,6 @@ namespace Catch {
// It can optionally be overridden in the derived class. // It can optionally be overridden in the derived class.
} }
IConfig const* m_config;
std::ostream& stream; std::ostream& stream;
LazyStat<TestRunInfo> currentTestRunInfo; LazyStat<TestRunInfo> currentTestRunInfo;