Debian Codegraph @

3rdparty/catch2/tests/ExtraTests/X21-PartialTestCaseEvents.cpp

raw symbols SCIP
1
2 // Copyright Catch2 Authors
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE.txt or copy at
5 // https://www.boost.org/LICENSE_1_0.txt)
6
7 // SPDX-License-Identifier: BSL-1.0
8
9 /**\file
10 * Registers custom reporter that reports testCase* events
11 *
12 * The resulting executable can then be used by an external Python script
13 * to verify that testCase{Starting,Ended} and testCasePartial{Starting,Ended}
14 * events are properly nested.
15 */
16
17
18 #include <catch2/catch_test_macros.hpp>
19 #include <catch2/reporters/catch_reporter_streaming_base.hpp>
20 #include <catch2/catch_test_case_info.hpp>
21 #include <catch2/reporters/catch_reporter_registrars.hpp>
22 #include <catch2/generators/catch_generators.hpp>
23
24
25 #include <iostream>
26
27 using Catch::TestCaseInfo;
28 using Catch::TestCaseStats;
29
30 class PartialReporter : public Catch::StreamingReporterBase {
31 public:
32 using StreamingReporterBase::StreamingReporterBase;
33
34 ~PartialReporter() override; // = default
35
36 static std::string getDescription() {
37 return "Special reporter for testing TestCasePartialStarting/Ended events";
38 }
39
40 //! Called _once_ for each TEST_CASE, no matter how many times it is entered
41 void testCaseStarting(TestCaseInfo const& testInfo) override {
42 std::cout << "TestCaseStarting: " << testInfo.name << '\n';
43 }
44 //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
45 void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override {
46 std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
47 }
48
49
50 //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
51 void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber) override {
52 std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
53 }
54 //! Called _once_ for each TEST_CASE, no matter how many times it is entered
55 void testCaseEnded(TestCaseStats const& testCaseStats) override {
56 std::cout << "TestCaseEnded: " << testCaseStats.testInfo->name << '\n';
57 }
58 };
59 PartialReporter::~PartialReporter() = default;
60
61
62 CATCH_REGISTER_REPORTER("partial", PartialReporter)
63
64 TEST_CASE("section") {
65 SECTION("A") {}
66 SECTION("B") {}
67 SECTION("C") {}
68 SECTION("D") {}
69 }
70
71 TEST_CASE("generator") {
72 auto _ = GENERATE(1, 2, 3, 4);
73 (void)_;
74 }