Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

ReporterRegistry now fully aggregated by Hub

Commit
764229ac4e854c688f91d751be4559f772a8aa05
Author
Phil Nash ·
Parents
e846e0744d99

Files · Download .tar.gz

Changes

 internal/catch_hub.hpp               | 18 ++++++++++++++----
 internal/catch_ireporterregistry.h   |  9 ++++++++-
 internal/catch_list.hpp              |  4 ++--
 internal/catch_reporter_registry.hpp | 12 ++----------
 internal/catch_runnerconfig.hpp      |  4 ++--
 5 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/internal/catch_hub.hpp b/internal/catch_hub.hpp
index dc708f24..8119e904 100644
--- a/internal/catch_hub.hpp
+++ b/internal/catch_hub.hpp
@@ -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
\ No newline at end of file
diff --git a/internal/catch_ireporterregistry.h b/internal/catch_ireporterregistry.h
index eade407a..e4f303a5 100644
--- a/internal/catch_ireporterregistry.h
+++ b/internal/catch_ireporterregistry.h
@@ -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
             (){}
 
@@ -111,7 +114,11 @@ namespace Catch
         virtual void registerReporter
             (   const std::string& name, 
                 IReporterFactory* factory 
-            ) = 0;        
+            ) = 0;
+        
+        virtual const FactoryMap& getFactories
+            () const = 0;
+
     };
     
     ///////////////////////////////////////////////////////////////////////////
diff --git a/internal/catch_list.hpp b/internal/catch_list.hpp
index 476f45fe..4b07cf9f 100644
--- a/internal/catch_list.hpp
+++ b/internal/catch_list.hpp
@@ -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()
diff --git a/internal/catch_reporter_registry.hpp b/internal/catch_reporter_registry.hpp
index 07e1cc77..5b193550 100644
--- a/internal/catch_reporter_registry.hpp
+++ b/internal/catch_reporter_registry.hpp
@@ -23,12 +23,6 @@ namespace Catch
     {
     public:
         
-        static ReporterRegistry& instance()
-        {
-            static ReporterRegistry instance;
-            return instance;
-        }
-        
         ~ReporterRegistry()
         {
             FactoryMap::const_iterator it =  m_factories.begin();
@@ -50,9 +44,7 @@ namespace Catch
         void registerReporter( const std::string& name, IReporterFactory* factory )
         {
             m_factories.insert( std::make_pair( name, factory ) );
-        }
-        
-        typedef std::map<std::string, IReporterFactory*> FactoryMap;
+        }        
 
         const FactoryMap& getFactories() const
         {
@@ -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>() );
         }
     }; 
 }
diff --git a/internal/catch_runnerconfig.hpp b/internal/catch_runnerconfig.hpp
index 6e11a451..cce92901 100644
--- a/internal/catch_runnerconfig.hpp
+++ b/internal/catch_runnerconfig.hpp
@@ -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();
         }