blib/lib/Test/Script.pm

filter: Statementstmt 98.0% 256 / 261 Branchbran 85.5% 89 / 104 Conditioncond 62.3% 38 / 61 MC/DCmcdc 25.8% 8 / 31 Subroutinesub 100% 47 / 47 Podpod 91.3% 21 / 23 totaltotal 87.1% 459 / 527 CC 82 SCAR 16.7
CC
82
Cov
90%
_run
14.3
script_compiles
10.0
_options
9.0
CRAP 5.3
↑ Summary
1 package Test::Script;
2  
3 # ABSTRACT: Basic cross-platform tests for scripts
4 15 our $VERSION = '1.31'; # VERSION
5  
6  
7 15 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use File::Spec::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Probe::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Capture::Tiny qw( capture );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use Test2::API qw( context );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use File::Temp qw( tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 15 our @ISA = 'Exporter';
21 15 our @EXPORT = qw{
22 script_compiles
23 script_compiles_ok
24 script_fails
25 script_runs
26 script_stdout_is
27 script_stdout_isnt
28 script_stdout_like
29 script_stdout_unlike
30 script_stderr_is
31 script_stderr_isnt
32 script_stderr_like
33 script_stderr_unlike
34 program_fails
35 program_runs
36 program_stdout_is
37 program_stdout_isnt
38 program_stdout_like
39 program_stdout_unlike
40 program_stderr_is
41 program_stderr_isnt
42 program_stderr_like
43 program_stderr_unlike
44 };
45  
46 16 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
47 16 my $class = shift;
48 16 my $pack = caller;
49 16 ▶ if(defined $_[0] && $_[0] =~ /^(?:no_plan|skip_all|tests)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^(?:no_plan|skip_all|tests)$/) { } 4 12 16
Condition100%3/3
defined $_[0] and $_[0] =~ /^(?:no_plan|skip_all|tests)$/
!ll&&!rl&&r
1114
MC/DC100%2/2
defined $_[0] and $_[0] =~ /^(?:no_plan|skip_all|tests)$/
defined $_[0] $_[0] =~ /^(?:no_plan|skip_all|tests)$/
Truth table100%3/3
A and B
A= defined $_[0]B= $_[0] =~ /^(?:no_plan|skip_all|tests)$/
ABresult
0X0
100
111
50 {
51 # icky back compat.
52 # do not use.
53 4 my $ctx = context();
54 4 ▶ if($_[0] eq 'tests')
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] eq 'tests') { } 2 2 4
elsif ($_[0] eq 'skip_all') { } 1 1 2
55 {
56 2 $ctx->plan($_[1]);
57 }
58 elsif($_[0] eq 'skip_all')
59 {
60 1 $ctx->plan(0, 'SKIP', $_[1]);
61 }
62 else
63 {
64 1 $ctx->hub->plan('NO PLAN');
65 }
66 3 $ctx->release;
67 3 foreach ( @EXPORT ) {
68 66 $class->export_to_level(1, $class, $_);
69 }
70 }
71 else
72 {
73 12 unshift @_, $class;
74 12 goto &Exporter::import;
75 }
76 }
77  
78 15 my $perl = undef;
79  
80 26 ▶sub perl () {
Subroutine perl: called CC=2 SCAR=6.9
Pod undocumented
81 26 ▶ $perl or
Branch: 1 branch
BranchTrueFalseTotal
$perl or $perl = "Probe::Perl"->find_perl_interpreter 21 5 26
82 $perl = Probe::Perl->find_perl_interpreter;
83 }
84  
85 26 ▶sub path ($) {
Subroutine path: called CC=3 SCAR=12.7
Pod undocumented
86 26 my $path = shift;
87 26 ▶ unless ( defined $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 26 26
88 0 croak("Did not provide a script name");
89 }
90 26 ▶ if ( File::Spec::Unix->file_name_is_absolute($path) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("File::Spec::Unix"->file_name_is_absolute($path)) 0 26 26
91 0 croak("Script name must be relative");
92 }
93 File::Spec->catfile(
94 26 File::Spec->curdir,
95 split /\//, $path
96 );
97 }
98  
99 #####################################################################
100 # Test Functions for Scripts
101  
102  
103 8 ▶sub script_compiles {
Subroutine script_compiles: called CC=10 SCAR=23.1
Pod documented
104 8 my $args = _script(shift);
105 8 my $unix = shift @$args;
106 8 my $path = path( $unix );
107 8 my $pargs = _perl_args($path);
108 8 my $dir = _preload_module();
109 8 my $cmd = [ perl, @$pargs, "-I$dir", '-M__TEST_SCRIPT__', '-c', $path, @$args ];
110 8 ▶ my ($stdout, $stderr) = capture { system(@$cmd) };
Subroutine __ANON__: called CC=1 SCAR=0.0
111 8 my $error = $@;
112 8 ▶ my $exit = $? ? ($? >> 8) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? ? : 4 4 8
113 8 ▶ my $signal = $? ? ($? & 127) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? ? : 4 4 8
114 8 ▶ my $ok = !! (
Condition77%7/9
$error eq '' && $exit == 0 && $signal == 0 && $stderr =~ /syntax OK\s+\z/is
!ll&&!rl&&r
404
$error eq "" and $exit == 0 and $signal == 0
!ll&&!rl&&r
314
$error eq "" and $exit == 0
!ll&&!rl&&r
035
MC/DC50%2/4
$error eq '' && $exit == 0 && $signal == 0 && $stderr =~ /syntax OK\s+\z/is
$error eq "" $exit == 0 $signal == 0 $stderr =~ /syntax OK\s+\z/is
Truth table60%3/5
A and B and C && D
A= $error eq ""B= $exit == 0C= $signal == 0D= $stderr =~ /syntax OK\s+\z/is
ABCDresult
0XXX0
10XX0
110X0
11100
11111
115 $error eq '' and $exit == 0 and $signal == 0 and $stderr =~ /syntax OK\s+\z/si
116 );
117  
118 8 my $ctx = context();
119 8 ▶ $ctx->ok( $ok, $_[0] || "Script $unix compiles" );
Condition100%2/2
$_[0] || "Script $unix compiles"
l!l
26
MC/DC100%1/1
$_[0] || "Script $unix compiles"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
120 8 ▶ $ctx->diag( "$exit - $stderr" ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 4 4 8
121 8 ▶ $ctx->diag( "exception: $error" ) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 8 8
122 8 ▶ $ctx->diag( "signal: $signal" ) if $signal;
Branch: 1 branch
BranchTrueFalseTotal
if $signal 1 7 8
123 8 $ctx->release;
124  
125 8 return $ok;
126 }
127  
128 # this is noticeably slower for long @INC lists (sometimes present in cpantesters
129 # boxes) than the previous implementation, which added a -I for every element in
130 # @INC. (also slower for more reasonable @INCs, but not noticeably). But it is
131 # safer as very long argument lists can break calls to system
132 sub _preload_module
133 26 ▶{
Subroutine _preload_module: called CC=5 SCAR=16.7
134 26 my @opts = ( '.test-script-XXXXXXXX', CLEANUP => 1);
135 26 ▶ if(-w File::Spec->curdir)
Branch: 1 branch
BranchTrueFalseTotal
if (-w 'File::Spec'->curdir) { } 26 0 26
136 26 { push @opts, DIR => File::Spec->curdir }
137 else
138 0 { push @opts, DIR => File::Spec->tmpdir }
139 26 my $dir = tempdir(@opts);
140 26 $dir = File::Spec->rel2abs($dir);
141 # this is hopefully a pm file that nobody would use
142 26 my $filename = File::Spec->catfile($dir, '__TEST_SCRIPT__.pm');
143 26 my $fh;
144 26 ▶ open($fh, '>', $filename)
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $filename or die "unable to open ${filename}: $!" 26 0 26
145 || die "unable to open $filename: $!";
146 print($fh 'unshift @INC, ',
147 join ',',
148 # quotemeta is overkill, but it will make sure that characters
149 # like " are quoted
150 208 map { '"' . quotemeta($_) . '"' }
151 26 ▶ grep { ! ref } @INC)
Branch: 1 branch
BranchTrueFalseTotal
print $fh "unshift \@INC, ", join(",", map({'"' . quotemeta($_) . '"';} grep({not ref $_;} @INC))) or die "unable to write ${filename}: $!" 26 0 26
152 || die "unable to write $filename: $!";
153 26 ▶ close($fh) || die "unable to close $filename: $!";;
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "unable to close ${filename}: $!" 26 0 26
154 26 $dir;
155 }
156  
157  
158 15 my $stdout;
159 my $stderr;
160  
161 18 ▶sub script_runs {
Subroutine script_runs: called CC=2 SCAR=6.9
Pod documented
162 18 my $args = _script(shift);
163 18 my $opt = _options(\$stdout, \$stderr, 1, \@_);
164 18 my $unix = shift @$args;
165 18 my $path = path( $unix );
166 18 my $pargs = [ @{ _perl_args($path) }, @{ $opt->{interpreter_options} } ];
167 18 my $dir = _preload_module();
168 18 my $cmd = [ perl, @$pargs, "-I$dir", '-M__TEST_SCRIPT__', $path, @$args ];
169 18 $stdout = '';
170 18 $stderr = '';
171  
172 18 ▶ unshift @_, "Script $unix runs" unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 12 6 18
173 18 unshift @_, $cmd, $opt;
174 18 goto &_run;
175 }
176  
177  
178 3 ▶sub script_fails {
Subroutine script_fails: called CC=3 SCAR=11.0
Pod documented
179 3 my $args = _script(shift);
180 3 my ( $opt, $testname ) = @_;
181 3 ▶ $testname = "Script $args->[0] fails" unless defined $testname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $testname 2 1 3
182 die "exit is a mandatory option for script_fails"
183 3 ▶ unless eval{ defined $opt->{exit} };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { defined $opt->{"exit"} } } 1 2 3
184 2 my $ctx = context();
185 2 return release $ctx, script_runs( $args, $opt, $testname );
186 }
187  
188 # Run a script or program and provide test events corresponding to the results.
189 # Call as _run(\@cmd, \%opt, "Test description")
190 36 ▶sub _run {
Subroutine _run: called CC=14 SCAR=26.6
191 36 my ($cmd, $opt, $description) = @_;
192  
193 36 ▶ if($opt->{stdin})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"stdin"}) 4 32 36
194 {
195 4 my $filename;
196  
197 4 ▶ if(ref($opt->{stdin}) eq 'SCALAR')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $opt->{'stdin'} eq 'SCALAR') { } 2 2 4
elsif (ref $opt->{'stdin'} eq '') { } 2 0 2
198 {
199 2 $filename = File::Spec->catfile(
200 tempdir(CLEANUP => 1),
201 'stdin.txt',
202 );
203 2 my $tmp;
204 2 ▶ open($tmp, '>', $filename) || die "unable to write to $filename";
Branch: 1 branch
BranchTrueFalseTotal
open $tmp, ">", $filename or die "unable to write to $filename" 2 0 2
205 2 print $tmp ${ $opt->{stdin} };
206 2 close $tmp;
207 }
208 elsif(ref($opt->{stdin}) eq '')
209 {
210 2 $filename = $opt->{stdin};
211 }
212 else
213 {
214 0 croak("stdin MUST be either a scalar reference or a string filename");
215 }
216  
217 4 my $fh;
218 4 ▶ open($fh, '<', $filename) || die "unable to open $filename $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $filename or die "unable to open $filename $!" 4 0 4
219 4 ▶ STDIN->fdopen( $fh, 'r' ) or die "unable to reopen stdin to $filename $!";
Branch: 1 branch
BranchTrueFalseTotal
"STDIN"->fdopen($fh, "r") or die "unable to reopen stdin to $filename $!" 4 0 4
220 }
221  
222 36 ▶ (${$opt->{stdout}}, ${$opt->{stderr}}) = capture { system(@$cmd) };
Subroutine __ANON__: called CC=1 SCAR=0.0
223  
224 36 my $error = $@;
225 36 ▶ my $exit = $? ? ($? >> 8) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? ? : 18 18 36
226 36 ▶ my $signal = $? ? ($? & 127) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? ? : 18 18 36
227 36 ▶ my $ok = !! ( $error eq '' and $exit == $opt->{exit} and $signal == $opt->{signal} );
Condition83%5/6
$error eq '' && $exit == $opt->{'exit'} && $signal == $opt->{'signal'}
!ll&&!rl&&r
10224
$error eq "" and $exit == $opt->{"exit"}
!ll&&!rl&&r
01026
MC/DC66%2/3
$error eq '' && $exit == $opt->{'exit'} && $signal == $opt->{'signal'}
$error eq "" $exit == $opt->{"exit"} $signal == $opt->{'signal'}
Truth table75%3/4
A and B && C
A= $error eq ""B= $exit == $opt->{"exit"}C= $signal == $opt->{'signal'}
ABCresult
0XX0
10X0
1100
1111
228  
229 36 my $ctx = context();
230 36 $ctx->ok( $ok, $description );
231 36 ▶ $ctx->diag( "$exit - " . ${$opt->{stderr}} ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 12 24 36
232 36 ▶ $ctx->diag( "exception: $error" ) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 36 36
233 36 ▶ $ctx->diag( "signal: $signal" ) unless $signal == $opt->{signal};
Branch: 1 branch
BranchTrueFalseTotal
unless $signal == $opt->{"signal"} 2 34 36
234 36 $ctx->release;
235  
236 36 return $ok;
237 }
238  
239 sub _like
240 36 ▶{
Subroutine _like: called CC=8 SCAR=20.8
241 36 my($text, $pattern, $regex, $not, $name) = @_;
242  
243 36 ▶ my $ok = $regex ? $text =~ $pattern : $text eq $pattern;
Branch: 1 branch
BranchTrueFalseTotal
$regex ? : 20 16 36
244 36 ▶ $ok = !$ok if $not;
Branch: 1 branch
BranchTrueFalseTotal
if $not 16 20 36
245  
246 36 my $ctx = context;
247 36 $ctx->ok( $ok, $name );
248 36 ▶ unless($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 16 20 36
249 16 $ctx->diag( "The output" );
250 16 $ctx->diag( " $_") for split /\n/, $text;
251 16 ▶ $ctx->diag( $not ? "does match" : "does not match" );
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 8 8 16
252 16 ▶ if($regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regex) { } 8 8 16
253 8 $ctx->diag( " $pattern" );
254 } else {
255 8 $ctx->diag( " $_" ) for split /\n/, $pattern;
256 }
257 }
258 36 $ctx->release;
259  
260 36 $ok;
261 }
262  
263  
264 sub script_stdout_is
265 2 ▶{
Subroutine script_stdout_is: called CC=2 SCAR=7.1
Pod documented
266 2 my($pattern, $name) = @_;
267 2 ▶ @_ = ($stdout, $pattern, 0, 0, $name || 'stdout matches' );
Condition50%1/2
$name || 'stdout matches'
l!l
02
MC/DC0%0/1
$name || 'stdout matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
268 2 goto &_like;
269 }
270  
271  
272 sub script_stdout_isnt
273 2 ▶{
Subroutine script_stdout_isnt: called CC=2 SCAR=7.1
Pod documented
274 2 my($pattern, $name) = @_;
275 2 ▶ @_ = ($stdout, $pattern, 0, 1, $name || 'stdout does not match' );
Condition50%1/2
$name || 'stdout does not match'
l!l
02
MC/DC0%0/1
$name || 'stdout does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
276 2 goto &_like;
277 }
278  
279  
280 sub script_stdout_like
281 4 ▶{
Subroutine script_stdout_like: called CC=2 SCAR=7.1
Pod documented
282 4 my($pattern, $name) = @_;
283 4 ▶ @_ = ($stdout, $pattern, 1, 0, $name || 'stdout matches' );
Condition50%1/2
$name || 'stdout matches'
l!l
04
MC/DC0%0/1
$name || 'stdout matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
284 4 goto &_like;
285 }
286  
287  
288 sub script_stdout_unlike
289 2 ▶{
Subroutine script_stdout_unlike: called CC=2 SCAR=7.1
Pod documented
290 2 my($pattern, $name) = @_;
291 2 ▶ @_ = ($stdout, $pattern, 1, 1, $name || 'stdout does not match' );
Condition50%1/2
$name || 'stdout does not match'
l!l
02
MC/DC0%0/1
$name || 'stdout does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
292 2 goto &_like;
293 }
294  
295  
296 sub script_stderr_is
297 2 ▶{
Subroutine script_stderr_is: called CC=2 SCAR=7.1
Pod documented
298 2 my($pattern, $name) = @_;
299 2 ▶ @_ = ($stderr, $pattern, 0, 0, $name || 'stderr matches' );
Condition50%1/2
$name || 'stderr matches'
l!l
02
MC/DC0%0/1
$name || 'stderr matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
300 2 goto &_like;
301 }
302  
303  
304 sub script_stderr_isnt
305 2 ▶{
Subroutine script_stderr_isnt: called CC=2 SCAR=7.1
Pod documented
306 2 my($pattern, $name) = @_;
307 2 ▶ @_ = ($stderr, $pattern, 0, 1, $name || 'stderr does not match' );
Condition50%1/2
$name || 'stderr does not match'
l!l
02
MC/DC0%0/1
$name || 'stderr does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
308 2 goto &_like;
309 }
310  
311  
312 sub script_stderr_like
313 2 ▶{
Subroutine script_stderr_like: called CC=2 SCAR=7.1
Pod documented
314 2 my($pattern, $name) = @_;
315 2 ▶ @_ = ($stderr, $pattern, 1, 0, $name || 'stderr matches' );
Condition50%1/2
$name || 'stderr matches'
l!l
02
MC/DC0%0/1
$name || 'stderr matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
316 2 goto &_like;
317 }
318  
319  
320 sub script_stderr_unlike
321 2 ▶{
Subroutine script_stderr_unlike: called CC=2 SCAR=7.1
Pod documented
322 2 my($pattern, $name) = @_;
323 2 ▶ @_ = ($stderr, $pattern, 1, 1, $name || 'stderr does not match' );
Condition50%1/2
$name || 'stderr does not match'
l!l
02
MC/DC0%0/1
$name || 'stderr does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
324 2 goto &_like;
325 }
326  
327 #####################################################################
328 # Test Functions for Programs
329  
330 15 my $program_stdout;
331 15 my $program_stderr;
332  
333  
334 19 ▶sub program_runs {
Subroutine program_runs: called CC=2 SCAR=6.9
Pod documented
335 19 my $cmd = _script(shift);
336 19 my $opt = _options(\$program_stdout, \$program_stderr, 0, \@_);
337 18 $program_stdout = '';
338 18 $program_stderr = '';
339  
340 18 ▶ unshift @_, "Program $$cmd[0] runs" unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 11 7 18
341 18 unshift @_, $cmd, $opt;
342 18 goto &_run;
343 }
344  
345  
346 6 ▶sub program_fails {
Subroutine program_fails: called CC=3 SCAR=11.0
Pod documented
347 6 my $cmd = _script(shift);
348 6 my ( $opt, $testname ) = @_;
349 6 ▶ $testname = 'program_fails' unless defined $testname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $testname 4 2 6
350 die "exit is a mandatory option for program_fails"
351 6 ▶ unless eval{ defined $opt->{exit} };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { defined $opt->{"exit"} } } 1 5 6
352 5 my $ctx = context();
353 5 return release $ctx, program_runs( $cmd, $opt, $testname );
354 }
355  
356  
357 sub program_stdout_is
358 2 ▶{
Subroutine program_stdout_is: called CC=2 SCAR=7.1
Pod documented
359 2 my($pattern, $name) = @_;
360 2 ▶ @_ = ($program_stdout, $pattern, 0, 0, $name || 'stdout matches' );
Condition50%1/2
$name || 'stdout matches'
l!l
02
MC/DC0%0/1
$name || 'stdout matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
361 2 goto &_like;
362 }
363  
364  
365 sub program_stdout_isnt
366 2 ▶{
Subroutine program_stdout_isnt: called CC=2 SCAR=7.1
Pod documented
367 2 my($pattern, $name) = @_;
368 2 ▶ @_ = ($program_stdout, $pattern, 0, 1, $name || 'stdout does not match' );
Condition50%1/2
$name || 'stdout does not match'
l!l
02
MC/DC0%0/1
$name || 'stdout does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
369 2 goto &_like;
370 }
371  
372  
373 sub program_stdout_like
374 4 ▶{
Subroutine program_stdout_like: called CC=2 SCAR=7.1
Pod documented
375 4 my($pattern, $name) = @_;
376 4 ▶ @_ = ($program_stdout, $pattern, 1, 0, $name || 'stdout matches' );
Condition50%1/2
$name || 'stdout matches'
l!l
04
MC/DC0%0/1
$name || 'stdout matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
377 4 goto &_like;
378 }
379  
380  
381 sub program_stdout_unlike
382 2 ▶{
Subroutine program_stdout_unlike: called CC=2 SCAR=7.1
Pod documented
383 2 my($pattern, $name) = @_;
384 2 ▶ @_ = ($program_stdout, $pattern, 1, 1, $name || 'stdout does not match' );
Condition50%1/2
$name || 'stdout does not match'
l!l
02
MC/DC0%0/1
$name || 'stdout does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
385 2 goto &_like;
386 }
387  
388  
389 sub program_stderr_is
390 2 ▶{
Subroutine program_stderr_is: called CC=2 SCAR=7.1
Pod documented
391 2 my($pattern, $name) = @_;
392 2 ▶ @_ = ($program_stderr, $pattern, 0, 0, $name || 'stderr matches' );
Condition50%1/2
$name || 'stderr matches'
l!l
02
MC/DC0%0/1
$name || 'stderr matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
393 2 goto &_like;
394 }
395  
396  
397 sub program_stderr_isnt
398 2 ▶{
Subroutine program_stderr_isnt: called CC=2 SCAR=7.1
Pod documented
399 2 my($pattern, $name) = @_;
400 2 ▶ @_ = ($program_stderr, $pattern, 0, 1, $name || 'stderr does not match' );
Condition50%1/2
$name || 'stderr does not match'
l!l
02
MC/DC0%0/1
$name || 'stderr does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
401 2 goto &_like;
402 }
403  
404  
405 sub program_stderr_like
406 2 ▶{
Subroutine program_stderr_like: called CC=2 SCAR=7.1
Pod documented
407 2 my($pattern, $name) = @_;
408 2 ▶ @_ = ($program_stderr, $pattern, 1, 0, $name || 'stderr matches' );
Condition50%1/2
$name || 'stderr matches'
l!l
02
MC/DC0%0/1
$name || 'stderr matches'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
409 2 goto &_like;
410 }
411  
412  
413 sub program_stderr_unlike
414 2 ▶{
Subroutine program_stderr_unlike: called CC=2 SCAR=7.1
Pod documented
415 2 my($pattern, $name) = @_;
416 2 ▶ @_ = ($program_stderr, $pattern, 1, 1, $name || 'stderr does not match' );
Condition50%1/2
$name || 'stderr does not match'
l!l
02
MC/DC0%0/1
$name || 'stderr does not match'
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
417 2 goto &_like;
418 }
419  
420  
421 ######################################################################
422 # Support Functions
423  
424 # Script params must be either a simple non-null string with the script
425 # name, or an array reference with one or more non-null strings.
426 55 ▶sub _script {
Subroutine _script: called CC=4 SCAR=14.2
427 55 my $in = shift;
428 55 ▶ if ( defined _STRING($in) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &_STRING($in)) 26 29 55
429 26 return [ $in ];
430 }
431 29 ▶ if ( _ARRAY($in) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_ARRAY($in)) 29 0 29
432 29 ▶ unless ( scalar grep { not defined _STRING($_) } @$in ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({not defined &_STRING($_);} @$in)) 29 0 29
433 29 return [ @$in ];
434 }
435 }
436 0 croak("Invalid command parameter");
437 }
438  
439 # Determine any extra arguments that need to be passed into Perl.
440 # ATM this is just -T.
441 26 ▶sub _perl_args {
Subroutine _perl_args: called CC=3 SCAR=11.0
442 26 my($script) = @_;
443 26 my $fh;
444 26 my $first_line = '';
445 26 ▶ if(open($fh, '<', $script))
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, "<", $script) 24 2 26
446 {
447 24 $first_line = <$fh>;
448 24 close $fh;
449 }
450 26 ▶ (grep /^-.*T/, split /\s+/, $first_line) ? ['-T'] : [];
Branch: 1 branch
BranchTrueFalseTotal
grep(/^-.*T/, split(/\s+/, $first_line, 0)) ? : 2 24 26
451 }
452  
453 # Inline some basic Params::Util functions
454  
455 37 ▶sub _options {
Subroutine _options: called CC=9 SCAR=22.0
456 37 my $ref_stdout = shift;
457 37 my $ref_stderr = shift;
458 37 my $permit_interpreter_options = shift;
459 37 ▶ my %options = ref($_[0]->[0]) eq 'HASH' ? %{ shift @{ $_[0] } }: ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0][0] eq 'HASH' ? : 20 17 37
460  
461 37 ▶ $options{exit} = 0 unless defined $options{exit};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"exit"} 28 9 37
462 37 ▶ $options{signal} = 0 unless defined $options{signal};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"signal"} 35 2 37
463 37 my $stdin = '';
464 #$options{stdin} = \$stdin unless defined $options{stdin};
465 37 ▶ $options{stdout} = $ref_stdout unless defined $options{stdout};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"stdout"} 35 2 37
466 37 ▶ $options{stderr} = $ref_stderr unless defined $options{stderr};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"stderr"} 35 2 37
467  
468 37 ▶ if(defined $options{interpreter_options})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{'interpreter_options'}) { } 3 34 37
469 {
470 3 ▶ die "interpreter_options not supported" unless $permit_interpreter_options;
Branch: 1 branch
BranchTrueFalseTotal
unless $permit_interpreter_options 1 2 3
471 2 ▶ unless(ref $options{interpreter_options} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $options{"interpreter_options"} eq "ARRAY") 1 1 2
472 {
473 1 require Text::ParseWords;
474 1 $options{interpreter_options} = [ Text::ParseWords::shellwords($options{interpreter_options}) ];
475 }
476 }
477 else
478 {
479 34 $options{interpreter_options} = [];
480 }
481  
482 36 \%options;
483 }
484  
485 29 ▶sub _ARRAY ($) {
Subroutine _ARRAY: called CC=3 SCAR=13.1
486 29 ▶ (ref $_[0] eq 'ARRAY' and @{$_[0]}) ? $_[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' && @{$_[0];} ? : 29 0 29
Condition33%1/3
ref $_[0] eq "ARRAY" and @{$_[0];}
!ll&&!rl&&r
0029
MC/DC0%0/2
ref $_[0] eq "ARRAY" and @{$_[0];}
ref $_[0] eq "ARRAY" @{$_[0];}
Truth table33%1/3
A and B
A= ref $_[0] eq "ARRAY"B= @{$_[0];}
ABresult
0X0
100
111
487 }
488  
489 121 ▶sub _STRING ($) {
Subroutine _STRING: called CC=4 SCAR=14.3
490 121 ▶ (defined $_[0] and ! ref $_[0] and length($_[0])) ? $_[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && !ref($_[0]) && length $_[0] ? : 92 29 121
Condition66%4/6
defined $_[0] and not ref $_[0] and length $_[0]
!ll&&!rl&&r
29092
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
02992
MC/DC33%1/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] not ref $_[0] length $_[0]
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
491 }
492  
493 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
494 # Alias to old name
495 15 *script_compiles_ok = *script_compiles;
496 }
497  
498 15 1;
499  
500 __END__
↑ Summary