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

summaryrefslogtreecommitdiffhomepage
path: root/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.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/X27-CapturedStdoutInTestCaseEvents.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/X27-CapturedStdoutInTestCaseEvents.cpp')
-rw-r--r--tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp b/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp
index 61aaa02a..20b39d78 100644
--- a/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp
+++ b/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp
@@ -12,23 +12,23 @@
* output).
*
* This is done by having a single test case that is entered multiple
- * times through generator, and a custom capturing reporter that knows
- * what it should expect captured from the test case.
+ * times through generator, and a capturing listener that knows what it
+ * should expect captured from the test case. It counts what differs and
+ * prints the count when the run ends.
*/
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_range.hpp>
-#include <catch2/reporters/catch_reporter_streaming_base.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>
-
#include <iostream>
#include <string>
-#include <utility>
-class TestReporter : public Catch::StreamingReporterBase {
+namespace {
+class TestListener : public Catch::EventListenerBase {
std::string stdOutString( uint64_t iter ){
return "stdout " + std::to_string( iter ) + '\n';
}
@@ -36,42 +36,40 @@ class TestReporter : public Catch::StreamingReporterBase {
return "stderr " + std::to_string( iter ) + '\n';
}
+ int m_errors = 0;
+
public:
- TestReporter( Catch::ReporterConfig&& _config ):
- StreamingReporterBase( std::move(_config) ) {
+ TestListener( Catch::IConfig const* config ):
+ EventListenerBase( config ) {
m_preferences.shouldRedirectStdOut = true;
- std::cout << "X27 - TestReporter constructed\n";
- }
-
- static std::string getDescription() {
- return "X27 test reporter";
}
void testCasePartialEnded( Catch::TestCaseStats const& stats,
uint64_t iter ) override {
if ( stats.stdOut != stdOutString( iter ) ) {
- std::cerr << "X27 ERROR in partial stdout\n" << stats.stdOut;
+ ++m_errors;
}
if ( stats.stdErr != stdErrString( iter ) ) {
- std::cerr << "X27 ERROR in partial stderr\n" << stats.stdErr;
+ ++m_errors;
}
}
void testCaseEnded( Catch::TestCaseStats const& stats ) override {
if ( stats.stdOut != "stdout 0\nstdout 1\nstdout 2\nstdout 3\nstdout 4\nstdout 5\n" ) {
- std::cerr << "X27 ERROR in full stdout\n" << stats.stdOut;
+ ++m_errors;
}
if ( stats.stdErr != "stderr 0\nstderr 1\nstderr 2\nstderr 3\nstderr 4\nstderr 5\n" ) {
- std::cerr << "X27 ERROR in full stderr\n" << stats.stdErr;
+ ++m_errors;
}
}
- ~TestReporter() override;
+ void testRunEnded( Catch::TestRunStats const& ) override {
+ std::cerr << "X27 - listener saw " << m_errors << " error(s)\n";
+ }
};
+} // namespace
-TestReporter::~TestReporter() = default;
-
-CATCH_REGISTER_REPORTER( "test-reporter", TestReporter )
+CATCH_REGISTER_LISTENER( TestListener )
TEST_CASE( "repeatedly entered test case" ) {
auto i = GENERATE( range(0, 6) );