mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Reduce the use of shared_ptrs for various Config objects
Ideally they would not be used at all, but the main config lifetime is a weird mess right now and will require further refactoring.
This commit is contained in:
parent
7134ad9913
commit
df2379218b
@ -51,7 +51,7 @@ namespace Catch {
|
|||||||
BeforeExit = 2,
|
BeforeExit = 2,
|
||||||
BeforeStartAndExit = BeforeStart | BeforeExit
|
BeforeStartAndExit = BeforeStart | BeforeExit
|
||||||
}; };
|
}; };
|
||||||
|
|
||||||
class TestSpec;
|
class TestSpec;
|
||||||
|
|
||||||
struct IConfig : NonCopyable {
|
struct IConfig : NonCopyable {
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig )
|
ReporterConfig::ReporterConfig( IConfig const* _fullConfig )
|
||||||
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
||||||
|
|
||||||
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
|
ReporterConfig::ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream )
|
||||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||||
|
|
||||||
std::ostream& ReporterConfig::stream() const { return *m_stream; }
|
std::ostream& ReporterConfig::stream() const { return *m_stream; }
|
||||||
IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; }
|
IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; }
|
||||||
|
|
||||||
|
|
||||||
TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}
|
TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}
|
||||||
|
@ -37,16 +37,16 @@ namespace Catch {
|
|||||||
struct TagInfo;
|
struct TagInfo;
|
||||||
|
|
||||||
struct ReporterConfig {
|
struct ReporterConfig {
|
||||||
explicit ReporterConfig( IConfigPtr const& _fullConfig );
|
explicit ReporterConfig( IConfig const* _fullConfig );
|
||||||
|
|
||||||
ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
|
ReporterConfig( IConfig const* _fullConfig, std::ostream& _stream );
|
||||||
|
|
||||||
std::ostream& stream() const;
|
std::ostream& stream() const;
|
||||||
IConfigPtr fullConfig() const;
|
IConfig const* fullConfig() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream* m_stream;
|
std::ostream* m_stream;
|
||||||
IConfigPtr m_fullConfig;
|
IConfig const* m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReporterPreferences {
|
struct ReporterPreferences {
|
||||||
@ -268,7 +268,7 @@ namespace Catch {
|
|||||||
using Listeners = std::vector<IReporterFactoryPtr>;
|
using Listeners = std::vector<IReporterFactoryPtr>;
|
||||||
|
|
||||||
virtual ~IReporterRegistry();
|
virtual ~IReporterRegistry();
|
||||||
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
|
virtual IStreamingReporterPtr create( std::string const& name, IConfig 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;
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,7 @@ namespace Catch {
|
|||||||
ReporterRegistry::~ReporterRegistry() = default;
|
ReporterRegistry::~ReporterRegistry() = default;
|
||||||
|
|
||||||
|
|
||||||
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
|
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfig const* config ) const {
|
||||||
auto it = m_factories.find( name );
|
auto it = m_factories.find( name );
|
||||||
if( it == m_factories.end() )
|
if( it == m_factories.end() )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -20,7 +20,7 @@ namespace Catch {
|
|||||||
ReporterRegistry();
|
ReporterRegistry();
|
||||||
~ReporterRegistry() override; // = default, out of line to allow fwd decl
|
~ReporterRegistry() override; // = default, out of line to allow fwd decl
|
||||||
|
|
||||||
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;
|
IStreamingReporterPtr create( std::string const& name, IConfig const* config ) const override;
|
||||||
|
|
||||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
|
void registerReporter( std::string const& name, IReporterFactoryPtr factory );
|
||||||
void registerListener( IReporterFactoryPtr factory );
|
void registerListener( IReporterFactoryPtr factory );
|
||||||
|
@ -33,14 +33,14 @@ namespace Catch {
|
|||||||
namespace {
|
namespace {
|
||||||
const int MaxExitCode = 255;
|
const int MaxExitCode = 255;
|
||||||
|
|
||||||
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
|
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfig const* config) {
|
||||||
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
|
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
|
||||||
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
|
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
|
||||||
|
|
||||||
return reporter;
|
return reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
|
IStreamingReporterPtr makeReporter(Config const* config) {
|
||||||
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
|
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
|
||||||
return createReporter(config->getReporterName(), config);
|
return createReporter(config->getReporterName(), config);
|
||||||
}
|
}
|
||||||
@ -273,7 +273,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create reporter(s) so we can route listings through them
|
// Create reporter(s) so we can route listings through them
|
||||||
auto reporter = makeReporter(m_config);
|
auto reporter = makeReporter(m_config.get());
|
||||||
|
|
||||||
// Handle list request
|
// Handle list request
|
||||||
if (list(*reporter, m_config)) {
|
if (list(*reporter, m_config)) {
|
||||||
|
@ -81,7 +81,7 @@ namespace Catch {
|
|||||||
// It can optionally be overridden in the derived class.
|
// It can optionally be overridden in the derived class.
|
||||||
}
|
}
|
||||||
|
|
||||||
IConfigPtr m_config;
|
IConfig const* m_config;
|
||||||
std::ostream& stream;
|
std::ostream& stream;
|
||||||
|
|
||||||
LazyStat<TestRunInfo> currentTestRunInfo;
|
LazyStat<TestRunInfo> currentTestRunInfo;
|
||||||
@ -227,7 +227,7 @@ namespace Catch {
|
|||||||
|
|
||||||
void skipTest(TestCaseInfo const&) override {}
|
void skipTest(TestCaseInfo const&) override {}
|
||||||
|
|
||||||
IConfigPtr m_config;
|
IConfig const* m_config;
|
||||||
std::ostream& stream;
|
std::ostream& stream;
|
||||||
std::vector<AssertionStats> m_assertions;
|
std::vector<AssertionStats> m_assertions;
|
||||||
std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
|
std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
|
||||||
|
Loading…
Reference in New Issue
Block a user