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ý2020-01-25 14:07:29 +0100
committerMartin Hořeňovský2020-01-25 14:07:29 +0100
commit7134ad9913a1bc206726b9f1c057e1e625a08c27 (patch)
tree8e94f1ed64d5a75a77505c0dab9da4c9e35923e3 /src/catch2
parent827733fe81201ec80749e3453167ff775c843d8a (diff)
downloadcatch3-7134ad9913a1bc206726b9f1c057e1e625a08c27.tar.gz
Replace shared_ptr with unique_ptr for reporters
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_interfaces_registry_hub.h6
-rw-r--r--src/catch2/catch_interfaces_reporter.h2
-rw-r--r--src/catch2/catch_registry_hub.cpp8
-rw-r--r--src/catch2/catch_reporter_registrars.hpp4
-rw-r--r--src/catch2/catch_reporter_registry.cpp34
-rw-r--r--src/catch2/catch_reporter_registry.h6
6 files changed, 32 insertions, 28 deletions
diff --git a/src/catch2/catch_interfaces_registry_hub.h b/src/catch2/catch_interfaces_registry_hub.h
index 91069cfd..fc63a0d0 100644
--- a/src/catch2/catch_interfaces_registry_hub.h
+++ b/src/catch2/catch_interfaces_registry_hub.h
@@ -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;
diff --git a/src/catch2/catch_interfaces_reporter.h b/src/catch2/catch_interfaces_reporter.h
index 36129741..97ce8ea0 100644
--- a/src/catch2/catch_interfaces_reporter.h
+++ b/src/catch2/catch_interfaces_reporter.h
@@ -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>;
diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp
index f49506a2..8194c417 100644
--- a/src/catch2/catch_registry_hub.cpp
+++ b/src/catch2/catch_registry_hub.cpp
@@ -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) );
diff --git a/src/catch2/catch_reporter_registrars.hpp b/src/catch2/catch_reporter_registrars.hpp
index 99be5577..cbc4fb73 100644
--- a/src/catch2/catch_reporter_registrars.hpp
+++ b/src/catch2/catch_reporter_registrars.hpp
@@ -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>() );
}
};
}
diff --git a/src/catch2/catch_reporter_registry.cpp b/src/catch2/catch_reporter_registry.cpp
index 92f0be89..beb8411e 100644
--- a/src/catch2/catch_reporter_registry.cpp
+++ b/src/catch2/catch_reporter_registry.cpp
@@ -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 {
diff --git a/src/catch2/catch_reporter_registry.h b/src/catch2/catch_reporter_registry.h
index e6aa86f4..456b76f8 100644
--- a/src/catch2/catch_reporter_registry.h
+++ b/src/catch2/catch_reporter_registry.h
@@ -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;