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.
This commit is contained in:
Martin Hořeňovský 2023-03-13 00:03:48 +01:00
parent 4f4ad8ada9
commit d0f70fdfd6
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
13 changed files with 94 additions and 112 deletions

View File

@ -216,7 +216,6 @@ set(INTERFACE_HEADERS
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_reporter.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_registry.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_tag_alias_registry.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_tag_alias_registry.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp
) )
@ -228,7 +227,6 @@ set(INTERFACE_SOURCES
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_registry.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_testcase.cpp
) )
set(INTERFACE_FILES ${INTERFACE_HEADERS} ${INTERFACE_SOURCES}) set(INTERFACE_FILES ${INTERFACE_HEADERS} ${INTERFACE_SOURCES})

View File

@ -20,6 +20,7 @@
#include <catch2/internal/catch_noncopyable.hpp> #include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/internal/catch_move_and_forward.hpp> #include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_reporter_registry.hpp>
namespace Catch { namespace Catch {
@ -31,7 +32,7 @@ namespace Catch {
public: // IRegistryHub public: // IRegistryHub
RegistryHub() = default; RegistryHub() = default;
IReporterRegistry const& getReporterRegistry() const override { ReporterRegistry const& getReporterRegistry() const override {
return m_reporterRegistry; return m_reporterRegistry;
} }
ITestCaseRegistry const& getTestCaseRegistry() const override { ITestCaseRegistry const& getTestCaseRegistry() const override {

View File

@ -19,7 +19,7 @@
#include <catch2/internal/catch_textflow.hpp> #include <catch2/internal/catch_textflow.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp> #include <catch2/internal/catch_windows_h_proxy.hpp>
#include <catch2/reporters/catch_reporter_multi.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/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/internal/catch_move_and_forward.hpp> #include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_stdstreams.hpp> #include <catch2/internal/catch_stdstreams.hpp>

View File

@ -30,7 +30,6 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp> #include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.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_tag_alias_registry.hpp>
#include <catch2/interfaces/catch_interfaces_testcase.hpp> #include <catch2/interfaces/catch_interfaces_testcase.hpp>

View File

@ -19,7 +19,7 @@ namespace Catch {
class ITestCaseRegistry; class ITestCaseRegistry;
class IExceptionTranslatorRegistry; class IExceptionTranslatorRegistry;
class IExceptionTranslator; class IExceptionTranslator;
class IReporterRegistry; class ReporterRegistry;
class IReporterFactory; class IReporterFactory;
class ITagAliasRegistry; class ITagAliasRegistry;
class ITestInvoker; class ITestInvoker;
@ -35,7 +35,7 @@ namespace Catch {
public: public:
virtual ~IRegistryHub(); // = default virtual ~IRegistryHub(); // = default
virtual IReporterRegistry const& getReporterRegistry() const = 0; virtual ReporterRegistry const& getReporterRegistry() const = 0;
virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0; virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;

View File

@ -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;
}

View File

@ -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

View File

@ -10,7 +10,7 @@
#include <catch2/catch_config.hpp> #include <catch2/catch_config.hpp>
#include <catch2/internal/catch_string_manip.hpp> #include <catch2/internal/catch_string_manip.hpp>
#include <catch2/interfaces/catch_interfaces_registry_hub.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_console_colour.hpp>
#include <catch2/internal/catch_parse_numbers.hpp> #include <catch2/internal/catch_parse_numbers.hpp>
#include <catch2/internal/catch_reporter_spec_parser.hpp> #include <catch2/internal/catch_reporter_spec_parser.hpp>
@ -144,7 +144,7 @@ namespace Catch {
auto const& reporterSpec = *parsed; auto const& reporterSpec = *parsed;
IReporterRegistry::FactoryMap const& factories = auto const& factories =
getRegistryHub().getReporterRegistry().getFactories(); getRegistryHub().getReporterRegistry().getFactories();
auto result = factories.find( reporterSpec.name() ); auto result = factories.find( reporterSpec.name() );

View File

@ -9,9 +9,9 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp> #include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.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_testcase.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.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_move_and_forward.hpp>
#include <catch2/internal/catch_case_insensitive_comparisons.hpp> #include <catch2/internal/catch_case_insensitive_comparisons.hpp>
@ -54,7 +54,7 @@ namespace Catch {
void listReporters(IEventListener& reporter) { void listReporters(IEventListener& reporter) {
std::vector<ReporterDescription> descriptions; std::vector<ReporterDescription> descriptions;
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); auto const& factories = getRegistryHub().getReporterRegistry().getFactories();
descriptions.reserve(factories.size()); descriptions.reserve(factories.size());
for (auto const& fac : factories) { for (auto const& fac : factories) {
descriptions.push_back({ fac.first, fac.second->getDescription() }); descriptions.push_back({ fac.first, fac.second->getDescription() });

View File

@ -5,61 +5,86 @@
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0 // 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_automake.hpp>
#include <catch2/reporters/catch_reporter_compact.hpp> #include <catch2/reporters/catch_reporter_compact.hpp>
#include <catch2/reporters/catch_reporter_console.hpp> #include <catch2/reporters/catch_reporter_console.hpp>
#include <catch2/reporters/catch_reporter_junit.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_sonarqube.hpp>
#include <catch2/reporters/catch_reporter_tap.hpp> #include <catch2/reporters/catch_reporter_tap.hpp>
#include <catch2/reporters/catch_reporter_teamcity.hpp> #include <catch2/reporters/catch_reporter_teamcity.hpp>
#include <catch2/reporters/catch_reporter_xml.hpp> #include <catch2/reporters/catch_reporter_xml.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_enforce.hpp>
namespace Catch { 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, // Because it is impossible to move out of initializer list,
// we have to add the elements manually // we have to add the elements manually
m_factories["Automake"] = Detail::make_unique<ReporterFactory<AutomakeReporter>>(); m_impl->factories["Automake"] =
m_factories["compact"] = Detail::make_unique<ReporterFactory<CompactReporter>>(); Detail::make_unique<ReporterFactory<AutomakeReporter>>();
m_factories["console"] = Detail::make_unique<ReporterFactory<ConsoleReporter>>(); m_impl->factories["compact"] =
m_factories["JUnit"] = Detail::make_unique<ReporterFactory<JunitReporter>>(); Detail::make_unique<ReporterFactory<CompactReporter>>();
m_factories["SonarQube"] = Detail::make_unique<ReporterFactory<SonarQubeReporter>>(); m_impl->factories["console"] =
m_factories["TAP"] = Detail::make_unique<ReporterFactory<TAPReporter>>(); Detail::make_unique<ReporterFactory<ConsoleReporter>>();
m_factories["TeamCity"] = Detail::make_unique<ReporterFactory<TeamCityReporter>>(); m_impl->factories["JUnit"] =
m_factories["XML"] = Detail::make_unique<ReporterFactory<XmlReporter>>(); 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; 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 { return IEventListenerPtr();
auto it = m_factories.find( name );
if( it == m_factories.end() )
return nullptr;
return it->second->create( CATCH_MOVE(config) );
} }
void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr factory ) { void ReporterRegistry::registerReporter( std::string const& name,
IReporterFactoryPtr factory ) {
CATCH_ENFORCE( name.find( "::" ) == name.npos, CATCH_ENFORCE( name.find( "::" ) == name.npos,
"'::' is not allowed in reporter name: '" + name + '\'' ); "'::' 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" ); 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( void ReporterRegistry::registerListener(
Detail::unique_ptr<EventListenerFactory> factory ) { 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 { std::map<std::string,
return m_factories; IReporterFactoryPtr,
} Detail::CaseInsensitiveLess> const&
IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { ReporterRegistry::getFactories() const {
return m_listeners; return m_impl->factories;
} }
} std::vector<Detail::unique_ptr<EventListenerFactory>> const&
ReporterRegistry::getListeners() const {
return m_impl->listeners;
}
} // namespace Catch

View File

@ -8,31 +8,48 @@
#ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED #ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#define CATCH_REPORTER_REGISTRY_HPP_INCLUDED #define CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/internal/catch_unique_ptr.hpp>
#include <map> #include <map>
#include <string>
#include <vector>
namespace Catch { namespace Catch {
class ReporterRegistry : public IReporterRegistry { 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: public:
ReporterRegistry(); 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 registerReporter( std::string const& name,
void registerListener( Detail::unique_ptr<EventListenerFactory> factory ); IReporterFactoryPtr factory );
FactoryMap const& getFactories() const override; void
Listeners const& getListeners() const override; registerListener( Detail::unique_ptr<EventListenerFactory> factory );
private: std::map<std::string,
FactoryMap m_factories; IReporterFactoryPtr,
Listeners m_listeners; Detail::CaseInsensitiveLess> const&
getFactories() const;
std::vector<Detail::unique_ptr<EventListenerFactory>> const&
getListeners() const;
}; };
}
} // end namespace Catch
#endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED #endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED

View File

@ -64,7 +64,6 @@ internal_headers = [
'interfaces/catch_interfaces_registry_hub.hpp', 'interfaces/catch_interfaces_registry_hub.hpp',
'interfaces/catch_interfaces_reporter.hpp', 'interfaces/catch_interfaces_reporter.hpp',
'interfaces/catch_interfaces_reporter_factory.hpp', 'interfaces/catch_interfaces_reporter_factory.hpp',
'interfaces/catch_interfaces_reporter_registry.hpp',
'interfaces/catch_interfaces_tag_alias_registry.hpp', 'interfaces/catch_interfaces_tag_alias_registry.hpp',
'interfaces/catch_interfaces_testcase.hpp', 'interfaces/catch_interfaces_testcase.hpp',
'internal/catch_assertion_handler.hpp', 'internal/catch_assertion_handler.hpp',
@ -189,7 +188,6 @@ internal_sources = files(
'interfaces/catch_interfaces_registry_hub.cpp', 'interfaces/catch_interfaces_registry_hub.cpp',
'interfaces/catch_interfaces_reporter.cpp', 'interfaces/catch_interfaces_reporter.cpp',
'interfaces/catch_interfaces_reporter_factory.cpp', 'interfaces/catch_interfaces_reporter_factory.cpp',
'interfaces/catch_interfaces_reporter_registry.cpp',
'interfaces/catch_interfaces_testcase.cpp', 'interfaces/catch_interfaces_testcase.cpp',
'internal/catch_assertion_handler.cpp', 'internal/catch_assertion_handler.cpp',
'internal/catch_case_insensitive_comparisons.cpp', 'internal/catch_case_insensitive_comparisons.cpp',

View File

@ -12,7 +12,6 @@
#include <catch2/catch_config.hpp> #include <catch2/catch_config.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/internal/catch_console_colour.hpp> #include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_list.hpp> #include <catch2/internal/catch_list.hpp>