Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal
diff options
context:
space:
mode:
authorPhil Nash2015-08-07 08:20:56 +0100
committerPhil Nash2015-08-07 08:20:56 +0100
commit368714e7aa09656344c8ac229963eb79e63b81ff (patch)
tree2fc4fc52fcda12eb07f99996494ed23be720df95 /include/internal
parent4cb74761d990be2fa65266c3e1d659a481493735 (diff)
downloadcatch3-368714e7aa09656344c8ac229963eb79e63b81ff.tar.gz
Added Listeners (programatically provided extra reporters)
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/catch_interfaces_registry_hub.h5
-rw-r--r--include/internal/catch_interfaces_reporter.h7
-rw-r--r--include/internal/catch_registry_hub.hpp15
-rw-r--r--include/internal/catch_reporter_registrars.hpp26
-rw-r--r--include/internal/catch_reporter_registry.hpp17
-rw-r--r--include/internal/catch_suppress_warnings.h5
6 files changed, 54 insertions, 21 deletions
diff --git a/include/internal/catch_interfaces_registry_hub.h b/include/internal/catch_interfaces_registry_hub.h
index b657183b..2a420bf3 100644
--- a/include/internal/catch_interfaces_registry_hub.h
+++ b/include/internal/catch_interfaces_registry_hub.h
@@ -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;
};
diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index 5d846d2d..46720fbb 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -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 );
diff --git a/include/internal/catch_registry_hub.hpp b/include/internal/catch_registry_hub.hpp
index cd6a4e07..47c1bb42 100644
--- a/include/internal/catch_registry_hub.hpp
+++ b/include/internal/catch_registry_hub.hpp
@@ -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 );
}
diff --git a/include/internal/catch_reporter_registrars.hpp b/include/internal/catch_reporter_registrars.hpp
index 51465556..0aed0823 100644
--- a/include/internal/catch_reporter_registrars.hpp
+++ b/include/internal/catch_reporter_registrars.hpp
@@ -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
diff --git a/include/internal/catch_reporter_registry.hpp b/include/internal/catch_reporter_registry.hpp
index 3e2ae4c9..b0ac2fba 100644
--- a/include/internal/catch_reporter_registry.hpp
+++ b/include/internal/catch_reporter_registry.hpp
@@ -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;
};
}
diff --git a/include/internal/catch_suppress_warnings.h b/include/internal/catch_suppress_warnings.h
index e459dfcc..094ed98b 100644
--- a/include/internal/catch_suppress_warnings.h
+++ b/include/internal/catch_suppress_warnings.h
@@ -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