Debian Codegraph @

3rdparty/catch2/docs/reporter-events.md

raw symbols SCIP
1 <a id="top"></a>
2 # Reporter events
3
4 **Contents**<br>
5 [Test running events](#test-running-events)<br>
6 [Benchmarking events](#benchmarking-events)<br>
7 [Listings events](#listings-events)<br>
8 [Miscellaneous events](#miscellaneous-events)<br>
9
10 Reporter events are one of the customization points for user code. They
11 are used by [reporters](reporters.md#top) to customize Catch2's output,
12 and by [event listeners](event-listeners.md#top) to perform in-process
13 actions under some conditions.
14
15 There are currently 21 reporter events in Catch2, split between 4 distinct
16 event groups:
17 * test running events (10 events)
18 * benchmarking (4 events)
19 * listings (3 events)
20 * miscellaneous (4 events)
21
22 ## Test running events
23
24 Test running events are always paired so that for each `fooStarting` event,
25 there is a `fooEnded` event. This means that the 10 test running events
26 consist of 5 pairs of events:
27
28 * `testRunStarting` and `testRunEnded`,
29 * `testCaseStarting` and `testCaseEnded`,
30 * `testCasePartialStarting` and `testCasePartialEnded`,
31 * `sectionStarting` and `sectionEnded`,
32 * `assertionStarting` and `assertionEnded`
33
34 ### `testRun` events
35
36 ```cpp
37 void testRunStarting( TestRunInfo const& testRunInfo );
38 void testRunEnded( TestRunStats const& testRunStats );
39 ```
40
41 The `testRun` events bookend the entire test run. `testRunStarting` is
42 emitted before the first test case is executed, and `testRunEnded` is
43 emitted after all the test cases have been executed.
44
45 ### `testCase` events
46
47 ```cpp
48 void testCaseStarting( TestCaseInfo const& testInfo );
49 void testCaseEnded( TestCaseStats const& testCaseStats );
50 ```
51
52 The `testCase` events bookend one _full_ run of a specific test case.
53 Individual runs through a test case, e.g. due to `SECTION`s or `GENERATE`s,
54 are handled by a different event.
55
56
57 ### `testCasePartial` events
58
59 > Introduced in Catch2 3.0.1
60
61 ```cpp
62 void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber );
63 void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber );
64 ```
65
66 `testCasePartial` events bookend one _partial_ run of a specific test case.
67 This means that for any given test case, these events can be emitted
68 multiple times, e.g. due to multiple leaf sections.
69
70 In regards to nesting with `testCase` events, `testCasePartialStarting`
71 will never be emitted before the corresponding `testCaseStarting`, and
72 `testCasePartialEnded` will always be emitted before the corresponding
73 `testCaseEnded`.
74
75
76 ### `section` events
77
78 ```cpp
79 void sectionStarting( SectionInfo const& sectionInfo );
80 void sectionEnded( SectionStats const& sectionStats );
81 ```
82
83 `section` events are emitted only for active `SECTION`s, that is, sections
84 that are entered. Sections that are skipped in this test case run-through
85 do not cause events to be emitted.
86
87 _Note that test cases always contain one implicit section. The event for
88 this section is emitted after the corresponding `testCasePartialStarting`
89 event._
90
91
92 ### `assertion` events
93
94 ```cpp
95 void assertionStarting( AssertionInfo const& assertionInfo );
96 void assertionEnded( AssertionStats const& assertionStats );
97 ```
98
99 The `assertionStarting` event is emitted before the expression in the
100 assertion is captured or evaluated and `assertionEnded` is emitted
101 afterwards. This means that given assertion like `REQUIRE(a + b == c + d)`,
102 Catch2 first emits `assertionStarting` event, then `a + b` and `c + d`
103 are evaluated, then their results are captured, the comparison is evaluated,
104 and then `assertionEnded` event is emitted.
105
106
107 ## Benchmarking events
108
109 > [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
110
111 ```cpp
112 void benchmarkPreparing( StringRef name ) override;
113 void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
114 void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
115 void benchmarkFailed( StringRef error ) override;
116 ```
117
118 Due to the benchmark lifecycle being bit more complicated, the benchmarking
119 events have their own category, even though they could be seen as parallel
120 to the `assertion*` events. You should expect running a benchmark to
121 generate at least 2 of the events above.
122
123 To understand the explanation below, you should read the [benchmarking
124 documentation](benchmarks.md#top) first.
125
126 * `benchmarkPreparing` event is sent after the environmental probe
127 finishes, but before the user code is first estimated.
128 * `benchmarkStarting` event is sent after the user code is estimated,
129 but has not been benchmarked yet.
130 * `benchmarkEnded` event is sent after the user code has been benchmarked,
131 and contains the benchmarking results.
132 * `benchmarkFailed` event is sent if either the estimation or the
133 benchmarking itself fails.
134
135
136 ## Listings events
137
138 > Introduced in Catch2 3.0.1.
139
140 Listings events are events that correspond to the test binary being
141 invoked with `--list-foo` flag.
142
143 There are currently 3 listing events, one for reporters, one for tests,
144 and one for tags. Note that they are not exclusive to each other.
145
146 ```cpp
147 void listReporters( std::vector<ReporterDescription> const& descriptions );
148 void listTests( std::vector<TestCaseHandle> const& tests );
149 void listTags( std::vector<TagInfo> const& tagInfos );
150 ```
151
152
153 ## Miscellaneous events
154
155 ```cpp
156 void reportInvalidTestSpec( StringRef unmatchedSpec );
157 void fatalErrorEncountered( StringRef error );
158 void noMatchingTestCases( StringRef unmatchedSpec );
159 ```
160
161 These are one-off events that do not neatly fit into other categories.
162
163 `reportInvalidTestSpec` is sent for each [test specification command line
164 argument](command-line.md#specifying-which-tests-to-run) that wasn't
165 parsed into a valid spec.
166
167 `fatalErrorEncountered` is sent when Catch2's POSIX signal handling
168 or Windows SE handler is called into with a fatal signal/exception.
169
170 `noMatchingTestCases` is sent for each user provided test specification
171 that did not match any registered tests.
172
173 ---
174
175 [Home](Readme.md#top)