mirror of https://github.com/catchorg/Catch2.git
ReporterRegistry now fully aggregated by Hub
This commit is contained in:
parent
e846e0744d
commit
764229ac4e
|
@ -22,12 +22,17 @@ namespace Catch
|
||||||
|
|
||||||
class Hub
|
class Hub
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
Hub();
|
Hub();
|
||||||
|
static Hub& me()
|
||||||
|
{
|
||||||
|
static Hub hub;
|
||||||
|
return hub;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
|
||||||
static IResultListener* getListener();
|
static IResultListener& getListener();
|
||||||
static IReporterRegistry* getReporterRegistry();
|
static IReporterRegistry& getReporterRegistry();
|
||||||
static ITestCaseRegistry* getTestCaseRegistry();
|
static ITestCaseRegistry& getTestCaseRegistry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::auto_ptr<IReporterRegistry> m_reporterRegistry;
|
std::auto_ptr<IReporterRegistry> m_reporterRegistry;
|
||||||
|
@ -44,6 +49,11 @@ namespace Catch
|
||||||
: m_reporterRegistry( new ReporterRegistry )
|
: m_reporterRegistry( new ReporterRegistry )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline IReporterRegistry& Hub::getReporterRegistry()
|
||||||
|
{
|
||||||
|
return *me().m_reporterRegistry.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_HUB_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_HUB_HPP_INCLUDED
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
|
@ -100,6 +101,8 @@ namespace Catch
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
struct IReporterRegistry
|
struct IReporterRegistry
|
||||||
{
|
{
|
||||||
|
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
||||||
|
|
||||||
virtual ~IReporterRegistry
|
virtual ~IReporterRegistry
|
||||||
(){}
|
(){}
|
||||||
|
|
||||||
|
@ -112,6 +115,10 @@ namespace Catch
|
||||||
( const std::string& name,
|
( const std::string& name,
|
||||||
IReporterFactory* factory
|
IReporterFactory* factory
|
||||||
) = 0;
|
) = 0;
|
||||||
|
|
||||||
|
virtual const FactoryMap& getFactories
|
||||||
|
() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -23,8 +23,8 @@ namespace Catch
|
||||||
if( config.listWhat() & RunnerConfig::listReports )
|
if( config.listWhat() & RunnerConfig::listReports )
|
||||||
{
|
{
|
||||||
std::cout << "Available reports:\n";
|
std::cout << "Available reports:\n";
|
||||||
ReporterRegistry::FactoryMap::const_iterator it = ReporterRegistry::instance().getFactories().begin();
|
ReporterRegistry::FactoryMap::const_iterator it = Hub::getReporterRegistry().getFactories().begin();
|
||||||
ReporterRegistry::FactoryMap::const_iterator itEnd = ReporterRegistry::instance().getFactories().end();
|
ReporterRegistry::FactoryMap::const_iterator itEnd = Hub::getReporterRegistry().getFactories().end();
|
||||||
for(; it != itEnd; ++it )
|
for(; it != itEnd; ++it )
|
||||||
{
|
{
|
||||||
// !TBD: consider listAs()
|
// !TBD: consider listAs()
|
||||||
|
|
|
@ -23,12 +23,6 @@ namespace Catch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static ReporterRegistry& instance()
|
|
||||||
{
|
|
||||||
static ReporterRegistry instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ReporterRegistry()
|
~ReporterRegistry()
|
||||||
{
|
{
|
||||||
FactoryMap::const_iterator it = m_factories.begin();
|
FactoryMap::const_iterator it = m_factories.begin();
|
||||||
|
@ -52,8 +46,6 @@ namespace Catch
|
||||||
m_factories.insert( std::make_pair( name, factory ) );
|
m_factories.insert( std::make_pair( name, factory ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
|
||||||
|
|
||||||
const FactoryMap& getFactories() const
|
const FactoryMap& getFactories() const
|
||||||
{
|
{
|
||||||
return m_factories;
|
return m_factories;
|
||||||
|
@ -81,7 +73,7 @@ namespace Catch
|
||||||
{
|
{
|
||||||
ReporterRegistrar( const std::string& name )
|
ReporterRegistrar( const std::string& name )
|
||||||
{
|
{
|
||||||
ReporterRegistry::instance().registerReporter( name, new ReporterFactory<T>() );
|
Hub::getReporterRegistry().registerReporter( name, new ReporterFactory<T>() );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ namespace Catch
|
||||||
{
|
{
|
||||||
if( m_reporter.get() )
|
if( m_reporter.get() )
|
||||||
return setError( "Only one reporter may be specified" );
|
return setError( "Only one reporter may be specified" );
|
||||||
setReporter( ReporterRegistry::instance().create( reporterName, m_reporterConfig ) );
|
setReporter( Hub::getReporterRegistry().create( reporterName, m_reporterConfig ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTestSpec( const std::string& testSpec )
|
void addTestSpec( const std::string& testSpec )
|
||||||
|
@ -141,7 +141,7 @@ namespace Catch
|
||||||
IReporter* getReporter()
|
IReporter* getReporter()
|
||||||
{
|
{
|
||||||
if( !m_reporter.get() )
|
if( !m_reporter.get() )
|
||||||
setReporter( ReporterRegistry::instance().create( "basic", m_reporterConfig ) );
|
setReporter( Hub::getReporterRegistry().create( "basic", m_reporterConfig ) );
|
||||||
return m_reporter.get();
|
return m_reporter.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue