mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 05:15:39 +02:00
Add new reporter event called for each test case enter/exit
This means that e.g. for `TEST_CASE` with two sibling `SECTION`s the event will fire twice, because the `TEST_CASE` will be entered twice. Closes #2107 (the event mentioned there already exists, but this is its counterpart that we also want to provide to users)
This commit is contained in:
@@ -172,6 +172,14 @@ if (MSVC)
|
||||
list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES} WindowsHeader)
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(PartialTestCaseEvents ${TESTS_DIR}/X21-PartialTestCaseEvents.cpp)
|
||||
target_link_libraries(PartialTestCaseEvents PRIVATE Catch2WithMain)
|
||||
add_test(
|
||||
NAME PartialTestCaseEvents
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $<TARGET_FILE:PartialTestCaseEvents>
|
||||
)
|
||||
|
||||
#add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp)
|
||||
#target_link_libraries(DebugBreakMacros Catch2)
|
||||
#add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break)
|
||||
|
74
tests/ExtraTests/X21-PartialTestCaseEvents.cpp
Normal file
74
tests/ExtraTests/X21-PartialTestCaseEvents.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
// 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
|
||||
* Registers custom reporter that reports testCase* events
|
||||
*
|
||||
* 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/catch_reporter_registrars.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using Catch::TestCaseInfo;
|
||||
using Catch::TestCaseStats;
|
||||
|
||||
class PartialReporter : public Catch::StreamingReporterBase {
|
||||
public:
|
||||
using StreamingReporterBase::StreamingReporterBase;
|
||||
|
||||
~PartialReporter() override; // = default
|
||||
|
||||
static std::string getDescription() {
|
||||
return "Special reporter for testing TestCasePartialStarting/Ended events";
|
||||
}
|
||||
|
||||
//! 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';
|
||||
}
|
||||
//! 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';
|
||||
}
|
||||
|
||||
|
||||
//! 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';
|
||||
}
|
||||
//! 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';
|
||||
}
|
||||
};
|
||||
PartialReporter::~PartialReporter() = default;
|
||||
|
||||
|
||||
CATCH_REGISTER_REPORTER("partial", PartialReporter)
|
||||
|
||||
TEST_CASE("section") {
|
||||
SECTION("A") {}
|
||||
SECTION("B") {}
|
||||
SECTION("C") {}
|
||||
SECTION("D") {}
|
||||
}
|
||||
|
||||
TEST_CASE("generator") {
|
||||
auto _ = GENERATE(1, 2, 3, 4);
|
||||
(void)_;
|
||||
}
|
Reference in New Issue
Block a user