mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Replace shared_ptr with unique_ptr for reporters
This commit is contained in:
parent
827733fe81
commit
7134ad9913
@ -28,7 +28,7 @@ namespace Catch {
|
||||
|
||||
class StartupExceptionRegistry;
|
||||
|
||||
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
||||
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
|
||||
|
||||
struct IRegistryHub {
|
||||
virtual ~IRegistryHub();
|
||||
@ -44,8 +44,8 @@ namespace Catch {
|
||||
|
||||
struct IMutableRegistryHub {
|
||||
virtual ~IMutableRegistryHub();
|
||||
virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
|
||||
virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
|
||||
virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
|
||||
virtual void registerListener( IReporterFactoryPtr factory ) = 0;
|
||||
virtual void registerTest(std::unique_ptr<TestCaseInfo>&& testInfo, std::unique_ptr<ITestInvoker>&& invoker) = 0;
|
||||
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
||||
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
||||
|
@ -261,7 +261,7 @@ namespace Catch {
|
||||
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
|
||||
virtual std::string getDescription() const = 0;
|
||||
};
|
||||
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
||||
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
|
||||
|
||||
struct IReporterRegistry {
|
||||
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
|
||||
|
@ -43,11 +43,11 @@ namespace Catch {
|
||||
}
|
||||
|
||||
public: // IMutableRegistryHub
|
||||
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
|
||||
m_reporterRegistry.registerReporter( name, factory );
|
||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
|
||||
m_reporterRegistry.registerReporter( name, std::move(factory) );
|
||||
}
|
||||
void registerListener( IReporterFactoryPtr const& factory ) override {
|
||||
m_reporterRegistry.registerListener( factory );
|
||||
void registerListener( IReporterFactoryPtr factory ) override {
|
||||
m_reporterRegistry.registerListener( std::move(factory) );
|
||||
}
|
||||
void registerTest( std::unique_ptr<TestCaseInfo>&& testInfo, std::unique_ptr<ITestInvoker>&& invoker ) override {
|
||||
m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) );
|
||||
|
@ -17,7 +17,7 @@ namespace Catch {
|
||||
class ReporterFactory : public IReporterFactory {
|
||||
|
||||
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
|
||||
return std::unique_ptr<T>( new T( config ) );
|
||||
return std::make_unique<T>( config );
|
||||
}
|
||||
|
||||
std::string getDescription() const override {
|
||||
@ -50,7 +50,7 @@ namespace Catch {
|
||||
public:
|
||||
|
||||
ListenerRegistrar() {
|
||||
getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
|
||||
getMutableRegistryHub().registerListener( std::make_unique<ListenerFactory>() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -18,17 +18,21 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ReporterRegistry::ReporterRegistry():
|
||||
m_factories({
|
||||
{"automake", std::make_shared<ReporterFactory<AutomakeReporter>>() },
|
||||
{"compact", std::make_shared<ReporterFactory<CompactReporter>>() },
|
||||
{"console", std::make_shared<ReporterFactory<ConsoleReporter>>() },
|
||||
{"junit", std::make_shared<ReporterFactory<JunitReporter>>() },
|
||||
{"sonarqube", std::make_shared<ReporterFactory<SonarQubeReporter>>() },
|
||||
{"tap", std::make_shared<ReporterFactory<TAPReporter>>() },
|
||||
{"teamcity", std::make_shared<ReporterFactory<TeamCityReporter>>() },
|
||||
{"xml", std::make_shared<ReporterFactory<XmlReporter>>() },
|
||||
}) {}
|
||||
ReporterRegistry::ReporterRegistry() {
|
||||
// Because it is impossible to move out of initializer list,
|
||||
// we have to add the elements manually
|
||||
m_factories["automake"] = std::make_unique<ReporterFactory<AutomakeReporter>>();
|
||||
m_factories["compact"] = std::make_unique<ReporterFactory<CompactReporter>>();
|
||||
m_factories["console"] = std::make_unique<ReporterFactory<ConsoleReporter>>();
|
||||
m_factories["junit"] = std::make_unique<ReporterFactory<JunitReporter>>();
|
||||
m_factories["sonarqube"] = std::make_unique<ReporterFactory<SonarQubeReporter>>();
|
||||
m_factories["tap"] = std::make_unique<ReporterFactory<TAPReporter>>();
|
||||
m_factories["teamcity"] = std::make_unique<ReporterFactory<TeamCityReporter>>();
|
||||
m_factories["xml"] = std::make_unique<ReporterFactory<XmlReporter>>();
|
||||
}
|
||||
|
||||
ReporterRegistry::~ReporterRegistry() = default;
|
||||
|
||||
|
||||
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
|
||||
auto it = m_factories.find( name );
|
||||
@ -37,11 +41,11 @@ namespace Catch {
|
||||
return it->second->create( ReporterConfig( config ) );
|
||||
}
|
||||
|
||||
void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
|
||||
m_factories.emplace(name, factory);
|
||||
void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr factory ) {
|
||||
m_factories.emplace(name, std::move(factory));
|
||||
}
|
||||
void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) {
|
||||
m_listeners.push_back( factory );
|
||||
void ReporterRegistry::registerListener( IReporterFactoryPtr factory ) {
|
||||
m_listeners.push_back( std::move(factory) );
|
||||
}
|
||||
|
||||
IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const {
|
||||
|
@ -18,12 +18,12 @@ namespace Catch {
|
||||
public:
|
||||
|
||||
ReporterRegistry();
|
||||
~ReporterRegistry() override = default;
|
||||
~ReporterRegistry() override; // = default, out of line to allow fwd decl
|
||||
|
||||
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
|
||||
|
||||
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory );
|
||||
void registerListener( IReporterFactoryPtr const& factory );
|
||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
|
||||
void registerListener( IReporterFactoryPtr factory );
|
||||
|
||||
FactoryMap const& getFactories() const override;
|
||||
Listeners const& getListeners() const override;
|
||||
|
Loading…
Reference in New Issue
Block a user