mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Event listeners no longer take reporter config in constructor
This also required splitting out Listener factory from the reporter factory hierarchy. In return, the listener factories only need to take in `IConfig const*`, which opens up further refactorings down the road in the colour selection and implementation.
This commit is contained in:
parent
18c58667d7
commit
4acc520f76
@ -51,7 +51,7 @@ namespace Catch {
|
|||||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
|
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
|
||||||
m_reporterRegistry.registerReporter( name, CATCH_MOVE(factory) );
|
m_reporterRegistry.registerReporter( name, CATCH_MOVE(factory) );
|
||||||
}
|
}
|
||||||
void registerListener( IReporterFactoryPtr factory ) override {
|
void registerListener( Detail::unique_ptr<EventListenerFactory> factory ) override {
|
||||||
m_reporterRegistry.registerListener( CATCH_MOVE(factory) );
|
m_reporterRegistry.registerListener( CATCH_MOVE(factory) );
|
||||||
}
|
}
|
||||||
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
|
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
|
||||||
|
@ -52,7 +52,7 @@ namespace Catch {
|
|||||||
|
|
||||||
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
|
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
|
||||||
for (auto const& listener : listeners) {
|
for (auto const& listener : listeners) {
|
||||||
multi->addListener(listener->create(Catch::ReporterConfig(config, config->defaultStream())));
|
multi->addListener(listener->create(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t reporterIdx = 0;
|
std::size_t reporterIdx = 0;
|
||||||
|
@ -86,4 +86,5 @@ namespace Catch {
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
IReporterFactory::~IReporterFactory() = default;
|
IReporterFactory::~IReporterFactory() = default;
|
||||||
|
EventListenerFactory::~EventListenerFactory() = default;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace Catch {
|
|||||||
struct SourceLineInfo;
|
struct SourceLineInfo;
|
||||||
|
|
||||||
class StartupExceptionRegistry;
|
class StartupExceptionRegistry;
|
||||||
|
class EventListenerFactory;
|
||||||
|
|
||||||
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ namespace Catch {
|
|||||||
struct IMutableRegistryHub {
|
struct IMutableRegistryHub {
|
||||||
virtual ~IMutableRegistryHub(); // = default
|
virtual ~IMutableRegistryHub(); // = default
|
||||||
virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
|
virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
|
||||||
virtual void registerListener( IReporterFactoryPtr factory ) = 0;
|
virtual void registerListener( Detail::unique_ptr<EventListenerFactory> factory ) = 0;
|
||||||
virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
|
virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
|
||||||
virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
|
virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
|
||||||
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct ReporterConfig;
|
struct ReporterConfig;
|
||||||
|
struct IConfig;
|
||||||
class IEventListener;
|
class IEventListener;
|
||||||
using IStreamingReporterPtr = Detail::unique_ptr<IEventListener>;
|
using IStreamingReporterPtr = Detail::unique_ptr<IEventListener>;
|
||||||
|
|
||||||
@ -27,6 +28,13 @@ namespace Catch {
|
|||||||
virtual std::string getDescription() const = 0;
|
virtual std::string getDescription() const = 0;
|
||||||
};
|
};
|
||||||
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
||||||
|
|
||||||
|
class EventListenerFactory {
|
||||||
|
public:
|
||||||
|
virtual ~EventListenerFactory(); // = default
|
||||||
|
virtual IStreamingReporterPtr create( IConfig const* config ) const = 0;
|
||||||
|
virtual std::string getDescription() const = 0;
|
||||||
|
};
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
|
#endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
|
||||||
|
@ -24,10 +24,11 @@ namespace Catch {
|
|||||||
struct IReporterFactory;
|
struct IReporterFactory;
|
||||||
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
|
||||||
struct ReporterConfig;
|
struct ReporterConfig;
|
||||||
|
class EventListenerFactory;
|
||||||
|
|
||||||
struct IReporterRegistry {
|
struct IReporterRegistry {
|
||||||
using FactoryMap = std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>;
|
using FactoryMap = std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>;
|
||||||
using Listeners = std::vector<IReporterFactoryPtr>;
|
using Listeners = std::vector<Detail::unique_ptr<EventListenerFactory>>;
|
||||||
|
|
||||||
virtual ~IReporterRegistry(); // = default
|
virtual ~IReporterRegistry(); // = default
|
||||||
virtual IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const = 0;
|
virtual IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const = 0;
|
||||||
|
@ -49,7 +49,8 @@ namespace Catch {
|
|||||||
"'::' is not allowed in reporter name: '" + name + '\'' );
|
"'::' is not allowed in reporter name: '" + name + '\'' );
|
||||||
m_factories.emplace(name, CATCH_MOVE(factory));
|
m_factories.emplace(name, CATCH_MOVE(factory));
|
||||||
}
|
}
|
||||||
void ReporterRegistry::registerListener( IReporterFactoryPtr factory ) {
|
void ReporterRegistry::registerListener(
|
||||||
|
Detail::unique_ptr<EventListenerFactory> factory ) {
|
||||||
m_listeners.push_back( CATCH_MOVE(factory) );
|
m_listeners.push_back( CATCH_MOVE(factory) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace Catch {
|
|||||||
IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const override;
|
IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const override;
|
||||||
|
|
||||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
|
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
|
||||||
void registerListener( IReporterFactoryPtr factory );
|
void registerListener( Detail::unique_ptr<EventListenerFactory> factory );
|
||||||
|
|
||||||
FactoryMap const& getFactories() const override;
|
FactoryMap const& getFactories() const override;
|
||||||
Listeners const& getListeners() const override;
|
Listeners const& getListeners() const override;
|
||||||
|
@ -21,8 +21,7 @@ namespace Catch {
|
|||||||
*/
|
*/
|
||||||
class EventListenerBase : public IEventListener {
|
class EventListenerBase : public IEventListener {
|
||||||
public:
|
public:
|
||||||
EventListenerBase( ReporterConfig const& config ):
|
using IEventListener::IEventListener;
|
||||||
IEventListener( config.fullConfig() ) {}
|
|
||||||
|
|
||||||
void reportInvalidTestSpec( StringRef unmatchedSpec ) override;
|
void reportInvalidTestSpec( StringRef unmatchedSpec ) override;
|
||||||
void fatalErrorEncountered( StringRef error ) override;
|
void fatalErrorEncountered( StringRef error ) override;
|
||||||
|
@ -43,9 +43,10 @@ namespace Catch {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class ListenerRegistrar {
|
class ListenerRegistrar {
|
||||||
|
|
||||||
class ListenerFactory : public IReporterFactory {
|
class TypedListenerFactory : public EventListenerFactory {
|
||||||
|
|
||||||
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
|
IStreamingReporterPtr
|
||||||
|
create( IConfig const* config ) const override {
|
||||||
return Detail::make_unique<T>(config);
|
return Detail::make_unique<T>(config);
|
||||||
}
|
}
|
||||||
std::string getDescription() const override {
|
std::string getDescription() const override {
|
||||||
@ -56,7 +57,7 @@ namespace Catch {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ListenerRegistrar() {
|
ListenerRegistrar() {
|
||||||
getMutableRegistryHub().registerListener( Detail::make_unique<ListenerFactory>() );
|
getMutableRegistryHub().registerListener( Detail::make_unique<TypedListenerFactory>() );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
class NonCapturingListener : public Catch::EventListenerBase {
|
class NonCapturingListener : public Catch::EventListenerBase {
|
||||||
public:
|
public:
|
||||||
NonCapturingListener( Catch::ReporterConfig const& config ):
|
NonCapturingListener( Catch::IConfig const* config ):
|
||||||
EventListenerBase( config ) {
|
EventListenerBase( config ) {
|
||||||
m_preferences.shouldRedirectStdOut = false;
|
m_preferences.shouldRedirectStdOut = false;
|
||||||
std::cerr << "X24 - NonCapturingListener initialized.\n";
|
std::cerr << "X24 - NonCapturingListener initialized.\n";
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
class CapturingListener : public Catch::EventListenerBase {
|
class CapturingListener : public Catch::EventListenerBase {
|
||||||
public:
|
public:
|
||||||
CapturingListener( Catch::ReporterConfig const& config ):
|
CapturingListener( Catch::IConfig const* config ):
|
||||||
EventListenerBase( config ) {
|
EventListenerBase( config ) {
|
||||||
m_preferences.shouldRedirectStdOut = true;
|
m_preferences.shouldRedirectStdOut = true;
|
||||||
std::cerr << "CapturingListener initialized\n";
|
std::cerr << "CapturingListener initialized\n";
|
||||||
|
@ -30,7 +30,7 @@ namespace {
|
|||||||
|
|
||||||
class TestListener : public Catch::EventListenerBase {
|
class TestListener : public Catch::EventListenerBase {
|
||||||
public:
|
public:
|
||||||
TestListener( Catch::ReporterConfig const& config ):
|
TestListener( Catch::IConfig const* config ):
|
||||||
EventListenerBase( config ) {
|
EventListenerBase( config ) {
|
||||||
std::cout << "X28 - TestListener constructed.\n";
|
std::cout << "X28 - TestListener constructed.\n";
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
MockListener( std::string witness,
|
MockListener( std::string witness,
|
||||||
std::vector<std::string>& recorder,
|
std::vector<std::string>& recorder,
|
||||||
Catch::ReporterConfig const& config ):
|
Catch::IConfig const* config ):
|
||||||
EventListenerBase( config ),
|
EventListenerBase( config ),
|
||||||
m_witness( witness ),
|
m_witness( witness ),
|
||||||
m_recorder( recorder )
|
m_recorder( recorder )
|
||||||
@ -187,10 +187,10 @@ TEST_CASE("Multireporter calls reporters and listeners in correct order",
|
|||||||
std::vector<std::string> records;
|
std::vector<std::string> records;
|
||||||
multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>(
|
multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>(
|
||||||
"Goodbye", records, rep_config ) );
|
"Goodbye", records, rep_config ) );
|
||||||
multiReporter.addListener( Catch::Detail::make_unique<MockListener>(
|
multiReporter.addListener(
|
||||||
"Hello", records, rep_config ) );
|
Catch::Detail::make_unique<MockListener>( "Hello", records, &config ) );
|
||||||
multiReporter.addListener( Catch::Detail::make_unique<MockListener>(
|
multiReporter.addListener(
|
||||||
"world", records, rep_config ) );
|
Catch::Detail::make_unique<MockListener>( "world", records, &config ) );
|
||||||
multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>(
|
multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>(
|
||||||
"world", records, rep_config ) );
|
"world", records, rep_config ) );
|
||||||
multiReporter.testRunStarting( { "" } );
|
multiReporter.testRunStarting( { "" } );
|
||||||
@ -206,7 +206,7 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
PreferenceListener( bool redirectStdout,
|
PreferenceListener( bool redirectStdout,
|
||||||
bool reportAllAssertions,
|
bool reportAllAssertions,
|
||||||
Catch::ReporterConfig const& config ):
|
Catch::IConfig const* config ):
|
||||||
EventListenerBase( config ) {
|
EventListenerBase( config ) {
|
||||||
m_preferences.shouldRedirectStdOut = redirectStdout;
|
m_preferences.shouldRedirectStdOut = redirectStdout;
|
||||||
m_preferences.shouldReportAllAssertions = reportAllAssertions;
|
m_preferences.shouldReportAllAssertions = reportAllAssertions;
|
||||||
@ -242,19 +242,19 @@ TEST_CASE("Multireporter updates ReporterPreferences properly",
|
|||||||
SECTION( "Adding listeners" ) {
|
SECTION( "Adding listeners" ) {
|
||||||
multiReporter.addListener(
|
multiReporter.addListener(
|
||||||
Catch::Detail::make_unique<PreferenceListener>(
|
Catch::Detail::make_unique<PreferenceListener>(
|
||||||
true, false, rep_config ) );
|
true, false, &config ) );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false );
|
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false );
|
||||||
|
|
||||||
multiReporter.addListener(
|
multiReporter.addListener(
|
||||||
Catch::Detail::make_unique<PreferenceListener>(
|
Catch::Detail::make_unique<PreferenceListener>(
|
||||||
false, true, rep_config ) );
|
false, true, &config ) );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true);
|
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true);
|
||||||
|
|
||||||
multiReporter.addListener(
|
multiReporter.addListener(
|
||||||
Catch::Detail::make_unique<PreferenceListener>(
|
Catch::Detail::make_unique<PreferenceListener>(
|
||||||
false, false, rep_config ) );
|
false, false, &config ) );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true );
|
||||||
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true );
|
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true );
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class ValidatingTestListener : public Catch::EventListenerBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ValidatingTestListener(Catch::ReporterConfig const& config) :
|
ValidatingTestListener(Catch::IConfig const* config) :
|
||||||
EventListenerBase(config) {
|
EventListenerBase(config) {
|
||||||
m_preferences.shouldReportAllAssertions = true;
|
m_preferences.shouldReportAllAssertions = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user