DOM.pm

filter: Statementstmt 99.2% 257 / 259 Branchbran 85.6% 125 / 146 Conditioncond 84.3% 70 / 83 MC/DCmcdc 67.3% 31 / 46 Subroutinesub 100% 24 / 24 Podpod 100% 5 / 5 totaltotal 90.9% 512 / 563 CC 113 SCAR 40.6
CC
113
Cov
93%
new
88.3
_entry_to_tapline
17.6
preprocess_ignorelines
5.1
CRAP 57.9
↑ Summary DOM/Archive.pm »
1 package TAP::DOM;
2 # git description: v0.97-7-g357ca13
3  
4 21 our $AUTHORITY = 'cpan:SCHWIGON';
5 # ABSTRACT: TAP as Document Object Model.
6 21 $TAP::DOM::VERSION = '0.98';
7 21 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 ▶use TAP::DOM::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use TAP::DOM::Summary;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use TAP::DOM::DocumentData;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use TAP::DOM::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use TAP::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use TAP::Parser::Aggregator;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 21 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 21 our $IS_PLAN = 1;
21 21 our $IS_OK = 2;
22 21 our $IS_TEST = 4;
23 21 our $IS_COMMENT = 8;
24 21 our $IS_UNKNOWN = 16;
25 21 our $IS_ACTUAL_OK = 32;
26 21 our $IS_VERSION = 64;
27 21 our $IS_PRAGMA = 128;
28 21 our $IS_UNPLANNED = 256;
29 21 our $IS_BAILOUT = 512;
30 21 our $IS_YAML = 1024;
31 21 our $HAS_SKIP = 2048;
32 21 our $HAS_TODO = 4096;
33  
34 21 our @tap_dom_args = (qw(ignore
35 ignorelines
36 dontignorelines
37 usebitsets
38 disable_global_kv_data
39 put_dangling_kv_data_under_lazy_plan
40 document_data_prefix
41 document_data_ignore
42 preprocess_ignorelines
43 preprocess_tap
44 noempty_tap
45 lowercase_fieldnames
46 lowercase_fieldvalues
47 trim_fieldvalues
48 ));
49  
50 21 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 21 our @EXPORT_OK = qw( $IS_PLAN
52 $IS_OK
53 $IS_TEST
54 $IS_COMMENT
55 $IS_UNKNOWN
56 $IS_ACTUAL_OK
57 $IS_VERSION
58 $IS_PRAGMA
59 $IS_UNPLANNED
60 $IS_BAILOUT
61 $IS_YAML
62 $HAS_SKIP
63 $HAS_TODO
64 );
65 21 our %EXPORT_TAGS = (constants => [ qw( $IS_PLAN
66 $IS_OK
67 $IS_TEST
68 $IS_COMMENT
69 $IS_UNKNOWN
70 $IS_ACTUAL_OK
71 $IS_VERSION
72 $IS_PRAGMA
73 $IS_UNPLANNED
74 $IS_BAILOUT
75 $IS_YAML
76 $HAS_SKIP
77 $HAS_TODO
78 ) ] );
79  
80 21 our %mnemonic = (
81 severity => {
82 1 => 'ok',
83 2 => 'ok_todo',
84 3 => 'ok_skip',
85 4 => 'notok_todo',
86 5 => 'notok',
87 6 => 'notok_skip', # forbidden TAP semantic, should never happen
88 },
89 );
90  
91 # TAP severity level definition:
92 #
93 # |--------+---------------+----------+--------------+----------+------------+----------|
94 # | *type* | is_ok | has_todo | is_actual_ok | has_skip | *mnemonic* | *tapcon* |
95 # |--------+---------------+----------+--------------+----------+------------+----------|
96 # | plan | undef | undef | undef | 1 | ok_skip | 3 |
97 # |--------+---------------+----------+--------------+----------+------------+----------|
98 # | test | 1 | 0 | 0 | 0 | ok | 1 |
99 # | test | 1 | 1 | 1 | 0 | ok_todo | 2 |
100 # | test | 1 | 0 | 0 | 1 | ok_skip | 3 |
101 # | test | 1 | 1 | 0 | 0 | notok_todo | 4 |
102 # | test | 0 | 0 | 0 | 0 | notok | 5 |
103 # | test | 0 | 0 | 0 | 1 | notok_skip | 6 |
104 # |--------+---------------+----------+--------------+----------+------------+----------|
105 # | | | | | | missing | 0 |
106 # |--------+---------------+----------+--------------+----------+------------+----------|
107 # | *type* | *value* | | | | | |
108 # |--------+---------------+----------+--------------+----------+------------+----------|
109 # | pragma | +tapdom_error | | | | notok | 5 |
110 # |--------+---------------+----------+--------------+----------+------------+----------|
111  
112 21 our $severity = {};
113 #
114 # {type} {is_ok} {has_todo} {is_actual_ok} {has_skip} = $severity;
115 #
116 21 $severity->{plan} {''} {0} {0} {1} = 3; # ok_skip
117 21 $severity->{test} {1} {0} {0} {0} = 1; # ok
118 21 $severity->{test} {1} {1} {1} {0} = 2; # ok_todo
119 21 $severity->{test} {1} {0} {0} {1} = 3; # ok_skip
120 21 $severity->{test} {1} {1} {0} {0} = 4; # notok_todo
121 21 $severity->{test} {0} {0} {0} {0} = 5; # notok
122 21 $severity->{test} {0} {0} {0} {1} = 6; # notok_skip
123  
124 21 our $obvious_tap_line = qr/(1\.\.|ok\s|not\s+ok\s|#|\s|tap\s+version|pragma|Bail out!)/i;
125  
126 21 our $noempty_tap = "pragma +tapdom_error\n# document was empty";
127  
128 use Class::XSAccessor
129 21 chained => 1,
130 accessors => [qw( plan
131 lines
132 pragmas
133 tests_planned
134 tests_run
135 version
136 is_good_plan
137 skip_all
138 start_time
139 end_time
140 has_problems
141 exit
142 parse_errors
143 parse_errors_msgs
144 summary
145 tapdom_config
146 document_data
147 21 ▶ )];
Subroutine BEGIN: called CC=1 SCAR=0.0
148  
149 sub _capture_group {
150 146 ▶ my ($s, $n) = @_; substr($s, $-[$n], $+[$n] - $-[$n]);
Subroutine _capture_group: called CC=1 SCAR=0.0
151 }
152  
153 # Optimize the TAP text before parsing it.
154 sub preprocess_ignorelines {
155 4 ▶ my %args = @_;
Subroutine preprocess_ignorelines: called CC=5 SCAR=16.2
Pod documented
156  
157 4 ▶ if ($args{tap}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"tap"}) 4 0 4
158  
159 4 ▶ if (my $ignorelines = $args{ignorelines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ignorelines = $args{"ignorelines"}) 4 0 4
160 4 my $dontignorelines = $args{dontignorelines};
161 4 my $tap = $args{tap};
162 4 ▶ if ($dontignorelines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dontignorelines) { } 2 2 4
163 # HIGHLY EXPERIMENTAL!
164 #
165 # We convert the 'dontignorelines' regex into a negative-lookahead
166 # condition and prepend it before the 'ignorelines'.
167 #
168 # Why? Because we want to utilize the cleanup in one single
169 # operation as fast as the regex engine can do it.
170 2 ▶ my $re_dontignorelines = $dontignorelines ? "(?!$dontignorelines)" : '';
Branch: 1 branch
BranchTrueFalseTotal
$dontignorelines ? : 2 0 2
171 2 my $re_filter = qr/^$re_dontignorelines$ignorelines.*[\r\n]*/m; # the /m scope needs to be here!
172 2 $tap =~ s/$re_filter//g;
173 } else {
174 2 $tap =~ s/^$ignorelines.*[\r\n]*//mg;
175 }
176 4 $args{tap} = $tap;
177 4 delete $args{ignorelines}; # don't try it again during parsing later
178 }
179 }
180  
181 4 return %args
182 }
183  
184 # Filter away obvious non-TAP lines before parsing it.
185 sub preprocess_tap {
186 4 ▶ my %args = @_;
Subroutine preprocess_tap: called CC=2 SCAR=7.0
Pod documented
187  
188 4 ▶ if ($args{tap}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"tap"}) 4 0 4
189 4 my $tap = $args{tap};
190 4 $tap =~ s/^(?!$obvious_tap_line).*[\r\n]*//mg;
191 4 $args{tap} = $tap;
192 }
193  
194 4 return %args
195 }
196  
197 # Mark empty TAP with replacement lines
198 sub noempty_tap {
199 21 ▶ my %args = @_;
Subroutine noempty_tap: called CC=5 SCAR=16.1
Pod documented
200  
201 21 ▶ if (defined($args{tap}) and $args{tap} eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'tap'} and $args{'tap'} eq '') { } 3 18 21
elsif (defined $args{'source'} and -z $args{'source'}) { } 1 33 34
Condition100%3/3
defined $args{"tap"} and $args{"tap"} eq ""
!ll&&!rl&&r
2163
MC/DC100%2/2
defined $args{"tap"} and $args{"tap"} eq ""
defined $args{"tap"} $args{"tap"} eq ""
Truth table100%3/3
A and B
A= defined $args{"tap"}B= $args{"tap"} eq ""
ABresult
0X0
100
111
202 3 $args{tap} = $noempty_tap;
203 }
204 ▶ elsif (defined($args{source}) and -z $args{source}) {
Condition100%3/3
defined $args{"source"} and -z $args{"source"}
!ll&&!rl&&r
1611
MC/DC100%2/2
defined $args{"source"} and -z $args{"source"}
defined $args{"source"} -z $args{"source"}
Truth table100%3/3
A and B
A= defined $args{"source"}B= -z $args{"source"}
ABresult
0X0
100
111
205 1 $args{tap} = $noempty_tap;
206 1 delete $args{source};
207 }
208  
209 21 return %args
210 }
211  
212 sub new {
213 # hash or hash ref
214 69 ▶ my $class = shift;
Subroutine new: called CC=85 SCAR=44.8
Pod documented
215 69 ▶ my %args = @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 69 69
216  
217 69 my @lines;
218 my $plan;
219 69 my $version;
220 69 my @pragmas;
221 69 my $bailout;
222 69 my %document_data;
223 69 my %dangling_kv_data;
224  
225 69 ▶ %args = preprocess_ignorelines(%args) if $args{preprocess_ignorelines};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"preprocess_ignorelines"} 4 65 69
226 69 ▶ %args = preprocess_tap(%args) if $args{preprocess_tap};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"preprocess_tap"} 4 65 69
227 69 ▶ %args = noempty_tap(%args) if $args{noempty_tap};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"noempty_tap"} 21 48 69
228  
229 69 my %IGNORE = map { $_ => 1 } @{$args{ignore}};
230 69 my $IGNORELINES = $args{ignorelines};
231 69 my $DONTIGNORELINES = $args{dontignorelines};
232 69 my $USEBITSETS = $args{usebitsets};
233 69 my $DISABLE_GLOBAL_KV_DATA = $args{disable_global_kv_data};
234 69 my $PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN = $args{put_dangling_kv_data_under_lazy_plan};
235 69 ▶ my $DOC_DATA_PREFIX = $args{document_data_prefix} || 'Test-';
Condition50%1/2
$args{'document_data_prefix'} || 'Test-'
l!l
069
MC/DC0%0/1
$args{'document_data_prefix'} || 'Test-'
$args{'document_data_prefix'}
Truth table50%1/2
A
A= $args{'document_data_prefix'}
Aresult
11
00
236 69 my $DOC_DATA_IGNORE = $args{document_data_ignore};
237 69 my $LOWERCASE_FIELDNAMES = $args{lowercase_fieldnames};
238 69 my $LOWERCASE_FIELDVALUES = $args{lowercase_fieldvalues};
239 69 my $TRIM_FIELDVALUES = $args{trim_fieldvalues};
240 69 my $NOEMPTY_TAP = $args{noempty_tap};
241 69 delete $args{ignore};
242 69 delete $args{ignorelines};
243 69 delete $args{dontignorelines};
244 69 delete $args{usebitsets};
245 69 delete $args{disable_global_kv_data};
246 69 delete $args{put_dangling_kv_data_under_lazy_plan};
247 69 delete $args{document_data_prefix};
248 69 delete $args{document_data_ignore};
249 69 delete $args{preprocess_ignorelines};
250 69 delete $args{preprocess_tap};
251 69 delete $args{noempty_tap};
252 69 delete $args{lowercase_fieldnames};
253 69 delete $args{lowercase_fieldvalues};
254 69 delete $args{trim_fieldvalues};
255  
256 69 my $document_data_regex = qr/^#\s*$DOC_DATA_PREFIX([^:]+)\s*:\s*(.*)$/;
257 69 ▶ my $document_data_ignore = defined($DOC_DATA_IGNORE) ? qr/$DOC_DATA_IGNORE/ : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $DOC_DATA_IGNORE ? : 5 64 69
258  
259 69 my $parser = TAP::Parser->new( { %args } );
260  
261 69 my $aggregate = TAP::Parser::Aggregator->new;
262 69 $aggregate->start;
263  
264 69 my $count_tap_lines = 0;
265 69 my $found_pragma_tapdom_error = 0;
266 69 ▶ while ( my $result = $parser->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $parser->next) 667 69 736
267 21 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
268  
269 667 ▶ next if $IGNORELINES && $result->raw =~ m/$IGNORELINES/ && !($DONTIGNORELINES && $result->raw =~ m/$DONTIGNORELINES/);
Branch: 1 branch
BranchTrueFalseTotal
if $IGNORELINES and $result->raw =~ /$IGNORELINES/ and not $DONTIGNORELINES && $result->raw =~ /$DONTIGNORELINES/ 26 641 667
Condition100%9/9
$IGNORELINES and $result->raw =~ /$IGNORELINES/ and not $DONTIGNORELINES && $result->raw =~ /$DONTIGNORELINES/
!ll&&!rl&&r
639226
$IGNORELINES and $result->raw =~ /$IGNORELINES/
!ll&&!rl&&r
6211828
$DONTIGNORELINES && $result->raw =~ /$DONTIGNORELINES/
!ll&&!rl&&r
14122
MC/DC100%4/4
$IGNORELINES and $result->raw =~ /$IGNORELINES/ and not $DONTIGNORELINES && $result->raw =~ /$DONTIGNORELINES/
$IGNORELINES $result->raw =~ /$IGNORELINES/ $DONTIGNORELINES $result->raw =~ /$DONTIGNORELINES/
Truth table100%5/5
A and B and not(C && D)
A= $IGNORELINESB= $result->raw =~ /$IGNORELINES/C= $DONTIGNORELINESD= $result->raw =~ /$DONTIGNORELINES/
ABCDresult
0XXX0
10XX0
11110
110X1
11101
270  
271 641 my $entry = TAP::DOM::Entry->new;
272 641 ▶ $entry->{is_has} = 0 if $USEBITSETS;
Branch: 1 branch
BranchTrueFalseTotal
if $USEBITSETS 7 634 641
273  
274 # test info
275 641 foreach (qw(type raw as_string )) {
276 1923 ▶ $entry->{$_} = $result->$_ unless $IGNORE{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $IGNORE{$_} 1883 40 1923
277 }
278  
279 641 ▶ if ($result->is_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_test) 174 467 641
280 174 foreach (qw(directive explanation number description )) {
281 696 ▶ $entry->{$_} = $result->$_ unless $IGNORE{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $IGNORE{$_} 688 8 696
282 }
283 174 foreach (qw(is_ok is_unplanned )) {
284 348 ▶ if ($USEBITSETS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEBITSETS) { } 8 340 348
285 8 ▶ $entry->{is_has} |= $result->$_ ? ${uc $_} : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 8 0 8
$result->$_ ? : 4 4 8
286 } else {
287 340 ▶ $entry->{$_} = $result->$_ ? 1 : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 340 0 340
$result->$_ ? : 168 172 340
288 }
289 }
290 }
291  
292 # plan
293 641 ▶ if ($result->is_plan) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_plan) 60 581 641
294 60 $plan = $result->as_string;
295 60 foreach (qw(directive explanation)) {
296 120 ▶ $entry->{$_} = $result->$_ unless $IGNORE{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $IGNORE{$_} 119 1 120
297 }
298  
299 # save Dangling kv_data to plan entry. The situation
300 # that we already collected kv_data but haven't got
301 # a plan yet should only happen in documents with
302 # lazy plans (plan at the end).
303 60 ▶ if ($PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN and keys %dangling_kv_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN and keys %dangling_kv_data) 0 60 60
Condition33%1/3
$PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN and keys %dangling_kv_data
!ll&&!rl&&r
6000
MC/DC0%0/2
$PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN and keys %dangling_kv_data
$PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN keys %dangling_kv_data
Truth table33%1/3
A and B
A= $PUT_DANGLING_KV_DATA_UNDER_LAZY_PLANB= keys %dangling_kv_data
ABresult
0X0
100
111
304 0 $entry->{kv_data}{$_} = $dangling_kv_data{$_} foreach keys %dangling_kv_data;
305 }
306 }
307  
308 # meta info
309 641 foreach ((qw(has_skip has_todo))) {
310 1282 ▶ if ($USEBITSETS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEBITSETS) { } 14 1268 1282
311 14 ▶ $entry->{is_has} |= $result->$_ ? ${uc $_} : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 14 0 14
$result->$_ ? : 2 12 14
312 } else {
313 1268 ▶ $entry->{$_} = $result->$_ ? 1 : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 1268 0 1268
$result->$_ ? : 38 1230 1268
314 }
315 }
316 # Idea:
317 # use constants
318 # map to constants
319 # then loop
320 641 foreach (qw( is_pragma is_comment is_bailout is_plan
321 is_version is_yaml is_unknown is_test))
322 {
323 5128 ▶ if ($USEBITSETS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEBITSETS) { } 56 5072 5128
324 56 ▶ $entry->{is_has} |= $result->$_ ? ${uc $_} : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 56 0 56
$result->$_ ? : 7 49 56
325 } else {
326 5072 ▶ $entry->{$_} = $result->$_ ? 1 : 0 unless $IGNORE{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $IGNORE{$_} 5072 0 5072
$result->$_ ? : 634 4438 5072
327 }
328 }
329 641 ▶ if (! $IGNORE{is_actual_ok}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($IGNORE{"is_actual_ok"}) 641 0 641
330 # XXX:
331 # I think it's confusing when the value of
332 # "is_actual_ok" only has a meaning when
333 # "has_todo" is true.
334 # This makes it difficult to evaluate later.
335 # But it's aligned with TAP::Parser
336 # which also sets this only on "has_todo".
337 #
338 # Maybe the problem is a general philosophical one
339 # in TAP::DOM to always have each hashkey existing.
340 # Hmmm...
341 641 ▶ my $is_actual_ok = ($result->has_todo && $result->is_actual_ok) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$result->has_todo && $result->is_actual_ok ? : 13 628 641
Condition100%3/3
$result->has_todo and $result->is_actual_ok
!ll&&!rl&&r
6141413
MC/DC100%2/2
$result->has_todo and $result->is_actual_ok
$result->has_todo $result->is_actual_ok
Truth table100%3/3
A and B
A= $result->has_todoB= $result->is_actual_ok
ABresult
0X0
100
111
342 641 ▶ if ($USEBITSETS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEBITSETS) { } 7 634 641
343 7 ▶ $entry->{is_has} |= $is_actual_ok ? $IS_ACTUAL_OK : 0;
Branch: 1 branch
BranchTrueFalseTotal
$is_actual_ok ? : 1 6 7
344 } else {
345 634 $entry->{is_actual_ok} = $is_actual_ok;
346 }
347 }
348 641 ▶ $entry->{data} = $result->data if $result->is_yaml && !$IGNORE{data};
Branch: 1 branch
BranchTrueFalseTotal
if $result->is_yaml and not $IGNORE{"data"} 28 613 641
Condition66%2/3
$result->is_yaml and not $IGNORE{"data"}
!ll&&!rl&&r
613028
MC/DC50%1/2
$result->is_yaml and not $IGNORE{"data"}
$result->is_yaml not $IGNORE{"data"}
Truth table66%2/3
A and not(B)
A= $result->is_yamlB= not $IGNORE{"data"}
ABresult
0X0
100
111
349  
350 641 ▶ if ($result->is_comment and $result->as_string =~ $document_data_regex)
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_comment and $result->as_string =~ /$document_data_regex/) 73 568 641
Condition100%3/3
$result->is_comment and $result->as_string =~ /$document_data_regex/
!ll&&!rl&&r
32724173
MC/DC100%2/2
$result->is_comment and $result->as_string =~ /$document_data_regex/
$result->is_comment $result->as_string =~ /$document_data_regex/
Truth table100%3/3
A and B
A= $result->is_commentB= $result->as_string =~ /$document_data_regex/
ABresult
0X0
100
111
351 {{ # extra block for 'last'
352 # we can't use $1, $2 because the regex could contain configured other groups
353 73 my ($key, $value) = (_capture_group($result->as_string, -2), _capture_group($result->as_string, -1));
354 73 $key =~ s/^\s+//; # strip leading whitespace
355 73 $key =~ s/\s+$//; # strip trailing whitespace
356  
357 # optional lowercase
358 73 ▶ $key = lc $key if $LOWERCASE_FIELDNAMES;
Branch: 1 branch
BranchTrueFalseTotal
if $LOWERCASE_FIELDNAMES 21 52 73
359 73 ▶ $value = lc $value if $LOWERCASE_FIELDVALUES;
Branch: 1 branch
BranchTrueFalseTotal
if $LOWERCASE_FIELDVALUES 28 45 73
360  
361 # optional value trimming
362 73 ▶ $value =~ s/\s+$// if $TRIM_FIELDVALUES; # there can be no leading whitespace
Branch: 1 branch
BranchTrueFalseTotal
if $TRIM_FIELDVALUES 2 71 73
363  
364 # skip this field according to regex
365 73 ▶ last if $DOC_DATA_IGNORE and $document_data_ignore and $key =~ $document_data_ignore;
Branch: 1 branch
BranchTrueFalseTotal
if $DOC_DATA_IGNORE and $document_data_ignore and $key =~ /$document_data_ignore/ 7 66 73
Condition83%5/6
$DOC_DATA_IGNORE and $document_data_ignore and $key =~ /$document_data_ignore/
!ll&&!rl&&r
52147
$DOC_DATA_IGNORE and $document_data_ignore
!ll&&!rl&&r
52021
MC/DC66%2/3
$DOC_DATA_IGNORE and $document_data_ignore and $key =~ /$document_data_ignore/
$DOC_DATA_IGNORE $document_data_ignore $key =~ /$document_data_ignore/
Truth table75%3/4
A and B and C
A= $DOC_DATA_IGNOREB= $document_data_ignoreC= $key =~ /$document_data_ignore/
ABCresult
0XX0
10X0
1100
1111
366  
367 # Store "# Test-key: value" entries also as
368 # 'kv_data' under their parent line.
369 # That line should be a test or a plan line, so that its
370 # place (or "data path") is structurally always the same.
371 66 ▶ if ($lines[-1]->is_test or $lines[-1]->is_plan or $lines[-1]->is_pragma) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[-1]->is_test or $lines[-1]->is_plan or $lines[-1]->is_pragma) { } 56 10 66
Condition100%6/6
$lines[-1]->is_test or $lines[-1]->is_plan or $lines[-1]->is_pragma
l!l&&r!l&&!r
54210
$lines[-1]->is_test or $lines[-1]->is_plan
l!l&&r!l&&!r
45912
MC/DC100%3/3
$lines[-1]->is_test or $lines[-1]->is_plan or $lines[-1]->is_pragma
$lines[-1]->is_test $lines[-1]->is_plan $lines[-1]->is_pragma
Truth table100%4/4
A or B or C
A= $lines[-1]->is_testB= $lines[-1]->is_planC= $lines[-1]->is_pragma
ABCresult
1XX1
01X1
0011
0000
372 56 $lines[-1]->{kv_data}{$key} = $value;
373 } else {
374 10 ▶ if (!$plan) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plan) 10 0 10
375 # We haven't got a plan yet, so that
376 # kv_data entry would get lost. As we
377 # might still get a lazy plan at end
378 # of document, so we save it up for
379 # that potential plan entry.
380 10 $dangling_kv_data{$key} = $value;
381 }
382 }
383 66 ▶ $document_data{$key} = $value unless $lines[-1]->is_test && $DISABLE_GLOBAL_KV_DATA;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[-1]->is_test and $DISABLE_GLOBAL_KV_DATA 66 0 66
Condition66%2/3
$lines[-1]->is_test and $DISABLE_GLOBAL_KV_DATA
!ll&&!rl&&r
21450
MC/DC0%0/2
$lines[-1]->is_test and $DISABLE_GLOBAL_KV_DATA
$lines[-1]->is_test $DISABLE_GLOBAL_KV_DATA
Truth table66%2/3
A and B
A= $lines[-1]->is_testB= $DISABLE_GLOBAL_KV_DATA
ABresult
0X0
100
111
384 }}
385  
386 # calculate severity
387 641 ▶ if ($entry->{is_test} or $entry->{is_plan}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"is_test"} or $entry->{"is_plan"}) 229 412 641
Condition100%3/3
$entry->{"is_test"} or $entry->{"is_plan"}
l!l&&r!l&&!r
17059412
MC/DC100%2/2
$entry->{"is_test"} or $entry->{"is_plan"}
$entry->{"is_test"} $entry->{"is_plan"}
Truth table100%3/3
A or B
A= $entry->{"is_test"}B= $entry->{"is_plan"}
ABresult
1X1
011
000
388 21 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
389 229 $count_tap_lines++;
390 $entry->{severity} = $severity
391 ->{$entry->{type}}
392 ->{$entry->{is_ok}}
393 ->{$entry->{has_todo}}
394 ->{$entry->{is_actual_ok}}
395 229 ->{$entry->{has_skip}};
396 }
397  
398 641 ▶ if ($entry->{is_pragma} or $entry->{is_unknown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"is_pragma"} or $entry->{"is_unknown"}) 31 610 641
Condition100%3/3
$entry->{"is_pragma"} or $entry->{"is_unknown"}
l!l&&r!l&&!r
724610
MC/DC100%2/2
$entry->{"is_pragma"} or $entry->{"is_unknown"}
$entry->{"is_pragma"} $entry->{"is_unknown"}
Truth table100%3/3
A or B
A= $entry->{"is_pragma"}B= $entry->{"is_unknown"}
ABresult
1X1
011
000
399 21 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
400 31 ▶ if ($entry->{raw} =~ /^pragma\s+\+tapdom_error\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{'raw'} =~ /^pragma\s+\+tapdom_error\s*$/) { } 6 25 31
401 6 $found_pragma_tapdom_error=1;
402 6 $entry->{severity} = 5;
403 6 $entry->{is_unknown} = 0;
404 6 $entry->{is_pragma} = 1;
405 6 $entry->{type} = 'pragma';
406 } else {
407 25 $entry->{severity} = 0;
408 }
409 }
410 641 ▶ $entry->{severity} = 0 if not defined $entry->{severity};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{"severity"} 448 193 641
411  
412 # yaml and comments are taken as children of the line before
413 641 ▶ if ($result->is_yaml or $result->is_comment and @lines)
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_yaml or $result->is_comment and @lines) { } 341 300 641
Condition100%6/6
$result->is_yaml or $result->is_comment and @lines
l!l&&r!l&&!r
28313300
$result->is_comment and @lines
!ll&&!rl&&r
2991313
MC/DC100%3/3
$result->is_yaml or $result->is_comment and @lines
$result->is_yaml $result->is_comment @lines
Truth table100%4/4
A or B and C
A= $result->is_yamlB= $result->is_commentC= @lines
ABCresult
1XX1
0111
00X0
0100
414 {
415 341 push @{ $lines[-1]->{_children} }, $entry;
416 }
417 else
418 {
419 300 push @lines, $entry;
420 }
421 }
422 69 @pragmas = $parser->pragmas;
423  
424 69 ▶ if (!$count_tap_lines and !$found_pragma_tapdom_error and $NOEMPTY_TAP) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $count_tap_lines || $found_pragma_tapdom_error and $NOEMPTY_TAP) 2 67 69
Condition100%6/6
not $count_tap_lines || $found_pragma_tapdom_error and $NOEMPTY_TAP
!ll&&!rl&&r
6432
$count_tap_lines || $found_pragma_tapdom_error
l!l&&r!l&&!r
5955
MC/DC100%3/3
not $count_tap_lines || $found_pragma_tapdom_error and $NOEMPTY_TAP
$count_tap_lines $found_pragma_tapdom_error $NOEMPTY_TAP
Truth table100%4/4
not(A || B) and C
A= $count_tap_linesB= $found_pragma_tapdom_errorC= $NOEMPTY_TAP
ABCresult
1XX0
01X0
0000
0011
425 # pragma +tapdom_error
426 2 my $error_entry = TAP::DOM::Entry->new(
427 'is_version' => 0,
428 'is_plan' => 0,
429 'is_test' => 0,
430 'is_comment' => 0,
431 'is_yaml' => 0,
432 'is_unknown' => 0,
433 'is_bailout' => 0,
434 'is_actual_ok' => 0,
435 'is_pragma' => 1,
436 'type' => 'pragma',
437 'raw' => 'pragma +tapdom_error',
438 'as_string' => 'pragma +tapdom_error',
439 'severity' => 5,
440 'has_todo' => 0,
441 'has_skip' => 0,
442 );
443 2 ▶ $error_entry->{is_has} = $IS_PRAGMA if $USEBITSETS;
Branch: 1 branch
BranchTrueFalseTotal
if $USEBITSETS 0 2 2
444 2 ▶ foreach (qw(raw type as_string explanation)) { delete $error_entry->{$_} if $IGNORE{$_} }
Branch: 1 branch
BranchTrueFalseTotal
if $IGNORE{$_} 0 8 8
445 # pragma +tapdom_error
446 2 my $error_comment = TAP::DOM::Entry->new(
447 'is_version' => 0,
448 'is_plan' => 0,
449 'is_test' => 0,
450 'is_comment' => 1,
451 'is_yaml' => 0,
452 'is_unknown' => 0,
453 'is_bailout' => 0,
454 'is_actual_ok' => 0,
455 'is_pragma' => 0,
456 'type' => 'comment',
457 'raw' => '# no tap lines',
458 'as_string' => '# no tap lines',
459 'severity' => 0,
460 'has_todo' => 0,
461 'has_skip' => 0,
462 );
463 2 ▶ $error_comment->{is_has} = $IS_COMMENT if $USEBITSETS;
Branch: 1 branch
BranchTrueFalseTotal
if $USEBITSETS 0 2 2
464 2 ▶ foreach (qw(raw type as_string explanation)) { delete $error_comment->{$_} if $IGNORE{$_} }
Branch: 1 branch
BranchTrueFalseTotal
if $IGNORE{$_} 0 8 8
465 2 ▶ $error_entry->{_children} //= [];
Condition50%1/2
$error_entry->{"_children"} //= []
l!l
02
MC/DC0%0/1
$error_entry->{"_children"} //= []
$error_entry->{"_children"}
Truth table50%1/2
A
A= $error_entry->{"_children"}
Aresult
11
00
466 2 push @{$error_entry->{_children}}, $error_comment;
467 2 push @lines, $error_entry;
468 2 push @pragmas, 'tapdom_error';
469 }
470  
471 69 $aggregate->add( main => $parser );
472 69 $aggregate->stop;
473  
474 69 ▶ my $summary = TAP::DOM::Summary->new
Branch: 3 branches
BranchTrueFalseTotal
$aggregate->all_passed ? : 50 19 69
$aggregate->has_problems ? : 19 50 69
$aggregate->has_errors ? : 17 52 69
475 (
476 failed => scalar $aggregate->failed,
477 parse_errors => scalar $aggregate->parse_errors,
478 planned => scalar $aggregate->planned,
479 passed => scalar $aggregate->passed,
480 skipped => scalar $aggregate->skipped,
481 todo => scalar $aggregate->todo,
482 todo_passed => scalar $aggregate->todo_passed,
483 wait => scalar $aggregate->wait,
484 exit => scalar $aggregate->exit,
485 elapsed => $aggregate->elapsed,
486 elapsed_timestr => $aggregate->elapsed_timestr,
487 all_passed => $aggregate->all_passed ? 1 : 0,
488 status => $aggregate->get_status,
489 total => $aggregate->total,
490 has_problems => $aggregate->has_problems ? 1 : 0,
491 has_errors => $aggregate->has_errors ? 1 : 0,
492 );
493  
494 69 my $tapdom_config = TAP::DOM::Config->new
495 (
496 ignore => \%IGNORE,
497 ignorelines => $IGNORELINES,
498 dontignorelines => $DONTIGNORELINES,
499 usebitsets => $USEBITSETS,
500 disable_global_kv_data => $DISABLE_GLOBAL_KV_DATA,
501 put_dangling_kv_data_under_lazy_plan => $PUT_DANGLING_KV_DATA_UNDER_LAZY_PLAN,
502 document_data_prefix => $DOC_DATA_PREFIX,
503 document_data_ignore => $DOC_DATA_IGNORE,
504 lowercase_fieldnames => $LOWERCASE_FIELDNAMES,
505 lowercase_fieldvalues => $LOWERCASE_FIELDVALUES,
506 trim_fieldvalues => $TRIM_FIELDVALUES,
507 noempty_tap => $NOEMPTY_TAP,
508 );
509  
510 69 my $document_data = TAP::DOM::DocumentData->new(%document_data);
511  
512 69 my $tapdata = {
513 plan => $plan,
514 lines => \@lines,
515 pragmas => \@pragmas,
516 tests_planned => $parser->tests_planned,
517 tests_run => $parser->tests_run,
518 version => $parser->version,
519 is_good_plan => $parser->is_good_plan,
520 skip_all => $parser->skip_all,
521 start_time => $parser->start_time,
522 end_time => $parser->end_time,
523 has_problems => $parser->has_problems,
524 exit => $parser->exit,
525 parse_errors => scalar $parser->parse_errors,
526 parse_errors_msgs => [ $parser->parse_errors ],
527 summary => $summary,
528 tapdom_config => $tapdom_config,
529 document_data => $document_data,
530 };
531 69 return bless $tapdata, $class;
532 }
533  
534 sub _entry_to_tapline
535 {
536 40 ▶ my ($self, $entry) = @_;
Subroutine _entry_to_tapline: called CC=16 SCAR=28.7
537  
538 40 my %IGNORE = %{$self->{tapdom_config}{ignore}};
539  
540 40 my $tapline = "";
541  
542 # ok/notok test lines
543 40 ▶ if ($entry->{is_test})
Branch: 2 branches
BranchTrueFalseTotal
if ($entry->{'is_test'}) { } 16 24 40
elsif ($entry->{'is_pragma'} or $entry->{'is_comment'} or $entry->{'is_bailout'} or $entry->{'is_yaml'}) { } 20 4 24
544 {
545 $tapline = join(" ",
546 # the original "NOT" is more difficult to reconstruct than it should...
547 ($entry->{has_todo}
548 ? $entry->{is_actual_ok} ? () : "not"
549 : $entry->{is_ok} ? () : "not"),
550 "ok",
551 ($entry->{number} || ()),
552 ($entry->{description} || ()),
553 ($entry->{has_skip} ? "# SKIP ".($entry->{explanation} || "")
554 16 ▶ : $entry->{has_todo }? "# TODO ".($entry->{explanation} || "")
Branch: 5 branches
BranchTrueFalseTotal
$entry->{'has_todo'} ? : 8 8 16
$entry->{'is_actual_ok'} ? : 4 4 8
$entry->{'is_ok'} ? : 8 0 8
$entry->{'has_skip'} ? : 2 14 16
$entry->{'has_todo'} ? : 8 6 14
Condition50%5/10
$entry->{'number'} || ()
l!l&&r!l&&!r
1600
$entry->{'description'} || ()
l!l&&r!l&&!r
1060
$entry->{'explanation'} || ''
l!l
20
$entry->{'explanation'} || ''
l!l
80
MC/DC0%0/2
$entry->{'number'} || ()
$entry->{'number'} ()
MC/DC0%0/2
$entry->{'description'} || ()
$entry->{'description'} ()
MC/DC0%0/1
$entry->{'explanation'} || ''
$entry->{'explanation'}
MC/DC0%0/1
$entry->{'explanation'} || ''
$entry->{'explanation'}
Truth table33%1/3
A || B
A= $entry->{'number'}B= ()
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $entry->{'description'}B= ()
ABresult
1X1
011
000
Truth table50%1/2
A
A= $entry->{'explanation'}
Aresult
11
00
Truth table50%1/2
A
A= $entry->{'explanation'}
Aresult
11
00
555 : ()),
556 );
557 }
558 # pragmas and meta lines, but no version nor plan
559 ▶ elsif ($entry->{is_pragma} ||
Condition88%8/9
$entry->{"is_pragma"} or $entry->{"is_comment"} or $entry->{"is_bailout"} or $entry->{"is_yaml"}
l!l&&r!l&&!r
1824
$entry->{"is_pragma"} or $entry->{"is_comment"} or $entry->{"is_bailout"}
l!l&&r!l&&!r
1806
$entry->{"is_pragma"} or $entry->{"is_comment"}
l!l&&r!l&&!r
2166
MC/DC75%3/4
$entry->{"is_pragma"} or $entry->{"is_comment"} or $entry->{"is_bailout"} or $entry->{"is_yaml"}
$entry->{"is_pragma"} $entry->{"is_comment"} $entry->{"is_bailout"} $entry->{"is_yaml"}
Truth table80%4/5
A or B or C or D
A= $entry->{"is_pragma"}B= $entry->{"is_comment"}C= $entry->{"is_bailout"}D= $entry->{"is_yaml"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
560 $entry->{is_comment} ||
561 $entry->{is_bailout} ||
562 $entry->{is_yaml})
563 {
564 20 ▶ $tapline = $IGNORE{raw} ? $entry->{as_string} : $entry->{raw}; # if "raw" was 'ignored' try "as_string"
Branch: 1 branch
BranchTrueFalseTotal
$IGNORE{'raw'} ? : 0 20 20
565 }
566 40 return $tapline;
567 }
568  
569 sub _lines_to_tap
570 {
571 8 ▶ my ($self, $lines) = @_;
Subroutine _lines_to_tap: called CC=4 SCAR=13.9
572  
573 8 my @taplines;
574 8 foreach my $entry (@$lines)
575 {
576 40 my $tapline = $self->_entry_to_tapline($entry);
577 40 ▶ push @taplines, $tapline if $tapline;
Branch: 1 branch
BranchTrueFalseTotal
if $tapline 36 4 40
578 40 ▶ push @taplines, $self->_lines_to_tap($entry->{_children}) if $entry->{_children};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"_children"} 6 34 40
579 }
580 8 return @taplines;
581 }
582  
583 sub to_tap
584 {
585 2 ▶ my ($self) = @_;
Subroutine to_tap: called CC=2 SCAR=6.9
Pod documented
586  
587 2 my @taplines = $self->_lines_to_tap($self->{lines});
588 2 unshift @taplines, $self->{plan};
589 2 unshift @taplines, "TAP version ".$self->{version};
590  
591 return wantarray
592 ? @taplines
593 2 ▶ : join("\n", @taplines)."\n";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
594 }
595  
596 21 1; # End of TAP::DOM
597  
598 __END__
↑ Summary DOM/Archive.pm »