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

summaryrefslogtreecommitdiffhomepage
path: root/tests/ExtraTests/X21-PartialTestCaseEvents.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-10-24 19:03:40 +0300
committerGitHub2026-10-24 19:03:40 +0300
commit4f1c759cffcb14bd6511e1d7c5fbace682e24f2d (patch)
tree415fe5d48a5b48650bba3747beaf245d727c4f61 /tests/ExtraTests/X21-PartialTestCaseEvents.cpp
parent83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff)
parent622188f9c08e4af35941c146979883ed4882410e (diff)
downloadcatch3-4f1c759cffcb14bd6511e1d7c5fbace682e24f2d.tar.gz
Merge pull request #15 from Progmasoft/feature/catch3-runner
Replace Catch2's runner with the Catch3 runner
Diffstat (limited to 'tests/ExtraTests/X21-PartialTestCaseEvents.cpp')
-rw-r--r--tests/ExtraTests/X21-PartialTestCaseEvents.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/tests/ExtraTests/X21-PartialTestCaseEvents.cpp b/tests/ExtraTests/X21-PartialTestCaseEvents.cpp
index aa5204c9..99002822 100644
--- a/tests/ExtraTests/X21-PartialTestCaseEvents.cpp
+++ b/tests/ExtraTests/X21-PartialTestCaseEvents.cpp
@@ -7,59 +7,61 @@
// SPDX-License-Identifier: BSL-1.0
/**\file
- * Registers custom reporter that reports testCase* events
+ * Registers a listener that records the testCase* events and prints them
+ * when the test run ends, outside any test, where the runner passes the
+ * output on.
*
* The resulting executable can then be used by an external Python script
* to verify that testCase{Starting,Ended} and testCasePartial{Starting,Ended}
* events are properly nested.
*/
-
#include <catch2/catch_test_macros.hpp>
-#include <catch2/reporters/catch_reporter_streaming_base.hpp>
#include <catch2/catch_test_case_info.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>
#include <catch2/generators/catch_generators.hpp>
-
#include <iostream>
+#include <string>
using Catch::TestCaseInfo;
using Catch::TestCaseStats;
-class PartialReporter : public Catch::StreamingReporterBase {
+namespace {
+class PartialListener : public Catch::EventListenerBase {
public:
- using StreamingReporterBase::StreamingReporterBase;
-
- ~PartialReporter() override; // = default
-
- static std::string getDescription() {
- return "Special reporter for testing TestCasePartialStarting/Ended events";
- }
+ using EventListenerBase::EventListenerBase;
//! Called _once_ for each TEST_CASE, no matter how many times it is entered
void testCaseStarting(TestCaseInfo const& testInfo) override {
- std::cout << "TestCaseStarting: " << testInfo.name << '\n';
+ m_events += "TestCaseStarting: " + testInfo.name + '\n';
}
//! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override {
- std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
+ m_events += "TestCaseStartingPartial: " + testInfo.name + '#' + std::to_string(partNumber) + '\n';
}
-
//! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber) override {
- std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
+ m_events += "TestCasePartialEnded: " + testCaseStats.testInfo->name + '#' + std::to_string(partNumber) + '\n';
}
+
//! Called _once_ for each TEST_CASE, no matter how many times it is entered
void testCaseEnded(TestCaseStats const& testCaseStats) override {
- std::cout << "TestCaseEnded: " << testCaseStats.testInfo->name << '\n';
+ m_events += "TestCaseEnded: " + testCaseStats.testInfo->name + '\n';
}
-};
-PartialReporter::~PartialReporter() = default;
+ void testRunEnded( Catch::TestRunStats const& ) override {
+ std::cout << "BEGIN EVENTS\n" << m_events << "END EVENTS\n" << std::flush;
+ }
+
+private:
+ std::string m_events;
+};
+} // namespace
-CATCH_REGISTER_REPORTER("partial", PartialReporter)
+CATCH_REGISTER_LISTENER(PartialListener)
TEST_CASE("section") {
SECTION("A") {}