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

Split EventListener base from streaming_base.hpp

The base was also renamed from `TestEventListenerBase` to
`EventListenerBase`, and modified to derive directly from the
reporter interface, rather than deriving from `StreamingReporterBase`.
Commit
33ad1ee2ac7beaae8d6bfa661213d13cecbce196
Author
Martin Hořeňovský ·
Parents
f9fdc96cbfbd

Files · Download .tar.gz

Changes

 docs/release-notes.md                              |  3 ++
 examples/210-Evt-EventListeners.cpp                |  6 +--
 src/CMakeLists.txt                                 |  1 +
 .../reporters/catch_reporter_combined_tu.cpp       | 29 +++++++++++++
 .../reporters/catch_reporter_event_listener.hpp    | 47 ++++++++++++++++++++++
 .../reporters/catch_reporter_streaming_base.cpp    | 10 -----
 .../reporters/catch_reporter_streaming_base.hpp    | 12 ------
 src/catch2/reporters/catch_reporters_all.hpp       |  1 +
 tests/SelfTest/TestRegistrations.cpp               |  6 +--
 9 files changed, 87 insertions(+), 28 deletions(-)

diff --git a/docs/release-notes.md b/docs/release-notes.md
index 7488012f..1c2b5ac9 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -114,6 +114,9 @@ new design.
   * You should instead include the appropriate headers as needed.
 * `CATCH_CONFIG_IMPL` has been removed.
   * The implementation is now compiled into a static library.
+* Event Listener interface has changed
+  * `TestEventListenerBase` was renamed to `EventListenerBase`
+  * `EventListenerBase` now directly derives from `IStreamingReporter`, instead of deriving from `StreamingReporterBase`
 
 
 
diff --git a/examples/210-Evt-EventListeners.cpp b/examples/210-Evt-EventListeners.cpp
index 89c828d5..7a025375 100644
--- a/examples/210-Evt-EventListeners.cpp
+++ b/examples/210-Evt-EventListeners.cpp
@@ -6,7 +6,7 @@
 // 3. Test cases
 
 #include <catch2/catch_test_macros.hpp>
-#include <catch2/reporters/catch_reporter_streaming_base.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
 #include <catch2/catch_reporter_registrars.hpp>
 #include <catch2/catch_test_case_info.hpp>
 #include <iostream>
@@ -303,9 +303,9 @@ char const * dashed_line =
     "--------------------------------------------------------------------------";
 
 
-struct MyListener : Catch::TestEventListenerBase {
+struct MyListener : Catch::EventListenerBase {
 
-    using TestEventListenerBase::TestEventListenerBase; // inherit constructor
+    using EventListenerBase::EventListenerBase; // inherit constructor
 
     // Get rid of Wweak-tables
     ~MyListener();
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a56d2989..4e4eab51 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -198,6 +198,7 @@ set(REPORTER_HEADERS
     ${SOURCES_DIR}/reporters/catch_reporter_compact.hpp
     ${SOURCES_DIR}/reporters/catch_reporter_console.hpp
     ${SOURCES_DIR}/reporters/catch_reporter_cumulative_base.hpp
+    ${SOURCES_DIR}/reporters/catch_reporter_event_listener.hpp
     ${SOURCES_DIR}/reporters/catch_reporter_helpers.hpp
     ${SOURCES_DIR}/reporters/catch_reporter_junit.hpp
     ${SOURCES_DIR}/reporters/catch_reporter_listening.hpp
diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp
index b0e1f10f..b0f8f7a0 100644
--- a/src/catch2/reporters/catch_reporter_combined_tu.cpp
+++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp
@@ -81,4 +81,33 @@ namespace Catch {
         }
         return out;
     }
+
+} // namespace Catch
+
+
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
+
+namespace Catch {
+    void EventListenerBase::assertionStarting( AssertionInfo const& ) {}
+
+    bool EventListenerBase::assertionEnded( AssertionStats const& ) {
+        return false;
+    }
+    void
+    EventListenerBase::listReporters( std::vector<ReporterDescription> const&,
+                                      IConfig const& ) {}
+    void EventListenerBase::listTests( std::vector<TestCaseHandle> const&,
+                                       IConfig const& ) {}
+    void EventListenerBase::listTags( std::vector<TagInfo> const&,
+                                      IConfig const& ) {}
+    void EventListenerBase::noMatchingTestCases( std::string const& ) {}
+    void EventListenerBase::testRunStarting( TestRunInfo const& ) {}
+    void EventListenerBase::testGroupStarting( GroupInfo const& ) {}
+    void EventListenerBase::testCaseStarting( TestCaseInfo const& ) {}
+    void EventListenerBase::sectionStarting( SectionInfo const& ) {}
+    void EventListenerBase::sectionEnded( SectionStats const& ) {}
+    void EventListenerBase::testCaseEnded( TestCaseStats const& ) {}
+    void EventListenerBase::testGroupEnded( TestGroupStats const& ) {}
+    void EventListenerBase::testRunEnded( TestRunStats const& ) {}
+    void EventListenerBase::skipTest( TestCaseInfo const& ) {}
 } // namespace Catch
diff --git a/src/catch2/reporters/catch_reporter_event_listener.hpp b/src/catch2/reporters/catch_reporter_event_listener.hpp
new file mode 100644
index 00000000..358b9954
--- /dev/null
+++ b/src/catch2/reporters/catch_reporter_event_listener.hpp
@@ -0,0 +1,47 @@
+#ifndef CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
+#define CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
+
+#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+
+namespace Catch {
+
+    /**
+     * Base class identifying listeners.
+     *
+     * Provides default implementation for all IStreamingReporter member
+     * functions, so that listeners implementations can pick which
+     * member functions it actually cares about.
+     */
+    class EventListenerBase : public IStreamingReporter {
+        IConfig const* m_config;
+
+    public:
+        EventListenerBase( ReporterConfig const& config ):
+            m_config( config.fullConfig() ) {}
+
+        void assertionStarting( AssertionInfo const& assertionInfo ) override;
+        bool assertionEnded( AssertionStats const& assertionStats ) override;
+
+        void
+        listReporters( std::vector<ReporterDescription> const& descriptions,
+                       IConfig const& config ) override;
+        void listTests( std::vector<TestCaseHandle> const& tests,
+                        IConfig const& config ) override;
+        void listTags( std::vector<TagInfo> const& tagInfos,
+                       IConfig const& config ) override;
+
+        void noMatchingTestCases( std::string const& spec ) override;
+        void testRunStarting( TestRunInfo const& testRunInfo ) override;
+        void testGroupStarting( GroupInfo const& groupInfo ) override;
+        void testCaseStarting( TestCaseInfo const& testInfo ) override;
+        void sectionStarting( SectionInfo const& sectionInfo ) override;
+        void sectionEnded( SectionStats const& sectionStats ) override;
+        void testCaseEnded( TestCaseStats const& testCaseStats ) override;
+        void testGroupEnded( TestGroupStats const& testGroupStats ) override;
+        void testRunEnded( TestRunStats const& testRunStats ) override;
+        void skipTest( TestCaseInfo const& testInfo ) override;
+    };
+
+} // end namespace Catch
+
+#endif // CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.cpp b/src/catch2/reporters/catch_reporter_streaming_base.cpp
index 73c63746..b37820ec 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.cpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.cpp
@@ -2,16 +2,6 @@
 
 namespace Catch {
 
-    TestEventListenerBase::TestEventListenerBase(
-        ReporterConfig const& _config ):
-        StreamingReporterBase( _config ) {}
-
-    void TestEventListenerBase::assertionStarting( AssertionInfo const& ) {}
-
-    bool TestEventListenerBase::assertionEnded( AssertionStats const& ) {
-        return false;
-    }
-
     StreamingReporterBase::~StreamingReporterBase() = default;
 
     void
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.hpp b/src/catch2/reporters/catch_reporter_streaming_base.hpp
index c31290cc..36e77aa6 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.hpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp
@@ -74,18 +74,6 @@ namespace Catch {
         std::vector<SectionInfo> m_sectionStack;
     };
 
-    struct TestEventListenerBase : StreamingReporterBase {
-        TestEventListenerBase( ReporterConfig const& _config );
-
-        void assertionStarting(AssertionInfo const&) override;
-        bool assertionEnded(AssertionStats const&) override;
-
-        // Event listeners should not use the default listing impl
-        void listReporters(std::vector<ReporterDescription> const&, IConfig const&) override {}
-        void listTests(std::vector<TestCaseHandle> const&, IConfig const&) override {}
-        void listTags(std::vector<TagInfo> const&, IConfig const&) override {}
-    };
-
 } // end namespace Catch
 
 #endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
diff --git a/src/catch2/reporters/catch_reporters_all.hpp b/src/catch2/reporters/catch_reporters_all.hpp
index 5531427b..6181697f 100644
--- a/src/catch2/reporters/catch_reporters_all.hpp
+++ b/src/catch2/reporters/catch_reporters_all.hpp
@@ -18,6 +18,7 @@
 #include <catch2/reporters/catch_reporter_compact.hpp>
 #include <catch2/reporters/catch_reporter_console.hpp>
 #include <catch2/reporters/catch_reporter_cumulative_base.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
 #include <catch2/reporters/catch_reporter_helpers.hpp>
 #include <catch2/reporters/catch_reporter_junit.hpp>
 #include <catch2/reporters/catch_reporter_listening.hpp>
diff --git a/tests/SelfTest/TestRegistrations.cpp b/tests/SelfTest/TestRegistrations.cpp
index ee5d0a15..cb8376bd 100644
--- a/tests/SelfTest/TestRegistrations.cpp
+++ b/tests/SelfTest/TestRegistrations.cpp
@@ -4,6 +4,7 @@
  */
 
 #include <catch2/catch_tag_alias_autoregistrar.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
 
 // Some example tag aliases
 CATCH_REGISTER_TAG_ALIAS( "[@nhf]", "[failing]~[.]" )
@@ -15,10 +16,9 @@ CATCH_REGISTER_TAG_ALIAS( "[@tricky]", "[tricky]~[.]" )
 #   pragma clang diagnostic ignored "-Wc++98-compat"
 #endif
 
-#include <catch2/reporters/catch_reporter_streaming_base.hpp>
 
-struct TestListener : Catch::TestEventListenerBase {
-    using TestEventListenerBase::TestEventListenerBase;
+struct TestListener : Catch::EventListenerBase {
+    using EventListenerBase::EventListenerBase;
 };
 
 #include <catch2/catch_reporter_registrars.hpp>