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ý2023-03-13 00:03:48 +0100
committerMartin Hořeňovský2023-03-22 23:58:44 +0100
commitd0f70fdfd661b50c1b8721ae70d49656dc68929b (patch)
tree04945f8cd0b93afe4fb345e9e942ad1f6028b2f9 /src/catch2
parent4f4ad8ada9d17292bb7435043b5453457a24a016 (diff)
downloadcatch3-d0f70fdfd661b50c1b8721ae70d49656dc68929b.tar.gz
Unify IReporterRegistry and ReporterRegistry
To keep the compilation firewall effect, the implementations are hidden behind a PIMPL. In this case it is probably not worth it, but we can inline it later if needed.
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_registry_hub.cpp3
-rw-r--r--src/catch2/catch_session.cpp2
-rw-r--r--src/catch2/interfaces/catch_interfaces_all.hpp1
-rw-r--r--src/catch2/interfaces/catch_interfaces_registry_hub.hpp4
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter_registry.cpp13
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter_registry.hpp42
-rw-r--r--src/catch2/internal/catch_commandline.cpp4
-rw-r--r--src/catch2/internal/catch_list.cpp4
-rw-r--r--src/catch2/internal/catch_reporter_registry.cpp83
-rw-r--r--src/catch2/internal/catch_reporter_registry.hpp45
-rw-r--r--src/catch2/meson.build2
11 files changed, 94 insertions, 109 deletions
diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp
index 243dd2b0..0e43db92 100644
--- a/src/catch2/catch_registry_hub.cpp
+++ b/src/catch2/catch_registry_hub.cpp
@@ -20,6 +20,7 @@
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
+#include <catch2/internal/catch_reporter_registry.hpp>
namespace Catch {
@@ -31,7 +32,7 @@ namespace Catch {
public: // IRegistryHub
RegistryHub() = default;
- IReporterRegistry const& getReporterRegistry() const override {
+ ReporterRegistry const& getReporterRegistry() const override {
return m_reporterRegistry;
}
ITestCaseRegistry const& getTestCaseRegistry() const override {
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index 43465f0c..a73334f4 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -19,7 +19,7 @@
#include <catch2/internal/catch_textflow.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp>
#include <catch2/reporters/catch_reporter_multi.hpp>
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
+#include <catch2/internal/catch_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
diff --git a/src/catch2/interfaces/catch_interfaces_all.hpp b/src/catch2/interfaces/catch_interfaces_all.hpp
index 87b746d8..7a0d0c29 100644
--- a/src/catch2/interfaces/catch_interfaces_all.hpp
+++ b/src/catch2/interfaces/catch_interfaces_all.hpp
@@ -30,7 +30,6 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
diff --git a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
index 8813b538..113f223e 100644
--- a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
+++ b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
@@ -19,7 +19,7 @@ namespace Catch {
class ITestCaseRegistry;
class IExceptionTranslatorRegistry;
class IExceptionTranslator;
- class IReporterRegistry;
+ class ReporterRegistry;
class IReporterFactory;
class ITagAliasRegistry;
class ITestInvoker;
@@ -35,7 +35,7 @@ namespace Catch {
public:
virtual ~IRegistryHub(); // = default
- virtual IReporterRegistry const& getReporterRegistry() const = 0;
+ virtual ReporterRegistry const& getReporterRegistry() const = 0;
virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
diff --git a/src/catch2/interfaces/catch_interfaces_reporter_registry.cpp b/src/catch2/interfaces/catch_interfaces_reporter_registry.cpp
deleted file mode 100644
index f620cbc8..00000000
--- a/src/catch2/interfaces/catch_interfaces_reporter_registry.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-
-// Copyright Catch2 Authors
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE.txt or copy at
-// https://www.boost.org/LICENSE_1_0.txt)
-
-// SPDX-License-Identifier: BSL-1.0
-
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
-
-namespace Catch {
- IReporterRegistry::~IReporterRegistry() = default;
-}
diff --git a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp
deleted file mode 100644
index 277d1761..00000000
--- a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-
-// Copyright Catch2 Authors
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE.txt or copy at
-// https://www.boost.org/LICENSE_1_0.txt)
-
-// SPDX-License-Identifier: BSL-1.0
-#ifndef CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
-#define CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
-
-#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
-#include <catch2/internal/catch_unique_ptr.hpp>
-
-#include <string>
-#include <vector>
-#include <map>
-
-namespace Catch {
-
- class IConfig;
-
- class IEventListener;
- using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
- class IReporterFactory;
- using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
- struct ReporterConfig;
- class EventListenerFactory;
-
- class IReporterRegistry {
- public:
- using FactoryMap = std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>;
- using Listeners = std::vector<Detail::unique_ptr<EventListenerFactory>>;
-
- virtual ~IReporterRegistry(); // = default
- virtual IEventListenerPtr create( std::string const& name, ReporterConfig&& config ) const = 0;
- virtual FactoryMap const& getFactories() const = 0;
- virtual Listeners const& getListeners() const = 0;
- };
-
-} // end namespace Catch
-
-#endif // CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 81aa073c..4ac1847b 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -10,7 +10,7 @@
#include <catch2/catch_config.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
+#include <catch2/internal/catch_reporter_registry.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_parse_numbers.hpp>
#include <catch2/internal/catch_reporter_spec_parser.hpp>
@@ -144,7 +144,7 @@ namespace Catch {
auto const& reporterSpec = *parsed;
- IReporterRegistry::FactoryMap const& factories =
+ auto const& factories =
getRegistryHub().getReporterRegistry().getFactories();
auto result = factories.find( reporterSpec.name() );
diff --git a/src/catch2/internal/catch_list.cpp b/src/catch2/internal/catch_list.cpp
index 263781d6..4eb8bb7d 100644
--- a/src/catch2/internal/catch_list.cpp
+++ b/src/catch2/internal/catch_list.cpp
@@ -9,9 +9,9 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
+#include <catch2/internal/catch_reporter_registry.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
@@ -54,7 +54,7 @@ namespace Catch {
void listReporters(IEventListener& reporter) {
std::vector<ReporterDescription> descriptions;
- IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
+ auto const& factories = getRegistryHub().getReporterRegistry().getFactories();
descriptions.reserve(factories.size());
for (auto const& fac : factories) {
descriptions.push_back({ fac.first, fac.second->getDescription() });
diff --git a/src/catch2/internal/catch_reporter_registry.cpp b/src/catch2/internal/catch_reporter_registry.cpp
index 4c0c44f4..8f13ae56 100644
--- a/src/catch2/internal/catch_reporter_registry.cpp
+++ b/src/catch2/internal/catch_reporter_registry.cpp
@@ -5,61 +5,86 @@
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
-#include <catch2/internal/catch_reporter_registry.hpp>
-#include <catch2/reporters/catch_reporter_registrars.hpp>
+#include <catch2/internal/catch_reporter_registry.hpp>
+#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
+#include <catch2/internal/catch_enforce.hpp>
+#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/reporters/catch_reporter_automake.hpp>
#include <catch2/reporters/catch_reporter_compact.hpp>
#include <catch2/reporters/catch_reporter_console.hpp>
#include <catch2/reporters/catch_reporter_junit.hpp>
+#include <catch2/reporters/catch_reporter_registrars.hpp>
#include <catch2/reporters/catch_reporter_sonarqube.hpp>
#include <catch2/reporters/catch_reporter_tap.hpp>
#include <catch2/reporters/catch_reporter_teamcity.hpp>
#include <catch2/reporters/catch_reporter_xml.hpp>
-#include <catch2/internal/catch_move_and_forward.hpp>
-#include <catch2/internal/catch_enforce.hpp>
namespace Catch {
+ struct ReporterRegistry::ReporterRegistryImpl {
+ std::vector<Detail::unique_ptr<EventListenerFactory>> listeners;
+ std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>
+ factories;
+ };
- ReporterRegistry::ReporterRegistry() {
+ ReporterRegistry::ReporterRegistry():
+ m_impl( Detail::make_unique<ReporterRegistryImpl>() ) {
// Because it is impossible to move out of initializer list,
// we have to add the elements manually
- m_factories["Automake"] = Detail::make_unique<ReporterFactory<AutomakeReporter>>();
- m_factories["compact"] = Detail::make_unique<ReporterFactory<CompactReporter>>();
- m_factories["console"] = Detail::make_unique<ReporterFactory<ConsoleReporter>>();
- m_factories["JUnit"] = Detail::make_unique<ReporterFactory<JunitReporter>>();
- m_factories["SonarQube"] = Detail::make_unique<ReporterFactory<SonarQubeReporter>>();
- m_factories["TAP"] = Detail::make_unique<ReporterFactory<TAPReporter>>();
- m_factories["TeamCity"] = Detail::make_unique<ReporterFactory<TeamCityReporter>>();
- m_factories["XML"] = Detail::make_unique<ReporterFactory<XmlReporter>>();
+ m_impl->factories["Automake"] =
+ Detail::make_unique<ReporterFactory<AutomakeReporter>>();
+ m_impl->factories["compact"] =
+ Detail::make_unique<ReporterFactory<CompactReporter>>();
+ m_impl->factories["console"] =
+ Detail::make_unique<ReporterFactory<ConsoleReporter>>();
+ m_impl->factories["JUnit"] =
+ Detail::make_unique<ReporterFactory<JunitReporter>>();
+ m_impl->factories["SonarQube"] =
+ Detail::make_unique<ReporterFactory<SonarQubeReporter>>();
+ m_impl->factories["TAP"] =
+ Detail::make_unique<ReporterFactory<TAPReporter>>();
+ m_impl->factories["TeamCity"] =
+ Detail::make_unique<ReporterFactory<TeamCityReporter>>();
+ m_impl->factories["XML"] =
+ Detail::make_unique<ReporterFactory<XmlReporter>>();
}
ReporterRegistry::~ReporterRegistry() = default;
+ IEventListenerPtr
+ ReporterRegistry::create( std::string const& name,
+ ReporterConfig&& config ) const {
+ auto it = m_impl->factories.find( name );
+ if ( it == m_impl->factories.end() ) return nullptr;
+ return it->second->create( CATCH_MOVE( config ) );
- IEventListenerPtr ReporterRegistry::create( std::string const& name, ReporterConfig&& config ) const {
- auto it = m_factories.find( name );
- if( it == m_factories.end() )
- return nullptr;
- return it->second->create( CATCH_MOVE(config) );
+ return IEventListenerPtr();
}
- void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr factory ) {
+ void ReporterRegistry::registerReporter( std::string const& name,
+ IReporterFactoryPtr factory ) {
CATCH_ENFORCE( name.find( "::" ) == name.npos,
- "'::' is not allowed in reporter name: '" + name + '\'' );
- auto ret = m_factories.emplace(name, CATCH_MOVE(factory));
- CATCH_ENFORCE( ret.second, "reporter using '" + name + "' as name was already registered" );
+ "'::' is not allowed in reporter name: '" + name +
+ '\'' );
+ auto ret = m_impl->factories.emplace( name, CATCH_MOVE( factory ) );
+ CATCH_ENFORCE( ret.second,
+ "reporter using '" + name +
+ "' as name was already registered" );
}
void ReporterRegistry::registerListener(
Detail::unique_ptr<EventListenerFactory> factory ) {
- m_listeners.push_back( CATCH_MOVE(factory) );
+ m_impl->listeners.push_back( CATCH_MOVE( factory ) );
}
- IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const {
- return m_factories;
- }
- IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const {
- return m_listeners;
+ std::map<std::string,
+ IReporterFactoryPtr,
+ Detail::CaseInsensitiveLess> const&
+ ReporterRegistry::getFactories() const {
+ return m_impl->factories;
}
-}
+ std::vector<Detail::unique_ptr<EventListenerFactory>> const&
+ ReporterRegistry::getListeners() const {
+ return m_impl->listeners;
+ }
+} // namespace Catch
diff --git a/src/catch2/internal/catch_reporter_registry.hpp b/src/catch2/internal/catch_reporter_registry.hpp
index 5577b9ef..92a88927 100644
--- a/src/catch2/internal/catch_reporter_registry.hpp
+++ b/src/catch2/internal/catch_reporter_registry.hpp
@@ -8,31 +8,48 @@
#ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#define CATCH_REPORTER_REGISTRY_HPP_INCLUDED
-#include <catch2/interfaces/catch_interfaces_reporter.hpp>
-#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
+#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
+#include <catch2/internal/catch_unique_ptr.hpp>
#include <map>
+#include <string>
+#include <vector>
namespace Catch {
- class ReporterRegistry : public IReporterRegistry {
- public:
+ class IEventListener;
+ using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
+ class IReporterFactory;
+ using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
+ struct ReporterConfig;
+ class EventListenerFactory;
+
+ class ReporterRegistry {
+ struct ReporterRegistryImpl;
+ Detail::unique_ptr<ReporterRegistryImpl> m_impl;
+ public:
ReporterRegistry();
- ~ReporterRegistry() override; // = default, out of line to allow fwd decl
+ ~ReporterRegistry(); // = default;
- IEventListenerPtr create( std::string const& name, ReporterConfig&& config ) const override;
+ IEventListenerPtr create( std::string const& name,
+ ReporterConfig&& config ) const;
- void registerReporter( std::string const& name, IReporterFactoryPtr factory );
- void registerListener( Detail::unique_ptr<EventListenerFactory> factory );
+ void registerReporter( std::string const& name,
+ IReporterFactoryPtr factory );
- FactoryMap const& getFactories() const override;
- Listeners const& getListeners() const override;
+ void
+ registerListener( Detail::unique_ptr<EventListenerFactory> factory );
- private:
- FactoryMap m_factories;
- Listeners m_listeners;
+ std::map<std::string,
+ IReporterFactoryPtr,
+ Detail::CaseInsensitiveLess> const&
+ getFactories() const;
+
+ std::vector<Detail::unique_ptr<EventListenerFactory>> const&
+ getListeners() const;
};
-}
+
+} // end namespace Catch
#endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED
diff --git a/src/catch2/meson.build b/src/catch2/meson.build
index 0e114065..fee3b4ed 100644
--- a/src/catch2/meson.build
+++ b/src/catch2/meson.build
@@ -64,7 +64,6 @@ internal_headers = [
'interfaces/catch_interfaces_registry_hub.hpp',
'interfaces/catch_interfaces_reporter.hpp',
'interfaces/catch_interfaces_reporter_factory.hpp',
- 'interfaces/catch_interfaces_reporter_registry.hpp',
'interfaces/catch_interfaces_tag_alias_registry.hpp',
'interfaces/catch_interfaces_testcase.hpp',
'internal/catch_assertion_handler.hpp',
@@ -189,7 +188,6 @@ internal_sources = files(
'interfaces/catch_interfaces_registry_hub.cpp',
'interfaces/catch_interfaces_reporter.cpp',
'interfaces/catch_interfaces_reporter_factory.cpp',
- 'interfaces/catch_interfaces_reporter_registry.cpp',
'interfaces/catch_interfaces_testcase.cpp',
'internal/catch_assertion_handler.cpp',
'internal/catch_case_insensitive_comparisons.cpp',