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ý2022-03-14 15:04:42 +0100
committerMartin Hořeňovský2022-03-18 00:36:18 +0100
commit4acc520f763f7a104d11d57afb8d3bab0bfa6ebc (patch)
tree4bcbf287b1db41c6d8608905ca82471545517992 /src/catch2
parent18c58667d780bfdc82d0e52d6ac6afc462e28f47 (diff)
downloadcatch3-4acc520f763f7a104d11d57afb8d3bab0bfa6ebc.tar.gz
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.
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_registry_hub.cpp2
-rw-r--r--src/catch2/catch_session.cpp2
-rw-r--r--src/catch2/interfaces/catch_interfaces_combined_tu.cpp1
-rw-r--r--src/catch2/interfaces/catch_interfaces_registry_hub.hpp3
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter_factory.hpp8
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter_registry.hpp3
-rw-r--r--src/catch2/internal/catch_reporter_registry.cpp3
-rw-r--r--src/catch2/internal/catch_reporter_registry.hpp2
-rw-r--r--src/catch2/reporters/catch_reporter_event_listener.hpp3
-rw-r--r--src/catch2/reporters/catch_reporter_registrars.hpp7
10 files changed, 23 insertions, 11 deletions
diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp
index edf9b2b5..1fca78fb 100644
--- a/src/catch2/catch_registry_hub.cpp
+++ b/src/catch2/catch_registry_hub.cpp
@@ -51,7 +51,7 @@ namespace Catch {
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
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) );
}
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index fc9b44c5..3a47974d 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -52,7 +52,7 @@ namespace Catch {
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
for (auto const& listener : listeners) {
- multi->addListener(listener->create(Catch::ReporterConfig(config, config->defaultStream())));
+ multi->addListener(listener->create(config));
}
std::size_t reporterIdx = 0;
diff --git a/src/catch2/interfaces/catch_interfaces_combined_tu.cpp b/src/catch2/interfaces/catch_interfaces_combined_tu.cpp
index b1ce0928..2e126a46 100644
--- a/src/catch2/interfaces/catch_interfaces_combined_tu.cpp
+++ b/src/catch2/interfaces/catch_interfaces_combined_tu.cpp
@@ -86,4 +86,5 @@ namespace Catch {
namespace Catch {
IReporterFactory::~IReporterFactory() = default;
+ EventListenerFactory::~EventListenerFactory() = default;
}
diff --git a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
index aeefeedb..1c40f2de 100644
--- a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
+++ b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
@@ -27,6 +27,7 @@ namespace Catch {
struct SourceLineInfo;
class StartupExceptionRegistry;
+ class EventListenerFactory;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
@@ -45,7 +46,7 @@ namespace Catch {
struct IMutableRegistryHub {
virtual ~IMutableRegistryHub(); // = default
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 registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
diff --git a/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp b/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp
index eb107c20..0f9b90cd 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp
@@ -15,6 +15,7 @@
namespace Catch {
struct ReporterConfig;
+ struct IConfig;
class IEventListener;
using IStreamingReporterPtr = Detail::unique_ptr<IEventListener>;
@@ -27,6 +28,13 @@ namespace Catch {
virtual std::string getDescription() const = 0;
};
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
#endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
diff --git a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp
index 904ffd03..7a7b275d 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp
@@ -24,10 +24,11 @@ namespace Catch {
struct IReporterFactory;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
struct ReporterConfig;
+ class EventListenerFactory;
struct IReporterRegistry {
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 IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const = 0;
diff --git a/src/catch2/internal/catch_reporter_registry.cpp b/src/catch2/internal/catch_reporter_registry.cpp
index 67687d1b..7ac3a606 100644
--- a/src/catch2/internal/catch_reporter_registry.cpp
+++ b/src/catch2/internal/catch_reporter_registry.cpp
@@ -49,7 +49,8 @@ namespace Catch {
"'::' is not allowed in reporter name: '" + name + '\'' );
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) );
}
diff --git a/src/catch2/internal/catch_reporter_registry.hpp b/src/catch2/internal/catch_reporter_registry.hpp
index a761e7cf..aaa99ba0 100644
--- a/src/catch2/internal/catch_reporter_registry.hpp
+++ b/src/catch2/internal/catch_reporter_registry.hpp
@@ -24,7 +24,7 @@ namespace Catch {
IStreamingReporterPtr create( std::string const& name, ReporterConfig const& config ) const override;
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
- void registerListener( IReporterFactoryPtr factory );
+ void registerListener( Detail::unique_ptr<EventListenerFactory> factory );
FactoryMap const& getFactories() const override;
Listeners const& getListeners() const override;
diff --git a/src/catch2/reporters/catch_reporter_event_listener.hpp b/src/catch2/reporters/catch_reporter_event_listener.hpp
index bf007c63..383b080a 100644
--- a/src/catch2/reporters/catch_reporter_event_listener.hpp
+++ b/src/catch2/reporters/catch_reporter_event_listener.hpp
@@ -21,8 +21,7 @@ namespace Catch {
*/
class EventListenerBase : public IEventListener {
public:
- EventListenerBase( ReporterConfig const& config ):
- IEventListener( config.fullConfig() ) {}
+ using IEventListener::IEventListener;
void reportInvalidTestSpec( StringRef unmatchedSpec ) override;
void fatalErrorEncountered( StringRef error ) override;
diff --git a/src/catch2/reporters/catch_reporter_registrars.hpp b/src/catch2/reporters/catch_reporter_registrars.hpp
index 8b02e61f..e607c368 100644
--- a/src/catch2/reporters/catch_reporter_registrars.hpp
+++ b/src/catch2/reporters/catch_reporter_registrars.hpp
@@ -43,9 +43,10 @@ namespace Catch {
template<typename T>
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);
}
std::string getDescription() const override {
@@ -56,7 +57,7 @@ namespace Catch {
public:
ListenerRegistrar() {
- getMutableRegistryHub().registerListener( Detail::make_unique<ListenerFactory>() );
+ getMutableRegistryHub().registerListener( Detail::make_unique<TypedListenerFactory>() );
}
};
}