Harness/Compatible/Straps.pm

filter: Statementstmt 13.2% 30 / 226 Branchbran 0.9% 1 / 108 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 19.3% 6 / 31 Podpod 100% 6 / 6 totaltotal 9.5% 43 / 450 CC 76 SCAR 50.6
CC
76
Cov
8%
_analyze_line
552.0
_analyze_iterator
110.0
_switches
110.0
CRAP 156.9
« Harness/Compatible.pm ↑ Summary Harness/Compatible/Util.pm »
1 # -*- Mode: cperl; cperl-indent-level: 4 -*-
2 package TAPx::Harness::Compatible::Straps;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $VERSION = '0.50_07';
7  
8 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use TAPx::Harness::Compatible::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use TAPx::Harness::Compatible::Point;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use TAPx::Harness::Compatible::Results;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Flags used as return values from our methods. Just for internal
14 # clarification.
15 1 my $YES = ( 1 == 1 );
16 1 my $NO = !$YES;
17  
18 =head1 NAME
19  
20 TAPx::Harness::Compatible::Straps - detailed analysis of test results
21  
22 =head1 SYNOPSIS
23  
24 use TAPx::Harness::Compatible::Straps;
25  
26 my $strap = TAPx::Harness::Compatible::Straps->new;
27  
28 # Various ways to interpret a test
29 my $results = $strap->analyze($name, \@test_output);
30 my $results = $strap->analyze_fh($name, $test_filehandle);
31 my $results = $strap->analyze_file($test_file);
32  
33 # UNIMPLEMENTED
34 my %total = $strap->total_results;
35  
36 # Altering the behavior of the strap UNIMPLEMENTED
37 my $verbose_output = $strap->dump_verbose();
38 $strap->dump_verbose_fh($output_filehandle);
39  
40  
41 =head1 DESCRIPTION
42  
43 B<THIS IS ALPHA SOFTWARE> in that the interface is subject to change
44 in incompatible ways. It is otherwise stable.
45  
46 TAPx::Harness::Compatible is limited to printing out its results. This makes
47 analysis of the test results difficult for anything but a human. To
48 make it easier for programs to work with test results, we provide
49 TAPx::Harness::Compatible::Straps. Instead of printing the results, straps
50 provide them as raw data. You can also configure how the tests are to
51 be run.
52  
53 The interface is currently incomplete. I<Please> contact the author
54 if you'd like a feature added or something change or just have
55 comments.
56  
57 =head1 CONSTRUCTION
58  
59 =head2 new()
60  
61 my $strap = TAPx::Harness::Compatible::Straps->new;
62  
63 Initialize a new strap.
64  
65 =cut
66  
67 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
68 0 my $class = shift;
69 0 my $self = bless {}, $class;
70  
71 0 $self->_init;
72  
73 0 return $self;
74 }
75  
76 =for private $strap->_init
77  
78 $strap->_init;
79  
80 Initialize the internal state of a strap to make it ready for parsing.
81  
82 =cut
83  
84 0 ▶sub _init {
Subroutine _init: not called CC=1 SCAR=6.9
85 0 my ($self) = shift;
86  
87 0 $self->{_is_vms} = ( $^O eq 'VMS' );
88 0 $self->{_is_win32} = ( $^O =~ /^(MS)?Win32$/ );
89 0 $self->{_is_macos} = ( $^O eq 'MacOS' );
90 }
91  
92 =head1 ANALYSIS
93  
94 =head2 $strap->analyze( $name, \@output_lines )
95  
96 my $results = $strap->analyze($name, \@test_output);
97  
98 Analyzes the output of a single test, assigning it the given C<$name>
99 for use in the total report. Returns the C<$results> of the test.
100 See L<Results>.
101  
102 C<@test_output> should be the raw output from the test, including
103 newlines.
104  
105 =cut
106  
107 0 ▶sub analyze {
Subroutine analyze: not called CC=1 SCAR=6.9
Pod documented
108 0 my ( $self, $name, $test_output ) = @_;
109  
110 0 my $it = TAPx::Harness::Compatible::Iterator->new($test_output);
111 0 return $self->_analyze_iterator( $name, $it );
112 }
113  
114 0 ▶sub _analyze_iterator {
Subroutine _analyze_iterator: not called CC=10 SCAR=47.0
115 0 my ( $self, $name, $it ) = @_;
116  
117 0 $self->_reset_file_state;
118 0 $self->{file} = $name;
119  
120 0 my $results = TAPx::Harness::Compatible::Results->new;
121  
122 # Set them up here so callbacks can have them.
123 0 $self->{totals}{$name} = $results;
124 0 ▶ while ( defined( my $line = $it->next ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $it->next)) 0 0 0
125 0 $self->_analyze_line( $line, $results );
126 0 ▶ last if $self->{saw_bailout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"saw_bailout"} 0 0 0
127 }
128  
129 0 ▶ $results->set_skip_all( $self->{skip_all} ) if defined $self->{skip_all};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"skip_all"} 0 0 0
130  
131 0 ▶ my $passed = ( ( $results->max == 0 ) && defined $results->skip_all )
Condition0%0/15
$results->max == 0 && defined $results->skip_all || $results->max && $results->seen && $results->max == $results->seen && $results->max == $results->ok
l!l&&r!l&&!r
000
$results->max == 0 and defined $results->skip_all
!ll&&!rl&&r
000
$results->max and $results->seen and $results->max == $results->seen and $results->max == $results->ok
!ll&&!rl&&r
000
$results->max and $results->seen and $results->max == $results->seen
!ll&&!rl&&r
000
$results->max and $results->seen
!ll&&!rl&&r
000
MC/DC0%0/6
$results->max == 0 && defined $results->skip_all || $results->max && $results->seen && $results->max == $results->seen && $results->max == $results->ok
$results->max == 0 defined $results->skip_all $results->max $results->seen $results->max == $results->seen $results->max == $results->ok
Truth table0%0/11
A and B || C and D and E and F
A= $results->max == 0B= defined $results->skip_allC= $results->maxD= $results->seenE= $results->max == $results->seenF= $results->max == $results->ok
ABCDEFresult
11XXXX1
0X11111
1011111
0X0XXX0
0X10XX0
0X110X0
0X11100
100XXX0
1010XX0
10110X0
1011100
132 || ( $results->max
133 && $results->seen
134 && $results->max == $results->seen
135 && $results->max == $results->ok );
136  
137 0 ▶ $results->set_passing( $passed ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$passed ? : 0 0 0
138  
139 0 return $results;
140 }
141  
142 0 ▶sub _analyze_line {
Subroutine _analyze_line: not called CC=23 SCAR=63.1
143 0 my $self = shift;
144 0 my $line = shift;
145 0 my $results = shift;
146  
147 0 $self->{line}++;
148  
149 0 my $linetype;
150 0 my $point = TAPx::Harness::Compatible::Point->from_test_line($line);
151 0 ▶ if ($point) {
Branch: 5 branches
BranchTrueFalseTotal
if ($point) { } 0 0 0
elsif ($line =~ /^not\s+$/) { } 0 0 0
elsif ($self->_is_header($line)) { } 0 0 0
elsif ($self->_is_bail_out($line, \$self->{'bailout_reason'})) { } 0 0 0
elsif (my $diagnostics = $self->_is_diagnostic_line($line)) { } 0 0 0
152 0 $linetype = 'test';
153  
154 0 $results->inc_seen;
155 0 ▶ $point->set_number( $self->{'next'} ) unless $point->number;
Branch: 1 branch
BranchTrueFalseTotal
unless $point->number 0 0 0
156  
157 # sometimes the 'not ' and the 'ok' are on different lines,
158 # happens often on VMS if you do:
159 # print "not " unless $test;
160 # print "ok $num\n";
161 0 ▶ if ( $self->{lone_not_line}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lone_not_line"} and $self->{"lone_not_line"} == $self->{"line"} - 1) 0 0 0
Condition0%0/3
$self->{"lone_not_line"} and $self->{"lone_not_line"} == $self->{"line"} - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"lone_not_line"} and $self->{"lone_not_line"} == $self->{"line"} - 1
$self->{"lone_not_line"} $self->{"lone_not_line"} == $self->{"line"} - 1
Truth table0%0/3
A and B
A= $self->{"lone_not_line"}B= $self->{"lone_not_line"} == $self->{"line"} - 1
ABresult
0X0
100
111
162 && ( $self->{lone_not_line} == $self->{line} - 1 ) )
163 {
164 0 $point->set_ok(0);
165 }
166  
167 0 ▶ if ( $self->{todo}{ $point->number } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"todo"}{$point->number}) 0 0 0
168 0 $point->set_directive_type('todo');
169 }
170  
171 0 ▶ if ( $point->is_todo ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($point->is_todo) { } 0 0 0
elsif ($point->is_skip) { } 0 0 0
172 0 $results->inc_todo;
173 0 ▶ $results->inc_bonus if $point->ok;
Branch: 1 branch
BranchTrueFalseTotal
if $point->ok 0 0 0
174 }
175 elsif ( $point->is_skip ) {
176 0 $results->inc_skip;
177 }
178  
179 0 ▶ $results->inc_ok if $point->pass;
Branch: 1 branch
BranchTrueFalseTotal
if $point->pass 0 0 0
180  
181 0 ▶ if ( ( $point->number > 100_000 )
Branch: 1 branch
BranchTrueFalseTotal
if ($point->number > 100000 and $point->number > ($self->{'max'} || 100000)) { } 0 0 0
Condition0%0/5
$point->number > 100000 and $point->number > ($self->{"max"} || 100000)
!ll&&!rl&&r
000
$self->{'max'} || 100000
l!l
00
MC/DC0%0/2
$point->number > 100000 and $point->number > ($self->{"max"} || 100000)
$point->number > 100000 $point->number > ($self->{"max"} || 100000)
MC/DC0%0/1
$self->{'max'} || 100000
$self->{'max'}
Truth table0%0/3
A and B
A= $point->number > 100000B= $point->number > ($self->{"max"} || 100000)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $self->{'max'}
Aresult
11
00
182 && ( $point->number > ( $self->{max} || 100_000 ) ) )
183 {
184 0 ▶ if ( !$self->{too_many_tests}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"too_many_tests"}++) 0 0 0
185 0 warn "Enormous test number seen [test ", $point->number,
186 "]\n";
187 0 warn "Can't detailize, too big.\n";
188 }
189 }
190 else {
191 0 my $details = {
192 ok => $point->pass,
193 actual_ok => $point->ok,
194 name => _def_or_blank( $point->description ),
195 type => _def_or_blank( $point->directive_type ),
196 reason => _def_or_blank( $point->directive_reason ),
197 };
198  
199 die 'Assertion failed'
200 unless defined( $details->{ok} )
201 0 ▶ && defined( $details->{actual_ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $details->{"ok"} and defined $details->{"actual_ok"} 0 0 0
Condition0%0/3
defined $details->{"ok"} and defined $details->{"actual_ok"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $details->{"ok"} and defined $details->{"actual_ok"}
defined $details->{"ok"} defined $details->{"actual_ok"}
Truth table0%0/3
A and B
A= defined $details->{"ok"}B= defined $details->{"actual_ok"}
ABresult
0X0
100
111
202 0 $results->set_details( $point->number, $details );
203 }
204 } # test point
205 elsif ( $line =~ /^not\s+$/ ) {
206 0 $linetype = 'other';
207  
208 # Sometimes the "not " and "ok" will be on separate lines on VMS.
209 # We catch this and remember we saw it.
210 0 $self->{lone_not_line} = $self->{line};
211 }
212 elsif ( $self->_is_header($line) ) {
213 0 $linetype = 'header';
214  
215 0 $self->{saw_header}++;
216  
217 0 $results->inc_max( $self->{max} );
218 }
219 elsif ( $self->_is_bail_out( $line, \$self->{bailout_reason} ) ) {
220 0 $linetype = 'bailout';
221 0 $self->{saw_bailout} = 1;
222 }
223 elsif ( my $diagnostics = $self->_is_diagnostic_line($line) ) {
224 0 $linetype = 'other';
225  
226 # XXX We can throw this away, really.
227 0 my $test = $results->details->[-1];
228 0 ▶ $test->{diagnostics} ||= '';
Condition0%0/2
$test->{"diagnostics"} ||= ""
l!l
00
MC/DC0%0/1
$test->{"diagnostics"} ||= ""
$test->{"diagnostics"}
Truth table0%0/2
A
A= $test->{"diagnostics"}
Aresult
11
00
229 0 $test->{diagnostics} .= $diagnostics;
230 }
231 else {
232 0 $linetype = 'other';
233 }
234  
235 0 ▶ $self->callback->( $self, $line, $linetype, $results ) if $self->callback;
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
236  
237 0 ▶ $self->{'next'} = $point->number + 1 if $point;
Branch: 1 branch
BranchTrueFalseTotal
if $point 0 0 0
238 } # _analyze_line
239  
240 0 ▶sub _is_diagnostic_line {
Subroutine _is_diagnostic_line: not called CC=2 SCAR=17.9
241 0 my ( $self, $line ) = @_;
242 0 ▶ return if index( $line, '# Looks like you failed' ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($line, "# Looks like you failed") == 0 0 0 0
243 0 $line =~ s/^#\s//;
244 0 return $line;
245 }
246  
247 =for private $strap->analyze_fh( $name, $test_filehandle )
248  
249 my $results = $strap->analyze_fh($name, $test_filehandle);
250  
251 Like C<analyze>, but it reads from the given filehandle.
252  
253 =cut
254  
255 0 ▶sub analyze_fh {
Subroutine analyze_fh: not called CC=1 SCAR=6.9
Pod documented
256 0 my ( $self, $name, $fh ) = @_;
257  
258 0 my $it = TAPx::Harness::Compatible::Iterator->new($fh);
259 0 return $self->_analyze_iterator( $name, $it );
260 }
261  
262 =head2 $strap->analyze_file( $test_file )
263  
264 my $results = $strap->analyze_file($test_file);
265  
266 Like C<analyze>, but it runs the given C<$test_file> and parses its
267 results. It will also use that name for the total report.
268  
269 =cut
270  
271 0 ▶sub analyze_file {
Subroutine analyze_file: not called CC=8 SCAR=42.8
Pod documented
272 0 my ( $self, $file ) = @_;
273  
274 0 ▶ unless ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
275 0 $self->{error} = "$file does not exist";
276 0 return;
277 }
278  
279 0 ▶ unless ( -r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 0 0
280 0 $self->{error} = "$file is not readable";
281 0 return;
282 }
283  
284 0 local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
285 0 ▶ if ($TAPx::Harness::Compatible::Debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TAPx::Harness::Compatible::Debug) 0 0 0
286 0 local $^W = 0; # ignore undef warnings
287 0 print "# PERL5LIB=$ENV{PERL5LIB}\n";
288 }
289  
290 # *sigh* this breaks under taint, but open -| is unportable.
291 0 my $line = $self->_command_line($file);
292  
293 0 ▶ unless ( open( FILE, "$line|" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open FILE, "$line|") 0 0 0
294 0 print "can't run $file. $!\n";
295 0 return;
296 }
297  
298 0 my $results = $self->analyze_fh( $file, \*FILE );
299 0 my $exit = close FILE;
300  
301 0 $results->set_wait($?);
302 0 ▶ if ( $? && $self->{_is_vms} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? and $self->{'_is_vms'}) { } 0 0 0
Condition0%0/3
$? and $self->{"_is_vms"}
!ll&&!rl&&r
000
MC/DC0%0/2
$? and $self->{"_is_vms"}
$? $self->{"_is_vms"}
Truth table0%0/3
A and B
A= $?B= $self->{"_is_vms"}
ABresult
0X0
100
111
303 0 eval q{use vmsish "status"; $results->set_exit($?); };
304 }
305 else {
306 0 $results->set_exit( _wait2exit($?) );
307 }
308 0 ▶ $results->set_passing(0) unless $? == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $? == 0 0 0 0
309  
310 0 $self->_restore_PERL5LIB();
311  
312 0 return $results;
313 }
314  
315 1 eval { require POSIX; &POSIX::WEXITSTATUS(0) };
316 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 1 1
317 0 ▶ *_wait2exit = sub { $_[0] >> 8 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
318 }
319 else {
320 0 ▶ *_wait2exit = sub { POSIX::WEXITSTATUS( $_[0] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
321 1 }
322  
323 =for private $strap->_command_line( $file )
324  
325 Returns the full command line that will be run to test I<$file>.
326  
327 =cut
328  
329 0 ▶sub _command_line {
Subroutine _command_line: not called CC=3 SCAR=24.8
330 0 my $self = shift;
331 0 my $file = shift;
332  
333 0 my $command = $self->_command();
334 0 my $switches = $self->_switches($file);
335  
336 0 ▶ $file = qq["$file"] if ( $file =~ /\s/ ) && ( $file !~ /^".*"$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\s/ and not $file =~ /^".*"$/ 0 0 0
Condition0%0/3
$file =~ /\s/ and not $file =~ /^".*"$/
!ll&&!rl&&r
000
MC/DC0%0/2
$file =~ /\s/ and not $file =~ /^".*"$/
$file =~ /\s/ not $file =~ /^".*"$/
Truth table0%0/3
A and not(B)
A= $file =~ /\s/B= not $file =~ /^".*"$/
ABresult
0X0
100
111
337 0 my $line = "$command $switches $file";
338  
339 0 return $line;
340 }
341  
342 =for private $strap->_command()
343  
344 Returns the command that runs the test. Combine this with C<_switches()>
345 to build a command line.
346  
347 Typically this is C<$^X>, but you can set C<$ENV{HARNESS_PERL}>
348 to use a different Perl than what you're running the harness under.
349 This might be to run a threaded Perl, for example.
350  
351 You can also overload this method if you've built your own strap subclass,
352 such as a PHP interpreter for a PHP-based strap.
353  
354 =cut
355  
356 0 ▶sub _command {
Subroutine _command: not called CC=4 SCAR=30.0
357 0 my $self = shift;
358  
359 0 ▶ return $ENV{HARNESS_PERL} if defined $ENV{HARNESS_PERL};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"HARNESS_PERL"} 0 0 0
360 0 ▶ return qq["$^X"] if $self->{_is_win32} && ( $^X =~ /[^\w\.\/\\]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_win32"} and $^X =~ m([^\w\./\\]) 0 0 0
Condition0%0/3
$self->{"_is_win32"} and $^X =~ m([^\w\./\\])
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_is_win32"} and $^X =~ m([^\w\./\\])
$self->{"_is_win32"} $^X =~ m([^\w\./\\])
Truth table0%0/3
A and B
A= $self->{"_is_win32"}B= $^X =~ m([^\w\./\\])
ABresult
0X0
100
111
361 0 return $^X;
362 }
363  
364 =for private $strap->_switches( $file )
365  
366 Formats and returns the switches necessary to run the test.
367  
368 =cut
369  
370 0 ▶sub _switches {
Subroutine _switches: not called CC=10 SCAR=47.0
371 0 my ( $self, $file ) = @_;
372  
373 my @existing_switches = $self->_cleaned_switches(
374 $TAPx::Harness::Compatible::Switches,
375 $ENV{HARNESS_PERL_SWITCHES}
376 0 );
377 0 my @derived_switches;
378  
379 0 local *TEST;
380 0 ▶ open( TEST, $file ) or print "can't open $file. $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open TEST, $file or print "can't open $file. $!\n" 0 0 0
381 0 my $shebang = <TEST>;
382 0 ▶ close(TEST) or print "can't close $file. $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close TEST or print "can't close $file. $!\n" 0 0 0
383  
384 0 my $taint = ( $shebang =~ /^#!.*\bperl.*\s-\w*([Tt]+)/ );
385 0 ▶ push( @derived_switches, "-$1" ) if $taint;
Branch: 1 branch
BranchTrueFalseTotal
if $taint 0 0 0
386  
387 # When taint mode is on, PERL5LIB is ignored. So we need to put
388 # all that on the command line as -Is.
389 # MacPerl's putenv is broken, so it will not see PERL5LIB, tainted or not.
390 0 ▶ if ( $taint || $self->{_is_macos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taint or $self->{"_is_macos"}) 0 0 0
Condition0%0/3
$taint or $self->{"_is_macos"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$taint or $self->{"_is_macos"}
$taint $self->{"_is_macos"}
Truth table0%0/3
A or B
A= $taintB= $self->{"_is_macos"}
ABresult
1X1
011
000
391 0 my @inc = $self->_filtered_INC;
392 0 push @derived_switches, map {"-I$_"} @inc;
393 }
394  
395 # Quote the argument if there's any whitespace in it, or if
396 # we're VMS, since VMS requires all parms quoted. Also, don't quote
397 # it if it's already quoted.
398 0 for (@derived_switches) {
399 0 ▶ $_ = qq["$_"] if ( ( /\s/ || $self->{_is_vms} ) && !/^".*"$/ );
Branch: 1 branch
BranchTrueFalseTotal
if /\s/ || $self->{"_is_vms"} and not /^".*"$/ 0 0 0
Condition0%0/6
/\s/ || $self->{"_is_vms"} and not /^".*"$/
!ll&&!rl&&r
000
/\s/ or $self->{"_is_vms"}
l!l&&r!l&&!r
000
MC/DC0%0/3
/\s/ || $self->{"_is_vms"} and not /^".*"$/
/\s/ $self->{"_is_vms"} not /^".*"$/
Truth table0%0/5
A or B and not(C)
A= /\s/B= $self->{"_is_vms"}C= not /^".*"$/
ABCresult
00X0
1X00
0100
1X11
0111
400 }
401 0 return join( " ", @existing_switches, @derived_switches );
402 }
403  
404 =for private $strap->_cleaned_switches( @switches_from_user )
405  
406 Returns only defined, non-blank, trimmed switches from the parms passed.
407  
408 =cut
409  
410 0 ▶sub _cleaned_switches {
Subroutine _cleaned_switches: not called CC=4 SCAR=30.0
411 0 my $self = shift;
412  
413 0 local $_;
414  
415 0 my @switches;
416 0 for (@_) {
417 0 my $switch = $_;
418 0 ▶ next unless defined $switch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $switch 0 0 0
419 0 $switch =~ s/^\s+//;
420 0 $switch =~ s/\s+$//;
421 0 ▶ push( @switches, $switch ) if $switch ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $switch ne "" 0 0 0
422 }
423  
424 0 return @switches;
425 }
426  
427 =for private $strap->_INC2PERL5LIB
428  
429 local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
430  
431 Takes the current value of C<@INC> and turns it into something suitable
432 for putting onto C<PERL5LIB>.
433  
434 =cut
435  
436 0 ▶sub _INC2PERL5LIB {
Subroutine _INC2PERL5LIB: not called CC=1 SCAR=6.9
437 0 my ($self) = shift;
438  
439 0 $self->{_old5lib} = $ENV{PERL5LIB};
440  
441 0 return join $Config{path_sep}, $self->_filtered_INC;
442 }
443  
444 =for private $strap->_filtered_INC()
445  
446 my @filtered_inc = $self->_filtered_INC;
447  
448 Shortens C<@INC> by removing redundant and unnecessary entries.
449 Necessary for OSes with limited command line lengths, like VMS.
450  
451 =cut
452  
453 0 ▶sub _filtered_INC {
Subroutine _filtered_INC: not called CC=6 SCAR=37.4
454 0 my ( $self, @inc ) = @_;
455 0 ▶ @inc = @INC unless @inc;
Branch: 1 branch
BranchTrueFalseTotal
unless @inc 0 0 0
456  
457 0 ▶ if ( $self->{_is_vms} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_is_vms'}) { } 0 0 0
elsif ($self->{'_is_win32'}) { } 0 0 0
458  
459 # VMS has a 255-byte limit on the length of %ENV entries, so
460 # toss the ones that involve perl_root, the install location
461 0 @inc = grep !/perl_root/i, @inc;
462  
463 }
464 elsif ( $self->{_is_win32} ) {
465  
466 # Lose any trailing backslashes in the Win32 paths
467 0 s/[\\\/+]$// foreach @inc;
468 }
469  
470 0 my %seen;
471 0 $seen{$_}++ foreach $self->_default_inc();
472 0 @inc = grep !$seen{$_}++, @inc;
473  
474 0 return @inc;
475 }
476  
477 { # Without caching, _default_inc() takes a huge amount of time
478 1 my %cache;
479  
480 0 ▶ sub _default_inc {
Subroutine _default_inc: not called CC=2 SCAR=17.9
481 0 my $self = shift;
482 0 my $perl = $self->_command;
483 $cache{$perl} ||= [
484 0 ▶ do {
Condition0%0/2
$cache{$perl} ||= [do { local $ENV{"PERL5LIB"}; my(@inc) = `$perl -le "print join qq[\\n], \@INC"`; chomp @inc }]
l!l
00
MC/DC0%0/1
$cache{$perl} ||= [do { local $ENV{"PERL5LIB"}; my(@inc) = `$perl -le "print join qq[\\n], \@INC"`; chomp @inc }]
$cache{$perl}
Truth table0%0/2
A
A= $cache{$perl}
Aresult
11
00
485 0 local $ENV{PERL5LIB};
486 0 my @inc = `$perl -le "print join qq[\\n], \@INC"`;
487 0 chomp @inc;
488 }
489 ];
490 0 return @{ $cache{$perl} };
491 }
492 }
493  
494 =for private $strap->_restore_PERL5LIB()
495  
496 $self->_restore_PERL5LIB;
497  
498 This restores the original value of the C<PERL5LIB> environment variable.
499 Necessary on VMS, otherwise a no-op.
500  
501 =cut
502  
503 1 ▶sub _restore_PERL5LIB {
Subroutine _restore_PERL5LIB: not called CC=3 SCAR=22.3
504 0 my ($self) = shift;
505  
506 0 ▶ return unless $self->{_is_vms};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_is_vms"} 0 0 0
507  
508 0 ▶ if ( defined $self->{_old5lib} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_old5lib"}) 0 0 0
509 0 $ENV{PERL5LIB} = $self->{_old5lib};
510 }
511 }
512  
513 =head1 Parsing
514  
515 Methods for identifying what sort of line you're looking at.
516  
517 =for private _is_diagnostic
518  
519 my $is_diagnostic = $strap->_is_diagnostic($line, \$comment);
520  
521 Checks if the given line is a comment. If so, it will place it into
522 C<$comment> (sans #).
523  
524 =cut
525  
526 0 ▶sub _is_diagnostic {
Subroutine _is_diagnostic: not called CC=2 SCAR=17.9
527 0 my ( $self, $line, $comment ) = @_;
528  
529 0 ▶ if ( $line =~ /^\s*\#(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*\#(.*)/) { } 0 0 0
530 0 $$comment = $1;
531 0 return $YES;
532 }
533 else {
534 0 return $NO;
535 }
536 }
537  
538 =for private _is_header
539  
540 my $is_header = $strap->_is_header($line);
541  
542 Checks if the given line is a header (1..M) line. If so, it places how
543 many tests there will be in C<< $strap->{max} >>, a list of which tests
544 are todo in C<< $strap->{todo} >> and if the whole test was skipped
545 C<< $strap->{skip_all} >> contains the reason.
546  
547 =cut
548  
549 # Regex for parsing a header. Will be run with /x
550 1 my $Extra_Header_Re = <<'REGEX';
551 ^
552 (?: \s+ todo \s+ ([\d \t]+) )? # optional todo set
553 (?: \s* \# \s* ([\w:]+\s?) (.*) )? # optional skip with optional reason
554 REGEX
555  
556 0 ▶sub _is_header {
Subroutine _is_header: not called CC=8 SCAR=42.8
557 0 my ( $self, $line ) = @_;
558  
559 0 ▶ if ( my ( $max, $extra ) = $line =~ /^1\.\.(\d+)(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ /^1\.\.(\d+)(.*)/) { } 0 0 0
560 0 $self->{max} = $max;
561 die 'Max # tests looks wrong'
562 0 ▶ unless $self->{max} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"max"} >= 0 0 0 0
563  
564 0 ▶ if ( defined $extra ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra) 0 0 0
565 0 my ( $todo, $skip, $reason ) = $extra =~ /$Extra_Header_Re/xo;
566  
567 0 ▶ $self->{todo} = { map { $_ => 1 } split /\s+/, $todo } if $todo;
Branch: 1 branch
BranchTrueFalseTotal
if $todo 0 0 0
568  
569 0 ▶ if ( $self->{max} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} == 0) 0 0 0
570 0 ▶ $reason = '' unless defined $skip and $skip =~ /^Skip/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skip and $skip =~ /^Skip/i 0 0 0
Condition0%0/3
defined $skip and $skip =~ /^Skip/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $skip and $skip =~ /^Skip/i
defined $skip $skip =~ /^Skip/i
Truth table0%0/3
A and B
A= defined $skipB= $skip =~ /^Skip/i
ABresult
0X0
100
111
571 }
572  
573 0 $self->{skip_all} = $reason;
574 }
575  
576 0 return $YES;
577 }
578 else {
579 0 return $NO;
580 }
581 }
582  
583 =for private _is_bail_out
584  
585 my $is_bail_out = $strap->_is_bail_out($line, \$reason);
586  
587 Checks if the line is a "Bail out!". Places the reason for bailing
588 (if any) in $reason.
589  
590 =cut
591  
592 0 ▶sub _is_bail_out {
Subroutine _is_bail_out: not called CC=3 SCAR=24.8
593 0 my ( $self, $line, $reason ) = @_;
594  
595 0 ▶ if ( $line =~ /^Bail out!\s*(.*)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Bail out!\s*(.*)/i) { } 0 0 0
596 0 ▶ $$reason = $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
597 0 return $YES;
598 }
599 else {
600 0 return $NO;
601 }
602 }
603  
604 =for private _reset_file_state
605  
606 $strap->_reset_file_state;
607  
608 Resets things like C<< $strap->{max} >> , C<< $strap->{skip_all} >>,
609 etc. so it's ready to parse the next file.
610  
611 =cut
612  
613 0 ▶sub _reset_file_state {
Subroutine _reset_file_state: not called CC=1 SCAR=6.9
614 0 my ($self) = shift;
615  
616 0 delete @{$self}{qw(max skip_all todo too_many_tests)};
617 0 $self->{line} = 0;
618 0 $self->{saw_header} = 0;
619 0 $self->{saw_bailout} = 0;
620 0 $self->{lone_not_line} = 0;
621 0 $self->{bailout_reason} = '';
622 0 $self->{'next'} = 1;
623 }
624  
625 =head1 EXAMPLES
626  
627 See F<examples/mini_harness.plx> for an example of use.
628  
629 =head1 AUTHOR
630  
631 Michael G Schwern C<< <schwern at pobox.com> >>, currently maintained by
632 Andy Lester C<< <andy at petdance.com> >>.
633  
634 =head1 SEE ALSO
635  
636 L<TAPx::Harness::Compatible>
637  
638 =cut
639  
640 0 ▶sub _def_or_blank {
Subroutine _def_or_blank: not called CC=2 SCAR=17.9
641 0 ▶ return $_[0] if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
642 0 return "";
643 }
644  
645 0 ▶sub set_callback {
Subroutine set_callback: not called CC=1 SCAR=6.9
Pod documented
646 0 my $self = shift;
647 0 $self->{callback} = shift;
648 }
649  
650 0 ▶sub callback {
Subroutine callback: not called CC=1 SCAR=6.9
Pod documented
651 0 my $self = shift;
652 0 return $self->{callback};
653 }
654  
655 1 1;
656  
657 =head1 TO DOCUMENT
658  
659 =over
660  
661 =item analyze_fh
662  
663 TODO: Document analyze_fh
664  
665 =item callback
666  
667 TODO: Document callback
668  
669 =item set_callback
670  
671 TODO: Document set_callback
672  
673 =back
« Harness/Compatible.pm ↑ Summary Harness/Compatible/Util.pm »