support/Test/Harness/Straps.pm

filter: Statementstmt 80.6% 179 / 222 Branchbran 50.0% 52 / 104 Conditioncond 31.3% 16 / 51 MC/DCmcdc 7.1% 2 / 28 Subroutinesub 89.6% 26 / 29 Podpod 75.0% 3 / 4 totaltotal 63.4% 278 / 438 CC 74 SCAR 29.2
CC
74
Cov
66%
_analyze_line
53.0
_switches
23.6
_analyze_iterator
15.1
CRAP 18.5
« blib/lib/Convert/Binary/C/Cached.pm ↑ Summary examples/elf.pl »
1 # -*- Mode: cperl; cperl-indent-level: 4 -*-
2 package Test::Harness::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.26';
7  
8 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Test::Harness::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Test::Harness::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Test::Harness::Point;
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 Test::Harness::Straps - detailed analysis of test results
21  
22 =head1 SYNOPSIS
23  
24 use Test::Harness::Straps;
25  
26 my $strap = Test::Harness::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 Test::Harness 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 Test::Harness::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 = Test::Harness::Straps->new;
62  
63 Initialize a new strap.
64  
65 =cut
66  
67 sub new {
68 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
69 1 my $self = bless {}, $class;
70  
71 1 $self->_init;
72  
73 1 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 sub _init {
85 1 ▶ my($self) = shift;
Subroutine _init: called CC=1 SCAR=0.0
86  
87 1 $self->{_is_vms} = ( $^O eq 'VMS' );
88 1 $self->{_is_win32} = ( $^O =~ /^(MS)?Win32$/ );
89 1 $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 sub analyze {
108 0 ▶ my($self, $name, $test_output) = @_;
Subroutine analyze: not called CC=1 SCAR=6.9
Pod documented
109  
110 0 my $it = Test::Harness::Iterator->new($test_output);
111 0 return $self->_analyze_iterator($name, $it);
112 }
113  
114  
115 sub _analyze_iterator {
116 58 ▶ my($self, $name, $it) = @_;
Subroutine _analyze_iterator: called CC=10 SCAR=27.2
117  
118 58 $self->_reset_file_state;
119 58 $self->{file} = $name;
120 58 my %totals = (
121 max => 0,
122 seen => 0,
123  
124 ok => 0,
125 todo => 0,
126 skip => 0,
127 bonus => 0,
128  
129 details => []
130 );
131  
132 # Set them up here so callbacks can have them.
133 58 $self->{totals}{$name} = \%totals;
134 58 ▶ while( defined(my $line = $it->next) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $it->next)) 64823 58 64881
135 64823 $self->_analyze_line($line, \%totals);
136 64823 ▶ last if $self->{saw_bailout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"saw_bailout"} 0 64823 64823
137 }
138  
139 58 ▶ $totals{skip_all} = $self->{skip_all} if defined $self->{skip_all};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"skip_all"} 0 58 58
140  
141 my $passed = ($totals{max} == 0 && defined $totals{skip_all}) ||
142 ($totals{max} && $totals{seen} &&
143 $totals{max} == $totals{seen} &&
144 58 ▶ $totals{max} == $totals{ok});
Condition33%5/15
$totals{'max'} == 0 && defined $totals{'skip_all'} || $totals{'max'} && $totals{'seen'} && $totals{'max'} == $totals{'seen'} && $totals{'max'} == $totals{'ok'}
l!l&&r!l&&!r
0580
$totals{"max"} == 0 and defined $totals{"skip_all"}
!ll&&!rl&&r
5800
$totals{"max"} and $totals{"seen"} and $totals{"max"} == $totals{"seen"} and $totals{"max"} == $totals{"ok"}
!ll&&!rl&&r
0058
$totals{"max"} and $totals{"seen"} and $totals{"max"} == $totals{"seen"}
!ll&&!rl&&r
0058
$totals{"max"} and $totals{"seen"}
!ll&&!rl&&r
0058
MC/DC0%0/6
$totals{'max'} == 0 && defined $totals{'skip_all'} || $totals{'max'} && $totals{'seen'} && $totals{'max'} == $totals{'seen'} && $totals{'max'} == $totals{'ok'}
$totals{"max"} == 0 defined $totals{"skip_all"} $totals{"max"} $totals{"seen"} $totals{"max"} == $totals{"seen"} $totals{"max"} == $totals{"ok"}
Truth table9%1/11
A and B || C and D and E and F
A= $totals{"max"} == 0B= defined $totals{"skip_all"}C= $totals{"max"}D= $totals{"seen"}E= $totals{"max"} == $totals{"seen"}F= $totals{"max"} == $totals{"ok"}
ABCDEFresult
11XXXX1
0X11111
1011111
0X0XXX0
0X10XX0
0X110X0
0X11100
100XXX0
1010XX0
10110X0
1011100
145 58 ▶ $totals{passing} = $passed ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$passed ? : 58 0 58
146  
147 58 return %totals;
148 }
149  
150  
151 sub _analyze_line {
152 64823 ▶ my $self = shift;
Subroutine _analyze_line: called CC=22 SCAR=39.7
153 64823 my $line = shift;
154 64823 my $totals = shift;
155  
156 64823 $self->{line}++;
157  
158 64823 my $linetype;
159 64823 my $point = Test::Harness::Point->from_test_line( $line );
160 64823 ▶ if ( $point ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($point) { } 48545 16278 64823
elsif ($line =~ /^not\s+$/) { } 0 16278 16278
elsif ($self->_is_header($line)) { } 58 16220 16278
elsif ($self->_is_bail_out($line, \$self->{'bailout_reason'})) { } 0 16220 16220
elsif (my $diagnostics = $self->_is_diagnostic_line($line)) { } 16220 0 16220
161 48545 $linetype = 'test';
162  
163 48545 $totals->{seen}++;
164 48545 ▶ $point->set_number( $self->{'next'} ) unless $point->number;
Branch: 1 branch
BranchTrueFalseTotal
unless $point->number 0 48545 48545
165  
166 # sometimes the 'not ' and the 'ok' are on different lines,
167 # happens often on VMS if you do:
168 # print "not " unless $test;
169 # print "ok $num\n";
170 48545 ▶ if ( $self->{lone_not_line} && ($self->{lone_not_line} == $self->{line} - 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lone_not_line"} and $self->{"lone_not_line"} == $self->{"line"} - 1) 0 48545 48545
Condition33%1/3
$self->{"lone_not_line"} and $self->{"lone_not_line"} == $self->{"line"} - 1
!ll&&!rl&&r
4854500
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 table33%1/3
A and B
A= $self->{"lone_not_line"}B= $self->{"lone_not_line"} == $self->{"line"} - 1
ABresult
0X0
100
111
171 0 $point->set_ok( 0 );
172 }
173  
174 48545 ▶ if ( $self->{todo}{$point->number} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"todo"}{$point->number}) 0 48545 48545
175 0 $point->set_directive_type( 'todo' );
176 }
177  
178 48545 ▶ if ( $point->is_todo ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($point->is_todo) { } 0 48545 48545
elsif ($point->is_skip) { } 556 47989 48545
179 0 $totals->{todo}++;
180 0 ▶ $totals->{bonus}++ if $point->ok;
Branch: 1 branch
BranchTrueFalseTotal
if $point->ok 0 0 0
181 }
182 elsif ( $point->is_skip ) {
183 556 $totals->{skip}++;
184 }
185  
186 48545 ▶ $totals->{ok}++ if $point->pass;
Branch: 1 branch
BranchTrueFalseTotal
if $point->pass 48545 0 48545
187  
188 48545 ▶ if ( ($point->number > 100_000) && ($point->number > ($self->{max}||100_000)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($point->number > 100000 and $point->number > ($self->{'max'} || 100000)) { } 0 48545 48545
Condition20%1/5
$point->number > 100000 and $point->number > ($self->{"max"} || 100000)
!ll&&!rl&&r
4854500
$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 table33%1/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
189 0 ▶ if ( !$self->{too_many_tests}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"too_many_tests"}++) 0 0 0
190 0 warn "Enormous test number seen [test ", $point->number, "]\n";
191 0 warn "Can't detailize, too big.\n";
192 }
193 }
194 else {
195 48545 my $details = {
196 ok => $point->pass,
197 actual_ok => $point->ok,
198 name => _def_or_blank( $point->description ),
199 type => _def_or_blank( $point->directive_type ),
200 reason => _def_or_blank( $point->directive_reason ),
201 };
202  
203 48545 ▶ assert( defined( $details->{ok} ) && defined( $details->{actual_ok} ) );
Condition33%1/3
defined $details->{'ok'} && defined $details->{'actual_ok'}
!ll&&!rl&&r
0048545
MC/DC0%0/2
defined $details->{'ok'} && defined $details->{'actual_ok'}
defined $details->{'ok'} defined $details->{'actual_ok'}
Truth table33%1/3
A && B
A= defined $details->{'ok'}B= defined $details->{'actual_ok'}
ABresult
0X0
100
111
204 48545 $totals->{details}[$point->number - 1] = $details;
205 }
206 } # test point
207 elsif ( $line =~ /^not\s+$/ ) {
208 0 $linetype = 'other';
209 # Sometimes the "not " and "ok" will be on separate lines on VMS.
210 # We catch this and remember we saw it.
211 0 $self->{lone_not_line} = $self->{line};
212 }
213 elsif ( $self->_is_header($line) ) {
214 58 $linetype = 'header';
215  
216 58 $self->{saw_header}++;
217  
218 58 $totals->{max} += $self->{max};
219 }
220 elsif ( $self->_is_bail_out($line, \$self->{bailout_reason}) ) {
221 0 $linetype = 'bailout';
222 0 $self->{saw_bailout} = 1;
223 }
224 elsif (my $diagnostics = $self->_is_diagnostic_line( $line )) {
225 16220 $linetype = 'other';
226 16220 my $test = $totals->{details}[-1];
227 16220 ▶ $test->{diagnostics} ||= '';
Condition100%2/2
$test->{"diagnostics"} ||= ""
l!l
64999721
MC/DC100%1/1
$test->{"diagnostics"} ||= ""
$test->{"diagnostics"}
Truth table100%2/2
A
A= $test->{"diagnostics"}
Aresult
11
00
228 16220 $test->{diagnostics} .= $diagnostics;
229 }
230 else {
231 0 $linetype = 'other';
232 }
233  
234 64823 ▶ $self->{callback}->($self, $line, $linetype, $totals) if $self->{callback};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback"} 64823 0 64823
235  
236 64823 ▶ $self->{'next'} = $point->number + 1 if $point;
Branch: 1 branch
BranchTrueFalseTotal
if $point 48545 16278 64823
237 } # _analyze_line
238  
239  
240 sub _is_diagnostic_line {
241 16220 ▶ my ($self, $line) = @_;
Subroutine _is_diagnostic_line: called CC=2 SCAR=7.0
242 16220 ▶ return if index( $line, '# Looks like you failed' ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($line, "# Looks like you failed") == 0 0 16220 16220
243 16220 $line =~ s/^#\s//;
244 16220 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 sub analyze_fh {
256 58 ▶ my($self, $name, $fh) = @_;
Subroutine analyze_fh: called CC=1 SCAR=0.0
Pod undocumented
257  
258 58 my $it = Test::Harness::Iterator->new($fh);
259 58 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 sub analyze_file {
272 58 ▶ my($self, $file) = @_;
Subroutine analyze_file: called CC=8 SCAR=25.9
Pod documented
273  
274 58 ▶ unless( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 58 58
275 0 $self->{error} = "$file does not exist";
276 0 return;
277 }
278  
279 58 ▶ unless( -r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 58 58
280 0 $self->{error} = "$file is not readable";
281 0 return;
282 }
283  
284 58 local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
285 58 ▶ if ( $Test::Harness::Debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Test::Harness::Debug) 0 58 58
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 58 my $line = $self->_command_line($file);
292  
293 58 ▶ unless ( open(FILE, "$line|" )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open FILE, "$line|") 0 58 58
294 0 print "can't run $file. $!\n";
295 0 return;
296 }
297  
298 58 my %results = $self->analyze_fh($file, \*FILE);
299 58 my $exit = close FILE;
300 58 $results{'wait'} = $?;
301 58 ▶ if( $? && $self->{_is_vms} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? and $self->{'_is_vms'}) { } 0 58 58
Condition33%1/3
$? and $self->{"_is_vms"}
!ll&&!rl&&r
5800
MC/DC0%0/2
$? and $self->{"_is_vms"}
$? $self->{"_is_vms"}
Truth table33%1/3
A and B
A= $?B= $self->{"_is_vms"}
ABresult
0X0
100
111
302 0 eval q{use vmsish "status"; $results{'exit'} = $?};
303 }
304 else {
305 58 $results{'exit'} = _wait2exit($?);
306 }
307 58 ▶ $results{passing} = 0 unless $? == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $? == 0 0 58 58
308  
309 58 $self->_restore_PERL5LIB();
310  
311 58 return %results;
312 }
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 58 ▶ *_wait2exit = sub { POSIX::WEXITSTATUS($_[0]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
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 sub _command_line {
330 58 ▶ my $self = shift;
Subroutine _command_line: called CC=3 SCAR=11.4
331 58 my $file = shift;
332  
333 58 my $command = $self->_command();
334 58 my $switches = $self->_switches($file);
335  
336 58 ▶ $file = qq["$file"] if ($file =~ /\s/) && ($file !~ /^".*"$/);
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\s/ and not $file =~ /^".*"$/ 0 58 58
Condition33%1/3
$file =~ /\s/ and not $file =~ /^".*"$/
!ll&&!rl&&r
5800
MC/DC0%0/2
$file =~ /\s/ and not $file =~ /^".*"$/
$file =~ /\s/ not $file =~ /^".*"$/
Truth table33%1/3
A and not(B)
A= $file =~ /\s/B= not $file =~ /^".*"$/
ABresult
0X0
100
111
337 58 my $line = "$command $switches $file";
338  
339 58 return $line;
340 }
341  
342  
343 =for private $strap->_command()
344  
345 Returns the command that runs the test. Combine this with C<_switches()>
346 to build a command line.
347  
348 Typically this is C<$^X>, but you can set C<$ENV{HARNESS_PERL}>
349 to use a different Perl than what you're running the harness under.
350 This might be to run a threaded Perl, for example.
351  
352 You can also overload this method if you've built your own strap subclass,
353 such as a PHP interpreter for a PHP-based strap.
354  
355 =cut
356  
357 sub _command {
358 116 ▶ my $self = shift;
Subroutine _command: called CC=4 SCAR=15.6
359  
360 116 ▶ return $ENV{HARNESS_PERL} if defined $ENV{HARNESS_PERL};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"HARNESS_PERL"} 0 116 116
361 116 ▶ return qq["$^X"] if $self->{_is_win32} && ($^X =~ /[^\w\.\/\\]/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_win32"} and $^X =~ m([^\w\./\\]) 0 116 116
Condition33%1/3
$self->{"_is_win32"} and $^X =~ m([^\w\./\\])
!ll&&!rl&&r
11600
MC/DC0%0/2
$self->{"_is_win32"} and $^X =~ m([^\w\./\\])
$self->{"_is_win32"} $^X =~ m([^\w\./\\])
Truth table33%1/3
A and B
A= $self->{"_is_win32"}B= $^X =~ m([^\w\./\\])
ABresult
0X0
100
111
362 116 return $^X;
363 }
364  
365  
366 =for private $strap->_switches( $file )
367  
368 Formats and returns the switches necessary to run the test.
369  
370 =cut
371  
372 sub _switches {
373 58 ▶ my($self, $file) = @_;
Subroutine _switches: called CC=10 SCAR=31.6
374  
375 58 my @existing_switches = $self->_cleaned_switches( $Test::Harness::Switches, $ENV{HARNESS_PERL_SWITCHES} );
376 58 my @derived_switches;
377  
378 58 local *TEST;
379 58 ▶ 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 58 58
380 58 my $shebang = <TEST>;
381 58 ▶ close(TEST) or print "can't close $file. $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close TEST or print "can't close $file. $!\n" 0 58 58
382  
383 58 my $taint = ( $shebang =~ /^#!.*\bperl.*\s-\w*([Tt]+)/ );
384 58 ▶ push( @derived_switches, "-$1" ) if $taint;
Branch: 1 branch
BranchTrueFalseTotal
if $taint 0 58 58
385  
386 # When taint mode is on, PERL5LIB is ignored. So we need to put
387 # all that on the command line as -Is.
388 # MacPerl's putenv is broken, so it will not see PERL5LIB, tainted or not.
389 58 ▶ if ( $taint || $self->{_is_macos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taint or $self->{"_is_macos"}) 0 58 58
Condition33%1/3
$taint or $self->{"_is_macos"}
l!l&&r!l&&!r
0058
MC/DC0%0/2
$taint or $self->{"_is_macos"}
$taint $self->{"_is_macos"}
Truth table33%1/3
A or B
A= $taintB= $self->{"_is_macos"}
ABresult
1X1
011
000
390 0 my @inc = $self->_filtered_INC;
391 0 push @derived_switches, map { "-I$_" } @inc;
392 }
393  
394 # Quote the argument if there's any whitespace in it, or if
395 # we're VMS, since VMS requires all parms quoted. Also, don't quote
396 # it if it's already quoted.
397 58 for ( @derived_switches ) {
398 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
399 }
400 58 return join( " ", @existing_switches, @derived_switches );
401 }
402  
403 =for private $strap->_cleaned_switches( @switches_from_user )
404  
405 Returns only defined, non-blank, trimmed switches from the parms passed.
406  
407 =cut
408  
409 sub _cleaned_switches {
410 58 ▶ my $self = shift;
Subroutine _cleaned_switches: called CC=4 SCAR=14.0
411  
412 58 local $_;
413  
414 58 my @switches;
415 58 for ( @_ ) {
416 116 my $switch = $_;
417 116 ▶ next unless defined $switch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $switch 0 116 116
418 116 $switch =~ s/^\s+//;
419 116 $switch =~ s/\s+$//;
420 116 ▶ push( @switches, $switch ) if $switch ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $switch ne "" 116 0 116
421 }
422  
423 58 return @switches;
424 }
425  
426 =for private $strap->_INC2PERL5LIB
427  
428 local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
429  
430 Takes the current value of C<@INC> and turns it into something suitable
431 for putting onto C<PERL5LIB>.
432  
433 =cut
434  
435 sub _INC2PERL5LIB {
436 58 ▶ my($self) = shift;
Subroutine _INC2PERL5LIB: called CC=1 SCAR=0.0
437  
438 58 $self->{_old5lib} = $ENV{PERL5LIB};
439  
440 58 return join $Config{path_sep}, $self->_filtered_INC;
441 }
442  
443 =for private $strap->_filtered_INC()
444  
445 my @filtered_inc = $self->_filtered_INC;
446  
447 Shortens C<@INC> by removing redundant and unnecessary entries.
448 Necessary for OSes with limited command line lengths, like VMS.
449  
450 =cut
451  
452 sub _filtered_INC {
453 58 ▶ my($self, @inc) = @_;
Subroutine _filtered_INC: called CC=6 SCAR=19.9
454 58 ▶ @inc = @INC unless @inc;
Branch: 1 branch
BranchTrueFalseTotal
unless @inc 58 0 58
455  
456 58 ▶ if( $self->{_is_vms} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_is_vms'}) { } 0 58 58
elsif ($self->{'_is_win32'}) { } 0 58 58
457 # VMS has a 255-byte limit on the length of %ENV entries, so
458 # toss the ones that involve perl_root, the install location
459 0 @inc = grep !/perl_root/i, @inc;
460  
461 }
462 elsif ( $self->{_is_win32} ) {
463 # Lose any trailing backslashes in the Win32 paths
464 0 s/[\\\/+]$// foreach @inc;
465 }
466  
467 58 my %seen;
468 58 $seen{$_}++ foreach $self->_default_inc();
469 58 @inc = grep !$seen{$_}++, @inc;
470  
471 58 return @inc;
472 }
473  
474  
475 { # Without caching, _default_inc() takes a huge amount of time
476 1 my %cache;
477 sub _default_inc {
478 58 ▶ my $self = shift;
Subroutine _default_inc: called CC=2 SCAR=6.9
479 58 my $perl = $self->_command;
480 58 ▶ $cache{$perl} ||= [do {
Condition100%2/2
$cache{$perl} ||= [do { local $ENV{"PERL5LIB"}; my(@inc) = `$perl -le "print join qq[\\n], \@INC"`; chomp @inc }]
l!l
571
MC/DC100%1/1
$cache{$perl} ||= [do { local $ENV{"PERL5LIB"}; my(@inc) = `$perl -le "print join qq[\\n], \@INC"`; chomp @inc }]
$cache{$perl}
Truth table100%2/2
A
A= $cache{$perl}
Aresult
11
00
481 1 local $ENV{PERL5LIB};
482 1 my @inc =`$perl -le "print join qq[\\n], \@INC"`;
483 1 chomp @inc;
484 }];
485 58 return @{$cache{$perl}};
486 }
487 }
488  
489  
490 =for private $strap->_restore_PERL5LIB()
491  
492 $self->_restore_PERL5LIB;
493  
494 This restores the original value of the C<PERL5LIB> environment variable.
495 Necessary on VMS, otherwise a no-op.
496  
497 =cut
498  
499 1 sub _restore_PERL5LIB {
500 59 ▶ my($self) = shift;
Subroutine _restore_PERL5LIB: called CC=3 SCAR=16.5
501  
502 59 ▶ return unless $self->{_is_vms};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_is_vms"} 59 0 59
503  
504 0 ▶ if (defined $self->{_old5lib}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_old5lib"}) 0 0 0
505 0 $ENV{PERL5LIB} = $self->{_old5lib};
506 }
507 }
508  
509 =head1 Parsing
510  
511 Methods for identifying what sort of line you're looking at.
512  
513 =for private _is_diagnostic
514  
515 my $is_diagnostic = $strap->_is_diagnostic($line, \$comment);
516  
517 Checks if the given line is a comment. If so, it will place it into
518 C<$comment> (sans #).
519  
520 =cut
521  
522 sub _is_diagnostic {
523 0 ▶ my($self, $line, $comment) = @_;
Subroutine _is_diagnostic: not called CC=2 SCAR=17.9
524  
525 0 ▶ if( $line =~ /^\s*\#(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*\#(.*)/) { } 0 0 0
526 0 $$comment = $1;
527 0 return $YES;
528 }
529 else {
530 0 return $NO;
531 }
532 }
533  
534 =for private _is_header
535  
536 my $is_header = $strap->_is_header($line);
537  
538 Checks if the given line is a header (1..M) line. If so, it places how
539 many tests there will be in C<< $strap->{max} >>, a list of which tests
540 are todo in C<< $strap->{todo} >> and if the whole test was skipped
541 C<< $strap->{skip_all} >> contains the reason.
542  
543 =cut
544  
545 # Regex for parsing a header. Will be run with /x
546 1 my $Extra_Header_Re = <<'REGEX';
547 ^
548 (?: \s+ todo \s+ ([\d \t]+) )? # optional todo set
549 (?: \s* \# \s* ([\w:]+\s?) (.*) )? # optional skip with optional reason
550 REGEX
551  
552 sub _is_header {
553 16278 ▶ my($self, $line) = @_;
Subroutine _is_header: called CC=7 SCAR=22.8
554  
555 16278 ▶ if( my($max, $extra) = $line =~ /^1\.\.(\d+)(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ /^1\.\.(\d+)(.*)/) { } 58 16220 16278
556 58 $self->{max} = $max;
557 58 assert( $self->{max} >= 0, 'Max # of tests looks right' );
558  
559 58 ▶ if( defined $extra ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra) 58 0 58
560 58 my($todo, $skip, $reason) = $extra =~ /$Extra_Header_Re/xo;
561  
562 58 ▶ $self->{todo} = { map { $_ => 1 } split /\s+/, $todo } if $todo;
Branch: 1 branch
BranchTrueFalseTotal
if $todo 0 58 58
563  
564 58 ▶ if( $self->{max} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} == 0) 0 58 58
565 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
566 }
567  
568 58 $self->{skip_all} = $reason;
569 }
570  
571 58 return $YES;
572 }
573 else {
574 16220 return $NO;
575 }
576 }
577  
578 =for private _is_bail_out
579  
580 my $is_bail_out = $strap->_is_bail_out($line, \$reason);
581  
582 Checks if the line is a "Bail out!". Places the reason for bailing
583 (if any) in $reason.
584  
585 =cut
586  
587 sub _is_bail_out {
588 16220 ▶ my($self, $line, $reason) = @_;
Subroutine _is_bail_out: called CC=3 SCAR=15.1
589  
590 16220 ▶ if( $line =~ /^Bail out!\s*(.*)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Bail out!\s*(.*)/i) { } 0 16220 16220
591 0 ▶ $$reason = $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
592 0 return $YES;
593 }
594 else {
595 16220 return $NO;
596 }
597 }
598  
599 =for private _reset_file_state
600  
601 $strap->_reset_file_state;
602  
603 Resets things like C<< $strap->{max} >> , C<< $strap->{skip_all} >>,
604 etc. so it's ready to parse the next file.
605  
606 =cut
607  
608 sub _reset_file_state {
609 58 ▶ my($self) = shift;
Subroutine _reset_file_state: called CC=1 SCAR=0.0
610  
611 58 delete @{$self}{qw(max skip_all todo too_many_tests)};
612 58 $self->{line} = 0;
613 58 $self->{saw_header} = 0;
614 58 $self->{saw_bailout}= 0;
615 58 $self->{lone_not_line} = 0;
616 58 $self->{bailout_reason} = '';
617 58 $self->{'next'} = 1;
618 }
619  
620 =head1 Results
621  
622 The C<%results> returned from C<analyze()> contain the following
623 information:
624  
625 passing true if the whole test is considered a pass
626 (or skipped), false if its a failure
627  
628 exit the exit code of the test run, if from a file
629 wait the wait code of the test run, if from a file
630  
631 max total tests which should have been run
632 seen total tests actually seen
633 skip_all if the whole test was skipped, this will
634 contain the reason.
635  
636 ok number of tests which passed
637 (including todo and skips)
638  
639 todo number of todo tests seen
640 bonus number of todo tests which
641 unexpectedly passed
642  
643 skip number of tests skipped
644  
645 So a successful test should have max == seen == ok.
646  
647  
648 There is one final item, the details.
649  
650 details an array ref reporting the result of
651 each test looks like this:
652  
653 $results{details}[$test_num - 1] =
654 { ok => is the test considered ok?
655 actual_ok => did it literally say 'ok'?
656 name => name of the test (if any)
657 diagnostics => test diagnostics (if any)
658 type => 'skip' or 'todo' (if any)
659 reason => reason for the above (if any)
660 };
661  
662 Element 0 of the details is test #1. I tried it with element 1 being
663 #1 and 0 being empty, this is less awkward.
664  
665 =head1 EXAMPLES
666  
667 See F<examples/mini_harness.plx> for an example of use.
668  
669 =head1 AUTHOR
670  
671 Michael G Schwern C<< <schwern at pobox.com> >>, currently maintained by
672 Andy Lester C<< <andy at petdance.com> >>.
673  
674 =head1 SEE ALSO
675  
676 L<Test::Harness>
677  
678 =cut
679  
680 sub _def_or_blank {
681 145635 ▶ return $_[0] if defined $_[0];
Subroutine _def_or_blank: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 21904 123731 145635
682 123731 return "";
683 }
684  
685 1 1;
« blib/lib/Convert/Binary/C/Cached.pm ↑ Summary examples/elf.pl »