mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
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:
parent
4f4ad8ada9
commit
d0f70fdfd6
@ -216,7 +216,6 @@ set(INTERFACE_HEADERS
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.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_testcase.hpp
|
||||
)
|
||||
@ -228,7 +227,6 @@ set(INTERFACE_SOURCES
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_registry.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.cpp
|
||||
)
|
||||
set(INTERFACE_FILES ${INTERFACE_HEADERS} ${INTERFACE_SOURCES})
|
||||
|
@ -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 {
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
@ -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() );
|
||||
|
||||
|
@ -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() });
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
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
|
||||
|
@ -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',
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <catch2/catch_config.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/internal/catch_console_colour.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_list.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user