mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Refactoring towards interface based config
This commit is contained in:
@@ -75,7 +75,7 @@ namespace Catch {
|
||||
};
|
||||
|
||||
|
||||
class Config : public IConfig {
|
||||
class Config : public SharedImpl<IConfig> {
|
||||
private:
|
||||
Config( Config const& other );
|
||||
Config& operator = ( Config const& other );
|
||||
@@ -123,10 +123,6 @@ namespace Catch {
|
||||
bool shouldDebugBreak() const {
|
||||
return m_data.shouldDebugBreak;
|
||||
}
|
||||
|
||||
virtual std::ostream& stream() const {
|
||||
return m_os;
|
||||
}
|
||||
|
||||
void setStreamBuf( std::streambuf* buf ) {
|
||||
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
||||
@@ -144,19 +140,11 @@ namespace Catch {
|
||||
filters.addFilter( TestCaseFilter( testSpec ) );
|
||||
m_data.filters.push_back( filters );
|
||||
}
|
||||
|
||||
virtual bool includeSuccessfulResults() const {
|
||||
return m_data.includeWhichResults == Include::SuccessfulResults;
|
||||
}
|
||||
|
||||
|
||||
int getCutoff() const {
|
||||
return m_data.cutoff;
|
||||
}
|
||||
|
||||
virtual bool allowThrows() const {
|
||||
return m_data.allowThrows;
|
||||
}
|
||||
|
||||
ConfigData const& data() const {
|
||||
return m_data;
|
||||
}
|
||||
@@ -164,6 +152,13 @@ namespace Catch {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// IConfig interface
|
||||
virtual bool allowThrows() const { return m_data.allowThrows; }
|
||||
virtual std::ostream& stream() const { return m_os; }
|
||||
virtual std::string name() const { return m_data.name; }
|
||||
virtual bool includeSuccessfulResults() const { return m_data.includeWhichResults == Include::SuccessfulResults; }
|
||||
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & ConfigData::WarnAbout::NoAssertions; }
|
||||
|
||||
private:
|
||||
ConfigData m_data;
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||
|
||||
#include "catch_interfaces_generators.h"
|
||||
#include "catch_ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -31,15 +32,15 @@ namespace Catch {
|
||||
virtual IRunner& getRunner() = 0;
|
||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
|
||||
virtual bool advanceGeneratorsForCurrentTest() = 0;
|
||||
virtual const IConfig* getConfig() const = 0;
|
||||
virtual Ptr<IConfig> getConfig() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct IMutableContext : IContext
|
||||
{
|
||||
virtual ~IMutableContext();
|
||||
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
|
||||
virtual void setRunner( IRunner* runner ) = 0;
|
||||
virtual void setConfig( const IConfig* config ) = 0;
|
||||
virtual void setConfig( Ptr<IConfig> const& config ) = 0;
|
||||
};
|
||||
|
||||
IContext& getCurrentContext();
|
||||
|
@@ -38,7 +38,7 @@ namespace Catch {
|
||||
return generators && generators->moveNext();
|
||||
}
|
||||
|
||||
virtual const IConfig* getConfig() const {
|
||||
virtual Ptr<IConfig> getConfig() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Catch {
|
||||
virtual void setRunner( IRunner* runner ) {
|
||||
m_runner = runner;
|
||||
}
|
||||
virtual void setConfig( const IConfig* config ) {
|
||||
virtual void setConfig( Ptr<IConfig> const& config ) {
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Catch {
|
||||
private:
|
||||
IRunner* m_runner;
|
||||
IResultCapture* m_resultCapture;
|
||||
const IConfig* m_config;
|
||||
Ptr<IConfig> m_config;
|
||||
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
||||
};
|
||||
|
||||
|
@@ -8,13 +8,22 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "catch_ptr.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct IConfig {
|
||||
struct IConfig : IShared {
|
||||
|
||||
virtual ~IConfig();
|
||||
|
||||
virtual bool allowThrows() const = 0;
|
||||
virtual std::ostream& stream() const = 0;
|
||||
virtual std::string name() const = 0;
|
||||
virtual bool includeSuccessfulResults() const = 0;
|
||||
virtual bool warnAboutMissingAssertions() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -24,17 +24,18 @@
|
||||
namespace Catch
|
||||
{
|
||||
struct ReporterConfig {
|
||||
ReporterConfig( std::ostream& _stream, ConfigData const& _fullConfig )
|
||||
explicit ReporterConfig( Ptr<IConfig> const& _fullConfig )
|
||||
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
ReporterConfig( Ptr<IConfig> const& _fullConfig, std::ostream& _stream )
|
||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
std::ostream& stream() const { return *m_stream; }
|
||||
std::string name() const { return m_fullConfig.name; }
|
||||
bool includeSuccessfulResults() const { return m_fullConfig.includeWhichResults == Include::SuccessfulResults; }
|
||||
bool warnAboutMissingAssertions() const { return m_fullConfig.warnings & ConfigData::WarnAbout::NoAssertions; }
|
||||
std::ostream& stream() const { return *m_stream; }
|
||||
Ptr<IConfig> fullConfig() const { return m_fullConfig; }
|
||||
|
||||
private:
|
||||
std::ostream* m_stream;
|
||||
ConfigData m_fullConfig;
|
||||
Ptr<IConfig> m_fullConfig;
|
||||
};
|
||||
|
||||
struct ReporterPreferences {
|
||||
@@ -217,7 +218,7 @@ namespace Catch
|
||||
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
||||
|
||||
StreamingReporterBase( ReporterConfig const& _config )
|
||||
: m_config( _config ),
|
||||
: m_config( _config.fullConfig() ),
|
||||
stream( _config.stream() )
|
||||
{}
|
||||
|
||||
@@ -264,7 +265,7 @@ namespace Catch
|
||||
testRunInfo.reset();
|
||||
}
|
||||
|
||||
ReporterConfig m_config;
|
||||
Ptr<IConfig> m_config;
|
||||
Option<TestRunInfo> testRunInfo;
|
||||
Option<GroupInfo> unusedGroupInfo;
|
||||
Option<TestCaseInfo> unusedTestCaseInfo;
|
||||
@@ -321,7 +322,7 @@ namespace Catch
|
||||
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
||||
|
||||
virtual ~IReporterRegistry();
|
||||
virtual IStreamingReporter* create( std::string const& name, ReporterConfig const& config ) const = 0;
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const = 0;
|
||||
virtual FactoryMap const& getFactories() const = 0;
|
||||
};
|
||||
|
||||
|
@@ -15,7 +15,7 @@ namespace Catch
|
||||
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
|
||||
{
|
||||
public:
|
||||
LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config );
|
||||
LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
|
||||
virtual ~LegacyReporterAdapter();
|
||||
|
||||
virtual ReporterPreferences getPreferences() const;
|
||||
@@ -33,7 +33,6 @@ namespace Catch
|
||||
|
||||
private:
|
||||
Ptr<IReporter> m_legacyReporter;
|
||||
ReporterConfig m_config;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -12,9 +12,8 @@
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config )
|
||||
: m_legacyReporter( legacyReporter ),
|
||||
m_config( config )
|
||||
LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
|
||||
: m_legacyReporter( legacyReporter )
|
||||
{}
|
||||
LegacyReporterAdapter::~LegacyReporterAdapter() {}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ namespace Catch {
|
||||
class ReporterFactory : public IReporterFactory {
|
||||
|
||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
|
||||
return new LegacyReporterAdapter( new T( config ), config );
|
||||
return new LegacyReporterAdapter( new T( config ) );
|
||||
}
|
||||
|
||||
virtual std::string getDescription() const {
|
||||
|
@@ -22,11 +22,11 @@ namespace Catch {
|
||||
deleteAllValues( m_factories );
|
||||
}
|
||||
|
||||
virtual IStreamingReporter* create( std::string const& name, ReporterConfig const& config ) const {
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const {
|
||||
FactoryMap::const_iterator it = m_factories.find( name );
|
||||
if( it == m_factories.end() )
|
||||
return NULL;
|
||||
return it->second->create( config );
|
||||
return it->second->create( ReporterConfig( config ) );
|
||||
}
|
||||
|
||||
void registerReporter( std::string const& name, IReporterFactory* factory ) {
|
||||
|
@@ -56,8 +56,8 @@ namespace Catch {
|
||||
|
||||
public:
|
||||
|
||||
explicit Runner( Config const& config, Ptr<IStreamingReporter> const& reporter )
|
||||
: m_runInfo( config.data().name ),
|
||||
explicit Runner( Ptr<Config> const& config, Ptr<IStreamingReporter> const& reporter )
|
||||
: m_runInfo( config->name() ),
|
||||
m_context( getCurrentMutableContext() ),
|
||||
m_runningTest( NULL ),
|
||||
m_config( config ),
|
||||
@@ -67,7 +67,7 @@ namespace Catch {
|
||||
m_prevConfig( m_context.getConfig() )
|
||||
{
|
||||
m_context.setRunner( this );
|
||||
m_context.setConfig( &m_config );
|
||||
m_context.setConfig( m_config.get() );
|
||||
m_context.setResultCapture( this );
|
||||
m_reporter->testRunStarting( m_runInfo );
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace Catch {
|
||||
Totals deltaTotals = m_totals.delta( prevTotals );
|
||||
bool missingAssertions = false;
|
||||
if( deltaTotals.assertions.total() == 0 &&
|
||||
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) ) {
|
||||
( m_config->data().warnings & ConfigData::WarnAbout::NoAssertions ) ) {
|
||||
m_totals.assertions.failed++;
|
||||
deltaTotals = m_totals.delta( prevTotals );
|
||||
missingAssertions = true;
|
||||
@@ -149,7 +149,7 @@ namespace Catch {
|
||||
return deltaTotals;
|
||||
}
|
||||
|
||||
Config const& config() const {
|
||||
Ptr<Config> config() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace Catch {
|
||||
Counts assertions = m_totals.assertions - prevAssertions;
|
||||
bool missingAssertions = false;
|
||||
if( assertions.total() == 0 &&
|
||||
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
|
||||
( m_config->data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
|
||||
!m_runningTest->isBranchSection() ) {
|
||||
m_totals.assertions.failed++;
|
||||
assertions.failed++;
|
||||
@@ -231,7 +231,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
virtual bool shouldDebugBreak() const {
|
||||
return m_config.shouldDebugBreak();
|
||||
return m_config->shouldDebugBreak();
|
||||
}
|
||||
|
||||
virtual std::string getCurrentTestName() const {
|
||||
@@ -247,7 +247,7 @@ namespace Catch {
|
||||
public:
|
||||
// !TBD We need to do this another way!
|
||||
bool aborting() const {
|
||||
return m_totals.assertions.failed == static_cast<std::size_t>( m_config.getCutoff() );
|
||||
return m_totals.assertions.failed == static_cast<std::size_t>( m_config->getCutoff() );
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -315,13 +315,13 @@ namespace Catch {
|
||||
RunningTest* m_runningTest;
|
||||
AssertionResult m_lastResult;
|
||||
|
||||
Config const& m_config;
|
||||
Ptr<Config> m_config;
|
||||
Totals m_totals;
|
||||
Ptr<IStreamingReporter> m_reporter;
|
||||
std::vector<MessageInfo> m_messages;
|
||||
IRunner* m_prevRunner;
|
||||
IResultCapture* m_prevResultCapture;
|
||||
const IConfig* m_prevConfig;
|
||||
Ptr<IConfig> m_prevConfig;
|
||||
AssertionInfo m_lastAssertionInfo;
|
||||
std::vector<UnfinishedSections> m_unfinishedSections;
|
||||
};
|
||||
|
Reference in New Issue
Block a user