Catch.xs

filter: Statementstmt 57.8% 137 / 237 Branchbran 36.0% 119 / 330 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 45.1% 256 / 567 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« t/bench.cc ↑ Summary t/test.cc »
1 #include <math.h> // this fixes win32 because <cmath> that is included by <catch.hpp> breaks <perl.h> unless previously included <math.h>
2 #include <vector>
3 #include <iostream>
4 #include <catch2/catch_session.hpp>
5 #include <catch2/internal/catch_string_manip.hpp>
6 #include <catch2/internal/catch_console_colour.hpp>
7 #include <catch2/reporters/catch_reporter_registrars.hpp>
8 #include <catch2/reporters/catch_reporter_streaming_base.hpp>
9 #include <xsheader.h>
10  
11 using namespace Catch;
12 using namespace std;
13  
14 static Catch::Session session;
15  
16 struct Printer {
17 50 Printer (ostream& _stream, const AssertionStats& _stats)
18 50 : stream(_stream), result(_stats.assertionResult), messages(_stats.infoMessages), itMessage(_stats.infoMessages.begin()) {}
19  
20 50 void print () {
21 50 itMessage = messages.begin();
22  
23 50 switch (result.getResultType()) {
24 50 case ResultWas::Ok:
25 case ResultWas::ExplicitSkip:
26 50 printOriginalExpression();
27 50 printReconstructedExpression();
28 50 printRemainingMessages();
29 50 break;
30 0 case ResultWas::ExpressionFailed:
31 0 printOriginalExpression();
32 0 printReconstructedExpression();
33 0 ▶ if (result.isOk()) printIssue(" # TODO");
Branch: 3 branches
BranchTrueFalseTotal
if (result.isOk()) printIssue(" # TODO"); 0 0 0
if (result.isOk()) printIssue(" # TODO"); 0 0 0
if (result.isOk()) printIssue(" # TODO"); 0 0 0
34 0 printRemainingMessages();
35 0 break;
36 0 case ResultWas::ThrewException:
37 0 ▶ printIssue("unexpected exception ");
Branch: 2 branches
BranchTrueFalseTotal
printIssue("unexpected exception "); 0 0 0
printIssue("unexpected exception "); 0 0 0
38 0 printExpressionWas();
39 0 printRemainingMessages();
40 0 break;
41 0 case ResultWas::FatalErrorCondition:
42 0 ▶ printIssue("fatal error condition with message:");
Branch: 2 branches
BranchTrueFalseTotal
printIssue("fatal error condition with message:"); 0 0 0
printIssue("fatal error condition with message:"); 0 0 0
43 0 printMessage();
44 0 printExpressionWas();
45 0 printRemainingMessages();
46 0 break;
47 0 case ResultWas::DidntThrowException:
48 0 ▶ printIssue("expected exception, got none");
Branch: 2 branches
BranchTrueFalseTotal
printIssue("expected exception, got none"); 0 0 0
printIssue("expected exception, got none"); 0 0 0
49 0 printExpressionWas();
50 0 printRemainingMessages();
51 0 break;
52 0 case ResultWas::Info:
53 0 stream << "#info";
54 0 printMessage();
55 0 printRemainingMessages();
56 0 break;
57 0 case ResultWas::Warning:
58 0 stream << "#warning";
59 0 printMessage();
60 0 printRemainingMessages();
61 0 break;
62 0 case ResultWas::ExplicitFailure:
63 0 ▶ printIssue("explicitly");
Branch: 2 branches
BranchTrueFalseTotal
printIssue("explicitly"); 0 0 0
printIssue("explicitly"); 0 0 0
64 0 printRemainingMessages();
65 0 break;
66 // These cases are here to prevent compiler warnings
67 0 case ResultWas::Unknown:
68 case ResultWas::FailureBit:
69 case ResultWas::Exception:
70 0 stream << "** unsupported ResultWas (should not happenned) **";
71 0 break;
72 }
73 50 }
74  
75 private:
76 132 static inline void expr_replace (string& expr, const string& c, const string& subs) {
77 132 size_t pos = expr.find(c);
78 135 ▶ while (pos < expr.length()) {
Branch: 1 branch
BranchTrueFalseTotal
while (pos < expr.length()) { 3 132 135
79 3 expr.replace(pos, c.length(), subs);
80 3 pos = expr.find(c, pos + subs.length());
81 }
82 132 }
83  
84 0 void printIssue (const string& issue) const {
85 0 stream << " " << issue;
86 0 }
87  
88 0 void printExpressionWas () {
89 0 ▶ if (!result.hasExpression()) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!result.hasExpression()) return; 0 0 0
90 0 stream << "; expression was:";
91 0 printOriginalExpression();
92 }
93  
94 50 void printOriginalExpression () const {
95 50 ▶ if (result.hasExpression()) stream << " " << result.getExpression();
Branch: 3 branches
BranchTrueFalseTotal
if (result.hasExpression()) stream << " " << result.getExpression(); 50 0 50
if (result.hasExpression()) stream << " " << result.getExpression(); 50 0 50
if (result.hasExpression()) stream << " " << result.getExpression(); 50 0 50
96 50 }
97  
98 50 void printReconstructedExpression () const {
99 50 ▶ if (!result.hasExpandedExpression()) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!result.hasExpandedExpression()) return; 50 0 50
if (!result.hasExpandedExpression()) return; 17 33 50
100 33 ▶ stream << " for: ";
Branch: 1 branch
BranchTrueFalseTotal
stream << " for: "; 33 0 33
101 33 ▶ string expr = result.getExpandedExpression();
Branch: 1 branch
BranchTrueFalseTotal
string expr = result.getExpandedExpression(); 33 0 33
102 // prevent "str" == "str" splitting into several lines
103 132 ▶ expr_replace(expr, "\"\r\n==\r\n\"", "\" == \"");
Branch: 3 branches
BranchTrueFalseTotal
expr_replace(expr, "\"\r\n==\r\n\"", "\" == \""); 33 0 33
expr_replace(expr, "\"\r\n==\r\n\"", "\" == \""); 33 0 33
expr_replace(expr, "\"\r\n==\r\n\"", "\" == \""); 33 0 33
104 132 ▶ expr_replace(expr, "\"\n==\n\"", "\" == \"");
Branch: 3 branches
BranchTrueFalseTotal
expr_replace(expr, "\"\n==\n\"", "\" == \""); 33 0 33
expr_replace(expr, "\"\n==\n\"", "\" == \""); 33 0 33
expr_replace(expr, "\"\n==\n\"", "\" == \""); 33 0 33
105 // replace remaining newlines in text/expressions
106 132 ▶ expr_replace(expr, "\r", "\\r");
Branch: 3 branches
BranchTrueFalseTotal
expr_replace(expr, "\r", "\\r"); 33 0 33
expr_replace(expr, "\r", "\\r"); 33 0 33
expr_replace(expr, "\r", "\\r"); 33 0 33
107 99 ▶ expr_replace(expr, "\n", "\\n");
Branch: 3 branches
BranchTrueFalseTotal
expr_replace(expr, "\n", "\\n"); 33 0 33
expr_replace(expr, "\n", "\\n"); 33 0 33
expr_replace(expr, "\n", "\\n"); 33 0 33
108 33 ▶ stream << expr;
Branch: 1 branch
BranchTrueFalseTotal
stream << expr; 33 0 33
109 33 }
110  
111 0 void printMessage () {
112 0 ▶ if (itMessage != messages.end()) {
Branch: 1 branch
BranchTrueFalseTotal
if (itMessage != messages.end()) { 0 0 0
113 0 stream << " '" << itMessage->message << "'";
114 0 ++itMessage;
115 }
116 0 }
117  
118 50 void printRemainingMessages () {
119 50 ▶ if (itMessage == messages.cend()) return;
Branch: 1 branch
BranchTrueFalseTotal
if (itMessage == messages.cend()) return; 50 0 50
120  
121 // using messages.end() directly (or auto) yields compilation error:
122 0 auto itEnd = messages.cend();
123 0 const size_t N = static_cast<size_t>(std::distance(itMessage, itEnd));
124  
125 0 ▶ stream << " with " << pluralise( N, "message" ) << ":";
Branch: 3 branches
BranchTrueFalseTotal
stream << " with " << pluralise( N, "message" ) << ":"; 0 0 0
stream << " with " << pluralise( N, "message" ) << ":"; 0 0 0
stream << " with " << pluralise( N, "message" ) << ":"; 0 0 0
126  
127 0 ▶ for (; itMessage != itEnd; ++itMessage) {
Branch: 1 branch
BranchTrueFalseTotal
for (; itMessage != itEnd; ++itMessage) { 0 0 0
128 // If this assertion is a warning ignore any INFO messages
129 0 ▶ if (itMessage->type != ResultWas::Info) {
Branch: 1 branch
BranchTrueFalseTotal
if (itMessage->type != ResultWas::Info) { 0 0 0
130 0 ▶ stream << "\n# " << itMessage->message;
Branch: 2 branches
BranchTrueFalseTotal
stream << "\n# " << itMessage->message; 0 0 0
stream << "\n# " << itMessage->message; 0 0 0
131 }
132 }
133 }
134  
135 ostream& stream;
136 AssertionResult const& result;
137 vector<MessageInfo> messages;
138 vector<MessageInfo>::const_iterator itMessage;
139 };
140  
141  
142 struct PerlReporter : StreamingReporterBase {
143 struct Scope {
144 uint32_t count;
145 uint32_t failed;
146 uint32_t depth;
147 string name;
148 string fullname;
149 };
150 static Scope context;
151  
152 0 ▶ static string getDescription () { return "Reports test results in perl test-harness compatible format"; }
Branch: 1 branch
BranchTrueFalseTotal
static string getDescription () { return "Reports test results in perl test-harness compatible format"; } 0 0 0
153  
154 5 PerlReporter (ReporterConfig&& config) : StreamingReporterBase(std::move(config)), scope(), sliding_scope(), fatal() {
155 5 m_preferences.shouldRedirectStdOut = false;
156 5 m_preferences.shouldReportAllAssertions = true;
157 5 }
158  
159 0 void noMatchingTestCases (StringRef unmatchedSpec) override {
160 0 startErrorLine() << "# No test cases matched '" << unmatchedSpec << "'" << endl;
161 0 }
162  
163 0 void reportInvalidTestSpec(StringRef invalidArgument) override {
164 0 startErrorLine() << "# invalid argument '" << invalidArgument << "'" << endl;
165 0 }
166  
167 5 void testRunStarting (const TestRunInfo&) override {
168 5 scopes.push_back(context);
169 5 scope = &scopes.back();
170 5 }
171  
172 5 void testRunEnded (const TestRunStats&) override {
173 5 context.count = scope->count;
174 5 context.failed = scope->failed;
175 5 scopes.clear();
176 5 scope = nullptr;
177 5 }
178  
179 13 void testCaseStarting (const TestCaseInfo&) override {}
180  
181 13 void testCaseEnded (const TestCaseStats&) override {
182 13 ▶ if (fatal) {
Branch: 1 branch
BranchTrueFalseTotal
if (fatal) { 0 13 13
183 0 commitAssertions();
184 0 sliding_scope = &scopes[1];
185 }
186 13 commitSlidingScope();
187 13 }
188  
189 43 void sectionStarting (const SectionInfo& info) override {
190 43 ▶ if (sliding_scope && sliding_scope->name == info.name) {
Branch: 3 branches
BranchTrueFalseTotal
if (sliding_scope && sliding_scope->name == info.name) { 21 22 43
if (sliding_scope && sliding_scope->name == info.name) { 12 9 21
if (sliding_scope && sliding_scope->name == info.name) { 12 31 43
191 12 ++sliding_scope;
192 12 return;
193 }
194 31 commitSlidingScope();
195 31 startScope(info);
196 }
197  
198 31 void startScope (const SectionInfo& info) {
199 31 ▶ startLine();
Branch: 1 branch
BranchTrueFalseTotal
startLine(); 31 0 31
200 31 ▶ auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name;
Branch: 6 branches
BranchTrueFalseTotal
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 18 13 31
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 18 0 18
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 18 0 18
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 13 0 13
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 18 13 31
auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name; 0 0 0
201 31 ▶ m_stream << "# Subtest: " << fullname << endl;
Branch: 3 branches
BranchTrueFalseTotal
m_stream << "# Subtest: " << fullname << endl; 31 0 31
m_stream << "# Subtest: " << fullname << endl; 31 0 31
m_stream << "# Subtest: " << fullname << endl; 31 0 31
202 31 scopes.push_back({0, 0, scope->depth + 1, info.name, fullname});
203 31 scope = &scopes.back();
204 62 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 31 0 31
} 31 0 31
} 31 0 31
} 0 0 0
205  
206 43 void sectionEnded (const SectionStats&) override {
207 43 ▶ if (fatal) return;
Branch: 1 branch
BranchTrueFalseTotal
if (fatal) return; 0 43 43
208 43 ▶ if (!sliding_scope) sliding_scope = scope + 1;
Branch: 1 branch
BranchTrueFalseTotal
if (!sliding_scope) sliding_scope = scope + 1; 22 21 43
209 43 --sliding_scope;
210 43 ▶ if (sliding_scope == &scopes[1]) commitAssertions();
Branch: 1 branch
BranchTrueFalseTotal
if (sliding_scope == &scopes[1]) commitAssertions(); 22 21 43
211 }
212  
213 44 void commitSlidingScope () {
214 44 ▶ if (!sliding_scope) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!sliding_scope) return; 22 22 44
215 22 size_t cnt = &scopes.back() - sliding_scope + 1;
216 53 ▶ while (cnt--) closeCurrentScope();
Branch: 1 branch
BranchTrueFalseTotal
while (cnt--) closeCurrentScope(); 31 22 53
217 22 sliding_scope = nullptr;
218 }
219  
220 31 void closeCurrentScope () {
221 31 ▶ auto name = scope->fullname;
Branch: 1 branch
BranchTrueFalseTotal
auto name = scope->fullname; 31 0 31
222 31 bool failed = scope->failed;
223 31 ▶ startLine() << "1.." << scope->count << endl;
Branch: 4 branches
BranchTrueFalseTotal
startLine() << "1.." << scope->count << endl; 31 0 31
startLine() << "1.." << scope->count << endl; 31 0 31
startLine() << "1.." << scope->count << endl; 31 0 31
startLine() << "1.." << scope->count << endl; 31 0 31
224 31 ▶ if (scope->failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (scope->failed) { 0 31 31
225 0 ▶ startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl;
Branch: 9 branches
BranchTrueFalseTotal
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl; 0 0 0
226 }
227  
228 31 scopes.pop_back();
229 31 ▶ if (scopes.empty()) throw "WTF?";
Branch: 1 branch
BranchTrueFalseTotal
if (scopes.empty()) throw "WTF?"; 0 31 31
230 31 scope = &scopes.back();
231  
232 31 ++scope->count;
233 31 ▶ startLine();
Branch: 1 branch
BranchTrueFalseTotal
startLine(); 31 0 31
234 31 ▶ if (failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (failed) { 0 31 31
235 0 ++scope->failed;
236 0 ▶ m_stream << "not ok";
Branch: 1 branch
BranchTrueFalseTotal
m_stream << "not ok"; 0 0 0
237 }
238 31 ▶ else m_stream << "ok";
Branch: 1 branch
BranchTrueFalseTotal
else m_stream << "ok"; 31 0 31
239 31 ▶ m_stream << " " << scope->count << " - [" << name << "]" << endl;
Branch: 6 branches
BranchTrueFalseTotal
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
m_stream << " " << scope->count << " - [" << name << "]" << endl; 31 0 31
240 31 }
241  
242 143 ostream& startLine () {
243 496 ▶ for (size_t i = 0; i < scope->depth; ++i) m_stream << " ";
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < scope->depth; ++i) m_stream << " "; 353 143 496
244 143 return m_stream;
245 }
246  
247 0 ostream& startErrorLine () {
248 0 ▶ for (size_t i = 0; i < scope->depth; ++i) std::cerr << " ";
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < scope->depth; ++i) std::cerr << " "; 0 0 0
249 0 return std::cerr;
250 }
251  
252 50 void assertionStarting (const AssertionInfo&) override {}
253  
254 50 void assertionEnded (const AssertionStats& stats) override {
255 50 ▶ ostringstream s;
Branch: 1 branch
BranchTrueFalseTotal
ostringstream s; 50 0 50
256 50 ▶ Printer(s, stats).print();
Branch: 2 branches
BranchTrueFalseTotal
Printer(s, stats).print(); 50 0 50
Printer(s, stats).print(); 50 0 50
257 50 assertions.push_back({stats, s.str()});
258 100 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 50 0 50
} 50 0 50
} 50 0 50
} 0 0 0
259  
260 22 void commitAssertions () {
261 72 ▶ for (auto& row : assertions) {
Branch: 1 branch
BranchTrueFalseTotal
for (auto& row : assertions) { 50 22 72
262 50 auto& stats = row.stats;
263 50 ▶ auto result = stats.assertionResult;
Branch: 1 branch
BranchTrueFalseTotal
auto result = stats.assertionResult; 50 0 50
264 // prevent diagnostic messages from counting
265 50 ▶ bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning;
Branch: 4 branches
BranchTrueFalseTotal
bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning; 50 0 50
bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning; 50 0 50
bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning; 50 0 50
bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning; 50 0 50
266  
267 50 Colour::Code color = Colour::None;
268 50 ▶ ostream& ss = result.succeeded() ? startLine() : startErrorLine();
Branch: 4 branches
BranchTrueFalseTotal
ostream& ss = result.succeeded() ? startLine() : startErrorLine(); 50 0 50
ostream& ss = result.succeeded() ? startLine() : startErrorLine(); 50 0 50
ostream& ss = result.succeeded() ? startLine() : startErrorLine(); 50 0 50
ostream& ss = result.succeeded() ? startLine() : startErrorLine(); 0 0 0
269  
270 50 ▶ if (is_test) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_test) { 50 0 50
271 50 ++scope->count;
272 50 ▶ if (result.succeeded()) {
Branch: 2 branches
BranchTrueFalseTotal
if (result.succeeded()) { 50 0 50
if (result.succeeded()) { 50 0 50
273 50 ▶ ss << "ok";
Branch: 1 branch
BranchTrueFalseTotal
ss << "ok"; 50 0 50
274 } else {
275 0 ++scope->failed;
276 0 ▶ ss << "not ok";
Branch: 1 branch
BranchTrueFalseTotal
ss << "not ok"; 0 0 0
277 0 color = Colour::ResultError;
278 }
279 50 ▶ ss << " " << scope->count << " -";
Branch: 3 branches
BranchTrueFalseTotal
ss << " " << scope->count << " -"; 50 0 50
ss << " " << scope->count << " -"; 50 0 50
ss << " " << scope->count << " -"; 50 0 50
280 }
281  
282 {
283 50 ▶ ColourImpl::ColourGuard cg = m_colour->guardColour(color); (void)cg;
Branch: 1 branch
BranchTrueFalseTotal
ColourImpl::ColourGuard cg = m_colour->guardColour(color); (void)cg; 50 0 50
284 50 ▶ ss << row.expr;
Branch: 1 branch
BranchTrueFalseTotal
ss << row.expr; 50 0 50
285 50 ▶ ss << " # at " << result.getSourceInfo();
Branch: 3 branches
BranchTrueFalseTotal
ss << " # at " << result.getSourceInfo(); 50 0 50
ss << " # at " << result.getSourceInfo(); 50 0 50
ss << " # at " << result.getSourceInfo(); 50 0 50
286 50 }
287  
288 50 ▶ ss << endl;
Branch: 1 branch
BranchTrueFalseTotal
ss << endl; 50 0 50
289  
290 50 ▶ if (is_test && !result.succeeded()) {
Branch: 4 branches
BranchTrueFalseTotal
if (is_test && !result.succeeded()) { 50 0 50
if (is_test && !result.succeeded()) { 50 0 50
if (is_test && !result.succeeded()) { 0 50 50
if (is_test && !result.succeeded()) { 0 50 50
291 0 ▶ startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl;
Branch: 8 branches
BranchTrueFalseTotal
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl; 0 0 0
292 }
293 50 }
294 22 assertions.clear();
295 22 }
296  
297 0 void fatalErrorEncountered (StringRef) override {
298 0 fatal = true;
299 0 }
300  
301 0 void benchmarkEnded(const BenchmarkStats<>& stats) override {
302 0 ostream& ss = startLine();
303 0 ++scope->count;
304 0 ss << "ok " << scope->count << " - ";
305 0 ▶ if (stats.info.name.length()) ss << stats.info.name << ": ";
Branch: 1 branch
BranchTrueFalseTotal
if (stats.info.name.length()) ss << stats.info.name << ": "; 0 0 0
306 0 ▶ ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl;
Branch: 6 branches
BranchTrueFalseTotal
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl; 0 0 0
307 0 }
308  
309 private:
310 struct AData {
311 AssertionStats stats;
312 string expr;
313 };
314  
315 vector<Scope> scopes;
316 Scope* scope;
317 Scope* sliding_scope;
318 vector<AData> assertions;
319 bool fatal;
320  
321 static constexpr const uint64_t usec = 1000;
322 static constexpr const uint64_t msec = 1000 * usec;
323 static constexpr const uint64_t sec = 1000 * msec;
324 static constexpr const uint64_t min = 60 * sec;
325  
326 0 static inline string spent (double ns) {
327 double val;
328 const char* units;
329 0 ▶ if (ns < usec) { val = ns; units = "ns"; }
Branch: 1 branch
BranchTrueFalseTotal
if (ns < usec) { val = ns; units = "ns"; } 0 0 0
330 0 ▶ else if (ns < msec) { val = ns / usec; units = "us"; }
Branch: 1 branch
BranchTrueFalseTotal
else if (ns < msec) { val = ns / usec; units = "us"; } 0 0 0
331 0 ▶ else if (ns < sec) { val = ns / static_cast<double>(msec); units = "ms"; }
Branch: 1 branch
BranchTrueFalseTotal
else if (ns < sec) { val = ns / static_cast<double>(msec); units = "ms"; } 0 0 0
332 0 ▶ else if (ns < min) { val = ns / static_cast<double>(sec); units = "s"; }
Branch: 1 branch
BranchTrueFalseTotal
else if (ns < min) { val = ns / static_cast<double>(sec); units = "s"; } 0 0 0
333 0 else { val = ns / static_cast<double>(min); units = "m"; }
334 char buf[30];
335 0 auto sz = snprintf(buf, sizeof(buf), "%.2f %s", val, units);
336 assert(sz > 0);
337 0 ▶ return string(buf, sz);
Branch: 1 branch
BranchTrueFalseTotal
return string(buf, sz); 0 0 0
338 }
339  
340 0 static inline string speed (double ns) {
341 double val;
342 const char* units;
343 0 ▶ if (ns < usec) { val = 1000/ns; units = "M"; }
Branch: 1 branch
BranchTrueFalseTotal
if (ns < usec) { val = 1000/ns; units = "M"; } 0 0 0
344 0 ▶ else if (ns < msec) { val = 1000000/ns; units = "K"; }
Branch: 1 branch
BranchTrueFalseTotal
else if (ns < msec) { val = 1000000/ns; units = "K"; } 0 0 0
345 0 else { val = 1000000000 / ns; units = ""; }
346 char buf[30];
347 0 auto sz = snprintf(buf, sizeof(buf), "%.2f %s/sec", val, units);
348 assert(sz > 0);
349 0 ▶ return string(buf, sz);
Branch: 1 branch
BranchTrueFalseTotal
return string(buf, sz); 0 0 0
350 }
351 };
352  
353 PerlReporter::Scope PerlReporter::context;
354  
355 CATCH_REGISTER_REPORTER("perl", PerlReporter);
356  
357 MODULE = Test::Catch PACKAGE = Test::Catch
358 PROTOTYPES: DISABLE
359  
360 bool _run (SV* count, SV* failed, int depth, ...) {
361 int err;
362 {
363 10 ▶ std::vector<const char*> argv = {"test"};
Branch: 1 branch
BranchTrueFalseTotal
std::vector<const char*> argv = {"test"}; 5 0 5
364  
365 9 ▶ for (int i = 3; i < items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (int i = 3; i < items; ++i) { 4 5 9
366 4 SV* arg = ST(i);
367 4 ▶ SvGETMAGIC(arg);
Branch: 1 branch
BranchTrueFalseTotal
SvGETMAGIC(arg); 4 0 4
368 4 ▶ if (!SvOK(arg)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(arg)) continue; 0 4 4
369 4 ▶ argv.push_back(SvPV_nolen(arg));
Branch: 1 branch
BranchTrueFalseTotal
argv.push_back(SvPV_nolen(arg)); 4 0 4
370 }
371  
372 5 ▶ argv.push_back("-i");
Branch: 1 branch
BranchTrueFalseTotal
argv.push_back("-i"); 5 0 5
373 5 ▶ argv.push_back("-r");
Branch: 1 branch
BranchTrueFalseTotal
argv.push_back("-r"); 5 0 5
374 5 ▶ argv.push_back("perl");
Branch: 2 branches
BranchTrueFalseTotal
argv.push_back("perl"); 5 0 5
argv.push_back("perl"); 5 0 5
375  
376 10 ▶ session.useConfigData({});
Branch: 2 branches
BranchTrueFalseTotal
session.useConfigData({}); 5 0 5
session.useConfigData({}); 5 0 5
377 5 ▶ err = session.applyCommandLine(argv.size(), argv.data());
Branch: 1 branch
BranchTrueFalseTotal
err = session.applyCommandLine(argv.size(), argv.data()); 5 0 5
378 5 }
379 5 ▶ if (err) croak("session.applyCommandLine: error %d", err);
Branch: 1 branch
BranchTrueFalseTotal
if (err) croak("session.applyCommandLine: error %d", err); 0 5 5
380  
381 5 PerlReporter::context.count = SvUV(count);
382 5 PerlReporter::context.failed = SvUV(failed);
383 5 PerlReporter::context.depth = depth;
384  
385 5 RETVAL = session.run() == 0;
386  
387 5 sv_setuv(count, PerlReporter::context.count);
388 5 sv_setuv(failed, PerlReporter::context.failed);
389 }
« t/bench.cc ↑ Summary t/test.cc »