blib/lib/App/Prove.pm

filter: Statementstmt 81.9% 227 / 277 Branchbran 69.8% 95 / 136 Conditioncond 73.9% 17 / 23 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 89.7% 35 / 39 Podpod 100% 5 / 5 totaltotal 77.7% 384 / 494 CC 89 SCAR 29.2
CC
89
Cov
78%
_get_args
58.4
run
14.5
process_args
11.1
CRAP 18.5
« blib/lib/TAP/Harness.pm ↑ Summary blib/lib/TAP/Parser/SourceHandler/Executable.pm »
1 package App::Prove;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use TAP::Harness::Env;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Text::ParseWords qw(shellwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use App::Prove::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use base 'TAP::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 App::Prove - Implements the C<prove> command.
18  
19 =head1 VERSION
20  
21 Version 3.52
22  
23 =cut
24  
25 6 our $VERSION = '3.52';
26  
27 =head1 DESCRIPTION
28  
29 L<Test::Harness> provides a command, C<prove>, which runs a TAP based
30 test suite and prints a report. The C<prove> command is a minimal
31 wrapper around an instance of this module.
32  
33 =head1 SYNOPSIS
34  
35 use App::Prove;
36  
37 my $app = App::Prove->new;
38 $app->process_args(@ARGV);
39 $app->run;
40  
41 =cut
42  
43 6 ▶use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
Subroutine BEGIN: called CC=1 SCAR=0.0
44 6 ▶use constant IS_VMS => $^O eq 'VMS';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 6 ▶use constant IS_UNIXY => !( IS_VMS || IS_WIN32 );
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 6 ▶use constant STATE_FILE => IS_UNIXY ? '.prove' : '_prove';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 6 ▶use constant RC_FILE => IS_UNIXY ? '.proverc' : '_proverc';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 6 ▶use constant PLUGINS => 'App::Prove::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 6 my @ATTR;
53  
54 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
55 6 @ATTR = qw(
56 archive argv blib show_count color directives exec failures comments
57 formatter harness includes modules plugins jobs lib merge parse quiet
58 really_quiet recurse backwards shuffle taint_fail taint_warn timer
59 verbose warnings_fail warnings_warn show_help show_man show_version
60 state_class test_args state dry extensions ignore_exit rules state_manager
61 normalize sources tapversion trap
62 statefile
63 );
64 6 __PACKAGE__->mk_methods(@ATTR);
65 }
66  
67 =head1 METHODS
68  
69 =head2 Class Methods
70  
71 =head3 C<new>
72  
73 Create a new C<App::Prove>. Optionally a hash ref of attribute
74 initializers may be passed.
75  
76 =cut
77  
78 # new() implementation supplied by TAP::Object
79  
80 65 ▶sub _initialize {
Subroutine _initialize: called CC=5 SCAR=16.1
81 65 my $self = shift;
82 65 ▶ my $args = shift || {};
Condition100%2/2
shift() || {}
l!l
578
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
83  
84 65 my @is_array = qw(
85 argv rc_opts includes modules state plugins rules sources
86 );
87  
88 # setup defaults:
89 65 for my $key (@is_array) {
90 520 $self->{$key} = [];
91 }
92  
93 65 for my $attr (@ATTR) {
94 2925 ▶ if ( exists $args->{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{$attr}) 99 2826 2925
95  
96 # TODO: Some validation here
97 99 $self->{$attr} = $args->{$attr};
98 }
99 }
100  
101 65 $self->state_class('App::Prove::State');
102 65 return $self;
103 }
104  
105 =head3 C<state_class>
106  
107 Getter/setter for the name of the class used for maintaining state. This
108 class should either subclass from C<App::Prove::State> or provide an identical
109 interface.
110  
111 =head3 C<state_manager>
112  
113 Getter/setter for the instance of the C<state_class>.
114  
115 =cut
116  
117 =head3 C<add_rc_file>
118  
119 $prove->add_rc_file('myproj/.proverc');
120  
121 Called before C<process_args> to prepend the contents of an rc file to
122 the options.
123  
124 =cut
125  
126 2 ▶sub add_rc_file {
Subroutine add_rc_file: called CC=4 SCAR=13.9
Pod documented
127 2 my ( $self, $rc_file ) = @_;
128  
129 2 local *RC;
130 2 ▶ open RC, "<$rc_file" or croak "Can't read $rc_file ($!)";
Branch: 1 branch
BranchTrueFalseTotal
open RC, "<$rc_file" or croak("Can't read $rc_file ($!)") 2 0 2
131 2 ▶ while ( defined( my $line = <RC> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline RC)) 9 2 11
132 9 push @{ $self->{rc_opts} },
133 9 ▶ grep { defined and not /^#/ }
Condition100%3/3
defined $_ && !/^#/
!ll&&!rl&&r
45213
MC/DC100%2/2
defined $_ && !/^#/
defined $_ !/^#/
Truth table100%3/3
A && not(B)
A= defined $_B= !/^#/
ABresult
0X0
100
111
134 $line =~ m{ ' ([^']*) ' | " ([^"]*) " | (\#.*) | (\S+) }xg;
135 }
136 2 close RC;
137 }
138  
139 =head3 C<process_args>
140  
141 $prove->process_args(@args);
142  
143 Processes the command-line arguments. Attributes will be set
144 appropriately. Any filenames may be found in the C<argv> attribute.
145  
146 Dies on invalid arguments.
147  
148 =cut
149  
150 40 ▶sub process_args {
Subroutine process_args: called CC=10 SCAR=24.1
Pod documented
151 40 my $self = shift;
152  
153 40 my @rc = RC_FILE;
154 40 unshift @rc, glob '~/' . RC_FILE if IS_UNIXY;
155  
156 # Preprocess meta-args.
157 40 my @args;
158 40 ▶ while ( defined( my $arg = shift ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $arg = shift())) 148 40 188
159 148 ▶ if ( $arg eq '--norc' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg eq '--norc') { } 40 108 148
elsif ($arg eq '--rc') { } 0 108 108
elsif ($arg =~ /^--rc=(.+)$/) { } 0 108 108
160 40 @rc = ();
161 }
162 elsif ( $arg eq '--rc' ) {
163 0 ▶ defined( my $rc = shift )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $rc = shift()) or croak("Missing argument to --rc") 0 0 0
164 or croak "Missing argument to --rc";
165 0 push @rc, $rc;
166 }
167 elsif ( $arg =~ m{^--rc=(.+)$} ) {
168 0 push @rc, $1;
169 }
170 else {
171 108 push @args, $arg;
172 }
173 }
174  
175 # Everything after the arisdottle '::' gets passed as args to
176 # test programs.
177 40 ▶ if ( defined( my $stop_at = _first_pos( '::', @args ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $stop_at = _first_pos("::", @args))) 1 39 40
178 1 my @test_args = splice @args, $stop_at;
179 1 shift @test_args;
180 1 $self->{test_args} = \@test_args;
181 }
182  
183 # Grab options from RC files
184 40 $self->add_rc_file($_) for grep -f, @rc;
185 40 unshift @args, @{ $self->{rc_opts} };
186  
187 0 ▶ if ( my @bad = map {"-$_"} grep {/^-(man|help)$/} @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad) = map({"-$_";} grep({/^-(man|help)$/;} @args))) 0 40 40
188 0 die "Long options should be written with two dashes: ",
189 join( ', ', @bad ), "\n";
190 }
191  
192 # And finally...
193  
194 {
195 40 local @ARGV = @args;
196 40 Getopt::Long::Configure(qw(no_ignore_case bundling pass_through));
197  
198 # Don't add coderefs to GetOptions
199 GetOptions(
200 'v|verbose' => \$self->{verbose},
201 'f|failures' => \$self->{failures},
202 'o|comments' => \$self->{comments},
203 'l|lib' => \$self->{lib},
204 'b|blib' => \$self->{blib},
205 's|shuffle' => \$self->{shuffle},
206 'color!' => \$self->{color},
207 'colour!' => \$self->{color},
208 'count!' => \$self->{show_count},
209 'c' => \$self->{color},
210 'D|dry' => \$self->{dry},
211 3 ▶ 'ext=s@' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
212 3 my ( $opt, $val ) = @_;
213  
214 # Workaround for Getopt::Long 2.25 handling of
215 # multivalue options
216 3 ▶ push @{ $self->{extensions} ||= [] }, $val;
Condition100%2/2
$self->{"extensions"} ||= []
l!l
12
MC/DC100%1/1
$self->{"extensions"} ||= []
$self->{"extensions"}
Truth table100%2/2
A
A= $self->{"extensions"}
Aresult
11
00
217 },
218 'harness=s' => \$self->{harness},
219 'ignore-exit' => \$self->{ignore_exit},
220 'source=s@' => $self->{sources},
221 'formatter=s' => \$self->{formatter},
222 'r|recurse' => \$self->{recurse},
223 'reverse' => \$self->{backwards},
224 'p|parse' => \$self->{parse},
225 'q|quiet' => \$self->{quiet},
226 'Q|QUIET' => \$self->{really_quiet},
227 'e|exec=s' => \$self->{exec},
228 'm|merge' => \$self->{merge},
229 'I=s@' => $self->{includes},
230 'M=s@' => $self->{modules},
231 'P=s@' => $self->{plugins},
232 'state=s@' => $self->{state},
233 'statefile=s' => \$self->{statefile},
234 'directives' => \$self->{directives},
235 'h|help|?' => \$self->{show_help},
236 'H|man' => \$self->{show_man},
237 'V|version' => \$self->{show_version},
238 'a|archive=s' => \$self->{archive},
239 'j|jobs=i' => \$self->{jobs},
240 'timer' => \$self->{timer},
241 'T' => \$self->{taint_fail},
242 't' => \$self->{taint_warn},
243 'W' => \$self->{warnings_fail},
244 'w' => \$self->{warnings_warn},
245 'normalize' => \$self->{normalize},
246 'rules=s@' => $self->{rules},
247 'tapversion=s' => \$self->{tapversion},
248 'trap' => \$self->{trap},
249 40 ▶ ) or croak('Unable to continue');
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("v|verbose", \$self->{"verbose"}, "f|failures", \$self->{"failures"}, "o|comments", \$self->{"comments"}, "l|lib", \$self->{"lib"}, "b|blib", \$self->{"blib"}, "s|shuffle", \$self->{"shuffle"}, "color!", \$self->{"color"}, "colour!", \$self->{"color"}, "count!", \$self->{"show_count"}, "c", \$self->{"color"}, "D|dry", \$self->{"dry"}, "ext=s\@", sub { my($opt, $val) = @_; push @{$self->{"extensions"} ||= [];}, $val; } , "harness=s", \$self->{"harness"}, "ignore-exit", \$self->{"ignore_exit"}, "source=s\@", $self->{"sources"}, "formatter=s", \$self->{"formatter"}, "r|recurse", \$self->{"recurse"}, "reverse", \$self->{"backwards"}, "p|parse", \$self->{"parse"}, "q|quiet", \$self->{"quiet"}, "Q|QUIET", \$self->{"really_quiet"}, "e|exec=s", \$self->{"exec"}, "m|merge", \$self->{"merge"}, "I=s\@", $self->{"includes"}, "M=s\@", $self->{"modules"}, "P=s\@", $self->{"plugins"}, "state=s\@", $self->{"state"}, "statefile=s", \$self->{"statefile"}, "directives", \$self->{"directives"}, "h|help|?", \$self->{"show_help"}, "H|man", \$self->{"show_man"}, "V|version", \$self->{"show_version"}, "a|archive=s", \$self->{"archive"}, "j|jobs=i", \$self->{"jobs"}, "timer", \$self->{"timer"}, "T", \$self->{"taint_fail"}, "t", \$self->{"taint_warn"}, "W", \$self->{"warnings_fail"}, "w", \$self->{"warnings_warn"}, "normalize", \$self->{"normalize"}, "rules=s\@", $self->{"rules"}, "tapversion=s", \$self->{"tapversion"}, "trap", \$self->{"trap"}) or croak("Unable to continue") 40 0 40
250  
251 # Stash the remainder of argv for later
252 40 $self->{argv} = [@ARGV];
253 }
254  
255 40 return;
256 }
257  
258 40 ▶sub _first_pos {
Subroutine _first_pos: called CC=3 SCAR=11.0
259 40 my $want = shift;
260 40 for ( 0 .. $#_ ) {
261 105 ▶ return $_ if $_[$_] eq $want;
Branch: 1 branch
BranchTrueFalseTotal
if $_[$_] eq $want 1 104 105
262 }
263 39 return;
264 }
265  
266 0 ▶sub _help {
Subroutine _help: not called CC=2 SCAR=17.9
267 0 my ( $self, $verbosity ) = @_;
268  
269 0 eval('use Pod::Usage 1.12 ()');
270 0 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
271 0 die 'Please install Pod::Usage for the --help option '
272 . '(or try `perldoc prove`.)'
273 . "\n ($@)";
274 }
275  
276 0 Pod::Usage::pod2usage( { -verbose => $verbosity } );
277  
278 0 return;
279 }
280  
281 3 ▶sub _color_default {
Subroutine _color_default: called CC=2 SCAR=8.1
282 3 my $self = shift;
283  
284 3 ▶ return -t STDOUT && !$ENV{HARNESS_NOTTY};
Condition33%1/3
-t STDOUT && !$ENV{'HARNESS_NOTTY'}
!ll&&!rl&&r
300
MC/DC0%0/2
-t STDOUT && !$ENV{'HARNESS_NOTTY'}
-t STDOUT !$ENV{'HARNESS_NOTTY'}
Truth table33%1/3
A && not(B)
A= -t STDOUTB= !$ENV{'HARNESS_NOTTY'}
ABresult
0X0
100
111
285 }
286  
287 61 ▶sub _get_args {
Subroutine _get_args: called CC=31 SCAR=40.7
288 61 my $self = shift;
289  
290 61 my %args;
291  
292 61 ▶ $args{trap} = 1 if $self->trap;
Branch: 1 branch
BranchTrueFalseTotal
if $self->trap 0 61 61
293  
294 61 ▶ if ( defined $self->color ? $self->color : $self->_color_default ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->color ? $self->color : $self->_color_default) 2 59 61
defined $self->color ? : 2 59 61
295 2 $args{color} = 1;
296 }
297 61 ▶ if ( !defined $self->show_count ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->show_count) { } 61 0 61
298 61 $args{show_count} = 1;
299 }
300 else {
301 0 $args{show_count} = $self->show_count;
302 }
303  
304 61 ▶ if ( $self->archive ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->archive) 0 61 61
305 0 $self->require_harness( archive => 'TAP::Harness::Archive' );
306 0 $args{archive} = $self->archive;
307 }
308  
309 61 ▶ if ( my $jobs = $self->jobs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $jobs = $self->jobs) 0 61 61
310 0 $args{jobs} = $jobs;
311 }
312  
313 61 ▶ if ( my $harness_opt = $self->harness ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $harness_opt = $self->harness) 0 61 61
314 0 $self->require_harness( harness => $harness_opt );
315 }
316  
317 61 ▶ if ( my $formatter = $self->formatter ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $formatter = $self->formatter) 1 60 61
318 1 $args{formatter_class} = $formatter;
319 }
320  
321 61 for my $handler ( @{ $self->sources } ) {
322 4 my ( $name, $config ) = $self->_parse_source($handler);
323 4 $args{sources}->{$name} = $config;
324 }
325  
326 61 ▶ if ( $self->ignore_exit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ignore_exit) 0 61 61
327 0 $args{ignore_exit} = 1;
328 }
329  
330 61 ▶ if ( $self->taint_fail && $self->taint_warn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->taint_fail and $self->taint_warn) 0 61 61
Condition66%2/3
$self->taint_fail and $self->taint_warn
!ll&&!rl&&r
6010
MC/DC0%0/2
$self->taint_fail and $self->taint_warn
$self->taint_fail $self->taint_warn
Truth table66%2/3
A and B
A= $self->taint_failB= $self->taint_warn
ABresult
0X0
100
111
331 0 die '-t and -T are mutually exclusive';
332 }
333  
334 61 ▶ if ( $self->warnings_fail && $self->warnings_warn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->warnings_fail and $self->warnings_warn) 0 61 61
Condition66%2/3
$self->warnings_fail and $self->warnings_warn
!ll&&!rl&&r
6010
MC/DC0%0/2
$self->warnings_fail and $self->warnings_warn
$self->warnings_fail $self->warnings_warn
Truth table66%2/3
A and B
A= $self->warnings_failB= $self->warnings_warn
ABresult
0X0
100
111
335 0 die '-w and -W are mutually exclusive';
336 }
337  
338 61 for my $a (qw( lib switches )) {
339 122 my $method = "_get_$a";
340 122 my $val = $self->$method();
341 122 ▶ $args{$a} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 11 111 122
342 }
343  
344 # Handle verbose, quiet, really_quiet flags
345 61 my %verb_map = ( verbose => 1, quiet => -1, really_quiet => -2, );
346  
347 61 ▶ my @verb_adj = map { $self->$_() ? $verb_map{$_} : () }
Branch: 1 branch
BranchTrueFalseTotal
$self->$_ ? : 9 174 183
348 keys %verb_map;
349  
350 61 ▶ die "Only one of verbose, quiet or really_quiet should be specified\n"
Branch: 1 branch
BranchTrueFalseTotal
if @verb_adj > 1 0 61 61
351 if @verb_adj > 1;
352  
353 61 ▶ $args{verbosity} = shift @verb_adj if @verb_adj;
Branch: 1 branch
BranchTrueFalseTotal
if @verb_adj 9 52 61
354  
355 61 for my $a (qw( merge failures comments timer directives normalize )) {
356 366 ▶ $args{$a} = 1 if $self->$a();
Branch: 1 branch
BranchTrueFalseTotal
if $self->$a 8 358 366
357 }
358  
359 61 ▶ $args{errors} = 1 if $self->parse;
Branch: 1 branch
BranchTrueFalseTotal
if $self->parse 3 58 61
360  
361 # defined but zero-length exec runs test files as binaries
362 61 ▶ $args{exec} = [ split( /\s+/, $self->exec ) ]
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->exec 5 56 61
363 if ( defined( $self->exec ) );
364  
365 61 ▶ $args{version} = $self->tapversion if defined( $self->tapversion );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->tapversion 0 61 61
366  
367 61 ▶ if ( defined( my $test_args = $self->test_args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $test_args = $self->test_args)) 1 60 61
368 1 $args{test_args} = $test_args;
369 }
370  
371 61 ▶ if ( @{ $self->rules } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->rules;}) 0 61 61
372 0 my @rules;
373 0 for ( @{ $self->rules } ) {
374 0 ▶ if (/^par=(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^par=(.*)/) { } 0 0 0
elsif (/^seq=(.*)/) { } 0 0 0
375 0 push @rules, $1;
376 }
377 elsif (/^seq=(.*)/) {
378 0 push @rules, { seq => $1 };
379 }
380 }
381 0 $args{rules} = { par => [@rules] };
382 }
383 61 ▶ $args{harness_class} = $self->{harness_class} if $self->{harness_class};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"harness_class"} 0 61 61
384  
385 61 return \%args;
386 }
387  
388 5 ▶sub _find_module {
Subroutine _find_module: called CC=5 SCAR=16.5
389 5 my ( $self, $class, @search ) = @_;
390  
391 5 ▶ croak "Bad module name $class"
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ /^ \w+ (?: :: \w+ ) *$/x 0 5 5
392 unless $class =~ /^ \w+ (?: :: \w+ ) *$/x;
393  
394 5 for my $pfx (@search) {
395 4 my $name = join( '::', $pfx, $class );
396 4 eval "require $name";
397 4 ▶ return $name unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 3 1 4
398 }
399  
400 2 eval "require $class";
401 2 ▶ return $class unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 2 0 2
402 0 return;
403 }
404  
405 5 ▶sub _load_extension {
Subroutine _load_extension: called CC=4 SCAR=14.2
406 5 my ( $self, $name, @search ) = @_;
407  
408 5 my @args = ();
409 5 ▶ if ( $name =~ /^(.*?)=(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(.*?)=(.*)/) 2 3 5
410 2 $name = $1;
411 2 @args = split( /,/, $2 );
412 }
413  
414 5 ▶ if ( my $class = $self->_find_module( $name, @search ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = $self->_find_module($name, @search)) { } 5 0 5
415 5 ▶ if ( $class->can('load') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can("load")) 5 0 5
416 5 $class->load( { app_prove => $self, args => [@args] } );
417 }
418 }
419 else {
420 0 croak "Can't load module $name";
421 }
422 }
423  
424 122 ▶sub _load_extensions {
Subroutine _load_extensions: called CC=2 SCAR=6.9
425 122 my ( $self, $ext, @search ) = @_;
426 122 $self->_load_extension( $_, @search ) for @$ext;
427 }
428  
429 4 ▶sub _parse_source {
Subroutine _parse_source: called CC=1 SCAR=0.0
430 4 my ( $self, $handler ) = @_;
431  
432 # Load any options.
433 4 ( my $opt_name = lc $handler ) =~ s/::/-/g;
434 4 local @ARGV = @{ $self->{argv} };
435 4 my %config;
436 Getopt::Long::GetOptions(
437 7 ▶ "$opt_name-option=s%" => sub {
Subroutine __ANON__: called CC=7 SCAR=19.6
438 7 my ( $name, $k, $v ) = @_;
439 7 ▶ if ( $v =~ /(?<!\\)=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /(?<!\\)=/) { } 2 5 7
440  
441 # It's a hash option.
442 croak "Option $name must be consistently used as a hash"
443 2 ▶ if exists $config{$k} && ref $config{$k} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if exists $config{$k} and ref $config{$k} ne "HASH" 0 2 2
Condition66%2/3
exists $config{$k} and ref $config{$k} ne "HASH"
!ll&&!rl&&r
110
MC/DC0%0/2
exists $config{$k} and ref $config{$k} ne "HASH"
exists $config{$k} ref $config{$k} ne "HASH"
Truth table66%2/3
A and B
A= exists $config{$k}B= ref $config{$k} ne "HASH"
ABresult
0X0
100
111
444 2 ▶ $config{$k} ||= {};
Condition100%2/2
$config{$k} ||= {}
l!l
11
MC/DC100%1/1
$config{$k} ||= {}
$config{$k}
Truth table100%2/2
A
A= $config{$k}
Aresult
11
00
445 2 my ( $hk, $hv ) = split /(?<!\\)=/, $v, 2;
446 2 $config{$k}{$hk} = $hv;
447 }
448 else {
449 5 $v =~ s/\\=/=/g;
450 5 ▶ if ( exists $config{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config{$k}) { } 1 4 5
451 $config{$k} = [ $config{$k} ]
452 1 ▶ unless ref $config{$k} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config{$k} eq "ARRAY" 1 0 1
453 1 push @{ $config{$k} } => $v;
454 }
455 else {
456 4 $config{$k} = $v;
457 }
458 }
459 }
460 4 );
461 4 $self->{argv} = \@ARGV;
462 4 return ( $handler, \%config );
463 }
464  
465 =head3 C<run>
466  
467 Perform whatever actions the command line args specified. The C<prove>
468 command line tool consists of the following code:
469  
470 use App::Prove;
471  
472 my $app = App::Prove->new;
473 $app->process_args(@ARGV);
474 exit( $app->run ? 0 : 1 ); # if you need the exit code
475  
476 =cut
477  
478 61 ▶sub run {
Subroutine run: called CC=9 SCAR=26.7
Pod documented
479 61 my $self = shift;
480  
481 61 ▶ unless ( $self->state_manager ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state_manager) 61 0 61
482 61 ▶ $self->state_manager(
Condition50%1/2
$self->statefile || '.prove'
l!l
061
MC/DC0%0/1
$self->statefile || '.prove'
$self->statefile
Truth table50%1/2
A
A= $self->statefile
Aresult
11
00
483 $self->state_class->new( { store => $self->statefile || STATE_FILE } ) );
484 }
485  
486 61 ▶ if ( $self->show_help ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->show_help) { } 0 61 61
elsif ($self->show_man) { } 0 61 61
elsif ($self->show_version) { } 0 61 61
elsif ($self->dry) { } 0 61 61
487 0 $self->_help(1);
488 }
489 elsif ( $self->show_man ) {
490 0 $self->_help(2);
491 }
492 elsif ( $self->show_version ) {
493 0 $self->print_version;
494 }
495 elsif ( $self->dry ) {
496 0 print "$_\n" for $self->_get_tests;
497 }
498 else {
499  
500 61 $self->_load_extensions( $self->modules );
501 61 $self->_load_extensions( $self->plugins, PLUGINS );
502  
503 61 ▶ local $ENV{TEST_VERBOSE} = 1 if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 3 58 61
504  
505 61 return $self->_runtests( $self->_get_args, $self->_get_tests );
506 }
507  
508 0 return 1;
509 }
510  
511 61 ▶sub _get_tests {
Subroutine _get_tests: called CC=5 SCAR=16.1
512 61 my $self = shift;
513  
514 61 my $state = $self->state_manager;
515 61 my $ext = $self->extensions;
516 61 ▶ $state->extensions($ext) if defined $ext;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ext 2 59 61
517 61 ▶ if ( defined( my $state_switch = $self->state ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $state_switch = $self->state)) 61 0 61
518 61 $state->apply_switch(@$state_switch);
519 }
520  
521 61 my @tests = $state->get_tests( $self->recurse, @{ $self->argv } );
522  
523 61 ▶ $self->_shuffle(@tests) if $self->shuffle;
Branch: 1 branch
BranchTrueFalseTotal
if $self->shuffle 3 58 61
524 61 ▶ @tests = reverse @tests if $self->backwards;
Branch: 1 branch
BranchTrueFalseTotal
if $self->backwards 2 59 61
525  
526 61 return @tests;
527 }
528  
529 2 ▶sub _runtests {
Subroutine _runtests: called CC=1 SCAR=0.0
530 2 my ( $self, $args, @tests ) = @_;
531 2 my $harness = TAP::Harness::Env->create($args);
532  
533 2 my $state = $self->state_manager;
534  
535 $harness->callback(
536 2 ▶ after_test => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
537 2 $state->observe_test(@_);
538 }
539 2 );
540  
541 $harness->callback(
542 2 ▶ after_runtests => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
543 2 $state->commit(@_);
544 }
545 2 );
546  
547 2 my $aggregator = $harness->runtests(@tests);
548  
549 2 return !$aggregator->has_errors;
550 }
551  
552 61 ▶sub _get_switches {
Subroutine _get_switches: called CC=6 SCAR=17.9
553 61 my $self = shift;
554 61 my @switches;
555  
556 # notes that -T or -t must be at the front of the switches!
557 61 ▶ if ( $self->taint_fail ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->taint_fail) { } 1 60 61
elsif ($self->taint_warn) { } 1 59 60
558 1 push @switches, '-T';
559 }
560 elsif ( $self->taint_warn ) {
561 1 push @switches, '-t';
562 }
563 61 ▶ if ( $self->warnings_fail ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->warnings_fail) { } 1 60 61
elsif ($self->warnings_warn) { } 1 59 60
564 1 push @switches, '-W';
565 }
566 elsif ( $self->warnings_warn ) {
567 1 push @switches, '-w';
568 }
569  
570 61 ▶ return @switches ? \@switches : ();
Branch: 1 branch
BranchTrueFalseTotal
@switches ? : 4 57 61
571 }
572  
573 61 ▶sub _get_lib {
Subroutine _get_lib: called CC=5 SCAR=16.1
574 61 my $self = shift;
575 61 my @libs;
576 61 ▶ if ( $self->lib ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lib) 3 58 61
577 3 push @libs, 'lib';
578 }
579 61 ▶ if ( $self->blib ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->blib) 3 58 61
580 3 push @libs, 'blib/lib', 'blib/arch';
581 }
582 61 ▶ if ( @{ $self->includes } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->includes;}) 1 60 61
583 1 push @libs, @{ $self->includes };
584 }
585  
586 #24926
587 61 @libs = map { File::Spec->rel2abs($_) } @libs;
588  
589 # Huh?
590 61 ▶ return @libs ? \@libs : ();
Branch: 1 branch
BranchTrueFalseTotal
@libs ? : 7 54 61
591 }
592  
593 0 ▶sub _shuffle {
Subroutine _shuffle: not called CC=2 SCAR=17.9
594 0 my $self = shift;
595  
596 # Fisher-Yates shuffle
597 0 my $i = @_;
598 0 ▶ while ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 0 0 0
599 0 my $j = rand $i--;
600 0 @_[ $i, $j ] = @_[ $j, $i ];
601 }
602 0 return;
603 }
604  
605 =head3 C<require_harness>
606  
607 Load a harness replacement class.
608  
609 $prove->require_harness($for => $class_name);
610  
611 =cut
612  
613 0 ▶sub require_harness {
Subroutine require_harness: not called CC=2 SCAR=17.9
Pod documented
614 0 my ( $self, $for, $class ) = @_;
615  
616 0 my ($class_name) = $class =~ /^(\w+(?:::\w+)*)/;
617  
618 # Emulate Perl's -MModule=arg1,arg2 behaviour
619 0 $class =~ s!^(\w+(?:::\w+)*)=(.*)$!$1 split(/,/,q{$2})!;
620  
621 0 eval("use $class;");
622 0 ▶ die "$class_name is required to use the --$for feature: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
623  
624 0 $self->{harness_class} = $class_name;
625  
626 0 return;
627 }
628  
629 =head3 C<print_version>
630  
631 Display the version numbers of the loaded L<TAP::Harness> and the
632 current Perl.
633  
634 =cut
635  
636 0 ▶sub print_version {
Subroutine print_version: not called CC=1 SCAR=6.9
Pod documented
637 0 my $self = shift;
638 0 require TAP::Harness;
639 0 printf(
640 "TAP::Harness v%s and Perl v%vd\n",
641 $TAP::Harness::VERSION, $^V
642 );
643  
644 0 return;
645 }
646  
647 6 1;
648  
649 # vim:ts=4:sw=4:et:sta
650  
651 __END__
« blib/lib/TAP/Harness.pm ↑ Summary blib/lib/TAP/Parser/SourceHandler/Executable.pm »