mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Added Listeners (programatically provided extra reporters)
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
||||
|
||||
#include <catch_ptr.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch {
|
||||
@@ -29,7 +31,8 @@ namespace Catch {
|
||||
|
||||
struct IMutableRegistryHub {
|
||||
virtual ~IMutableRegistryHub();
|
||||
virtual void registerReporter( std::string const& name, IReporterFactory* factory ) = 0;
|
||||
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
|
||||
virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
|
||||
virtual void registerTest( TestCase const& testInfo ) = 0;
|
||||
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
||||
};
|
||||
|
@@ -240,6 +240,7 @@ namespace Catch
|
||||
|
||||
// The return value indicates if the messages buffer should be cleared:
|
||||
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
|
||||
|
||||
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
||||
@@ -249,18 +250,20 @@ namespace Catch
|
||||
};
|
||||
|
||||
|
||||
struct IReporterFactory {
|
||||
struct IReporterFactory : IShared {
|
||||
virtual ~IReporterFactory();
|
||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
|
||||
virtual std::string getDescription() const = 0;
|
||||
};
|
||||
|
||||
struct IReporterRegistry {
|
||||
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
||||
typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
|
||||
typedef std::vector<Ptr<IReporterFactory> > Listeners;
|
||||
|
||||
virtual ~IReporterRegistry();
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const = 0;
|
||||
virtual FactoryMap const& getFactories() const = 0;
|
||||
virtual Listeners const& getListeners() const = 0;
|
||||
};
|
||||
|
||||
Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
|
||||
|
@@ -26,24 +26,27 @@ namespace Catch {
|
||||
public: // IRegistryHub
|
||||
RegistryHub() {
|
||||
}
|
||||
virtual IReporterRegistry const& getReporterRegistry() const {
|
||||
virtual IReporterRegistry const& getReporterRegistry() const override {
|
||||
return m_reporterRegistry;
|
||||
}
|
||||
virtual ITestCaseRegistry const& getTestCaseRegistry() const {
|
||||
virtual ITestCaseRegistry const& getTestCaseRegistry() const override {
|
||||
return m_testCaseRegistry;
|
||||
}
|
||||
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() {
|
||||
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override {
|
||||
return m_exceptionTranslatorRegistry;
|
||||
}
|
||||
|
||||
public: // IMutableRegistryHub
|
||||
virtual void registerReporter( std::string const& name, IReporterFactory* factory ) {
|
||||
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) override {
|
||||
m_reporterRegistry.registerReporter( name, factory );
|
||||
}
|
||||
virtual void registerTest( TestCase const& testInfo ) {
|
||||
virtual void registerListener( Ptr<IReporterFactory> const& factory ) override {
|
||||
m_reporterRegistry.registerListener( factory );
|
||||
}
|
||||
virtual void registerTest( TestCase const& testInfo ) override {
|
||||
m_testCaseRegistry.registerTest( testInfo );
|
||||
}
|
||||
virtual void registerTranslator( const IExceptionTranslator* translator ) {
|
||||
virtual void registerTranslator( const IExceptionTranslator* translator ) override {
|
||||
m_exceptionTranslatorRegistry.registerTranslator( translator );
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ namespace Catch {
|
||||
template<typename T>
|
||||
class ReporterRegistrar {
|
||||
|
||||
class ReporterFactory : public IReporterFactory {
|
||||
class ReporterFactory : public SharedImpl<IReporterFactory> {
|
||||
|
||||
// *** Please Note ***:
|
||||
// - If you end up here looking at a compiler error because it's trying to register
|
||||
@@ -64,11 +64,35 @@ namespace Catch {
|
||||
getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ListenerRegistrar {
|
||||
|
||||
class ListenerFactory : public SharedImpl<IReporterFactory> {
|
||||
|
||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
|
||||
return new T( config );
|
||||
}
|
||||
virtual std::string getDescription() const {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
ListenerRegistrar() {
|
||||
getMutableRegistryHub().registerListener( new ListenerFactory() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
|
||||
namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
|
||||
|
||||
#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
|
||||
namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
|
||||
|
||||
#define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
|
||||
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
|
||||
|
@@ -18,27 +18,32 @@ namespace Catch {
|
||||
|
||||
public:
|
||||
|
||||
virtual ~ReporterRegistry() {
|
||||
deleteAllValues( m_factories );
|
||||
}
|
||||
virtual ~ReporterRegistry() override {}
|
||||
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const {
|
||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const override {
|
||||
FactoryMap::const_iterator it = m_factories.find( name );
|
||||
if( it == m_factories.end() )
|
||||
return CATCH_NULL;
|
||||
return it->second->create( ReporterConfig( config ) );
|
||||
}
|
||||
|
||||
void registerReporter( std::string const& name, IReporterFactory* factory ) {
|
||||
void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
|
||||
m_factories.insert( std::make_pair( name, factory ) );
|
||||
}
|
||||
void registerListener( Ptr<IReporterFactory> const& factory ) {
|
||||
m_listeners.push_back( factory );
|
||||
}
|
||||
|
||||
FactoryMap const& getFactories() const {
|
||||
virtual FactoryMap const& getFactories() const override {
|
||||
return m_factories;
|
||||
}
|
||||
virtual Listeners const& getListeners() const override {
|
||||
return m_listeners;
|
||||
}
|
||||
|
||||
private:
|
||||
FactoryMap m_factories;
|
||||
Listeners m_listeners;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -5,9 +5,6 @@
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#ifndef TWOBLUECUBES_CATCH_SUPPRESS_WARNINGS_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_SUPPRESS_WARNINGS_H_INCLUDED
|
||||
|
||||
#ifdef __clang__
|
||||
# ifdef __ICC // icpc defines the __clang__ macro
|
||||
# pragma warning(push)
|
||||
@@ -29,5 +26,3 @@
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wpadded"
|
||||
#endif
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_SUPPRESS_WARNINGS_H_INCLUDED
|
||||
|
Reference in New Issue
Block a user