Catch_xsgen.cc

filter: Statementstmt 93.7% 15 / 16 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 55.8% 19 / 34 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« t/test.cc ↑ Summary blib/arch/Test/Catch.x/info »
1 /*
2 * This file was generated automatically by XS::Install::FrozenShit::ParseXS version 3.57 from the
3 * contents of Catch.xs. Do not edit this file, edit Catch.xs instead.
4 *
5 * ANY CHANGES MADE HERE WILL BE LOST!
6 *
7 */
8  
9 #line 1 "Catch.xs"
10 #include <math.h> // this fixes win32 because <cmath> that is included by <catch.hpp> breaks <perl.h> unless previously included <math.h>
11 #include <vector>
12 #include <iostream>
13 #include <catch2/catch_session.hpp>
14 #include <catch2/internal/catch_string_manip.hpp>
15 #include <catch2/internal/catch_console_colour.hpp>
16 #include <catch2/reporters/catch_reporter_registrars.hpp>
17 #include <catch2/reporters/catch_reporter_streaming_base.hpp>
18 #include <xsheader.h>
19  
20 using namespace Catch;
21 using namespace std;
22  
23 static Catch::Session session;
24  
25 struct Printer {
26 Printer (ostream& _stream, const AssertionStats& _stats)
27 : stream(_stream), result(_stats.assertionResult), messages(_stats.infoMessages), itMessage(_stats.infoMessages.begin()) {}
28  
29 void print () {
30 itMessage = messages.begin();
31  
32 switch (result.getResultType()) {
33 case ResultWas::Ok:
34 case ResultWas::ExplicitSkip:
35 printOriginalExpression();
36 printReconstructedExpression();
37 printRemainingMessages();
38 break;
39 case ResultWas::ExpressionFailed:
40 printOriginalExpression();
41 printReconstructedExpression();
42 if (result.isOk()) printIssue(" # TODO");
43 printRemainingMessages();
44 break;
45 case ResultWas::ThrewException:
46 printIssue("unexpected exception ");
47 printExpressionWas();
48 printRemainingMessages();
49 break;
50 case ResultWas::FatalErrorCondition:
51 printIssue("fatal error condition with message:");
52 printMessage();
53 printExpressionWas();
54 printRemainingMessages();
55 break;
56 case ResultWas::DidntThrowException:
57 printIssue("expected exception, got none");
58 printExpressionWas();
59 printRemainingMessages();
60 break;
61 case ResultWas::Info:
62 stream << "#info";
63 printMessage();
64 printRemainingMessages();
65 break;
66 case ResultWas::Warning:
67 stream << "#warning";
68 printMessage();
69 printRemainingMessages();
70 break;
71 case ResultWas::ExplicitFailure:
72 printIssue("explicitly");
73 printRemainingMessages();
74 break;
75 // These cases are here to prevent compiler warnings
76 case ResultWas::Unknown:
77 case ResultWas::FailureBit:
78 case ResultWas::Exception:
79 stream << "** unsupported ResultWas (should not happenned) **";
80 break;
81 }
82 }
83  
84 private:
85 static inline void expr_replace (string& expr, const string& c, const string& subs) {
86 size_t pos = expr.find(c);
87 while (pos < expr.length()) {
88 expr.replace(pos, c.length(), subs);
89 pos = expr.find(c, pos + subs.length());
90 }
91 }
92  
93 void printIssue (const string& issue) const {
94 stream << " " << issue;
95 }
96  
97 void printExpressionWas () {
98 if (!result.hasExpression()) return;
99 stream << "; expression was:";
100 printOriginalExpression();
101 }
102  
103 void printOriginalExpression () const {
104 if (result.hasExpression()) stream << " " << result.getExpression();
105 }
106  
107 void printReconstructedExpression () const {
108 if (!result.hasExpandedExpression()) return;
109 stream << " for: ";
110 string expr = result.getExpandedExpression();
111 // prevent "str" == "str" splitting into several lines
112 expr_replace(expr, "\"\r\n==\r\n\"", "\" == \"");
113 expr_replace(expr, "\"\n==\n\"", "\" == \"");
114 // replace remaining newlines in text/expressions
115 expr_replace(expr, "\r", "\\r");
116 expr_replace(expr, "\n", "\\n");
117 stream << expr;
118 }
119  
120 void printMessage () {
121 if (itMessage != messages.end()) {
122 stream << " '" << itMessage->message << "'";
123 ++itMessage;
124 }
125 }
126  
127 void printRemainingMessages () {
128 if (itMessage == messages.cend()) return;
129  
130 // using messages.end() directly (or auto) yields compilation error:
131 auto itEnd = messages.cend();
132 const size_t N = static_cast<size_t>(std::distance(itMessage, itEnd));
133  
134 stream << " with " << pluralise( N, "message" ) << ":";
135  
136 for (; itMessage != itEnd; ++itMessage) {
137 // If this assertion is a warning ignore any INFO messages
138 if (itMessage->type != ResultWas::Info) {
139 stream << "\n# " << itMessage->message;
140 }
141 }
142 }
143  
144 ostream& stream;
145 AssertionResult const& result;
146 vector<MessageInfo> messages;
147 vector<MessageInfo>::const_iterator itMessage;
148 };
149  
150  
151 struct PerlReporter : StreamingReporterBase {
152 struct Scope {
153 uint32_t count;
154 uint32_t failed;
155 uint32_t depth;
156 string name;
157 string fullname;
158 };
159 static Scope context;
160  
161 static string getDescription () { return "Reports test results in perl test-harness compatible format"; }
162  
163 PerlReporter (ReporterConfig&& config) : StreamingReporterBase(std::move(config)), scope(), sliding_scope(), fatal() {
164 m_preferences.shouldRedirectStdOut = false;
165 m_preferences.shouldReportAllAssertions = true;
166 }
167  
168 void noMatchingTestCases (StringRef unmatchedSpec) override {
169 startErrorLine() << "# No test cases matched '" << unmatchedSpec << "'" << endl;
170 }
171  
172 void reportInvalidTestSpec(StringRef invalidArgument) override {
173 startErrorLine() << "# invalid argument '" << invalidArgument << "'" << endl;
174 }
175  
176 void testRunStarting (const TestRunInfo&) override {
177 scopes.push_back(context);
178 scope = &scopes.back();
179 }
180  
181 void testRunEnded (const TestRunStats&) override {
182 context.count = scope->count;
183 context.failed = scope->failed;
184 scopes.clear();
185 scope = nullptr;
186 }
187  
188 void testCaseStarting (const TestCaseInfo&) override {}
189  
190 void testCaseEnded (const TestCaseStats&) override {
191 if (fatal) {
192 commitAssertions();
193 sliding_scope = &scopes[1];
194 }
195 commitSlidingScope();
196 }
197  
198 void sectionStarting (const SectionInfo& info) override {
199 if (sliding_scope && sliding_scope->name == info.name) {
200 ++sliding_scope;
201 return;
202 }
203 commitSlidingScope();
204 startScope(info);
205 }
206  
207 void startScope (const SectionInfo& info) {
208 startLine();
209 auto fullname = scope->fullname.length() ? (scope->fullname + " / " + info.name) : info.name;
210 m_stream << "# Subtest: " << fullname << endl;
211 scopes.push_back({0, 0, scope->depth + 1, info.name, fullname});
212 scope = &scopes.back();
213 }
214  
215 void sectionEnded (const SectionStats&) override {
216 if (fatal) return;
217 if (!sliding_scope) sliding_scope = scope + 1;
218 --sliding_scope;
219 if (sliding_scope == &scopes[1]) commitAssertions();
220 }
221  
222 void commitSlidingScope () {
223 if (!sliding_scope) return;
224 size_t cnt = &scopes.back() - sliding_scope + 1;
225 while (cnt--) closeCurrentScope();
226 sliding_scope = nullptr;
227 }
228  
229 void closeCurrentScope () {
230 auto name = scope->fullname;
231 bool failed = scope->failed;
232 startLine() << "1.." << scope->count << endl;
233 if (scope->failed) {
234 startErrorLine() << "# Looks like you failed " << scope->failed << " test of " << scope->count << " at [" << name << "]." << endl;
235 }
236  
237 scopes.pop_back();
238 if (scopes.empty()) throw "WTF?";
239 scope = &scopes.back();
240  
241 ++scope->count;
242 startLine();
243 if (failed) {
244 ++scope->failed;
245 m_stream << "not ok";
246 }
247 else m_stream << "ok";
248 m_stream << " " << scope->count << " - [" << name << "]" << endl;
249 }
250  
251 ostream& startLine () {
252 for (size_t i = 0; i < scope->depth; ++i) m_stream << " ";
253 return m_stream;
254 }
255  
256 ostream& startErrorLine () {
257 for (size_t i = 0; i < scope->depth; ++i) std::cerr << " ";
258 return std::cerr;
259 }
260  
261 void assertionStarting (const AssertionInfo&) override {}
262  
263 void assertionEnded (const AssertionStats& stats) override {
264 ostringstream s;
265 Printer(s, stats).print();
266 assertions.push_back({stats, s.str()});
267 }
268  
269 void commitAssertions () {
270 for (auto& row : assertions) {
271 auto& stats = row.stats;
272 auto result = stats.assertionResult;
273 // prevent diagnostic messages from counting
274 bool is_test = result.getResultType() != ResultWas::Info && result.getResultType() != ResultWas::Warning;
275  
276 Colour::Code color = Colour::None;
277 ostream& ss = result.succeeded() ? startLine() : startErrorLine();
278  
279 if (is_test) {
280 ++scope->count;
281 if (result.succeeded()) {
282 ss << "ok";
283 } else {
284 ++scope->failed;
285 ss << "not ok";
286 color = Colour::ResultError;
287 }
288 ss << " " << scope->count << " -";
289 }
290  
291 {
292 ColourImpl::ColourGuard cg = m_colour->guardColour(color); (void)cg;
293 ss << row.expr;
294 ss << " # at " << result.getSourceInfo();
295 }
296  
297 ss << endl;
298  
299 if (is_test && !result.succeeded()) {
300 startErrorLine() << "#\e[1;31m Failed test in section [" << scope->fullname << "] at " << result.getSourceInfo() << "\e[0m" << endl;
301 }
302 }
303 assertions.clear();
304 }
305  
306 void fatalErrorEncountered (StringRef) override {
307 fatal = true;
308 }
309  
310 void benchmarkEnded(const BenchmarkStats<>& stats) override {
311 ostream& ss = startLine();
312 ++scope->count;
313 ss << "ok " << scope->count << " - ";
314 if (stats.info.name.length()) ss << stats.info.name << ": ";
315 ss << speed(stats.mean.point.count()) << ", " << spent(stats.mean.point.count()) << endl;
316 }
317  
318 private:
319 struct AData {
320 AssertionStats stats;
321 string expr;
322 };
323  
324 vector<Scope> scopes;
325 Scope* scope;
326 Scope* sliding_scope;
327 vector<AData> assertions;
328 bool fatal;
329  
330 static constexpr const uint64_t usec = 1000;
331 static constexpr const uint64_t msec = 1000 * usec;
332 static constexpr const uint64_t sec = 1000 * msec;
333 static constexpr const uint64_t min = 60 * sec;
334  
335 static inline string spent (double ns) {
336 double val;
337 const char* units;
338 if (ns < usec) { val = ns; units = "ns"; }
339 else if (ns < msec) { val = ns / usec; units = "us"; }
340 else if (ns < sec) { val = ns / static_cast<double>(msec); units = "ms"; }
341 else if (ns < min) { val = ns / static_cast<double>(sec); units = "s"; }
342 else { val = ns / static_cast<double>(min); units = "m"; }
343 char buf[30];
344 auto sz = snprintf(buf, sizeof(buf), "%.2f %s", val, units);
345 assert(sz > 0);
346 return string(buf, sz);
347 }
348  
349 static inline string speed (double ns) {
350 double val;
351 const char* units;
352 if (ns < usec) { val = 1000/ns; units = "M"; }
353 else if (ns < msec) { val = 1000000/ns; units = "K"; }
354 else { val = 1000000000 / ns; units = ""; }
355 char buf[30];
356 auto sz = snprintf(buf, sizeof(buf), "%.2f %s/sec", val, units);
357 assert(sz > 0);
358 return string(buf, sz);
359 }
360 };
361  
362 PerlReporter::Scope PerlReporter::context;
363  
364 CATCH_REGISTER_REPORTER("perl", PerlReporter);
365  
366 #line 367 "Catch_xsgen.cc"
367 #ifndef PERL_UNUSED_VAR
368 # define PERL_UNUSED_VAR(var) if (0) var = var
369 #endif
370  
371 #ifndef dVAR
372 # define dVAR dNOOP
373 #endif
374  
375  
376 /* This stuff is not part of the API! You have been warned. */
377 #ifndef PERL_VERSION_DECIMAL
378 # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
379 #endif
380 #ifndef PERL_DECIMAL_VERSION
381 # define PERL_DECIMAL_VERSION \
382 PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
383 #endif
384 #ifndef PERL_VERSION_GE
385 # define PERL_VERSION_GE(r,v,s) \
386 (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
387 #endif
388 #ifndef PERL_VERSION_LE
389 # define PERL_VERSION_LE(r,v,s) \
390 (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
391 #endif
392  
393 /* XS_INTERNAL is the explicit static-linkage variant of the default
394 * XS macro.
395 *
396 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
397 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
398 * for anything but the BOOT XSUB.
399 *
400 * See XSUB.h in core!
401 */
402  
403  
404 /* TODO: This might be compatible further back than 5.10.0. */
405 #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
406 # undef XS_EXTERNAL
407 # undef XS_INTERNAL
408 # if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
409 # define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
410 # define XS_INTERNAL(name) STATIC XSPROTO(name)
411 # endif
412 # if defined(__SYMBIAN32__)
413 # define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
414 # define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
415 # endif
416 # ifndef XS_EXTERNAL
417 # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
418 # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
419 # define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
420 # else
421 # ifdef __cplusplus
422 # define XS_EXTERNAL(name) extern "C" XSPROTO(name)
423 # define XS_INTERNAL(name) static XSPROTO(name)
424 # else
425 # define XS_EXTERNAL(name) XSPROTO(name)
426 # define XS_INTERNAL(name) STATIC XSPROTO(name)
427 # endif
428 # endif
429 # endif
430 #endif
431  
432 /* perl >= 5.10.0 && perl <= 5.15.1 */
433  
434  
435 /* The XS_EXTERNAL macro is used for functions that must not be static
436 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
437 * macro defined, the best we can do is assume XS is the same.
438 * Dito for XS_INTERNAL.
439 */
440 #ifndef XS_EXTERNAL
441 # define XS_EXTERNAL(name) XS(name)
442 #endif
443 #ifndef XS_INTERNAL
444 # define XS_INTERNAL(name) XS(name)
445 #endif
446  
447 /* Now, finally, after all this mess, we want an XS::Install::FrozenShit::ParseXS
448 * internal macro that we're free to redefine for varying linkage due
449 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
450 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
451 */
452  
453 #undef XS_EUPXS
454 #if defined(PERL_EUPXS_ALWAYS_EXPORT)
455 # define XS_EUPXS(name) XS_EXTERNAL(name)
456 #else
457 /* default to internal */
458 # define XS_EUPXS(name) XS_INTERNAL(name)
459 #endif
460  
461 #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
462 #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
463  
464 /* prototype to pass -Wmissing-prototypes */
465 STATIC void
466 S_croak_xs_usage(const CV *const cv, const char *const params);
467  
468 STATIC void
469 S_croak_xs_usage(const CV *const cv, const char *const params)
470 {
471 const GV *const gv = CvGV(cv);
472  
473 PERL_ARGS_ASSERT_CROAK_XS_USAGE;
474  
475 if (gv) {
476 const char *const gvname = GvNAME(gv);
477 const HV *const stash = GvSTASH(gv);
478 const char *const hvname = stash ? HvNAME(stash) : NULL;
479  
480 if (hvname)
481 Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
482 else
483 Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
484 } else {
485 /* Pants. I don't think that it should be possible to get here. */
486 Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
487 }
488 }
489 #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
490  
491 #define croak_xs_usage S_croak_xs_usage
492  
493 #endif
494  
495 /* NOTE: the prototype of newXSproto() is different in versions of perls,
496 * so we define a portable version of newXSproto()
497 */
498 #ifdef newXS_flags
499 #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
500 #else
501 #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
502 #endif /* !defined(newXS_flags) */
503  
504 #if PERL_VERSION_LE(5, 21, 5)
505 # define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
506 #else
507 # define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
508 #endif
509  
510 /* simple backcompat versions of the TARGx() macros with no optimisation */
511 #ifndef TARGi
512 # define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv)
513 # define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv)
514 # define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv)
515 #endif
516  
517 #line 518 "Catch_xsgen.cc"
518  
519  
520 5 XS_EUPXS(XS_Test__Catch__run)
521 {
522 5 dVAR; dXSARGS;
523 5 ▶ if (items < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 3) 0 5 5
524 0 croak_xs_usage(cv, "count, failed, depth, ...");
525 {
526 bool RETVAL;
527 5 SV* count = ST(0)
528 ;
529 5 SV* failed = ST(1)
530 ;
531 5 int depth = (int)SvIV(ST(2))
532 ;
533 #line 361 "Catch.xs"
534 int err;
535 {
536 std::vector<const char*> argv = {"test"};
537  
538 for (int i = 3; i < items; ++i) {
539 SV* arg = ST(i);
540 SvGETMAGIC(arg);
541 if (!SvOK(arg)) continue;
542 argv.push_back(SvPV_nolen(arg));
543 }
544  
545 argv.push_back("-i");
546 argv.push_back("-r");
547 argv.push_back("perl");
548  
549 session.useConfigData({});
550 err = session.applyCommandLine(argv.size(), argv.data());
551 }
552 if (err) croak("session.applyCommandLine: error %d", err);
553  
554 PerlReporter::context.count = SvUV(count);
555 PerlReporter::context.failed = SvUV(failed);
556 PerlReporter::context.depth = depth;
557  
558 RETVAL = session.run() == 0;
559  
560 sv_setuv(count, PerlReporter::context.count);
561 sv_setuv(failed, PerlReporter::context.failed);
562 #line 563 "Catch_xsgen.cc"
563 5 ▶ ST(0) = boolSV(RETVAL);
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = boolSV(RETVAL); 5 0 5
564 }
565 5 XSRETURN(1);
566 5 ▶}
Branch: 7 branches
BranchTrueFalseTotal
} 5 0 5
} 5 0 5
} 0 0 0
} 0 0 0
} 0 0 0
} 0 0 0
} 0 0 0
567  
568 #ifdef __cplusplus
569 extern "C" {
570 #endif
571  
572 2 XS_EXTERNAL(boot_Test__Catch)
573 {
574 #if PERL_VERSION_LE(5, 21, 5)
575 dVAR; dXSARGS;
576 #else
577 2 dVAR; dXSBOOTARGSXSAPIVERCHK;
578 #endif
579 #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
580 char* file = __FILE__;
581 #else
582 2 const char* file = __FILE__;
583 #endif
584  
585 PERL_UNUSED_VAR(file);
586  
587 PERL_UNUSED_VAR(cv); /* -W */
588 PERL_UNUSED_VAR(items); /* -W */
589 #if PERL_VERSION_LE(5, 21, 5)
590 XS_VERSION_BOOTCHECK;
591 # ifdef XS_APIVERSION_BOOTCHECK
592 XS_APIVERSION_BOOTCHECK;
593 # endif
594 #endif
595  
596 2 newXS_deffile("Test::Catch::_run", XS_Test__Catch__run);
597 #if PERL_VERSION_LE(5, 21, 5)
598 # if PERL_VERSION_GE(5, 9, 0)
599 if (PL_unitcheckav)
600 call_list(PL_scopestack_ix, PL_unitcheckav);
601 # endif
602 XSRETURN_YES;
603 #else
604 2 Perl_xs_boot_epilog(aTHX_ ax);
605 #endif
606 2 }
607  
608 #ifdef __cplusplus
609 }
610 #endif
« t/test.cc ↑ Summary blib/arch/Test/Catch.x/info »