catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Migrated Config and IConfig to shared_ptr (from Ptr)
- Commit
338ba6b9baa4ee01e2653a12cd1f33234b88bd87- Author
- Phil Nash ·
- Parents
41afd0c3d44c
Changes
include/catch_session.hpp | 16 ++++++++-------- include/internal/catch_config.hpp | 5 +---- include/internal/catch_console_colour_impl.hpp | 4 ++-- include/internal/catch_context.h | 6 ++++-- include/internal/catch_context_impl.hpp | 6 +++--- include/internal/catch_interfaces_config.h | 5 +++-- include/internal/catch_interfaces_reporter.h | 10 +++++----- include/internal/catch_reporter_registry.hpp | 2 +- include/internal/catch_run_context.hpp | 6 +++--- include/reporters/catch_reporter_bases.hpp | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 8d200aa6..91aff563 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -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; diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 24afda6e..8be68a81 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -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: diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp index 426bba29..f15494ab 100644 --- a/include/internal/catch_console_colour_impl.hpp +++ b/include/internal/catch_console_colour_impl.hpp @@ -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; diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h index 8b683864..77a7d3ac 100644 --- a/include/internal/catch_context.h +++ b/include/internal/catch_context.h @@ -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(); diff --git a/include/internal/catch_context_impl.hpp b/include/internal/catch_context_impl.hpp index b9488c6e..43210693 100644 --- a/include/internal/catch_context_impl.hpp +++ b/include/internal/catch_context_impl.hpp @@ -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; diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h index 5730a8cd..d9479e07 100644 --- a/include/internal/catch_interfaces_config.h +++ b/include/internal/catch_interfaces_config.h @@ -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 diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index a1c5aa57..07524b93 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -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; }; diff --git a/include/internal/catch_reporter_registry.hpp b/include/internal/catch_reporter_registry.hpp index 7a0c783a..ad212437 100644 --- a/include/internal/catch_reporter_registry.hpp +++ b/include/internal/catch_reporter_registry.hpp @@ -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; diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp index 23c4654a..78051d21 100644 --- a/include/internal/catch_run_context.hpp +++ b/include/internal/catch_run_context.hpp @@ -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; diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index d94c15b4..6c8e4541 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -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;