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

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-01-28 00:00:52 +0100
committerMartin Hořeňovský2022-01-28 00:00:52 +0100
commite53a75b425374b99fdcd53f6242f0e14cbb82140 (patch)
treeb63bd1bc5ff0324ddbe238a5b49a53296de53e35 /tests
parent4ff8b27bb6bed4b8b309e56cd269b4f1fbc24e89 (diff)
downloadcatch3-e53a75b425374b99fdcd53f6242f0e14cbb82140.tar.gz
Add integration test for listener-reporter event ordering
Diffstat (limited to 'tests')
-rw-r--r--tests/ExtraTests/CMakeLists.txt13
-rw-r--r--tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp97
2 files changed, 110 insertions, 0 deletions
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 ); }