10 use vars qw( $VERSION );
22 # Allow cuddling the paths with the -I
23 @ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
25 # Stick any default switches at the beginning, so they can be overridden
26 # by the command line switches.
27 unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
29 Getopt::Long::Configure( "no_ignore_case" );
30 Getopt::Long::Configure( "bundling" );
33 'd|debug' => \$Test::Harness::debug,
35 'h|help|?' => sub {pod2usage({-verbose => 1, -input => \*DATA}); exit},
36 'H|man' => sub {pod2usage({-verbose => 2, -input => \*DATA}); exit},
39 'r|recurse' => \$recurse,
40 's|shuffle' => \$shuffle,
41 't' => sub { unshift @switches, "-t" }, # Always want -t up front
42 'T' => sub { unshift @switches, "-T" }, # Always want -T up front
43 'timer' => \$Test::Harness::Timer,
44 'v|verbose' => \$Test::Harness::verbose,
45 'V|version' => sub { print_version(); exit; },
49 $ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
51 # Build up extensions regex
52 @ext = map { split /,/ } @ext;
54 @ext = ("t") unless @ext;
55 my $ext_regex = join( "|", map { quotemeta } @ext );
56 $ext_regex = qr/\.($ext_regex)$/;
58 # Handle blib includes
60 my @blibdirs = blibdirs();
62 unshift @includes, @blibdirs;
64 warn "No blib directories found.\n";
70 unshift @includes, "lib";
73 # Build up TH switches
74 push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
75 $Test::Harness::Switches = join( " ", @switches );
76 print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
79 @ARGV = File::Spec->curdir unless @ARGV;
80 push( @tests, -d $_ ? all_in( $_ ) : $_ ) for map { glob } @ARGV;
83 shuffle(@tests) if $shuffle;
85 print join( "\n", @tests, "" );
87 print "# ", scalar @tests, " tests to run\n" if $Test::Harness::debug;
98 if ( opendir( DH, $start ) ) {
99 while ( my $file = readdir DH ) {
100 next if $file eq File::Spec->updir || $file eq File::Spec->curdir;
101 next if $file eq ".svn";
102 next if $file eq "CVS";
104 my $currfile = File::Spec->catfile( $start, $file );
105 if ( -d $currfile ) {
106 push( @hits, all_in( $currfile ) ) if $recurse;
108 push( @hits, $currfile ) if $currfile =~ $ext_regex;
119 # Fisher-Yates shuffle
123 @_[$i, $j] = @_[$j, $i];
128 printf( "prove v%s, using Test::Harness v%s and Perl v%vd\n",
129 $VERSION, $Test::Harness::VERSION, $^V );
132 # Stolen directly from blib.pm
134 my $dir = File::Spec->curdir;
136 ($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--;
138 my $archdir = "arch";
139 if ( $^O eq "MacOS" ) {
140 # Double up the MP::A so that it's not used only once.
141 $archdir = $MacPerl::Architecture = $MacPerl::Architecture;
146 my $blib = File::Spec->catdir( $dir, "blib" );
147 my $blib_lib = File::Spec->catdir( $blib, "lib" );
148 my $blib_arch = File::Spec->catdir( $blib, $archdir );
150 if ( -d $blib && -d $blib_arch && -d $blib_lib ) {
151 return ($blib_arch,$blib_lib);
153 $dir = File::Spec->catdir($dir, File::Spec->updir);
155 warn "$0: Cannot find blib\n";
163 prove -- A command-line tool for running tests against Test::Harness
167 prove [options] [files/directories]
171 -b, --blib Adds blib/lib to the path for your tests, a la "use blib".
172 -d, --debug Includes extra debugging information.
173 -D, --dry Dry run: Show the tests to run, but don't run them.
174 --ext=x Extensions (defaults to .t)
175 -h, --help Display this help
176 -H, --man Longer manpage for prove
177 -I Add libraries to @INC, as Perl's -I
178 -l, --lib Add lib to the path for your tests.
179 -r, --recurse Recursively descend into directories.
180 -s, --shuffle Run the tests in a random order.
181 -T Enable tainting checks
182 -t Enable tainting warnings
183 --timer Print elapsed time after each test file
184 -v, --verbose Display standard output of test scripts while running them.
185 -V, --version Display version info
187 Single-character options may be stacked. Default options may be set by
188 specifying the PROVE_SWITCHES environment variable.
192 F<prove> is a command-line interface to the test-running functionality
193 of C<Test::Harness>. With no arguments, it will run all tests in the
196 Shell metacharacters may be used with command lines options and will be exanded
199 =head1 PROVE VS. "MAKE TEST"
201 F<prove> has a number of advantages over C<make test> when doing development.
205 =item * F<prove> is designed as a development tool
207 Perl users typically run the test harness through a makefile via
208 C<make test>. That's fine for module distributions, but it's
209 suboptimal for a test/code/debug development cycle.
211 =item * F<prove> is granular
213 F<prove> lets your run against only the files you want to check.
214 Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
217 =item * F<prove> has an easy verbose mode
219 F<prove> has a C<-v> option to see the raw output from the tests.
220 To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
223 =item * F<prove> can run under taint mode
225 F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
228 =item * F<prove> can shuffle tests
230 You can use F<prove>'s C<--shuffle> option to try to excite problems
231 that don't show up when tests are run in the same order every time.
233 =item * F<prove> doesn't rely on a make tool
235 Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
236 to do so. F<prove> has no external dependencies.
238 =item * Not everything is a module
240 More and more users are using Perl's testing tools outside the
241 context of a module distribution, and may not even use a makefile
246 =head1 COMMAND LINE OPTIONS
250 Adds blib/lib to the path for your tests, a la "use blib".
254 Include debug information about how F<prove> is being run. This
255 option doesn't show the output from the test scripts. That's handled
260 Dry run: Show the tests to run, but don't run them.
262 =head2 --ext=extension
264 Specify extensions of the test files to run. By default, these are .t,
265 but you may have other non-.t test files, most likely .sh shell scripts.
266 The --ext is repeatable.
270 Add libraries to @INC, as Perl's -I.
274 Add C<lib> to @INC. Equivalent to C<-Ilib>.
278 Descends into subdirectories of any directories specified, looking for tests.
282 Sometimes tests are accidentally dependent on tests that have been
283 run before. This switch will shuffle the tests to be run prior to
284 running them, thus ensuring that hidden dependencies in the test
285 order are likely to be revealed. The author hopes the run the
286 algorithm on the preceding sentence to see if he can produce something
287 slightly less awkward.
291 Runs test programs under perl's -t taint warning mode.
295 Runs test programs under perl's -T taint mode.
299 Print elapsed time after each test file
303 Display standard output of test scripts while running them. Also sets
304 TEST_VERBOSE in case your tests rely on them.
308 Display version info.
312 Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
313 You can also mail bugs, fixes and enhancements to
314 C<< <bug-test-harness@rt.cpan.org> >>.
322 Shuffled tests must be recreatable
328 Andy Lester C<< <andy@petdance.com> >>
332 Copyright 2005 by Andy Lester C<< <andy@petdance.com> >>.
334 This program is free software; you can redistribute it and/or
335 modify it under the same terms as Perl itself.
337 See L<http://www.perl.com/perl/misc/Artistic.html>.