File indexing completed on 2025-09-18 09:08:50
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_INTERFACES_REPORTER_HPP_INCLUDED
0009 #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED
0010
0011 #include <catch2/catch_section_info.hpp>
0012 #include <catch2/catch_totals.hpp>
0013 #include <catch2/catch_assertion_result.hpp>
0014 #include <catch2/internal/catch_message_info.hpp>
0015 #include <catch2/internal/catch_stringref.hpp>
0016 #include <catch2/internal/catch_test_run_info.hpp>
0017 #include <catch2/internal/catch_unique_ptr.hpp>
0018 #include <catch2/benchmark/detail/catch_benchmark_stats.hpp>
0019
0020 #include <map>
0021 #include <string>
0022 #include <vector>
0023 #include <iosfwd>
0024
0025 namespace Catch {
0026
0027 struct ReporterDescription;
0028 struct ListenerDescription;
0029 struct TagInfo;
0030 struct TestCaseInfo;
0031 class TestCaseHandle;
0032 class IConfig;
0033 class IStream;
0034 enum class ColourMode : std::uint8_t;
0035
0036 struct ReporterConfig {
0037 ReporterConfig( IConfig const* _fullConfig,
0038 Detail::unique_ptr<IStream> _stream,
0039 ColourMode colourMode,
0040 std::map<std::string, std::string> customOptions );
0041
0042 ReporterConfig( ReporterConfig&& ) = default;
0043 ReporterConfig& operator=( ReporterConfig&& ) = default;
0044 ~ReporterConfig();
0045
0046 Detail::unique_ptr<IStream> takeStream() &&;
0047 IConfig const* fullConfig() const;
0048 ColourMode colourMode() const;
0049 std::map<std::string, std::string> const& customOptions() const;
0050
0051 private:
0052 Detail::unique_ptr<IStream> m_stream;
0053 IConfig const* m_fullConfig;
0054 ColourMode m_colourMode;
0055 std::map<std::string, std::string> m_customOptions;
0056 };
0057
0058 struct AssertionStats {
0059 AssertionStats( AssertionResult const& _assertionResult,
0060 std::vector<MessageInfo> const& _infoMessages,
0061 Totals const& _totals );
0062
0063 AssertionStats( AssertionStats const& ) = default;
0064 AssertionStats( AssertionStats && ) = default;
0065 AssertionStats& operator = ( AssertionStats const& ) = delete;
0066 AssertionStats& operator = ( AssertionStats && ) = delete;
0067
0068 AssertionResult assertionResult;
0069 std::vector<MessageInfo> infoMessages;
0070 Totals totals;
0071 };
0072
0073 struct SectionStats {
0074 SectionStats( SectionInfo&& _sectionInfo,
0075 Counts const& _assertions,
0076 double _durationInSeconds,
0077 bool _missingAssertions );
0078
0079 SectionInfo sectionInfo;
0080 Counts assertions;
0081 double durationInSeconds;
0082 bool missingAssertions;
0083 };
0084
0085 struct TestCaseStats {
0086 TestCaseStats( TestCaseInfo const& _testInfo,
0087 Totals const& _totals,
0088 std::string&& _stdOut,
0089 std::string&& _stdErr,
0090 bool _aborting );
0091
0092 TestCaseInfo const * testInfo;
0093 Totals totals;
0094 std::string stdOut;
0095 std::string stdErr;
0096 bool aborting;
0097 };
0098
0099 struct TestRunStats {
0100 TestRunStats( TestRunInfo const& _runInfo,
0101 Totals const& _totals,
0102 bool _aborting );
0103
0104 TestRunInfo runInfo;
0105 Totals totals;
0106 bool aborting;
0107 };
0108
0109
0110
0111
0112 struct ReporterPreferences {
0113
0114
0115 bool shouldRedirectStdOut = false;
0116
0117
0118 bool shouldReportAllAssertions = false;
0119 };
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 class IEventListener {
0134 protected:
0135
0136 ReporterPreferences m_preferences;
0137
0138 IConfig const* m_config;
0139
0140 public:
0141 IEventListener( IConfig const* config ): m_config( config ) {}
0142
0143 virtual ~IEventListener();
0144
0145
0146
0147
0148 ReporterPreferences const& getPreferences() const {
0149 return m_preferences;
0150 }
0151
0152
0153 virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0;
0154
0155 virtual void reportInvalidTestSpec( StringRef invalidArgument ) = 0;
0156
0157
0158
0159
0160
0161
0162 virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
0163
0164
0165 virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
0166
0167 virtual void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber ) = 0;
0168
0169 virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
0170
0171
0172 virtual void benchmarkPreparing( StringRef benchmarkName ) = 0;
0173
0174 virtual void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) = 0;
0175
0176 virtual void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) = 0;
0177
0178 virtual void benchmarkFailed( StringRef benchmarkName ) = 0;
0179
0180
0181 virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
0182
0183
0184 virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
0185
0186
0187 virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
0188
0189 virtual void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber ) = 0;
0190
0191 virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
0192
0193
0194
0195
0196
0197 virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
0198
0199
0200
0201
0202
0203
0204
0205 virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
0206
0207
0208 virtual void fatalErrorEncountered( StringRef error ) = 0;
0209
0210
0211 virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0;
0212
0213 virtual void listListeners(std::vector<ListenerDescription> const& descriptions) = 0;
0214
0215 virtual void listTests(std::vector<TestCaseHandle> const& tests) = 0;
0216
0217 virtual void listTags(std::vector<TagInfo> const& tags) = 0;
0218 };
0219 using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
0220
0221 }
0222
0223 #endif