blib/lib/Test/Verbose.pm

filter: Statementstmt 59.0% 183 / 310 Branchbran 33.4% 75 / 224 Conditioncond 21.6% 29 / 134 MC/DCmcdc 8.0% 6 / 75 Subroutinesub 67.7% 21 / 31 Podpod 68.4% 13 / 19 totaltotal 41.2% 327 / 793 CC 159 SCAR 73.9
CC
159
Cov
43%
test
4556.0
test_scripts_for_pod_file
30.0
new
23.6
CRAP 1621.5
↑ Summary
1 package Test::Verbose;
2  
3 1 $VERSION = 0.010;
4  
5 #BEGIN {
6 # *CORE::GLOBAL::chdir = \&my_chdir;
7 #}
8 #
9 #sub my_chdir {
10 # warn $_[0], " at ", join " ", map defined $_ ? $_ : "undef", caller(0), "\n";
11 # CORE::chdir( $_[0] );
12 #}
13  
14 =head1 NAME
15  
16 Test::Verbose - Run 'make TEST_VERBOSE=1' on one or more test files
17  
18 =head1 SYNOPSIS
19  
20 # from the command line. man tv for more details.
21 $ tv lib/Foo.pm # test this module
22 $ tv t/*.t # run these tests
23  
24 # from a module
25 use Test::Verbose qw( test_verbose );
26 test_verbose( @module_and_test_script_filenames );
27  
28 For more control, you can use the object oriented interface.
29  
30 See also the L<tv> command.
31  
32 =head1 DESCRIPTION
33  
34 Given a list of test scripts, source file names, directories and/or
35 package names, attempts to find and execute the appropriate test
36 scripts.
37  
38 This (via the associated tv command) is useful when developing code or
39 test scripts: just map "tv %" to a key in your editor and press it
40 frequently (where "%" is your editor's macro for "the file being
41 edited).
42  
43 Before doing anything, this module identifies the working directory for
44 the project by scanning the current directory and it's ancestors,
45 stopping at the first directory that contains a "t" directory.
46  
47 If an explicitly named item (other than POD files) cannot be tested, an
48 exception is thrown.
49  
50 Here is how each name passed in is treated:
51  
52 =over
53  
54 =item test script
55  
56 An explicitly mentioned test script is selected, no source files need be
57 parsed. Names of test scripts are recognized by ending in ".t" and, if
58 they exist on the filesystem, by being a file (and not a directory).
59  
60 =item source file
61  
62 Source files ending in ".pl", ".pm", or ".pod" are run through
63 C<podchecker>, then perl -cw before any tests are run. This
64 forces useful POD and does a quick shortcircuit syntax check of the
65 source files before the possibly length make test gets run.
66  
67 Source files are parsed (very naively) looking for C<package> declarations
68 and for test scripts listed in special POD comments:
69  
70 =for test_script foo.t bar.t
71 baz.t
72  
73 Also, all test scripts are parsed looking for C<use> and C<require>
74 statements and for POD that looks like:
75  
76 =for file lib/Foo.pm
77  
78 or
79  
80 =for package Foo
81  
82 . All test scripts pertaining to a given file and any packages in it
83 are then selected.
84  
85 Before any test scripts are run, source files are run through
86 L<podchecker|podchecker> and through C<perl -cw>. The former is to
87 check POD, something normal test suites don't do, and the latter is
88 because running C<make test ...> for a distribution with a lot of
89 modules can be slow and I want to give per-module feedback ASAP.
90  
91 The paths listed in C<=for file> must be paths relative to the project
92 root and not contain "..". Hmmm, they can also be absolute paths, but
93 why would you do that?
94  
95 Names of source files are recognized by not ending in ".t" and not
96 looking like a package name or, if they do look like a package name, by
97 existing on the filesystem.
98  
99 =item directory
100  
101 Directories are travered looking for files with the extensions ".t",
102 ".pm", ".pod", or ".pl". These are then treated as though they had been
103 explicitly named. Note that this notion of "looks like a source file"
104 differs from that used when a source file is explicitly passed (where
105 any extension other than .t may be used).
106  
107 =item package name
108  
109 If a name looks like a legal package name (Contains only word characters
110 and "::" digraphs) and does not exist on the filesystem, then it is
111 assumed to be a package name. In this case, all explicitly mentioned
112 source files and test script files are scanned as normal, as well as
113 those found by scanning the main project directory and (only) it's lib
114 and t subdirectories. Files found there are not selected, but are used
115 to determine what tests to run for a package.
116  
117 =back
118  
119 =head1 .tvrc file
120  
121 If a .tvrc file is found in a project's root directory, it is run just
122 before any tests. This allows you to set important env. vars:
123  
124 $ENV{DBI_USER}="barries";
125 $ENV{DBI_PASS}="yuck";
126  
127 $tv->pure_perl = 1;
128  
129 This support is experimental but should be ok for now. Options set here
130 may be overridden on the command line.
131  
132 =head1 FUNCTIONS
133  
134 test_verbose( @names );
135 test_verbose( @names, \%options );
136  
137 Shortcut for
138  
139 my $tv = Test::Verbose->new( %options )->test( @names );
140  
141 =cut
142  
143 1 @EXPORT_OK = qw( test_verbose is_win32 );
144 1 @ISA = qw( Exporter );
145  
146 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
147  
148 1 ▶use constant debugging => $ENV{TVDEBUG} ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'TVDEBUG'} ? : 0 1 1
149 1 ▶use constant is_win32 => $^O =~ /Win32/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
150 1 ▶use constant MAKE => is_win32 ? "nmake.exe" : "make";
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
&is_win32() ? : 0 1 1
151  
152 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
153 1 require Exporter;
154 1 require Carp;
155 1 require Cwd;
156 1 require File::Spec;
157 }
158  
159 0 ▶sub test_verbose {
Subroutine test_verbose: not called CC=2 SCAR=17.9
Pod undocumented
160 0 ▶ my $options = ref $_[-1] eq "HASH" ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 0 0 0
161 0 return Test::Verbose->new( %$options )->test( @_ );
162 }
163  
164 =head1 METHODS
165  
166 =over
167  
168 =item new
169  
170 Takes a list of options:
171  
172 =over
173  
174 =item Debug
175  
176 Runs the test scripts directly using perl C<-d>. Causes ExtUtils to
177 be ignored.
178  
179 =item Dir
180  
181 What directory to look for t/ and run make(1) in. Undefined causes
182 the instance to search for a directory containing a directory named "t"
183 in the current directory and its parents.
184  
185 =item JustPrint
186  
187 Print out the command to be executed.
188  
189 =item ExtUtils
190  
191 Don't use C<make test TEST_VERBOSE=1 ...>, use
192 C<perl '-MExtUtils::Command::MM' -e 'test_harness(1,\'lib\')' ...>
193 instead.
194 Useful if you don't have a Makefile.PL; might not work on all versions
195 of perl.
196  
197 =back
198  
199 =cut
200  
201 6 ▶sub new {
Subroutine new: called CC=12 SCAR=31.6
Pod documented
202 6 my $proto = shift;
203 6 ▶ my $self = bless {}, ref $proto ? ref $proto : $proto;
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 6 6
204  
205 6 $self->load_rc;
206  
207 6 my %options = @_;
208  
209 6 for ( keys %options ) {
210 $self->{$_} = $options{$_}
211 0 ▶ if defined $options{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{$_} 0 0 0
212 }
213  
214 $self->{TestPOD} = $self->{Compile} = $self->{RunTests} = 1
215 6 ▶ unless $self->{TestPOD} || $self->{Compile} || $self->{RunTests};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"TestPOD"} or $self->{"Compile"} or $self->{"RunTests"} 6 0 6
Condition33%2/6
$self->{"TestPOD"} or $self->{"Compile"} or $self->{"RunTests"}
l!l&&r!l&&!r
006
$self->{"TestPOD"} or $self->{"Compile"}
l!l&&r!l&&!r
006
MC/DC0%0/3
$self->{"TestPOD"} or $self->{"Compile"} or $self->{"RunTests"}
$self->{"TestPOD"} $self->{"Compile"} $self->{"RunTests"}
Truth table25%1/4
A or B or C
A= $self->{"TestPOD"}B= $self->{"Compile"}C= $self->{"RunTests"}
ABCresult
1XX1
01X1
0011
0000
216  
217 6 ▶ $self->{TestPOD} = 0 if $self->{NoPOD};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NoPOD"} 0 6 6
218 6 ▶ $self->{Compile} = 0 if $self->{NoCompile};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NoCompile"} 0 6 6
219 6 ▶ $self->{RunTests} = 0 if $self->{NoTests};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NoTests"} 0 6 6
220  
221 6 ▶ $self->{DoubleQuiet} ||= $self->{TripleQuiet};
Condition33%1/3
$self->{"DoubleQuiet"} ||= $self->{"TripleQuiet"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$self->{"DoubleQuiet"} ||= $self->{"TripleQuiet"}
$self->{"DoubleQuiet"} $self->{"TripleQuiet"}
Truth table33%1/3
A ||= B
A= $self->{"DoubleQuiet"}B= $self->{"TripleQuiet"}
ABresult
1X1
011
000
222 6 ▶ $self->{Quiet} ||= $self->{DoubleQuiet};
Condition33%1/3
$self->{"Quiet"} ||= $self->{"DoubleQuiet"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$self->{"Quiet"} ||= $self->{"DoubleQuiet"}
$self->{"Quiet"} $self->{"DoubleQuiet"}
Truth table33%1/3
A ||= B
A= $self->{"Quiet"}B= $self->{"DoubleQuiet"}
ABresult
1X1
011
000
223  
224 6 return $self;
225 }
226  
227 =item load_rc
228  
229 Scans for and loads the .tvrc file.
230  
231 NOTE: may be expanded in the future to load multiple RC files.
232  
233 So far, only a few attributes are available, will add more as I need
234 to.
235  
236 For 100% pure perl modules, a common .tvrc is:
237  
238 $tv->pure_perl = 1;
239  
240 . And a way to shush tv from printing out all the good news is:
241  
242 $tv->quiet = 1;
243  
244 =cut
245  
246 6 ▶sub load_rc {
Subroutine load_rc: called CC=5 SCAR=24.0
Pod documented
247 6 my $self = shift;
248  
249 6 my $rc_file = ".tvrc";
250  
251 6 my $d = $self->dir;
252  
253 6 $self->{ConfigClass} = join "", "Test::Verbose::Config::", int $self;
254
255 $rc_file = -e $rc_file
256 6 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
-e $rc_file ? : 0 6 6
257 0 ▶ open RC_FILE, "<$rc_file" or die "$!: $rc_file";
Branch: 1 branch
BranchTrueFalseTotal
open RC_FILE, "<$rc_file" or die "$!: $rc_file" 0 0 0
258 0 local $/ = undef;
259 0 my $code = <RC_FILE>;
260 0 close RC_FILE;
261 0 my $self_class = ref $self;
262 0 bless $self, $self->{ConfigClass};
263 0 my $fn = File::Spec->rel2abs( $rc_file, $d );
264 0 join "",
265 "package $self->{ConfigClass};\n",
266 "no strict;\n",
267 "\@ISA = qw( ", $self_class, " );\n",
268 "use strict;\n",
269 "our \$tv;",
270 "sub AUTOLOAD {};\n",
271 "#line 1 $fn\n",
272 $code,
273 "\n",
274 "1;";
275 }
276 : undef;
277  
278 6 ▶ if ( defined $rc_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rc_file) 0 6 6
279 {
280 0 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.2
281 0 ${"$self->{ConfigClass}::tv"} = $self;
282 }
283  
284 0 ▶ eval $rc_file or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval $rc_file or die $@ 0 0 0
285 }
286  
287 }
288  
289 =item dir
290  
291 my $dir = $tv->dir;
292 $tv->dir( undef ); ## clear old setting
293 $tv->dir( "foo" ); ## prevent chdir( ".." ) searching
294 $tv->dir = "foo";
295  
296 Looks for t/ or lib/ in the current directory or in any parent directory.
297 C<chdir()>s up the directory tree until t/ is found, then back to the
298 directory it started in, so make sure you have permissions to C<chdir()>
299 up and back.
300  
301 Passing a Dir => $dir option to new prevents this method for searching
302 for a name,
303  
304 =cut
305  
306 26 ▶sub dir: lvalue {
Subroutine dir: called CC=9 SCAR=22.5
Pod documented
307 26 my $self = shift;
308  
309 26 ▶ $self->{Dir} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 26 26
310
311 26 ▶ if ( defined wantarray && ! defined $self->{Dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray and not defined $self->{"Dir"}) 6 20 26
Condition66%2/3
defined wantarray and not defined $self->{"Dir"}
!ll&&!rl&&r
0206
MC/DC50%1/2
defined wantarray and not defined $self->{"Dir"}
defined wantarray not defined $self->{"Dir"}
Truth table66%2/3
A and not(B)
A= defined wantarrayB= not defined $self->{"Dir"}
ABresult
0X0
100
111
312 6 warn "tv: searching for project directory\n" if debugging;
313 6 my $cwd = Cwd::cwd;
314 ## cd up until we find a directory that has a "t" subdirectory
315 ## this is for folks whose editor's working directories might be
316 ## down in t/ or lib/, etc.
317 6 my $last_d = $cwd;
318 6 ▶ until ( -d "t" || -d "lib" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "t" or -d "lib") 3 6 9
Condition66%2/3
-d "t" or -d "lib"
l!l&&r!l&&!r
603
MC/DC50%1/2
-d "t" or -d "lib"
-d "t" -d "lib"
Truth table66%2/3
A or B
A= -d "t"B= -d "lib"
ABresult
1X1
011
000
319 3 ▶ chdir( File::Spec->updir )
Branch: 1 branch
BranchTrueFalseTotal
chdir "File::Spec"->updir or die "tv: $! while cd()ing upwards looking for t/ or lib/" 3 0 3
320 or die "tv: $! while cd()ing upwards looking for t/ or lib/";
321 3 my $new_d = Cwd::cwd;
322 3 ▶ die "tv: could not find t/ or lib/ in any parent of $cwd\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $new_d eq length $last_d 0 3 3
323 if length $new_d eq length $last_d;
324 3 $last_d = $new_d;
325 }
326 6 $self->{Dir} = Cwd::cwd;
327 6 warn "tv: ...found $self->{Dir}\n" if debugging;
328 6 ▶ chdir $cwd or die "tv: $! chdir()ing back to '$cwd'";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or die "tv: $! chdir()ing back to '${cwd}'" 6 0 6
329 }
330  
331 26 $self->{Dir};
332 }
333  
334  
335 =item pure_perl
336  
337 $tv->pure_perl = 1;
338 print $tv->pure_perl;
339  
340 =cut
341  
342 0 ▶sub pure_perl: lvalue {
Subroutine pure_perl: not called CC=2 SCAR=17.9
Pod documented
343 0 my $self = shift;
344 0 ▶ $self->{PurePerl} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
345 0 $self->{PurePerl};
346 }
347  
348 =item quiet
349  
350 $tv->quiet = 1;
351  
352 =cut
353  
354 0 ▶sub quiet: lvalue {
Subroutine quiet: not called CC=2 SCAR=17.9
Pod documented
355 0 my $self = shift;
356 0 ▶ $self->{Quiet} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
357 0 $self->{Quiet};
358 }
359  
360 =item double_quiet
361  
362 $tv->double_quiet = 1;
363  
364 =cut
365  
366 0 ▶sub double_quiet: lvalue {
Subroutine double_quiet: not called CC=2 SCAR=17.9
Pod documented
367 0 my $self = shift;
368 0 ▶ $self->{DoubleQuiet} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
369 0 $self->{DoubleQuiet};
370 }
371  
372 =item triple_quiet
373  
374 $tv->triple_quiet = 1;
375  
376 =cut
377  
378 0 ▶sub triple_quiet: lvalue {
Subroutine triple_quiet: not called CC=2 SCAR=17.9
Pod documented
379 0 my $self = shift;
380 0 ▶ $self->{DoubleQuiet} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
381 0 $self->{DoubleQuiet};
382 }
383  
384 =item is_test_script
385  
386 $self->is_test_script; ## tests $_
387 $self->is_test_script( $name );
388  
389 Returns true if the name looks like the name of a test script (ends in .t).
390 File does not need to exist.
391  
392 Overload this to alter Test::Verbose's perceptions.
393  
394 =cut
395  
396 30 ▶sub is_test_script {
Subroutine is_test_script: called CC=4 SCAR=14.3
Pod documented
397 30 my $self = shift;
398 30 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 30 30
399 30 ▶ /\.t\z/ && ( ! -e || -f _ );
Branch: 1 branch
BranchTrueFalseTotal
/\.t\z/ and !(-e $_) || -f _ 25 5 30
Condition66%4/6
/\.t\z/ && (!(-e $_) || -f _)
!ll&&!rl&&r
5025
not -e $_ or -f _
l!l&&r!l&&!r
1240
MC/DC33%1/3
/\.t\z/ && (!(-e $_) || -f _)
/\.t\z/ not -e $_ -f _
Truth table75%3/4
A && not(B) or C
A= /\.t\z/B= not -e $_C= -f _
ABCresult
0XX0
1000
11X1
1011
400 }
401  
402  
403 =item is_pod_file
404  
405 $self->is_pod_file; ## tests $_
406 $self->is_pod_file( $name );
407  
408 Returns true if the name looks like the name of a pod file (ends in
409 .pod). File does not need to exist, but must be a file if it
410 does.
411  
412 Overload this to alter Test::Verbose's perceptions.
413  
414 =cut
415  
416 2 ▶sub is_pod_file {
Subroutine is_pod_file: called CC=4 SCAR=18.7
Pod documented
417 2 my $self = shift;
418 2 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
419 2 ▶ /\.(pod)\z/ && ( ! -e || -f _ );
Branch: 1 branch
BranchTrueFalseTotal
/\.(pod)\z/ and !(-e $_) || -f _ 0 2 2
Condition16%1/6
/\.(pod)\z/ && (!(-e $_) || -f _)
!ll&&!rl&&r
200
not -e $_ or -f _
l!l&&r!l&&!r
000
MC/DC0%0/3
/\.(pod)\z/ && (!(-e $_) || -f _)
/\.(pod)\z/ not -e $_ -f _
Truth table25%1/4
A && not(B) or C
A= /\.(pod)\z/B= not -e $_C= -f _
ABCresult
0XX0
1000
11X1
1011
420 }
421  
422  
423 =item is_source_file
424  
425 $self->is_source_file; ## tests $_
426 $self->is_source_file( $name );
427  
428 Returns true if the name looks like the name of a source file (ends in
429 .pm, .pod or .pl). File does not need to exist, but must be a file if it
430 does.
431  
432 This is only used when traversing directory trees, otherwise a file name
433 (ie not a package) is assumed to be a source file if it is not a test
434 file.
435  
436 Overload this to alter Test::Verbose's perceptions.
437  
438 =cut
439  
440 18 ▶sub is_source_file {
Subroutine is_source_file: called CC=4 SCAR=15.0
Pod documented
441 18 my $self = shift;
442 18 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 18 18
443 18 ▶ /\.(pm|pl|pod)\z/ && ( ! -e || -f _ );
Branch: 1 branch
BranchTrueFalseTotal
/\.(pm|pl|pod)\z/ and !(-e $_) || -f _ 2 16 18
Condition50%3/6
/\.(pm|pl|pod)\z/ && (!(-e $_) || -f _)
!ll&&!rl&&r
1602
not -e $_ or -f _
l!l&&r!l&&!r
020
MC/DC33%1/3
/\.(pm|pl|pod)\z/ && (!(-e $_) || -f _)
/\.(pm|pl|pod)\z/ not -e $_ -f _
Truth table50%2/4
A && not(B) or C
A= /\.(pm|pl|pod)\z/B= not -e $_C= -f _
ABCresult
0XX0
1000
11X1
1011
444 }
445  
446  
447 =item is_package
448  
449 $self->is_test_script; ## tests $_
450 $self->is_test_script( $name );
451  
452 Returns trues if the name looks like the name of a package (contains
453 only /\w/ and "::") and is not a name that exists (ie C<! -e>).
454  
455 Overload this to alter Test::Verbose's perceptions.
456  
457 =cut
458  
459  
460 9 ▶sub is_package {
Subroutine is_package: called CC=3 SCAR=11.1
Pod documented
461 9 my $self = shift;
462 9 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 9 9
463 9 ▶ /\A(\w|::)+\z/ && ! -e;
Branch: 1 branch
BranchTrueFalseTotal
/\A(\w|::)+\z/ and not -e $_ 3 6 9
464 }
465  
466  
467 =item unhandled
468  
469 $self->unhandled( @_ );
470  
471 die()s with any unhandled names.
472  
473 Overload this to alter the default.
474  
475 =cut
476  
477 0 ▶sub unhandled {
Subroutine unhandled: not called CC=2 SCAR=17.9
Pod documented
478 0 my $self = shift;
479  
480 0 ▶ warn "tv: no test scripts found for: ", join( ", ", @_ ), "\n",
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
481 "Try adding '=for test_script ...' to the source",
482 @_ > 1 ? "s" : "",
483 " or 'use ...;' or '=for package ...' to the test scripts\n";
484 }
485  
486 =item look_up_scripts
487  
488 my @scripts = $tv->look_up_test_scripts( @_ );
489  
490 Looks up the scripts for any names that don't look like test scripts.
491  
492 die()s if a non-test script cannot be found.
493  
494 use =for tv dont_test to prevent this error.
495  
496 All test scripts returned will have the form "t/foo.t", and the result
497 is sorted. No test script name will be returned more than once.
498  
499 =cut
500  
501 6 ▶sub test_scripts_for {
Subroutine test_scripts_for: called CC=8 SCAR=22.8
Pod undocumented
502 6 my $self = shift;
503  
504 6 my @test_scripts;
505  
506 6 local $self->{Names} = [ $self->_traverse_dirs( @_ ) ];
507  
508 6 for ( @{$self->{Names}} ) {
509 12 ▶ if ( $self->is_test_script ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->is_test_script) { } 9 3 12
elsif ($self->is_package) { } 1 2 3
elsif (-d $_) { } 0 2 2
elsif ($self->is_pod_file) { } 0 2 2
510 9 push @test_scripts, $_;
511 }
512 elsif ( $self->is_package ) {
513 1 my @t = $self->test_scripts_for_package;
514 1 ▶ if ( @t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) { } 1 0 1
515 1 push @test_scripts, @t;
516 }
517 else {
518 0 push @{$self->{Unhandled}}, $_;
519 }
520 }
521 elsif ( -d ) {
522 0 Carp::confess "BUG: this code branch should be unreachable";
523 # my @t = $self->test_scripts_for_dir;
524 # if ( @t ) {
525 # push @test_scripts, @t;
526 # }
527 # else {
528 # push @{$self->{Unhandled}}, $_;
529 # }
530 }
531 elsif ( $self->is_pod_file ) {
532 0 push @{$self->{PodChecks}}, $_;
533 0 push @test_scripts, $self->test_scripts_for_pod_file;
534 # It is not an error for a pod file to not have a test
535 # script.
536 }
537 else {
538 # It's a code file
539 2 push @{$self->{CompileChecks}}, $_;
540 2 my @t = $self->test_scripts_for_file;
541 2 ▶ if ( @t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) { } 2 0 2
542 2 push @test_scripts, @t;
543 }
544 else {
545 0 push @{$self->{Unhandled}}, $_;
546 }
547 }
548 }
549  
550 6 my %seen;
551 return sort grep !$seen{$_}++, map {
552 ## Make all test scripts look like "t/foo.t"
553 6 $_ = File::Spec->canonpath( $_ );
554 22 s{^(?![\\/])(t[\\/])?}{t/};
555 22 $_;
556 } @test_scripts
557 }
558  
559  
560 9 ▶sub _slurp_and_split {
Subroutine _slurp_and_split: called CC=3 SCAR=11.0
561 9 my @items = split /\s+/, $1;
562 9 local $_;
563 9 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 12 0 12
564 12 ▶ last if /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 9 3 12
565 3 push @items, split /\s+/;
566 }
567  
568 9 return grep length, @items;
569 }
570  
571  
572 10 ▶sub _traverse_dirs {
Subroutine _traverse_dirs: called CC=3 SCAR=11.0
573 10 my $self = shift;
574 10 my @names = @_;
575  
576 return map {
577 10 my $dir = $_;
578 -d $dir
579 13 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
-d $dir ? : 6 7 13
580 6 my @results;
581 6 warn "tv: traversing $_\n" if debugging;
582 6 require File::Find;
583 File::Find::find(
584 24 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
585 24 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (-f $_ and $self->is_source_file || $self->is_test_script) 18 6 24
Condition66%4/6
-f $_ and $self->is_source_file || $self->is_test_script
!ll&&!rl&&r
6018
$self->is_source_file or $self->is_test_script
l!l&&r!l&&!r
2160
MC/DC33%1/3
-f $_ and $self->is_source_file || $self->is_test_script
-f $_ $self->is_source_file $self->is_test_script
Truth table75%3/4
A and B or C
A= -f $_B= $self->is_source_fileC= $self->is_test_script
ABCresult
0XX0
1000
11X1
1011
586 -f
587 && ( $self->is_source_file ||
588 $self->is_test_script
589 )
590 ) {
591 18 push @results, $File::Find::name;
592 18 push @{$self->{FilesInDir}->{$dir}},
593 $File::Find::name;
594 }
595 },
596 6 $_
597 );
598 6 ▶ @results ? @results : $_;
Branch: 1 branch
BranchTrueFalseTotal
@results ? : 6 0 6
599 }
600 : $dir;
601 } @names;
602 }
603  
604  
605 3 ▶sub _scan_source_files {
Subroutine _scan_source_files: called CC=12 SCAR=25.0
606 3 my $self = shift;
607  
608 my @files = grep ! $self->is_package && ! $self->is_test_script,
609 3 ▶ @{$self->{Names}};
Condition66%2/3
$self->is_package || $self->is_test_script
l!l&&r!l&&!r
102
MC/DC50%1/2
$self->is_package || $self->is_test_script
$self->is_package $self->is_test_script
Truth table66%2/3
A || B
A= $self->is_packageB= $self->is_test_script
ABresult
1X1
011
000
610  
611 3 ▶ if ( grep $self->is_package, @{$self->{Names}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep $self->is_package, @{$$self{"Names"};}) 1 2 3
612 ## Scan all likely source files to look for those that
613 ## might contain the package.
614 push @files,
615 $self->_traverse_dirs( File::Spec->catdir( $self->dir, 'lib') ),
616 1 do {
617 # Look for source files in the project dir's top level.
618 1 opendir D, $self->dir;
619 1 ▶ my @f = grep
Condition33%1/3
-f $_ && $self->is_source_file
!ll&&!rl&&r
400
MC/DC0%0/2
-f $_ && $self->is_source_file
-f $_ $self->is_source_file
Truth table33%1/3
A && B
A= -f $_B= $self->is_source_file
ABresult
0X0
100
111
620 -f && $self->is_source_file,
621 readdir D;
622 1 close D;
623 1 @f = map File::Spec->catdir( $self->dir, $_ ), @f;
624 };
625 }
626  
627 3 my $cwd = Cwd::cwd;
628  
629 3 for my $code_file ( @files ) {
630 3 warn "tv: scanning code file $code_file\n" if debugging;
631 3 ▶ open F, $code_file or die "tv: $!: $code_file";
Branch: 1 branch
BranchTrueFalseTotal
open F, $code_file or die "tv: $!: $code_file" 3 0 3
632 3 my $abs_fn = File::Spec->canonpath(
633 File::Spec->rel2abs( $code_file, $cwd )
634 );
635  
636 3 my $package = "main";
637 3 local $/ = "\n";
638 3 local $_;
639 3 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 24 3 27
640 24 ▶ if ( /^=for\s+test_scripts?\s+(.*)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^=for\s+test_scripts?\s+(.*)/) { } 3 21 24
elsif (/^\s*package\s+(\S+)\s*;/) { } 3 18 21
elsif (/^=/) { } 3 15 18
641 3 my @scripts = _slurp_and_split;
642 3 warn "tv: $abs_fn, $package =for test_scripts ",
643 join( " ", @scripts ), "\n"
644 if debugging;
645 3 push @{$self->{Files}->{$abs_fn}}, @scripts;
646 3 push @{$self->{Packages}->{$package}}, @scripts;
647 }
648 elsif ( /^\s*package\s+(\S+)\s*;/ ) {
649 3 $package = $1;
650 3 warn "tv: $abs_fn declares $package\n" if debugging;
651 3 push @{$self->{PackagesForFile}->{$abs_fn}}, $package;
652 }
653 elsif ( /^=/ ) {
654 3 push @{$self->{PodChecks}}, $code_file
655 3 ▶ unless grep $_ eq $code_file, @{$self->{PodChecks}};
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ eq $code_file), @{$$self{"PodChecks"};}) 3 0 3
656 }
657 }
658 3 ▶ close F or die "tv: $! closing $code_file";
Branch: 1 branch
BranchTrueFalseTotal
close F or die "tv: $! closing $code_file" 3 0 3
659 }
660  
661 3 1;
662 }
663  
664  
665 3 ▶sub _scan_test_scripts {
Subroutine _scan_test_scripts: called CC=11 SCAR=24.1
666 3 my $self = shift;
667  
668 3 my $cwd = Cwd::cwd;
669  
670 3 ▶ chdir $self->dir or Carp::croak "$!: ", $self->dir, "\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $self->dir or Carp::croak("$!: ", $self->dir, "\n") 3 0 3
671 3 my @all_test_scripts = grep /.t\z/, $self->_traverse_dirs( "t" );
672 3 ▶ chdir $cwd or Carp::croak "$!: $cwd\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or Carp::croak("$!: $cwd\n") 3 0 3
673  
674 3 ▶ warn "tv: no test scripts (t/*.t) found for project\n" unless @all_test_scripts;
Branch: 1 branch
BranchTrueFalseTotal
unless @all_test_scripts 0 3 3
675  
676 3 for my $test_script ( @all_test_scripts ) {
677 12 warn "tv: scanning test script $test_script\n" if debugging;
678 12 ▶ open F, File::Spec->catfile( $self->dir, $test_script )
Branch: 1 branch
BranchTrueFalseTotal
open F, "File::Spec"->catfile($self->dir, $test_script) or Carp::croak("$!: $test_script\n") 12 0 12
679 or Carp::croak "$!: $test_script\n";
680  
681 12 local $/ = "\n";
682 12 local $_;
683 12 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 84 12 96
684 84 ▶ if ( /^=for\s+packages?\s+(.*)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^=for\s+packages?\s+(.*)/) { } 3 81 84
elsif (/^=for\s+files?\s+(.*)/) { } 3 78 81
elsif (/\s*(use|require)\s+([\w:]+)/) { } 15 63 78
685 3 my @pkgs = _slurp_and_split;
686 3 warn "tv: $test_script =for packages ", join( " ", @pkgs ), "\n"
687 if debugging;
688 3 map push( @{$self->{Packages}->{$_}}, $test_script ), @pkgs;
689 }
690 elsif ( /^=for\s+files?\s+(.*)/ ) {
691 3 my @files = map
692 File::Spec->canonpath(
693 File::Spec->rel2abs( $_, $self->dir )
694 ), _slurp_and_split;
695 3 warn "tv: $test_script =for files ", join( " ", @files ), "\n"
696 if debugging;
697 map
698 3 push( @{$self->{Files}->{$_}}, $test_script ),
699 @files;
700 }
701 elsif ( /\s*(use|require)\s+([\w:]+)/ ) {
702 15 warn "tv: $test_script $1s $2\n" if debugging;
703 15 push @{$self->{Packages}->{$2}}, $test_script;
704 }
705 }
706 12 ▶ close F or die "tv: $! closing $test_script";
Branch: 1 branch
BranchTrueFalseTotal
close F or die "tv: $! closing $test_script" 12 0 12
707 }
708  
709 3 1;
710 }
711  
712  
713 3 ▶sub test_scripts_for_package {
Subroutine test_scripts_for_package: called CC=5 SCAR=16.8
Pod undocumented
714 3 my $self = shift;
715 3 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
716  
717 3 ▶ $self->{ScannedSourceFiles} ||= $self->_scan_source_files;
Condition66%2/3
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
$self->{"ScannedSourceFiles"} $self->_scan_source_files
Truth table66%2/3
A ||= B
A= $self->{"ScannedSourceFiles"}B= $self->_scan_source_files
ABresult
1X1
011
000
718 3 ▶ $self->{ScannedTestScripts} ||= $self->_scan_test_scripts;
Condition66%2/3
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
$self->{"ScannedTestScripts"} $self->_scan_test_scripts
Truth table66%2/3
A ||= B
A= $self->{"ScannedTestScripts"}B= $self->_scan_test_scripts
ABresult
1X1
011
000
719  
720 return exists $self->{Packages}->{$_}
721 3 ▶ ? @{$self->{Packages}->{$_}}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'Packages'}{$_} ? : 3 0 3
722 : ();
723 }
724  
725  
726 2 ▶sub test_scripts_for_file {
Subroutine test_scripts_for_file: called CC=6 SCAR=20.2
Pod undocumented
727 2 my $self = shift;
728 2 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
729  
730 2 ▶ $self->{ScannedSourceFiles} ||= $self->_scan_source_files;
Condition33%1/3
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
$self->{"ScannedSourceFiles"} $self->_scan_source_files
Truth table33%1/3
A ||= B
A= $self->{"ScannedSourceFiles"}B= $self->_scan_source_files
ABresult
1X1
011
000
731 2 ▶ $self->{ScannedTestScripts} ||= $self->_scan_test_scripts;
Condition33%1/3
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
$self->{"ScannedTestScripts"} $self->_scan_test_scripts
Truth table33%1/3
A ||= B
A= $self->{"ScannedTestScripts"}B= $self->_scan_test_scripts
ABresult
1X1
011
000
732  
733 2 local $_ = File::Spec->canonpath(
734 File::Spec->rel2abs( $_, Cwd::cwd )
735 );
736  
737 return (
738 exists $self->{Files}->{$_}
739 2 ▶ ? @{$self->{Files}->{$_}}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'PackagesForFile'}{$_} ? : 2 0 2
740 : (),
741 exists $self->{PackagesForFile}->{$_}
742 ? map $self->test_scripts_for_package,
743 2 ▶ @{$self->{PackagesForFile}->{$_}}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'Files'}{$_} ? : 2 0 2
744 : (),
745 );
746 }
747  
748  
749 0 ▶sub test_scripts_for_pod_file {
Subroutine test_scripts_for_pod_file: not called CC=5 SCAR=34.0
Pod undocumented
750 0 my $self = shift;
751 0 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
752  
753 0 ▶ $self->{ScannedSourceFiles} ||= $self->_scan_source_files;
Condition0%0/3
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ScannedSourceFiles"} ||= $self->_scan_source_files
$self->{"ScannedSourceFiles"} $self->_scan_source_files
Truth table0%0/3
A ||= B
A= $self->{"ScannedSourceFiles"}B= $self->_scan_source_files
ABresult
1X1
011
000
754 0 ▶ $self->{ScannedTestScripts} ||= $self->_scan_test_scripts;
Condition0%0/3
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ScannedTestScripts"} ||= $self->_scan_test_scripts
$self->{"ScannedTestScripts"} $self->_scan_test_scripts
Truth table0%0/3
A ||= B
A= $self->{"ScannedTestScripts"}B= $self->_scan_test_scripts
ABresult
1X1
011
000
755  
756 0 local $_ = File::Spec->canonpath(
757 File::Spec->rel2abs( $_, Cwd::cwd )
758 );
759  
760 return
761 exists $self->{Files}->{$_}
762 0 ▶ ? @{$self->{Files}->{$_}}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'Files'}{$_} ? : 0 0 0
763 : ();
764 }
765  
766  
767 #sub test_scripts_for_dir {
768 # my $self = shift;
769 # local $_ = shift if @_;
770 #
771 # $self->{ScannedSourceFiles} ||= $self->_scan_source_files;
772 # $self->{ScannedTestScripts} ||= $self->_scan_test_scripts;
773 #
774 # return
775 # exists $self->{FilesInDir}->{$_}
776 # ? map
777 # $self->is_test_script
778 # ? $_
779 # : $self->test_scripts_for_file,
780 # @{$self->{FilesInDir}->{$_}}
781 # : ();
782 #}
783  
784  
785 =item test
786  
787 $self->test( @test_scripts );
788  
789 chdir()s to C<$self->dir> and C<exec()>s make test.
790  
791 =cut
792  
793 0 ▶sub _esc {
Subroutine _esc: not called CC=2 SCAR=17.9
794 map
795 m{[^\w./\\=:-]}
796 0 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
m[[^\w./\\=:-]] ? : 0 0 0
797 0 local $_ = $_;
798 0 s/([\\'])/\\$1/g;
799 0 "'$_'";
800 }
801 : $_,
802 @_;
803 }
804  
805 0 ▶sub call_config_handler {
Subroutine call_config_handler: not called CC=2 SCAR=17.9
Pod undocumented
806 0 my $self = shift;
807 0 my $handler = shift;
808  
809 0 my $sub = $self->{ConfigClass}->can( $handler );
810 0 ▶ return unless $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub 0 0 0
811  
812 0 $sub->( $self, @_ );
813 }
814  
815  
816 0 ▶sub test {
Subroutine test: not called CC=67 SCAR=84.2
Pod documented
817 0 my $self = shift;
818  
819 0 my $cwd = Cwd::cwd;
820 0 my $d = $self->dir;
821 0 ▶ chdir $d or die "tv: $!: $d";
Branch: 1 branch
BranchTrueFalseTotal
chdir $d or die "tv: $!: $d" 0 0 0
822  
823 ## TODO: an option to name the log file.
824 0 ▶ open LOG, ">tv.log" unless $self->{NoLog};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"NoLog"} 0 0 0
825  
826 0 $self->call_config_handler( "before_testing_do", @_ );
827  
828 0 $self->{PodChecks} = [];
829 0 $self->{CompileChecks} = [];
830 0 $self->{Unhandled} = [];
831  
832 0 ▶ my @scripts = @_ ? $self->test_scripts_for( @_ ) : ();
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
833  
834 0 ▶ if ( $self->{TestPOD} && @{$self->{PodChecks}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"TestPOD"} and @{$self->{"PodChecks"};}) 0 0 0
Condition0%0/3
$self->{"TestPOD"} and @{$self->{"PodChecks"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"TestPOD"} and @{$self->{"PodChecks"};}
$self->{"TestPOD"} @{$self->{"PodChecks"};}
Truth table0%0/3
A and B
A= $self->{"TestPOD"}B= @{$self->{"PodChecks"};}
ABresult
0X0
100
111
835 ## NOTE: not using $^X here because podchecker may be from a
836 ## newer perl. Could lead to unexpected behavior, but very, very
837 ## probably not.
838 0 warn "tv\$ podchecker ", join( " ", _esc @{$self->{PodChecks}} ), "\n"
839 0 ▶ if $self->{JustPrint} || !$self->{DoubleQuiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"JustPrint"} or not $self->{"DoubleQuiet"} 0 0 0
Condition0%0/3
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
$self->{"JustPrint"} not $self->{"DoubleQuiet"}
Truth table0%0/3
A or not(B)
A= $self->{"JustPrint"}B= not $self->{"DoubleQuiet"}
ABresult
1X1
011
000
840 ## TODO: log the output of this
841 0 system "podchecker", @{$self->{PodChecks}}
842 and die "tv: POD checks failed, not running further tests.\n"
843 0 ▶ unless $self->{JustPrint};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"JustPrint"} 0 0 0
Condition0%0/5
$self->{'JustPrint'} || system('podchecker', @{$self->{'PodChecks'};}) && die("tv: POD checks failed, not running further tests.\n")
l!l&&r!l&&!r
000
system "podchecker", @{$self->{"PodChecks"};} and die "tv: POD checks failed, not running further tests.\n"
!ll
00
MC/DC0%0/2
$self->{'JustPrint'} || system('podchecker', @{$self->{'PodChecks'};}) && die("tv: POD checks failed, not running further tests.\n")
$self->{'JustPrint'} system "podchecker", @{$self->{"PodChecks"};}
Truth table0%0/3
A || B
A= $self->{'JustPrint'}B= system "podchecker", @{$self->{"PodChecks"};}
ABresult
1X1
011
000
844 }
845  
846 0 ▶ if ( $self->{Compile} && @{$self->{CompileChecks}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Compile"} and @{$self->{"CompileChecks"};}) 0 0 0
Condition0%0/3
$self->{"Compile"} and @{$self->{"CompileChecks"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Compile"} and @{$self->{"CompileChecks"};}
$self->{"Compile"} @{$self->{"CompileChecks"};}
Truth table0%0/3
A and B
A= $self->{"Compile"}B= @{$self->{"CompileChecks"};}
ABresult
0X0
100
111
847 warn "tv\$ perl -Ilib -cw ",
848 0 join( " ", _esc @{$self->{CompileChecks}} ),
849 "\n"
850 0 ▶ if $self->{JustPrint} || !$self->{DoubleQuiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"JustPrint"} or not $self->{"DoubleQuiet"} 0 0 0
Condition0%0/3
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
$self->{"JustPrint"} not $self->{"DoubleQuiet"}
Truth table0%0/3
A or not(B)
A= $self->{"JustPrint"}B= not $self->{"DoubleQuiet"}
ABresult
1X1
011
000
851  
852 ## TODO: log the output of this
853 0 system $^X, "-Ilib", "-cw", @{$self->{CompileChecks}}
854 and die "tv: compile test failed, not running further tests.\n"
855 0 ▶ unless $self->{JustPrint};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"JustPrint"} 0 0 0
Condition0%0/5
$self->{'JustPrint'} || system($^X, '-Ilib', '-cw', @{$self->{'CompileChecks'};}) && die("tv: compile test failed, not running further tests.\n")
l!l&&r!l&&!r
000
system $^X, "-Ilib", "-cw", @{$self->{"CompileChecks"};} and die "tv: compile test failed, not running further tests.\n"
!ll
00
MC/DC0%0/2
$self->{'JustPrint'} || system($^X, '-Ilib', '-cw', @{$self->{'CompileChecks'};}) && die("tv: compile test failed, not running further tests.\n")
$self->{'JustPrint'} system $^X, "-Ilib", "-cw", @{$self->{"CompileChecks"};}
Truth table0%0/3
A || B
A= $self->{'JustPrint'}B= system $^X, "-Ilib", "-cw", @{$self->{"CompileChecks"};}
ABresult
1X1
011
000
856 }
857  
858 0 $self->unhandled( @{$self->{Unhandled}} )
859 0 ▶ if @{$self->{Unhandled}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"Unhandled"};} 0 0 0
860  
861 0 ▶ return 0 unless $self->{RunTests} && @scripts;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RunTests"} and @scripts 0 0 0
Condition0%0/3
$self->{"RunTests"} and @scripts
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"RunTests"} and @scripts
$self->{"RunTests"} @scripts
Truth table0%0/3
A and B
A= $self->{"RunTests"}B= @scripts
ABresult
0X0
100
111
862  
863 0 ▶ my $debug = $self->{Debug} || $self->{DebugRun};
Condition0%0/3
$self->{'Debug'} || $self->{'DebugRun'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'Debug'} || $self->{'DebugRun'}
$self->{'Debug'} $self->{'DebugRun'}
Truth table0%0/3
A || B
A= $self->{'Debug'}B= $self->{'DebugRun'}
ABresult
1X1
011
000
864  
865 my @cmds =
866 $debug
867 ? (
868 [ MAKE, "pm_to_blib" ],
869 map [ $^X, "-w", "-Iblib/lib", "-d", $_ ], @scripts
870 )
871 : $self->{PurePerl}
872 ? map [ $^X, "-w", "-Ilib", $_ ], @scripts
873 : $self->{ExtUtils}
874 ? [
875 0 ▶ $^X,
Branch: 4 branches
BranchTrueFalseTotal
$debug ? : 0 0 0
$self->{'PurePerl'} ? : 0 0 0
$self->{'ExtUtils'} ? : 0 0 0
@_ ? : 0 0 0
876 qw( -MExtUtils::Command::MM -e ),
877 "test_harness(1,'lib')",
878 @scripts
879 ]
880 : [ MAKE, qw( test TEST_VERBOSE=1 ),
881 @_
882 ? "TEST_FILES=" . join " ", @scripts
883 : (),
884 ];
885  
886 0 ▶ my $nonlazy_dyn_link = $self->{ExtUtils} || $debug;
Condition0%0/3
$self->{'ExtUtils'} || $debug
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'ExtUtils'} || $debug
$self->{'ExtUtils'} $debug
Truth table0%0/3
A || B
A= $self->{'ExtUtils'}B= $debug
ABresult
1X1
011
000
887 0 ▶ local $ENV{PERL_DL_NONLAZY} = 1 if $nonlazy_dyn_link;
Branch: 1 branch
BranchTrueFalseTotal
if $nonlazy_dyn_link 0 0 0
888  
889 0 ▶ my $db_opts = $ENV{PERLDB_OPTS} || "";
Condition0%0/2
$ENV{'PERLDB_OPTS'} || ''
l!l
00
MC/DC0%0/1
$ENV{'PERLDB_OPTS'} || ''
$ENV{'PERLDB_OPTS'}
Truth table0%0/2
A
A= $ENV{'PERLDB_OPTS'}
Aresult
11
00
890 0 ▶ if ( $self->{DebugRun} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DebugRun"}) 0 0 0
891 0 ▶ $db_opts = " $db_opts" if length $db_opts;
Branch: 1 branch
BranchTrueFalseTotal
if length $db_opts 0 0 0
892 0 $db_opts = "NonStop$db_opts";
893 }
894 0 ▶ local $ENV{PERLDB_OPTS} = $db_opts if length $db_opts;
Branch: 1 branch
BranchTrueFalseTotal
if length $db_opts 0 0 0
895  
896 0 ▶ warn <<TOHERE if $self->{DebugRun};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DebugRun"} 0 0 0
897  
898 tv: ** Running in debug mode, use interrupt (often ^C), \$DB::single=1, **
899 tv: ** or rerun with -dd if you need to enter the debugger on startup. **
900  
901 TOHERE
902  
903 0 my @result_codes;
904  
905 0 for ( @cmds ) {
906 0 my $cmd = join " ", _esc @$_;
907  
908 0 ▶ $cmd = qq{PERL_DL_NONLAZY=1 $cmd} if $nonlazy_dyn_link;
Branch: 1 branch
BranchTrueFalseTotal
if $nonlazy_dyn_link 0 0 0
909 0 ▶ $cmd = qq{PERLDB_OPTS="$db_opts" $cmd} if length $db_opts;
Branch: 1 branch
BranchTrueFalseTotal
if length $db_opts 0 0 0
910  
911 warn "tv\$ $cmd\n"
912 0 ▶ if $self->{JustPrint} || !$self->{DoubleQuiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"JustPrint"} or not $self->{"DoubleQuiet"} 0 0 0
Condition0%0/3
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"JustPrint"} or not $self->{"DoubleQuiet"}
$self->{"JustPrint"} not $self->{"DoubleQuiet"}
Truth table0%0/3
A or not(B)
A= $self->{"JustPrint"}B= not $self->{"DoubleQuiet"}
ABresult
1X1
011
000
913  
914 0 ▶ next if $self->{JustPrint};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"JustPrint"} 0 0 0
915  
916 0 require IPC::Open3;
917  
918 ## Collect both stderr and stdout in to one stream; don't
919 ## want select() and this lets the OS interleave output
920 ## better, I hope.
921 0 my $pid = IPC::Open3::open3( \*STDIN, my $out, undef, @$_ );
922 0 ▶ die "tv: $!: $cmd\n" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
923  
924 0 my @out;
925 my $saw_lone_not;
926 0 my $last_ok_line = "";
927 0 my $saw_ok;
928 0 ▶ while ( <$out> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $out)) 0 0 0
929 0 print LOG;
930 0 ▶ print unless $self->{Quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Quiet"} 0 0 0
931 0 ▶ push @out, $_ if $self->{Quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Quiet"} 0 0 0
932  
933 0 ▶ $saw_lone_not = 1, next if /^not\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^not\s*$/ 0 0 0
934  
935 0 my ( $not, $ok, $what, $number, $why ) =
936 /\A((?:not\s+)?)(ok\b)\s*(\d*)(?:#\s*(\S+))?/;
937  
938 0 ▶ next unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
939  
940 0 $saw_ok = 1;
941  
942 0 ▶ if ( $ok
Branch: 2 branches
BranchTrueFalseTotal
if ($ok and not $saw_lone_not and !$not || ($why || '') =~ /TODO/i) { } 0 0 0
elsif ($not or $saw_lone_not and $ok and $self->{'Quiet'} and not $self->{'DoubleQuiet'}) { } 0 0 0
Condition0%0/11
$ok and not $saw_lone_not and !$not || ($why || "") =~ /TODO/i
!ll&&!rl&&r
000
$ok and not $saw_lone_not
!ll&&!rl&&r
000
not $not or ($why || "") =~ /TODO/i
l!l&&r!l&&!r
000
$why || ''
l!l
00
MC/DC0%0/4
$ok and not $saw_lone_not and !$not || ($why || "") =~ /TODO/i
$ok not $saw_lone_not not $not $why
Truth table0%0/5
A and not(B) and not(C) or D
A= $okB= not $saw_lone_notC= not $notD= $why
ABCDresult
0XXX0
10XX0
11000
111X1
11011
943 && ! $saw_lone_not
944 && ( ! $not || ( $why || "" ) =~ /TODO/i )
945 ) {
946 0 @out = ();
947 }
948 ▶ elsif (
Condition0%0/12
$not or $saw_lone_not and $ok and $self->{"Quiet"} and not $self->{"DoubleQuiet"}
l!l&&r!l&&!r
000
$saw_lone_not and $ok and $self->{"Quiet"} and not $self->{"DoubleQuiet"}
!ll&&!rl&&r
000
$saw_lone_not and $ok and $self->{"Quiet"}
!ll&&!rl&&r
000
$saw_lone_not and $ok
!ll&&!rl&&r
000
MC/DC0%0/5
$not or $saw_lone_not and $ok and $self->{"Quiet"} and not $self->{"DoubleQuiet"}
$not $saw_lone_not $ok $self->{"Quiet"} not $self->{"DoubleQuiet"}
Truth table0%0/6
A or B and C and D and not(E)
A= $notB= $saw_lone_notC= $okD= $self->{"Quiet"}E= not $self->{"DoubleQuiet"}
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
949 $not || ( $saw_lone_not && $ok )
950 && $self->{Quiet}
951 && ! $self->{DoubleQuiet}
952 ) {
953 0 ▶ if ( defined $cmd && @cmds > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cmd and @cmds > 1) 0 0 0
Condition0%0/3
defined $cmd and @cmds > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cmd and @cmds > 1
defined $cmd @cmds > 1
Truth table0%0/3
A and B
A= defined $cmdB= @cmds > 1
ABresult
0X0
100
111
954 0 ▶ print $cmd, ":\n" if $self->{Quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Quiet"} 0 0 0
955 0 $cmd = undef;
956 }
957 0 ▶ print $saw_lone_not ? "not $_" : $_;
Branch: 1 branch
BranchTrueFalseTotal
$saw_lone_not ? : 0 0 0
958 }
959 0 $saw_lone_not = 0;
960 0 ▶ $last_ok_line = ( $saw_lone_not ? "not " : "" ) . $_ if $ok;
Branch: 2 branches
BranchTrueFalseTotal
if $ok 0 0 0
$saw_lone_not ? : 0 0 0
961 }
962  
963 ## Emit the next bit even in DoubleQuiet mode; it's usually
964 ## the All tests sucessful. At least when I'm driving it ;).
965 0 ▶ if ( ! $self->{TripleQuiet} && @out ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"TripleQuiet"} and @out) 0 0 0
Condition0%0/3
not $self->{"TripleQuiet"} and @out
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"TripleQuiet"} and @out
not $self->{"TripleQuiet"} @out
Truth table0%0/3
not(A) and B
A= not $self->{"TripleQuiet"}B= @out
ABresult
0X0
100
111
966 0 ▶ if ( defined $cmd && @cmds > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cmd and @cmds > 1) 0 0 0
Condition0%0/3
defined $cmd and @cmds > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cmd and @cmds > 1
defined $cmd @cmds > 1
Truth table0%0/3
A and B
A= defined $cmdB= @cmds > 1
ABresult
0X0
100
111
967 0 ▶ print $cmd, ":\n" if $self->{DoubleQuiet};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DoubleQuiet"} 0 0 0
968 0 $cmd = undef;
969 }
970 print
971 0 ▶ $saw_ok ? "tv: after last 'ok/not ok':\n" : $last_ok_line,
Branch: 1 branch
BranchTrueFalseTotal
$saw_ok ? : 0 0 0
972 @out;
973 }
974  
975 0 ▶ waitpid $pid, 0 or warn "$! waiting on PID $pid";
Branch: 1 branch
BranchTrueFalseTotal
waitpid $pid, 0 or warn "$! waiting on PID $pid" 0 0 0
976  
977 0 push @result_codes, $? >> 8;
978 }
979  
980 0 close LOG;
981  
982 0 ▶ (grep $_, @result_codes )[0] || 0;
Branch: 1 branch
BranchTrueFalseTotal
(grep $_, @result_codes)[0] or 0 0 0 0
983 }
984  
985 =back
986  
987 =head1 ASSumptions and LIMITATIONS
988  
989 =over
990  
991 =item *
992  
993 Test scripts with spaces in their filenames will screw up, since these
994 are interpolated in to a single, space delimited make(1) variable like so:
995  
996 make test TEST_VERBOSE=1 "TEST_FILES=t/spaced out name.t"
997  
998 =item *
999  
1000 Your make must be called "make". I will alter this assumption as soon
1001 as I need this on Win32 again. Feel free to submit patches.
1002  
1003 =item *
1004  
1005 Speaking of which, although this module has a nod to portability, it
1006 has not been tested on platforms other than Unix, so there be dragons
1007 there. They should be easy to fix, so please patch away.
1008  
1009 =item *
1010  
1011 The source code scanners look for /^\s*(use|require)\s+([\w:])/ (in test
1012 scripts) and /^\s*package\s+(\S+);/, and so are easily fooled.
1013  
1014 =back
1015  
1016 =cut
1017  
1018 =head1 COPYRIGHT
1019  
1020 Copyright 2002 R. Barrie Slaymaker, All Rights Reserver
1021  
1022 =head1 LICENSE
1023  
1024 You may use this module under the terms of the BSD, GNU, or Artistic
1025 licenses.
1026  
1027 =head1 AUTHOR
1028  
1029 Barrie Slaymaker <barries@slaysys.com>
1030  
1031 =cut
1032  
1033 1 1;
↑ Summary