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

Add integration test for listener-reporter event ordering

Commit
e53a75b425374b99fdcd53f6242f0e14cbb82140
Author
Martin Hořeňovský ·
Parents
4ff8b27bb6be

Files · Download .tar.gz

Changes

 tests/ExtraTests/CMakeLists.txt                    | 13 +++
 .../X28-ListenersGetEventsBeforeReporters.cpp      | 97 ++++++++++++++++++++++
 2 files changed, 110 insertions(+)

diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index 1ac08445..8e6b3094 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -326,6 +326,18 @@ set_tests_properties(
     FAIL_REGULAR_EXPRESSION "X26 - assertionEnded"
 )
 
+add_executable(ListenersGetEventsBeforeReporters ${TESTS_DIR}/X28-ListenersGetEventsBeforeReporters.cpp)
+target_link_libraries(ListenersGetEventsBeforeReporters PRIVATE Catch2::Catch2WithMain)
+add_test(
+  NAME ListenersGetEventsBeforeReporters
+  COMMAND ListenersGetEventsBeforeReporters --reporter test-reporter
+)
+set_tests_properties(
+    ListenersGetEventsBeforeReporters
+  PROPERTIES
+    PASS_REGULAR_EXPRESSION "X28 - TestReporter constructed"
+    FAIL_REGULAR_EXPRESSION "X28 - ERROR"
+)
 
 add_executable(DuplicatedTestCases-SameNameAndTags ${TESTS_DIR}/X31-DuplicatedTestCases.cpp)
 target_link_libraries(DuplicatedTestCases-SameNameAndTags PRIVATE Catch2::Catch2WithMain)
@@ -412,6 +424,7 @@ set( EXTRA_TEST_BINARIES
     DuplicatedTestCases-SameNameDifferentTags
     DuplicatedTestCases-DuplicatedTestCaseMethods
     NoTests
+    ListenersGetEventsBeforeReporters
 #    DebugBreakMacros
 )
 
diff --git a/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp b/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp
new file mode 100644
index 00000000..37d14928
--- /dev/null
+++ b/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp
@@ -0,0 +1,97 @@
+
+//              Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+//   (See accompanying file LICENSE_1_0.txt or copy at
+//        https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+/**\file
+ * Test that the different events are sent to listeners before they are
+ * sent to the reporters.
+ *
+ * We only do this for a subset of the events, as doing all of them would
+ * be annoying, and we can assume that their implementation is roughly
+ * the same, and thus if few work, all work.
+ */
+
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
+#include <catch2/reporters/catch_reporter_registrars.hpp>
+#include <catch2/reporters/catch_reporter_streaming_base.hpp>
+#include <iostream>
+
+namespace {
+
+    static bool testRunStartingReceivedByListener = false;
+    static bool testRunEndedReceivedByListener = false;
+    static bool assertionStartingReceivedByListener = false;
+    static bool assertionEndedReceivedByListener = false;
+
+    class TestListener : public Catch::EventListenerBase {
+    public:
+        TestListener( Catch::ReporterConfig const& config ):
+            EventListenerBase( config ) {
+            std::cout << "X28 - TestListener constructed.\n";
+        }
+
+        void testRunStarting( Catch::TestRunInfo const& ) override {
+            testRunStartingReceivedByListener = true;
+        }
+
+        void testRunEnded( Catch::TestRunStats const& ) override {
+            testRunEndedReceivedByListener = true;
+        }
+
+        void assertionStarting( Catch::AssertionInfo const& ) override {
+            assertionStartingReceivedByListener = true;
+        }
+
+        void assertionEnded( Catch::AssertionStats const& ) override {
+            assertionEndedReceivedByListener = true;
+        }
+    };
+
+    class TestReporter : public Catch::StreamingReporterBase {
+    public:
+        TestReporter( Catch::ReporterConfig const& _config ):
+            StreamingReporterBase( _config ) {
+            std::cout << "X28 - TestReporter constructed\n";
+        }
+
+        void testRunStarting( Catch::TestRunInfo const& ) override {
+            if ( !testRunStartingReceivedByListener ) {
+                std::cout << "X28 - ERROR\n";
+            }
+        }
+
+        void testRunEnded( Catch::TestRunStats const& ) override {
+            if ( !testRunEndedReceivedByListener ) {
+                std::cout << "X28 - ERROR\n";
+            }
+        }
+
+        void assertionStarting( Catch::AssertionInfo const& ) override {
+            if ( !assertionStartingReceivedByListener ) {
+                std::cout << "X28 - ERROR\n";
+            }
+        }
+
+        void assertionEnded( Catch::AssertionStats const& ) override {
+            if ( !assertionEndedReceivedByListener ) {
+                std::cout << "X28 - ERROR\n";
+            }
+        }
+
+        static std::string getDescription() { return "X28 test reporter"; }
+        ~TestReporter() override;
+    };
+
+    TestReporter::~TestReporter() = default;
+
+} // end unnamed namespace
+
+CATCH_REGISTER_REPORTER( "test-reporter", TestReporter )
+CATCH_REGISTER_LISTENER( TestListener )
+
+TEST_CASE( "Dummy test case" ) { REQUIRE( 1 == 1 ); }