mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 23:36:11 +01:00
Migrated IStreamingReporter from Ptr to std::shared_ptr
This commit is contained in:
parent
a96f25c716
commit
0844d6e867
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Ptr<IStreamingReporter> createReporter( std::string const& reporterName, IConfigPtr const& config ) {
|
IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) {
|
||||||
Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config );
|
IStreamingReporterPtr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config );
|
||||||
if( !reporter ) {
|
if( !reporter ) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "No reporter registered with name: '" << reporterName << "'";
|
oss << "No reporter registered with name: '" << reporterName << "'";
|
||||||
@ -31,17 +31,17 @@ namespace Catch {
|
|||||||
return reporter;
|
return reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<IStreamingReporter> makeReporter( std::shared_ptr<Config> const& config ) {
|
IStreamingReporterPtr makeReporter( std::shared_ptr<Config> const& config ) {
|
||||||
std::vector<std::string> reporters = config->getReporterNames();
|
std::vector<std::string> reporters = config->getReporterNames();
|
||||||
if( reporters.empty() )
|
if( reporters.empty() )
|
||||||
reporters.push_back( "console" );
|
reporters.push_back( "console" );
|
||||||
|
|
||||||
Ptr<IStreamingReporter> reporter;
|
IStreamingReporterPtr reporter;
|
||||||
for( auto const& name : reporters )
|
for( auto const& name : reporters )
|
||||||
reporter = addReporter( reporter, createReporter( name, config ) );
|
reporter = addReporter( reporter, createReporter( name, config ) );
|
||||||
return reporter;
|
return reporter;
|
||||||
}
|
}
|
||||||
Ptr<IStreamingReporter> addListeners( IConfigPtr const& config, Ptr<IStreamingReporter> reporters ) {
|
IStreamingReporterPtr addListeners( IConfigPtr const& config, IStreamingReporterPtr reporters ) {
|
||||||
auto const& listeners = getRegistryHub().getReporterRegistry().getListeners();
|
auto const& listeners = getRegistryHub().getReporterRegistry().getListeners();
|
||||||
for( auto const& listener : listeners )
|
for( auto const& listener : listeners )
|
||||||
reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) );
|
reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) );
|
||||||
@ -53,7 +53,7 @@ namespace Catch {
|
|||||||
|
|
||||||
IConfigPtr iconfig = config;
|
IConfigPtr iconfig = config;
|
||||||
|
|
||||||
Ptr<IStreamingReporter> reporter = makeReporter( config );
|
IStreamingReporterPtr reporter = makeReporter( config );
|
||||||
reporter = addListeners( iconfig, reporter );
|
reporter = addListeners( iconfig, reporter );
|
||||||
|
|
||||||
RunContext context( iconfig, reporter );
|
RunContext context( iconfig, reporter );
|
||||||
|
@ -204,7 +204,7 @@ namespace Catch
|
|||||||
|
|
||||||
class MultipleReporters;
|
class MultipleReporters;
|
||||||
|
|
||||||
struct IStreamingReporter : IShared {
|
struct IStreamingReporter {
|
||||||
virtual ~IStreamingReporter();
|
virtual ~IStreamingReporter();
|
||||||
|
|
||||||
// Implementing class must also provide the following static method:
|
// Implementing class must also provide the following static method:
|
||||||
@ -234,11 +234,11 @@ namespace Catch
|
|||||||
|
|
||||||
virtual MultipleReporters* tryAsMulti() { return nullptr; }
|
virtual MultipleReporters* tryAsMulti() { return nullptr; }
|
||||||
};
|
};
|
||||||
|
using IStreamingReporterPtr = std::shared_ptr<IStreamingReporter>;
|
||||||
|
|
||||||
struct IReporterFactory {
|
struct IReporterFactory {
|
||||||
virtual ~IReporterFactory();
|
virtual ~IReporterFactory();
|
||||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
|
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
|
||||||
virtual std::string getDescription() const = 0;
|
virtual std::string getDescription() const = 0;
|
||||||
};
|
};
|
||||||
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
||||||
@ -248,12 +248,12 @@ namespace Catch
|
|||||||
using Listeners = std::vector<IReporterFactoryPtr>;
|
using Listeners = std::vector<IReporterFactoryPtr>;
|
||||||
|
|
||||||
virtual ~IReporterRegistry();
|
virtual ~IReporterRegistry();
|
||||||
virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const = 0;
|
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
|
||||||
virtual FactoryMap const& getFactories() const = 0;
|
virtual FactoryMap const& getFactories() const = 0;
|
||||||
virtual Listeners const& getListeners() const = 0;
|
virtual Listeners const& getListeners() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
|
IStreamingReporterPtr addReporter( IStreamingReporterPtr const& existingReporter, IStreamingReporterPtr const& additionalReporter );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ namespace Catch {
|
|||||||
|
|
||||||
class ReporterFactory : public IReporterFactory {
|
class ReporterFactory : public IReporterFactory {
|
||||||
|
|
||||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
|
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const {
|
||||||
return new T( config );
|
return std::make_shared<T>( config );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string getDescription() const {
|
virtual std::string getDescription() const {
|
||||||
@ -38,8 +38,8 @@ namespace Catch {
|
|||||||
|
|
||||||
class ListenerFactory : public IReporterFactory {
|
class ListenerFactory : public IReporterFactory {
|
||||||
|
|
||||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
|
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const {
|
||||||
return new T( config );
|
return std::make_shared<T>( config );
|
||||||
}
|
}
|
||||||
virtual std::string getDescription() const {
|
virtual std::string getDescription() const {
|
||||||
return std::string();
|
return std::string();
|
||||||
|
@ -20,7 +20,7 @@ namespace Catch {
|
|||||||
|
|
||||||
virtual ~ReporterRegistry() override {}
|
virtual ~ReporterRegistry() override {}
|
||||||
|
|
||||||
virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const override {
|
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override {
|
||||||
FactoryMap::const_iterator it = m_factories.find( name );
|
FactoryMap::const_iterator it = m_factories.find( name );
|
||||||
if( it == m_factories.end() )
|
if( it == m_factories.end() )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -59,7 +59,7 @@ namespace Catch {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit RunContext( IConfigPtr const& _config, Ptr<IStreamingReporter> const& reporter )
|
explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr const& reporter )
|
||||||
: m_runInfo( _config->name() ),
|
: m_runInfo( _config->name() ),
|
||||||
m_context( getCurrentMutableContext() ),
|
m_context( getCurrentMutableContext() ),
|
||||||
m_config( _config ),
|
m_config( _config ),
|
||||||
@ -355,7 +355,7 @@ namespace Catch {
|
|||||||
|
|
||||||
IConfigPtr m_config;
|
IConfigPtr m_config;
|
||||||
Totals m_totals;
|
Totals m_totals;
|
||||||
Ptr<IStreamingReporter> m_reporter;
|
IStreamingReporterPtr m_reporter;
|
||||||
std::vector<MessageInfo> m_messages;
|
std::vector<MessageInfo> m_messages;
|
||||||
AssertionInfo m_lastAssertionInfo;
|
AssertionInfo m_lastAssertionInfo;
|
||||||
std::vector<SectionEndInfo> m_unfinishedSections;
|
std::vector<SectionEndInfo> m_unfinishedSections;
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class MultipleReporters : public SharedImpl<IStreamingReporter> {
|
class MultipleReporters : public SharedImpl<IStreamingReporter> {
|
||||||
typedef std::vector<Ptr<IStreamingReporter> > Reporters;
|
typedef std::vector<IStreamingReporterPtr > Reporters;
|
||||||
Reporters m_reporters;
|
Reporters m_reporters;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add( Ptr<IStreamingReporter> const& reporter ) {
|
void add( IStreamingReporterPtr const& reporter ) {
|
||||||
m_reporters.push_back( reporter );
|
m_reporters.push_back( reporter );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,14 +101,14 @@ public: // IStreamingReporter
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
|
IStreamingReporterPtr addReporter( IStreamingReporterPtr const& existingReporter, IStreamingReporterPtr const& additionalReporter ) {
|
||||||
Ptr<IStreamingReporter> resultingReporter;
|
IStreamingReporterPtr resultingReporter;
|
||||||
|
|
||||||
if( existingReporter ) {
|
if( existingReporter ) {
|
||||||
MultipleReporters* multi = existingReporter->tryAsMulti();
|
MultipleReporters* multi = existingReporter->tryAsMulti();
|
||||||
if( !multi ) {
|
if( !multi ) {
|
||||||
multi = new MultipleReporters;
|
multi = new MultipleReporters;
|
||||||
resultingReporter = Ptr<IStreamingReporter>( multi );
|
resultingReporter = IStreamingReporterPtr( multi );
|
||||||
if( existingReporter )
|
if( existingReporter )
|
||||||
multi->add( existingReporter );
|
multi->add( existingReporter );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user