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

Previous implementation didn't work

It relied on calling a virtual method from a base constructer
Commit
058b21e604dd3486fe4f7957e4a4485104943905
Author
Baruch Burstein ·
Parents
f7493475230a

Files · Download .tar.gz

Changes

 include/internal/catch_impl.hpp               | 10 ++++++----
 include/internal/catch_interfaces_reporter.h  |  5 ++---
 include/reporters/catch_reporter_automake.hpp |  2 +-
 include/reporters/catch_reporter_bases.hpp    | 21 ++++++++++-----------
 include/reporters/catch_reporter_compact.hpp  |  2 +-
 include/reporters/catch_reporter_console.hpp  |  2 +-
 include/reporters/catch_reporter_junit.hpp    |  2 +-
 include/reporters/catch_reporter_multi.hpp    | 18 ++----------------
 include/reporters/catch_reporter_tap.hpp      |  2 +-
 include/reporters/catch_reporter_teamcity.hpp |  2 +-
 include/reporters/catch_reporter_xml.hpp      |  2 +-
 11 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp
index 2306af7f..242d9f82 100644
--- a/include/internal/catch_impl.hpp
+++ b/include/internal/catch_impl.hpp
@@ -77,10 +77,12 @@ namespace Catch {
     TestCaseStats::~TestCaseStats() {}
     TestGroupStats::~TestGroupStats() {}
     TestRunStats::~TestRunStats() {}
-    CumulativeReporterBase::SectionNode::~SectionNode() {}
-    CumulativeReporterBase::~CumulativeReporterBase() {}
-
-    StreamingReporterBase::~StreamingReporterBase() {}
+    template<typename DerivedT>
+    CumulativeReporterBase<DerivedT>::SectionNode::~SectionNode() {}
+    template<typename DerivedT>
+    CumulativeReporterBase<DerivedT>::~CumulativeReporterBase() {}
+    template<typename DerivedT>
+    StreamingReporterBase<DerivedT>::~StreamingReporterBase() {}
     ConsoleReporter::~ConsoleReporter() {}
     CompactReporter::~CompactReporter() {}
     IRunner::~IRunner() {}
diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index ea68aa54..5eae83cc 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -208,13 +208,12 @@ namespace Catch
     struct IStreamingReporter {
         virtual ~IStreamingReporter();
 
-        // Implementing class must also provide the following static method:
+        // Implementing class must also provide the following static methods:
         // static std::string getDescription();
+        // static std::set<Verbosity> getSupportedVerbosities()
 
         virtual ReporterPreferences getPreferences() const = 0;
 
-        virtual std::set<Verbosity> const& getSupportedVerbosities() const = 0;
-
         virtual void noMatchingTestCases( std::string const& spec ) = 0;
 
         virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
diff --git a/include/reporters/catch_reporter_automake.hpp b/include/reporters/catch_reporter_automake.hpp
index 00478e1f..7a841a1a 100644
--- a/include/reporters/catch_reporter_automake.hpp
+++ b/include/reporters/catch_reporter_automake.hpp
@@ -16,7 +16,7 @@
 
 namespace Catch {
 
-    struct AutomakeReporter : StreamingReporterBase {
+    struct AutomakeReporter : StreamingReporterBase<AutomakeReporter> {
         AutomakeReporter( ReporterConfig const& _config )
           :   StreamingReporterBase( _config )
         {}
diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp
index f6a8d28e..9089b616 100644
--- a/include/reporters/catch_reporter_bases.hpp
+++ b/include/reporters/catch_reporter_bases.hpp
@@ -41,7 +41,7 @@ namespace Catch {
         }
     }
 
-
+    template<typename DerivedT>
     struct StreamingReporterBase : IStreamingReporter {
 
         StreamingReporterBase( ReporterConfig const& _config )
@@ -49,16 +49,15 @@ namespace Catch {
             stream( _config.stream() )
         {
             m_reporterPrefs.shouldRedirectStdOut = false;
-            CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
+            CATCH_ENFORCE( DerivedT::getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
         }
 
         virtual ReporterPreferences getPreferences() const override {
             return m_reporterPrefs;
         }
 
-        virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
-            static std::set<Verbosity> supported{ Verbosity::Normal };
-            return supported;
+        static std::set<Verbosity> getSupportedVerbosities() {
+            return { Verbosity::Normal };
         }
 
         virtual ~StreamingReporterBase() override;
@@ -110,6 +109,7 @@ namespace Catch {
         ReporterPreferences m_reporterPrefs;
     };
 
+    template<typename DerivedT>
     struct CumulativeReporterBase : IStreamingReporter {
         template<typename T, typename ChildNodeT>
         struct Node {
@@ -161,7 +161,7 @@ namespace Catch {
             stream( _config.stream() )
         {
             m_reporterPrefs.shouldRedirectStdOut = false;
-            CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
+            CATCH_ENFORCE( DerivedT::getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
         }
         ~CumulativeReporterBase();
 
@@ -169,9 +169,8 @@ namespace Catch {
             return m_reporterPrefs;
         }
 
-        virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
-            static std::set<Verbosity> supported{ Verbosity::Normal };
-            return supported;
+        static std::set<Verbosity> getSupportedVerbosities() {
+            return { Verbosity::Normal };
         }
 
         virtual void testRunStarting( TestRunInfo const& ) override {}
@@ -189,7 +188,7 @@ namespace Catch {
             }
             else {
                 SectionNode& parentNode = *m_sectionStack.back();
-                SectionNode::ChildSections::const_iterator it =
+                typename SectionNode::ChildSections::const_iterator it =
                     std::find_if(   parentNode.childSections.begin(),
                                     parentNode.childSections.end(),
                                     BySectionInfo( sectionInfo ) );
@@ -284,7 +283,7 @@ namespace Catch {
     }
 
 
-    struct TestEventListenerBase : StreamingReporterBase {
+    struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> {
         TestEventListenerBase( ReporterConfig const& _config )
         :   StreamingReporterBase( _config )
         {}
diff --git a/include/reporters/catch_reporter_compact.hpp b/include/reporters/catch_reporter_compact.hpp
index 1579a608..ff461f14 100644
--- a/include/reporters/catch_reporter_compact.hpp
+++ b/include/reporters/catch_reporter_compact.hpp
@@ -15,7 +15,7 @@
 
 namespace Catch {
 
-    struct CompactReporter : StreamingReporterBase {
+    struct CompactReporter : StreamingReporterBase<CompactReporter> {
 
         using StreamingReporterBase::StreamingReporterBase;
 
diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index bbe38a87..3c2130f8 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -19,7 +19,7 @@
 namespace Catch {
 
 
-    struct ConsoleReporter : StreamingReporterBase {
+    struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
         using StreamingReporterBase::StreamingReporterBase;
 
         virtual ~ConsoleReporter() override;
diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp
index cebdf3c7..08652565 100644
--- a/include/reporters/catch_reporter_junit.hpp
+++ b/include/reporters/catch_reporter_junit.hpp
@@ -47,7 +47,7 @@ namespace Catch {
 
     }
 
-    class JunitReporter : public CumulativeReporterBase {
+    class JunitReporter : public CumulativeReporterBase<JunitReporter> {
     public:
         JunitReporter( ReporterConfig const& _config )
         :   CumulativeReporterBase( _config ),
diff --git a/include/reporters/catch_reporter_multi.hpp b/include/reporters/catch_reporter_multi.hpp
index 57f0974c..36d56584 100644
--- a/include/reporters/catch_reporter_multi.hpp
+++ b/include/reporters/catch_reporter_multi.hpp
@@ -15,23 +15,9 @@ namespace Catch {
 class MultipleReporters : public IStreamingReporter {
     typedef std::vector<IStreamingReporterPtr> Reporters;
     Reporters m_reporters;
-    std::set<Verbosity> m_verbosities;
 
 public:
     void add( IStreamingReporterPtr&& reporter ) {
-        if( m_reporters.empty() ) {
-            m_verbosities = reporter->getSupportedVerbosities();
-        }
-        else {
-            for( auto it = m_verbosities.cbegin(); it != m_verbosities.cend(); ) {
-                if( reporter->getSupportedVerbosities().count( *it ) == 0 ) {
-                    it = m_verbosities.erase(it);
-                }
-                else {
-                    ++it;
-                }
-            }
-        }
         m_reporters.push_back( std::move( reporter ) );
     }
 
@@ -41,8 +27,8 @@ public: // IStreamingReporter
         return m_reporters[0]->getPreferences();
     }
 
-    virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
-        return m_verbosities;
+    static std::set<Verbosity> getSupportedVerbosities() {
+        return { };
     }
 
     virtual void noMatchingTestCases( std::string const& spec ) override {
diff --git a/include/reporters/catch_reporter_tap.hpp b/include/reporters/catch_reporter_tap.hpp
index b34acac3..40106649 100644
--- a/include/reporters/catch_reporter_tap.hpp
+++ b/include/reporters/catch_reporter_tap.hpp
@@ -19,7 +19,7 @@
 
 namespace Catch {
 
-    struct TAPReporter : StreamingReporterBase {
+    struct TAPReporter : StreamingReporterBase<TAPReporter> {
 
         using StreamingReporterBase::StreamingReporterBase;
 
diff --git a/include/reporters/catch_reporter_teamcity.hpp b/include/reporters/catch_reporter_teamcity.hpp
index 623ae6a3..33548987 100644
--- a/include/reporters/catch_reporter_teamcity.hpp
+++ b/include/reporters/catch_reporter_teamcity.hpp
@@ -23,7 +23,7 @@
 
 namespace Catch {
 
-    struct TeamCityReporter : StreamingReporterBase {
+    struct TeamCityReporter : StreamingReporterBase<TeamCityReporter> {
         TeamCityReporter( ReporterConfig const& _config )
         :   StreamingReporterBase( _config )
         {
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp
index b99ec11f..d685e979 100644
--- a/include/reporters/catch_reporter_xml.hpp
+++ b/include/reporters/catch_reporter_xml.hpp
@@ -16,7 +16,7 @@
 #include "../internal/catch_timer.h"
 
 namespace Catch {
-    class XmlReporter : public StreamingReporterBase {
+    class XmlReporter : public StreamingReporterBase<XmlReporter> {
     public:
         XmlReporter( ReporterConfig const& _config )
         :   StreamingReporterBase( _config ),