mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Migrated Config and IConfig to shared_ptr (from Ptr)
This commit is contained in:
parent
41afd0c3d4
commit
338ba6b9ba
@ -21,8 +21,8 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
|
||||
Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
|
||||
Ptr<IStreamingReporter> createReporter( std::string const& reporterName, IConfigPtr const& config ) {
|
||||
Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config );
|
||||
if( !reporter ) {
|
||||
std::ostringstream oss;
|
||||
oss << "No reporter registered with name: '" << reporterName << "'";
|
||||
@ -31,7 +31,7 @@ namespace Catch {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
|
||||
Ptr<IStreamingReporter> makeReporter( std::shared_ptr<Config> const& config ) {
|
||||
std::vector<std::string> reporters = config->getReporterNames();
|
||||
if( reporters.empty() )
|
||||
reporters.push_back( "console" );
|
||||
@ -41,7 +41,7 @@ namespace Catch {
|
||||
reporter = addReporter( reporter, createReporter( name, config ) );
|
||||
return reporter;
|
||||
}
|
||||
Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
|
||||
Ptr<IStreamingReporter> addListeners( IConfigPtr const& config, Ptr<IStreamingReporter> reporters ) {
|
||||
IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
|
||||
for( auto const& listener : listeners )
|
||||
reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) );
|
||||
@ -49,9 +49,9 @@ namespace Catch {
|
||||
}
|
||||
|
||||
|
||||
Totals runTests( Ptr<Config> const& config ) {
|
||||
Totals runTests( std::shared_ptr<Config> const& config ) {
|
||||
|
||||
Ptr<IConfig const> iconfig = config.get();
|
||||
IConfigPtr iconfig = config;
|
||||
|
||||
Ptr<IStreamingReporter> reporter = makeReporter( config );
|
||||
reporter = addListeners( iconfig, reporter );
|
||||
@ -195,14 +195,14 @@ namespace Catch {
|
||||
}
|
||||
Config& config() {
|
||||
if( !m_config )
|
||||
m_config = new Config( m_configData );
|
||||
m_config = std::make_shared<Config>( m_configData );
|
||||
return *m_config;
|
||||
}
|
||||
private:
|
||||
Clara::CommandLine<ConfigData> m_cli;
|
||||
std::vector<Clara::Parser::Token> m_unusedTokens;
|
||||
ConfigData m_configData;
|
||||
Ptr<Config> m_config;
|
||||
std::shared_ptr<Config> m_config;
|
||||
};
|
||||
|
||||
bool Session::alreadyInstantiated = false;
|
||||
|
@ -56,10 +56,7 @@ namespace Catch {
|
||||
};
|
||||
|
||||
|
||||
class Config : public SharedImpl<IConfig> {
|
||||
private:
|
||||
Config( Config const& other );
|
||||
Config& operator = ( Config const& other );
|
||||
class Config : public IConfig {
|
||||
virtual void dummy();
|
||||
public:
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace {
|
||||
IColourImpl* platformColourInstance() {
|
||||
static Win32ColourImpl s_instance;
|
||||
|
||||
Ptr<IConfig const> config = getCurrentContext().getConfig();
|
||||
IConfigPtr config = getCurrentContext().getConfig();
|
||||
UseColour::YesOrNo colourMode = config
|
||||
? config->useColour()
|
||||
: UseColour::Auto;
|
||||
@ -150,7 +150,7 @@ namespace {
|
||||
|
||||
IColourImpl* platformColourInstance() {
|
||||
ErrnoGuard guard;
|
||||
Ptr<IConfig const> config = getCurrentContext().getConfig();
|
||||
IConfigPtr config = getCurrentContext().getConfig();
|
||||
UseColour::YesOrNo colourMode = config
|
||||
? config->useColour()
|
||||
: UseColour::Auto;
|
||||
|
@ -21,6 +21,8 @@ namespace Catch {
|
||||
struct IGeneratorsForTest;
|
||||
struct IConfig;
|
||||
|
||||
using IConfigPtr = std::shared_ptr<IConfig const>;
|
||||
|
||||
struct IContext
|
||||
{
|
||||
virtual ~IContext();
|
||||
@ -29,7 +31,7 @@ namespace Catch {
|
||||
virtual IRunner* getRunner() = 0;
|
||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
|
||||
virtual bool advanceGeneratorsForCurrentTest() = 0;
|
||||
virtual Ptr<IConfig const> getConfig() const = 0;
|
||||
virtual IConfigPtr getConfig() const = 0;
|
||||
};
|
||||
|
||||
struct IMutableContext : IContext
|
||||
@ -37,7 +39,7 @@ namespace Catch {
|
||||
virtual ~IMutableContext();
|
||||
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
|
||||
virtual void setRunner( IRunner* runner ) = 0;
|
||||
virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
|
||||
virtual void setConfig( IConfigPtr const& config ) = 0;
|
||||
};
|
||||
|
||||
IContext& getCurrentContext();
|
||||
|
@ -40,7 +40,7 @@ namespace Catch {
|
||||
return generators && generators->moveNext();
|
||||
}
|
||||
|
||||
virtual Ptr<IConfig const> getConfig() const {
|
||||
virtual IConfigPtr getConfig() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ namespace Catch {
|
||||
virtual void setRunner( IRunner* runner ) {
|
||||
m_runner = runner;
|
||||
}
|
||||
virtual void setConfig( Ptr<IConfig const> const& config ) {
|
||||
virtual void setConfig( IConfigPtr const& config ) {
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
private:
|
||||
Ptr<IConfig const> m_config;
|
||||
IConfigPtr m_config;
|
||||
IRunner* m_runner = nullptr;
|
||||
IResultCapture* m_resultCapture = nullptr;
|
||||
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
||||
|
@ -45,7 +45,7 @@ namespace Catch {
|
||||
|
||||
class TestSpec;
|
||||
|
||||
struct IConfig : IShared {
|
||||
struct IConfig : NonCopyable {
|
||||
|
||||
virtual ~IConfig();
|
||||
|
||||
@ -63,8 +63,9 @@ namespace Catch {
|
||||
virtual unsigned int rngSeed() const = 0;
|
||||
virtual UseColour::YesOrNo useColour() const = 0;
|
||||
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
|
||||
|
||||
};
|
||||
|
||||
using IConfigPtr = std::shared_ptr<IConfig const>;
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||
|
@ -25,18 +25,18 @@
|
||||
namespace Catch
|
||||
{
|
||||
struct ReporterConfig {
|
||||
explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
|
||||
explicit ReporterConfig( IConfigPtr const& _fullConfig )
|
||||
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
|
||||
ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
|
||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
std::ostream& stream() const { return *m_stream; }
|
||||
Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
|
||||
IConfigPtr fullConfig() const { return m_fullConfig; }
|
||||
|
||||
private:
|
||||
std::ostream* m_stream;
|
||||
Ptr<IConfig const> m_fullConfig;
|
||||
IConfigPtr m_fullConfig;
|
||||
};
|
||||
|
||||
struct ReporterPreferences {
|
||||
@ -247,7 +247,7 @@ namespace Catch
|
||||
typedef std::vector<Ptr<IReporterFactory> > Listeners;
|
||||
|
||||
virtual ~IReporterRegistry();
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
|
||||
virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const = 0;
|
||||
virtual FactoryMap const& getFactories() const = 0;
|
||||
virtual Listeners const& getListeners() const = 0;
|
||||
};
|
||||
|
@ -20,7 +20,7 @@ namespace Catch {
|
||||
|
||||
virtual ~ReporterRegistry() override {}
|
||||
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const override {
|
||||
virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const override {
|
||||
FactoryMap::const_iterator it = m_factories.find( name );
|
||||
if( it == m_factories.end() )
|
||||
return nullptr;
|
||||
|
@ -59,7 +59,7 @@ namespace Catch {
|
||||
|
||||
public:
|
||||
|
||||
explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
|
||||
explicit RunContext( IConfigPtr const& _config, Ptr<IStreamingReporter> const& reporter )
|
||||
: m_runInfo( _config->name() ),
|
||||
m_context( getCurrentMutableContext() ),
|
||||
m_config( _config ),
|
||||
@ -128,7 +128,7 @@ namespace Catch {
|
||||
return deltaTotals;
|
||||
}
|
||||
|
||||
Ptr<IConfig const> config() const {
|
||||
IConfigPtr config() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ namespace Catch {
|
||||
ITracker* m_currentSectionTracker;
|
||||
AssertionResult m_lastResult;
|
||||
|
||||
Ptr<IConfig const> m_config;
|
||||
IConfigPtr m_config;
|
||||
Totals m_totals;
|
||||
Ptr<IStreamingReporter> m_reporter;
|
||||
std::vector<MessageInfo> m_messages;
|
||||
|
@ -92,7 +92,7 @@ namespace Catch {
|
||||
// It can optionally be overridden in the derived class.
|
||||
}
|
||||
|
||||
Ptr<IConfig const> m_config;
|
||||
IConfigPtr m_config;
|
||||
std::ostream& stream;
|
||||
|
||||
LazyStat<TestRunInfo> currentTestRunInfo;
|
||||
@ -244,7 +244,7 @@ namespace Catch {
|
||||
result.expandDecomposedExpression();
|
||||
}
|
||||
|
||||
Ptr<IConfig const> m_config;
|
||||
IConfigPtr m_config;
|
||||
std::ostream& stream;
|
||||
std::vector<AssertionStats> m_assertions;
|
||||
std::vector<std::vector<Ptr<SectionNode> > > m_sections;
|
||||
|
Loading…
Reference in New Issue
Block a user