Some small clean-ups and refactorings

- removed previous instance saves in RunContext (they were a hang-over from embedded contexts)
- started cleaning up config usage
This commit is contained in:
Phil Nash 2015-09-28 01:09:06 -07:00
parent 0c1c9fa922
commit a0de07d45b
5 changed files with 17 additions and 25 deletions

View File

@ -43,7 +43,7 @@ namespace Catch {
reporter = addReporter( reporter, createReporter( *it, config ) ); reporter = addReporter( reporter, createReporter( *it, config ) );
return reporter; return reporter;
} }
Ptr<IStreamingReporter> addListeners( Ptr<IConfig> const& config, Ptr<IStreamingReporter> reporters ) { Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners(); IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end(); for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
it != itEnd; it != itEnd;
@ -67,12 +67,14 @@ namespace Catch {
Totals runTests( Ptr<Config> const& config ) { Totals runTests( Ptr<Config> const& config ) {
Ptr<IConfig const> iconfig = config.get();
std::ofstream ofs; std::ofstream ofs;
openStreamInto( config, ofs ); openStreamInto( config, ofs );
Ptr<IStreamingReporter> reporter = makeReporter( config ); Ptr<IStreamingReporter> reporter = makeReporter( config );
reporter = addListeners( config.get(), reporter ); reporter = addListeners( iconfig, reporter );
RunContext context( config.get(), reporter ); RunContext context( iconfig, reporter );
Totals totals; Totals totals;
@ -82,17 +84,17 @@ namespace Catch {
if( !testSpec.hasFilters() ) if( !testSpec.hasFilters() )
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *config ); std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end(); for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
it != itEnd; it != itEnd;
++it ) { ++it ) {
if( !context.aborting() && matchTest( *it, testSpec, *config ) ) if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
totals += context.runTest( *it ); totals += context.runTest( *it );
else else
reporter->skipTest( *it ); reporter->skipTest( *it );
} }
context.testGroupEnded( config->name(), totals, 1, 1 ); context.testGroupEnded( iconfig->name(), totals, 1, 1 );
return totals; return totals;
} }

View File

@ -26,18 +26,18 @@
namespace Catch namespace Catch
{ {
struct ReporterConfig { struct ReporterConfig {
explicit ReporterConfig( Ptr<IConfig> const& _fullConfig ) explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
ReporterConfig( Ptr<IConfig> const& _fullConfig, std::ostream& _stream ) ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {} : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
std::ostream& stream() const { return *m_stream; } std::ostream& stream() const { return *m_stream; }
Ptr<IConfig> fullConfig() const { return m_fullConfig; } Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
private: private:
std::ostream* m_stream; std::ostream* m_stream;
Ptr<IConfig> m_fullConfig; Ptr<IConfig const> m_fullConfig;
}; };
struct ReporterPreferences { struct ReporterPreferences {
@ -261,7 +261,7 @@ namespace Catch
typedef std::vector<Ptr<IReporterFactory> > Listeners; typedef std::vector<Ptr<IReporterFactory> > Listeners;
virtual ~IReporterRegistry(); virtual ~IReporterRegistry();
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const = 0; virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> 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;
}; };

View File

@ -20,7 +20,7 @@ namespace Catch {
virtual ~ReporterRegistry() CATCH_OVERRIDE {} virtual ~ReporterRegistry() CATCH_OVERRIDE {}
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const CATCH_OVERRIDE { virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_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 CATCH_NULL; return CATCH_NULL;

View File

@ -64,10 +64,7 @@ namespace Catch {
m_context( getCurrentMutableContext() ), m_context( getCurrentMutableContext() ),
m_activeTestCase( CATCH_NULL ), m_activeTestCase( CATCH_NULL ),
m_config( _config ), m_config( _config ),
m_reporter( reporter ), m_reporter( reporter )
m_prevRunner( m_context.getRunner() ),
m_prevResultCapture( m_context.getResultCapture() ),
m_prevConfig( m_context.getConfig() )
{ {
m_context.setRunner( this ); m_context.setRunner( this );
m_context.setConfig( m_config ); m_context.setConfig( m_config );
@ -77,10 +74,6 @@ namespace Catch {
virtual ~RunContext() { virtual ~RunContext() {
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
m_context.setRunner( m_prevRunner );
m_context.setConfig( Ptr<IConfig const>() );
m_context.setResultCapture( m_prevResultCapture );
m_context.setConfig( m_prevConfig );
} }
void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) { void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
@ -330,9 +323,6 @@ namespace Catch {
Totals m_totals; Totals m_totals;
Ptr<IStreamingReporter> m_reporter; Ptr<IStreamingReporter> m_reporter;
std::vector<MessageInfo> m_messages; std::vector<MessageInfo> m_messages;
IRunner* m_prevRunner;
IResultCapture* m_prevResultCapture;
Ptr<IConfig const> m_prevConfig;
AssertionInfo m_lastAssertionInfo; AssertionInfo m_lastAssertionInfo;
std::vector<SectionEndInfo> m_unfinishedSections; std::vector<SectionEndInfo> m_unfinishedSections;
}; };

View File

@ -65,7 +65,7 @@ namespace Catch {
// It can optionally be overridden in the derived class. // It can optionally be overridden in the derived class.
} }
Ptr<IConfig> m_config; Ptr<IConfig const> m_config;
std::ostream& stream; std::ostream& stream;
LazyStat<TestRunInfo> currentTestRunInfo; LazyStat<TestRunInfo> currentTestRunInfo;
@ -204,7 +204,7 @@ namespace Catch {
virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {} virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
Ptr<IConfig> m_config; Ptr<IConfig const> m_config;
std::ostream& stream; std::ostream& stream;
std::vector<AssertionStats> m_assertions; std::vector<AssertionStats> m_assertions;
std::vector<std::vector<Ptr<SectionNode> > > m_sections; std::vector<std::vector<Ptr<SectionNode> > > m_sections;