| 1 | package TAP::Tree; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use v5.10.1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | our $VERSION = 'v0.0.5'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Encode qw[decode]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 26 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | tap_file => $params{tap_file}, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | tap_ref => $params{tap_ref}, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | tap_tree => $params{tap_tree}, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | utf8 => $params{utf8}, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 26 | is_parsed => undef, | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | result => { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | plan => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | testline => [], | ||||||||||||||||||||||||||||||||||||||||||
| 31 | bailout => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 26 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | $self->_validate; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | $self->_initialize; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub is_utf8 { return $_[0]->{utf8} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_utf8: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | sub is_parsed { return $_[0]->{is_parsed} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_parsed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | sub _check_for_parsed { croak "not parsed" unless $_[0]->is_parsed } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_for_parsed: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | sub summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
summary: called CC=13 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | $self->_check_for_parsed; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | my $failed_tests = 0; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | for my $testline ( @{ $self->{result}{testline} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | ▶ | $failed_tests++ if ( $testline->{result} == 0 && ! $testline->{todo} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$testline->{"result"} == 0 and not $testline->{"todo"}
MC/DC100%2/2
$testline->{"result"} == 0 and not $testline->{"todo"}
$testline->{"result"} == 0
not $testline->{"todo"}
Truth table100%3/3
A and not(B)
A= $testline->{"result"} == 0B= not $testline->{"todo"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | my $is_bailout = $self->{result}{bailout} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | my $ran_tests = scalar @{ $self->{result}{testline} }; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | my $is_good_plan = ( defined $self->{result}{plan}{number} ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | my $is_ran_all_tests = ( $is_good_plan and $ran_tests != 0 and $self->{result}{plan}{number} == $ran_tests ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$is_good_plan and $ran_tests != 0 and $self->{"result"}{"plan"}{"number"} == $ran_tests
$is_good_plan and $ran_tests != 0
MC/DC33%1/3
$is_good_plan and $ran_tests != 0 and $self->{"result"}{"plan"}{"number"} == $ran_tests
$is_good_plan
$ran_tests != 0
$self->{"result"}{"plan"}{"number"} == $ran_tests
Truth table50%2/4
A and B and C
A= $is_good_planB= $ran_tests != 0C= $self->{"result"}{"plan"}{"number"} == $ran_tests
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | my $summary = { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | version => $self->{result}{version}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | is_skipped_all => defined $self->{result}{plan}{skip_all} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | skip_all_msg => $self->{result}{plan}{skip_all} ? | ||||||||||||||||||||||||||||||||||||||||||
| 69 | $self->{result}{plan}{directive} : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | is_bailout => defined $self->{result}{bailout} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | bailout_msg => $self->{result}{bailout} ? | ||||||||||||||||||||||||||||||||||||||||||
| 73 | $self->{result}{bailout}{message} : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | planned_tests => $self->{result}{plan}{number}, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ran_tests => $ran_tests, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | failed_tests => $failed_tests, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | is_good_plan => $is_good_plan, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | is_ran_all_tests => $is_ran_all_tests, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # for backward compatibility | ||||||||||||||||||||||||||||||||||||||||||
| 83 | bailout => $self->{result}{bailout}, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | plan => $self->{result}{plan}, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | tests => scalar @{ $self->{result}{testline} }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | fail => $failed_tests, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | return $summary; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub tap_tree { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tap_tree: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | $self->_check_for_parsed; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | return $self->{result}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | sub create_tap_tree_iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_tap_tree_iterator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | require TAP::Tree::Iterator; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my $iterator = TAP::Tree::Iterator->new( tap_tree => $self->tap_tree, %params ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | return $iterator; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | ▶ | sub _validate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate: called CC=15 SCAR=40.9
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | ▶ | if ( $self->{tap_ref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 23 | ▶ | if ( $self->{tap_file} or $self->{tap_tree} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"tap_file"} or $self->{"tap_tree"}
MC/DC0%0/2
$self->{"tap_file"} or $self->{"tap_tree"}
$self->{"tap_file"}
$self->{"tap_tree"}
Truth table33%1/3
A or B
A= $self->{"tap_file"}B= $self->{"tap_tree"}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | croak "Excessive parameter"; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 23 | ▶ | if ( ref( $self->{tap_ref} ) ne 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | croak "Parameter 'tap_ref' is not scalar reference"; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 23 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | if ( $self->{tap_file} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | if ( $self->{tap_ref} or $self->{tap_tree} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"tap_ref"} or $self->{"tap_tree"}
MC/DC0%0/2
$self->{"tap_ref"} or $self->{"tap_tree"}
$self->{"tap_ref"}
$self->{"tap_tree"}
Truth table33%1/3
A or B
A= $self->{"tap_ref"}B= $self->{"tap_tree"}
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | croak "Excessive parameter"; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | if ( ! -e -f -r -T $self->{tap_file} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | croak "Paramter 'tap_file' is invalid:$self->{tap_file}"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | if ( $self->{tap_tree} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( $self->{tap_file} or $self->{tap_ref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"tap_file"} or $self->{"tap_ref"}
MC/DC0%0/2
$self->{"tap_file"} or $self->{"tap_ref"}
$self->{"tap_file"}
$self->{"tap_ref"}
Truth table0%0/3
A or B
A= $self->{"tap_file"}B= $self->{"tap_ref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | croak "Excessive parameter"; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( ref( $self->{tap_tree} ) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | croak "Parameter 'tap_tree' is not hash reference"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my @keys = qw[version plan testline]; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | for my $key ( @keys ) { | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( ! defined $self->{tap_tree}{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | croak "Parameter 'tap_tree' is invalid tap tree:$key"; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | croak "No required parameter ( tap_ref or tap_file ot tap_tree )"; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 25 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=2 SCAR=10.1
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 25 | ▶ | if ( $self->{tap_tree} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->{result} = $self->{tap_tree}; # Not deep copy. | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{is_parsed}++; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 25 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 25 | ▶ | if ( $self->{is_parsed} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | croak "TAP is already parsed."; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 25 | ▶ | my $path = ( $self->{tap_file} ) ? $self->{tap_file} : $self->{tap_ref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | open my $fh, '<', $path; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 25 | $self->{result} = $self->_parse( $fh ); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 25 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 25 | $self->{is_parsed}++; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 25 | return $self->{result}; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 25 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 25 | my ( $self, $fh ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 25 | my $result = { | |||||||||||||||||||||||||||||||||||||||||
| 193 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | plan => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | testline => [], | ||||||||||||||||||||||||||||||||||||||||||
| 196 | bailout => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | parse_error => [], | ||||||||||||||||||||||||||||||||||||||||||
| 198 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 25 | my @subtest_lines; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 25 | ▶ | while ( my $line_raw = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 134 | ▶ | my $line = ( $self->{utf8} ) ? decode( 'UTF-8', $line_raw ) : $line_raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 134 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 134 | ▶ | next if ( $line =~ /!\s*#/ ); # skip all comments. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | # Bail Out! | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # NOTE | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # 'Test-Simple < 0.98_01' can't handle BAIL_OUT in subtest correctly. | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # Since TAP-Tree requires 'Test-Simple >= 1.001002'. | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 134 | ▶ | if ( $line =~ /^Bail out!\s+(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | $result->{bailout} = { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | str => $line, | |||||||||||||||||||||||||||||||||||||||||
| 216 | message => $1, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # tap version | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # Deleted the parsing code for the version of tha TAP. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # Since a specified of a version is unnecessary | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # for the version lower than 12 | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # It is due to add when supporting version 13. | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # plan | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 131 | ▶ | if ( $line =~ /^(\s*)1\.\.\d+(\s#.*)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 37 | ▶ | if ( $1 ) { # subtest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 13 | push @subtest_lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 24 | ▶ | if ( $result->{plan}{number} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | croak "Invalid TAP sequence. Plan is already specified."; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 24 | $result->{plan} = $self->_parse_plan( $line ); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 37 | next; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # testline | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 94 | ▶ | if ( $line =~ /^(\s*)(not )?ok/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 71 | ▶ | if ( $1 ) { # subtest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 22 | push @subtest_lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 49 | my $subtest = $self->_parse_subtest( \@subtest_lines ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 49 | push @{ $result->{testline} }, | |||||||||||||||||||||||||||||||||||||||||
| 253 | $self->_parse_testline( $line, $subtest ); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 71 | next; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | # 'unknown' line. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | push @{ $self->{result}{parse_error} }, $line; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 25 | ▶ | if ( ! $result->{version} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 25 | $result->{version}{number} = 12; # Default tap version is '12' now. | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 25 | ▶ | if ( ! $result->{plan} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | $result->{plan}{number} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 25 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 37 | ▶ | sub _parse_plan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_plan: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 37 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 37 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 37 | my $plan = { | |||||||||||||||||||||||||||||||||||||||||
| 279 | str => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 280 | number => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 281 | skip_all => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 282 | directive => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 283 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 37 | $line =~ /^1\.\.(\d+)\s*(# .*)?/; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 37 | $plan->{number} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 37 | ▶ | $plan->{skip_all}++ if ( $plan->{number} == 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 37 | ▶ | if ( $2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | $plan->{directive} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | $plan->{directive} =~ s/^#\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 37 | return $plan; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 70 | ▶ | sub _parse_testline { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_testline: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 70 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 70 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 70 | my $subtest = shift; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 70 | my $testline = { | |||||||||||||||||||||||||||||||||||||||||
| 306 | str => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 307 | result => undef, # 1 (ok) or 0 (not ok) | ||||||||||||||||||||||||||||||||||||||||||
| 308 | test_number => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 309 | description => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 310 | directive => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 311 | todo => undef, # is todo test? | ||||||||||||||||||||||||||||||||||||||||||
| 312 | skip => undef, # is skipped? | ||||||||||||||||||||||||||||||||||||||||||
| 313 | subtest => $subtest, | ||||||||||||||||||||||||||||||||||||||||||
| 314 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 70 | $line =~ /(not )?ok\s*(\d+)?(.*)?/; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 70 | ▶ | $testline->{result} = $1 ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 70 | ▶ | $testline->{test_number} = $2 if $2; # test number is optional | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 70 | my $msg = $3; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 70 | ▶ | if ( $msg && $msg =~ /^\s?(-\s.+?)?\s*(#\s.+?)?\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$msg and $msg =~ /^\s?(-\s.+?)?\s*(#\s.+?)?\s*$/
MC/DC50%1/2
$msg and $msg =~ /^\s?(-\s.+?)?\s*(#\s.+?)?\s*$/
$msg
$msg =~ /^\s?(-\s.+?)?\s*(#\s.+?)?\s*$/
Truth table66%2/3
A and B
A= $msgB= $msg =~ /^\s?(-\s.+?)?\s*(#\s.+?)?\s*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 68 | ▶ | if ( $1 ) { # matched description | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 64 | $testline->{description} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 64 | $testline->{description} =~ s/^-\s//; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 68 | ▶ | if ( $2 ) { # matched directive | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | $testline->{directive} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | $testline->{directive} =~ s/^#\s//; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | ▶ | $testline->{todo}++ if ( $testline->{directive} =~ /TODO/i ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 5 | ▶ | $testline->{skip}++ if ( $testline->{directive} =~ /skip/i ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 70 | return $testline; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 70 | ▶ | sub _parse_subtest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_subtest: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 70 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 70 | my $subtest_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 70 | ▶ | return unless $subtest_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 70 | ▶ | return unless @{ $subtest_ref }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 13 | my $subtest_result = { | |||||||||||||||||||||||||||||||||||||||||
| 350 | plan => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 351 | testline => [], | ||||||||||||||||||||||||||||||||||||||||||
| 352 | subtest => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 353 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 13 | my $indent; | |||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 13 | $subtest_ref->[-1] =~ /^(\s+).*/; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 13 | $indent = length( $1 ); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 13 | my @subtest_more; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 13 | ▶ | while( @{ $subtest_ref } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 48 | my $subtest_line = shift @{ $subtest_ref }; | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 48 | my ( $indent_current, $line ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 48 | $subtest_line =~ /^(\s+)(.*)/; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 48 | $indent_current = length( $1 ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | 48 | $line = $2; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 48 | ▶ | if ( $indent_current > $indent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 14 | push @subtest_more, $subtest_line; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | # parse plan | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 34 | ▶ | if ( $line =~ /^1\.\.\d+/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 13 | $subtest_result->{plan} = $self->_parse_plan( $line ); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 13 | next; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | # parse testline | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 21 | ▶ | if ( $line =~ /^(not )?ok/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 21 | my $subtest = $self->_parse_subtest( \@subtest_more ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 21 | push @{ $subtest_result->{testline} }, | |||||||||||||||||||||||||||||||||||||||||
| 387 | $self->_parse_testline( $line, $subtest ); | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 21 | next; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 13 | return $subtest_result; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | __END__ | ||||||||||||||||||||||||||||||||||||||||||