• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Created by Phil on 31/12/2010.
3  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 #ifndef TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
9 #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
10 
11 #include "catch_section_info.h"
12 #include "catch_common.h"
13 #include "catch_config.hpp"
14 #include "catch_totals.h"
15 #include "catch_test_case_info.h"
16 #include "catch_assertionresult.h"
17 #include "catch_message.h"
18 #include "catch_option.hpp"
19 #include "catch_stringref.h"
20 
21 
22 #include <string>
23 #include <iosfwd>
24 #include <map>
25 #include <set>
26 #include <memory>
27 
28 namespace Catch {
29 
30     struct ReporterConfig {
31         explicit ReporterConfig( IConfigPtr const& _fullConfig );
32 
33         ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
34 
35         std::ostream& stream() const;
36         IConfigPtr fullConfig() const;
37 
38     private:
39         std::ostream* m_stream;
40         IConfigPtr m_fullConfig;
41     };
42 
43     struct ReporterPreferences {
44         bool shouldRedirectStdOut = false;
45         bool shouldReportAllAssertions = false;
46     };
47 
48     template<typename T>
49     struct LazyStat : Option<T> {
50         LazyStat& operator=( T const& _value ) {
51             Option<T>::operator=( _value );
52             used = false;
53             return *this;
54         }
resetLazyStat55         void reset() {
56             Option<T>::reset();
57             used = false;
58         }
59         bool used = false;
60     };
61 
62     struct TestRunInfo {
63         TestRunInfo( std::string const& _name );
64         std::string name;
65     };
66     struct GroupInfo {
67         GroupInfo(  std::string const& _name,
68                     std::size_t _groupIndex,
69                     std::size_t _groupsCount );
70 
71         std::string name;
72         std::size_t groupIndex;
73         std::size_t groupsCounts;
74     };
75 
76     struct AssertionStats {
77         AssertionStats( AssertionResult const& _assertionResult,
78                         std::vector<MessageInfo> const& _infoMessages,
79                         Totals const& _totals );
80 
81         AssertionStats( AssertionStats const& )              = default;
82         AssertionStats( AssertionStats && )                  = default;
83         AssertionStats& operator = ( AssertionStats const& ) = delete;
84         AssertionStats& operator = ( AssertionStats && )     = delete;
85         virtual ~AssertionStats();
86 
87         AssertionResult assertionResult;
88         std::vector<MessageInfo> infoMessages;
89         Totals totals;
90     };
91 
92     struct SectionStats {
93         SectionStats(   SectionInfo const& _sectionInfo,
94                         Counts const& _assertions,
95                         double _durationInSeconds,
96                         bool _missingAssertions );
97         SectionStats( SectionStats const& )              = default;
98         SectionStats( SectionStats && )                  = default;
99         SectionStats& operator = ( SectionStats const& ) = default;
100         SectionStats& operator = ( SectionStats && )     = default;
101         virtual ~SectionStats();
102 
103         SectionInfo sectionInfo;
104         Counts assertions;
105         double durationInSeconds;
106         bool missingAssertions;
107     };
108 
109     struct TestCaseStats {
110         TestCaseStats(  TestCaseInfo const& _testInfo,
111                         Totals const& _totals,
112                         std::string const& _stdOut,
113                         std::string const& _stdErr,
114                         bool _aborting );
115 
116         TestCaseStats( TestCaseStats const& )              = default;
117         TestCaseStats( TestCaseStats && )                  = default;
118         TestCaseStats& operator = ( TestCaseStats const& ) = default;
119         TestCaseStats& operator = ( TestCaseStats && )     = default;
120         virtual ~TestCaseStats();
121 
122         TestCaseInfo testInfo;
123         Totals totals;
124         std::string stdOut;
125         std::string stdErr;
126         bool aborting;
127     };
128 
129     struct TestGroupStats {
130         TestGroupStats( GroupInfo const& _groupInfo,
131                         Totals const& _totals,
132                         bool _aborting );
133         TestGroupStats( GroupInfo const& _groupInfo );
134 
135         TestGroupStats( TestGroupStats const& )              = default;
136         TestGroupStats( TestGroupStats && )                  = default;
137         TestGroupStats& operator = ( TestGroupStats const& ) = default;
138         TestGroupStats& operator = ( TestGroupStats && )     = default;
139         virtual ~TestGroupStats();
140 
141         GroupInfo groupInfo;
142         Totals totals;
143         bool aborting;
144     };
145 
146     struct TestRunStats {
147         TestRunStats(   TestRunInfo const& _runInfo,
148                         Totals const& _totals,
149                         bool _aborting );
150 
151         TestRunStats( TestRunStats const& )              = default;
152         TestRunStats( TestRunStats && )                  = default;
153         TestRunStats& operator = ( TestRunStats const& ) = default;
154         TestRunStats& operator = ( TestRunStats && )     = default;
155         virtual ~TestRunStats();
156 
157         TestRunInfo runInfo;
158         Totals totals;
159         bool aborting;
160     };
161 
162     struct BenchmarkInfo {
163         std::string name;
164     };
165     struct BenchmarkStats {
166         BenchmarkInfo info;
167         std::size_t iterations;
168         uint64_t elapsedTimeInNanoseconds;
169     };
170 
171     struct IStreamingReporter {
172         virtual ~IStreamingReporter() = default;
173 
174         // Implementing class must also provide the following static methods:
175         // static std::string getDescription();
176         // static std::set<Verbosity> getSupportedVerbosities()
177 
178         virtual ReporterPreferences getPreferences() const = 0;
179 
180         virtual void noMatchingTestCases( std::string const& spec ) = 0;
181 
182         virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
183         virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
184 
185         virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
186         virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
187 
188         // *** experimental ***
benchmarkStartingIStreamingReporter189         virtual void benchmarkStarting( BenchmarkInfo const& ) {}
190 
191         virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
192 
193         // The return value indicates if the messages buffer should be cleared:
194         virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
195 
196         // *** experimental ***
benchmarkEndedIStreamingReporter197         virtual void benchmarkEnded( BenchmarkStats const& ) {}
198 
199         virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
200         virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
201         virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
202         virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
203 
204         virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
205 
206         // Default empty implementation provided
207         virtual void fatalErrorEncountered( StringRef name );
208 
209         virtual bool isMulti() const;
210     };
211     using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
212 
213     struct IReporterFactory {
214         virtual ~IReporterFactory();
215         virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
216         virtual std::string getDescription() const = 0;
217     };
218     using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
219 
220     struct IReporterRegistry {
221         using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
222         using Listeners = std::vector<IReporterFactoryPtr>;
223 
224         virtual ~IReporterRegistry();
225         virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
226         virtual FactoryMap const& getFactories() const = 0;
227         virtual Listeners const& getListeners() const = 0;
228     };
229 
230 } // end namespace Catch
231 
232 #endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
233