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