blib/lib/Test2/Formatter/YAMLEnhancedTAP.pm

filter: Statementstmt 100% 55 / 55 Branchbran 70.0% 14 / 20 Conditioncond 65.3% 17 / 26 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 79.6% 98 / 123 CC 21 SCAR 29.8
CC
21
Cov
85%
write
25.0
BEGIN
1.0
BEGIN
1.0
CRAP 19.7
↑ Summary
1 package Test2::Formatter::YAMLEnhancedTAP;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use TAP::Parser::YAMLish::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'Test2::Formatter::TAP';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.0.5';
9  
10 # Private: TAP::Parser::YAMLish::Writer instance to write YAML TAP snippets
11 # it didn't really like YAML::PP in the output for whatever reason
12 1 my $_yaml_writer = TAP::Parser::YAMLish::Writer->new;
13  
14 1 ▶sub _yamilify_message {
Subroutine _yamilify_message: called CC=1 SCAR=0.0
15 1 my ($self, $frame, $event, $message) = @_;
16 1 my (undef, $filename, $lineno, $caller_class) = @{$frame};
17  
18 1 my $yaml = "";
19 # Cleanup comments
20 1 $message =~ s/#\s+//gm;
21 # Cleanup extra newlines
22 1 chomp($message);
23  
24 # Build the YAML.
25 1 $_yaml_writer->write({
26 at => {
27 test_num => 0,
28 filename => $filename,
29 line => $lineno
30 },
31 emitter => $caller_class,
32 message => $message
33 }, \$yaml);
34  
35 # indent two spaces for the TAP parser.
36 1 $yaml =~ s/^/ /mg;
37 # add an extra newline for readability
38 1 $yaml .= "\n";
39 1 return $yaml;
40 }
41  
42 #
43 5 ▶sub print_optimal_pass {
Subroutine print_optimal_pass: called CC=1 SCAR=0.0
Pod undocumented
44 5 my $self = shift;
45 5 my $ret = $self->SUPER::print_optimal_pass(@_);
46 5 $self->{_optimal_pass_happened} = $ret;
47 5 return $ret;
48 }
49  
50 5 ▶sub write {
Subroutine write: called CC=21 SCAR=32.2
Pod documented
51 5 my ($self, $e, $num, $f) = @_;
52  
53 # The most common case, a pass event with no amnesty and a normal name.
54 5 ▶ return if $self->print_optimal_pass($e, $num);
Branch: 1 branch
BranchTrueFalseTotal
if $self->print_optimal_pass($e, $num) 0 5 5
55  
56 5 ▶ $f ||= $e->facet_data;
Condition33%1/3
$f ||= $e->facet_data
l!l&&r!l&&!r
500
MC/DC0%0/2
$f ||= $e->facet_data
$f $e->facet_data
Truth table33%1/3
A ||= B
A= $fB= $e->facet_data
ABresult
1X1
011
000
57 5 my $frame = $f->{trace}{frame};
58  
59 5 ▶ $self->encoding($f->{control}->{encoding}) if $f->{control}->{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"encoding"} 0 5 5
60  
61 5 ▶ my @tap = $self->event_tap($f, $num) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@tap) = $self->event_tap($f, $num) or return 4 1 5
62  
63 4 ▶ $self->{MADE_ASSERTION} = 1 if $f->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"assert"} 1 3 4
64  
65 4 ▶ my $nesting = $f->{trace}->{nested} || 0;
Condition50%1/2
$f->{'trace'}{'nested'} || 0
l!l
04
MC/DC0%0/1
$f->{'trace'}{'nested'} || 0
$f->{'trace'}{'nested'}
Truth table50%1/2
A
A= $f->{'trace'}{'nested'}
Aresult
11
00
66 4 my $handles = $self->{handles};
67 4 my $indent = ' ' x $nesting;
68  
69 # Local is expensive! Only do it if we really need to.
70 4 ▶ local ($\, $,) = (undef, '') if $\ || $,;
Branch: 1 branch
BranchTrueFalseTotal
if $\ or $, 0 4 4
Condition33%1/3
$\ or $,
l!l&&r!l&&!r
004
MC/DC0%0/2
$\ or $,
$\ $,
Truth table33%1/3
A or B
A= $\B= $,
ABresult
1X1
011
000
71  
72 4 for my $set (@tap) {
73 4 my ($hid, $msg) = @$set;
74 4 ▶ next unless $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg 0 4 4
75 4 ▶ my $io = $handles->[$hid] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $io = $handles->[$hid] or next 4 0 4
76  
77 print $io "\n"
78 if $ENV{HARNESS_ACTIVE}
79 && $hid == $self->SUPER::OUT_ERR()
80 4 ▶ && $self->{_LAST_FH} != $io
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} and $hid == $self->SUPER::OUT_ERR and $self->{"_LAST_FH"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test / 1 3 4
Condition77%7/9
$ENV{"HARNESS_ACTIVE"} and $hid == $self->SUPER::OUT_ERR and $self->{"_LAST_FH"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test /
!ll&&!rl&&r
301
$ENV{"HARNESS_ACTIVE"} and $hid == $self->SUPER::OUT_ERR and $self->{"_LAST_FH"} != $io
!ll&&!rl&&r
211
$ENV{"HARNESS_ACTIVE"} and $hid == $self->SUPER::OUT_ERR
!ll&&!rl&&r
022
MC/DC50%2/4
$ENV{"HARNESS_ACTIVE"} and $hid == $self->SUPER::OUT_ERR and $self->{"_LAST_FH"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test /
$ENV{"HARNESS_ACTIVE"} $hid == $self->SUPER::OUT_ERR $self->{"_LAST_FH"} != $io $msg =~ /^#\s*Failed( \(TODO\))? test /
Truth table60%3/5
A and B and C and D
A= $ENV{"HARNESS_ACTIVE"}B= $hid == $self->SUPER::OUT_ERRC= $self->{"_LAST_FH"} != $ioD= $msg =~ /^#\s*Failed( \(TODO\))? test /
ABCDresult
0XXX0
10XX0
110X0
11100
11111
81 && $msg =~ m/^#\s*Failed( \(TODO\))? test /;
82  
83 4 my (undef, $filename, $lineno, $caller_class) = @{$frame};
84  
85 4 my $is_comment = $msg =~ m/^#/;
86 4 my $is_not_subtest_call = $caller_class ne 'Test::More::subtest';
87 4 my $is_failed_msg = $msg =~ m/Looks like you failed/;
88 4 my $filename_not_within_t_dir = $filename =~ m/^(t|xt)/;
89  
90 4 ▶ $msg = $self->_yamilify_message($frame, $e, $msg)
Branch: 1 branch
BranchTrueFalseTotal
if $is_comment and $is_not_subtest_call and not $is_failed_msg and $filename_not_within_t_dir 1 3 4
Condition77%7/9
$is_comment and $is_not_subtest_call and not $is_failed_msg and $filename_not_within_t_dir
!ll&&!rl&&r
301
$is_comment and $is_not_subtest_call and not $is_failed_msg
!ll&&!rl&&r
211
$is_comment and $is_not_subtest_call
!ll&&!rl&&r
202
MC/DC50%2/4
$is_comment and $is_not_subtest_call and not $is_failed_msg and $filename_not_within_t_dir
$is_comment $is_not_subtest_call not $is_failed_msg $filename_not_within_t_dir
Truth table60%3/5
A and B and not(C) and D
A= $is_commentB= $is_not_subtest_callC= not $is_failed_msgD= $filename_not_within_t_dir
ABCDresult
0XXX0
10XX0
110X0
11100
11111
91 if $is_comment
92 && $is_not_subtest_call
93 && !$is_failed_msg
94 && $filename_not_within_t_dir;
95  
96 4 ▶ $msg =~ s/^/$indent/mg if $nesting;
Branch: 1 branch
BranchTrueFalseTotal
if $nesting 0 4 4
97 4 print $io $msg;
98 4 $self->{_LAST_FH} = $io;
99 }
100 }
101  
102 1 1;
103 __END__
↑ Summary