mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
Add integration test for listener-reporter event ordering
This commit is contained in:
parent
4ff8b27bb6
commit
e53a75b425
@ -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
|
||||
)
|
||||
|
||||
|
97
tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp
Normal file
97
tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp
Normal file
@ -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 ); }
|
Loading…
Reference in New Issue
Block a user