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 'v|verbose' => \$Test::Harness::verbose,
44 'V|version' => sub { print_version(); exit; },
48 $ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
50 # Build up extensions regex
51 @ext = map { split /,/ } @ext;
53 @ext = ("t") unless @ext;
54 my $ext_regex = join( "|", map { quotemeta } @ext );
55 $ext_regex = qr/\.($ext_regex)$/;
57 # Handle blib includes
59 my @blibdirs = blibdirs();
61 unshift @includes, @blibdirs;
63 warn "No blib directories found.\n";
69 unshift @includes, "lib";
72 # Build up TH switches
73 push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
74 $Test::Harness::Switches = join( " ", @switches );
75 print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
78 @ARGV = File::Spec->curdir unless @ARGV;
79 push( @tests, -d $_ ? all_in( $_ ) : $_ ) for map { glob } @ARGV;
82 shuffle(@tests) if $shuffle;
84 print join( "\n", @tests, "" );
86 print "# ", scalar @tests, " tests to run\n" if $Test::Harness::debug;
97 if ( opendir( DH, $start ) ) {
98 while ( my $file = readdir DH ) {
99 next if $file eq File::Spec->updir || $file eq File::Spec->curdir;
100 next if $file eq ".svn";
101 next if $file eq "CVS";
103 my $currfile = File::Spec->catfile( $start, $file );
104 if ( -d $currfile ) {
105 push( @hits, all_in( $currfile ) ) if $recurse;
107 push( @hits, $currfile ) if $currfile =~ $ext_regex;
118 # Fisher-Yates shuffle
122 @_[$i, $j] = @_[$j, $i];
127 printf( "prove v%s, using Test::Harness v%s and Perl v%vd\n",
128 $VERSION, $Test::Harness::VERSION, $^V );
131 # Stolen directly from blib.pm
133 my $dir = File::Spec->curdir;
135 ($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--;
137 my $archdir = "arch";
138 if ( $^O eq "MacOS" ) {
139 # Double up the MP::A so that it's not used only once.
140 $archdir = $MacPerl::Architecture = $MacPerl::Architecture;
145 my $blib = File::Spec->catdir( $dir, "blib" );
146 my $blib_lib = File::Spec->catdir( $blib, "lib" );
147 my $blib_arch = File::Spec->catdir( $blib, $archdir );
149 if ( -d $blib && -d $blib_arch && -d $blib_lib ) {
150 return ($blib_arch,$blib_lib);
152 $dir = File::Spec->catdir($dir, File::Spec->updir);
154 warn "$0: Cannot find blib\n";
162 prove -- A command-line tool for running tests against Test::Harness
166 prove [options] [files/directories]
170 -b, --blib Adds blib/lib to the path for your tests, a la "use blib".
171 -d, --debug Includes extra debugging information.
172 -D, --dry Dry run: Show the tests to run, but don't run them.
173 --ext=x Extensions (defaults to .t)
174 -h, --help Display this help
175 -H, --man Longer manpage for prove
176 -I Add libraries to @INC, as Perl's -I
177 -l, --lib Add lib to the path for your tests.
178 -r, --recurse Recursively descend into directories.
179 -s, --shuffle Run the tests in a random order.
180 -T Enable tainting checks
181 -t Enable tainting warnings
182 -v, --verbose Display standard output of test scripts while running them.
183 -V, --version Display version info
185 Single-character options may be stacked. Default options may be set by
186 specifying the PROVE_SWITCHES environment variable.
190 F<prove> is a command-line interface to the test-running functionality
191 of C<Test::Harness>. With no arguments, it will run all tests in the
194 Shell metacharacters may be used with command lines options and will be exanded
197 =head1 PROVE VS. "MAKE TEST"
199 F<prove> has a number of advantages over C<make test> when doing development.
203 =item * F<prove> is designed as a development tool
205 Perl users typically run the test harness through a makefile via
206 C<make test>. That's fine for module distributions, but it's
207 suboptimal for a test/code/debug development cycle.
209 =item * F<prove> is granular
211 F<prove> lets your run against only the files you want to check.
212 Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
215 =item * F<prove> has an easy verbose mode
217 F<prove> has a C<-v> option to see the raw output from the tests.
218 To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
221 =item * F<prove> can run under taint mode
223 F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
226 =item * F<prove> can shuffle tests
228 You can use F<prove>'s C<--shuffle> option to try to excite problems
229 that don't show up when tests are run in the same order every time.
231 =item * F<prove> doesn't rely on a make tool
233 Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
234 to do so. F<prove> has no external dependencies.
236 =item * Not everything is a module
238 More and more users are using Perl's testing tools outside the
239 context of a module distribution, and may not even use a makefile
244 =head1 COMMAND LINE OPTIONS
248 Adds blib/lib to the path for your tests, a la "use blib".
252 Include debug information about how F<prove> is being run. This
253 option doesn't show the output from the test scripts. That's handled
258 Dry run: Show the tests to run, but don't run them.
260 =head2 --ext=extension
262 Specify extensions of the test files to run. By default, these are .t,
263 but you may have other non-.t test files, most likely .sh shell scripts.
264 The --ext is repeatable.
268 Add libraries to @INC, as Perl's -I.
272 Add C<lib> to @INC. Equivalent to C<-Ilib>.
276 Descends into subdirectories of any directories specified, looking for tests.
280 Sometimes tests are accidentally dependent on tests that have been
281 run before. This switch will shuffle the tests to be run prior to
282 running them, thus ensuring that hidden dependencies in the test
283 order are likely to be revealed. The author hopes the run the
284 algorithm on the preceding sentence to see if he can produce something
285 slightly less awkward.
289 Runs test programs under perl's -t taint warning mode.
293 Runs test programs under perl's -T taint mode.
297 Display standard output of test scripts while running them. Also sets
298 TEST_VERBOSE in case your tests rely on them.
302 Display version info.
306 Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
307 You can also mail bugs, fixes and enhancements to
308 C<< <bug-test-harness@rt.cpan.org> >>.
316 Shuffled tests must be recreatable
322 Andy Lester C<< <andy@petdance.com> >>
326 Copyright 2003 by Andy Lester C<< <andy@petdance.com> >>.
328 This program is free software; you can redistribute it and/or
329 modify it under the same terms as Perl itself.
331 See L<http://www.perl.com/perl/misc/Artistic.html>.