6 use Test::Harness::Util qw( all_in blibdirs shuffle );
12 use vars qw( $VERSION );
23 # Allow cuddling the paths with the -I
24 @ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
26 # Stick any default switches at the beginning, so they can be overridden
27 # by the command line switches.
28 unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
30 Getopt::Long::Configure( "no_ignore_case" );
31 Getopt::Long::Configure( "bundling" );
34 'd|debug' => \$Test::Harness::debug,
36 'h|help|?' => sub {pod2usage({-verbose => 1}); exit},
37 'H|man' => sub {pod2usage({-verbose => 2}); exit},
40 'perl' => \$ENV{HARNESS_PERL},
41 'r|recurse' => \$recurse,
42 's|shuffle' => \$shuffle,
43 't' => sub { unshift @switches, "-t" }, # Always want -t up front
44 'T' => sub { unshift @switches, "-T" }, # Always want -T up front
45 'w' => sub { push @switches, '-w' },
46 'W' => sub { push @switches, '-W' },
47 'timer' => \$Test::Harness::Timer,
48 'v|verbose' => \$Test::Harness::verbose,
49 'V|version' => sub { print_version(); exit; },
52 $ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
54 # Handle blib includes
56 my @blibdirs = blibdirs();
58 unshift @includes, @blibdirs;
61 warn "No blib directories found.\n";
67 unshift @includes, "lib";
70 # Build up TH switches
71 push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
72 $Test::Harness::Switches = join( " ", @switches );
73 print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
75 @ARGV = File::Spec->curdir unless @ARGV;
78 if ( $] >= 5.006001 ) {
80 @argv_globbed = map { File::Glob::bsd_glob($_) } @ARGV;
83 @argv_globbed = map { glob } @ARGV;
86 for ( @argv_globbed ) {
87 push( @tests, -d $_ ? all_in( { recurse => $recurse, start => $_ } ) : $_ )
91 shuffle(@tests) if $shuffle;
93 print join( "\n", @tests, "" );
96 print "# ", scalar @tests, " tests to run\n" if $Test::Harness::debug;
102 printf( "prove v%s, using Test::Harness v%s and Perl v%vd\n",
103 $VERSION, $Test::Harness::VERSION, $^V );
110 prove -- A command-line tool for running tests against Test::Harness
114 prove [options] [files/directories]
118 -b, --blib Adds blib/lib to the path for your tests, a la "use blib"
119 -d, --debug Includes extra debugging information
120 -D, --dry Dry run: Show the tests to run, but don't run them
121 -h, --help Display this help
122 -H, --man Longer manpage for prove
123 -I Add libraries to @INC, as Perl's -I
124 -l, --lib Add lib to the path for your tests
125 --perl Sets the name of the Perl executable to use
126 -r, --recurse Recursively descend into directories
127 -s, --shuffle Run the tests in a random order
128 -T Enable tainting checks
129 -t Enable tainting warnings
130 --timer Print elapsed time after each test file
131 -v, --verbose Display standard output of test scripts while running them
132 -V, --version Display version info
134 Single-character options may be stacked. Default options may be set by
135 specifying the PROVE_SWITCHES environment variable.
139 F<prove> is a command-line interface to the test-running functionality
140 of C<Test::Harness>. With no arguments, it will run all tests in the
143 Shell metacharacters may be used with command lines options and will be exanded
144 via C<File::Glob::bsd_glob>.
146 =head1 PROVE VS. "MAKE TEST"
148 F<prove> has a number of advantages over C<make test> when doing development.
152 =item * F<prove> is designed as a development tool
154 Perl users typically run the test harness through a makefile via
155 C<make test>. That's fine for module distributions, but it's
156 suboptimal for a test/code/debug development cycle.
158 =item * F<prove> is granular
160 F<prove> lets your run against only the files you want to check.
161 Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
164 =item * F<prove> has an easy verbose mode
166 F<prove> has a C<-v> option to see the raw output from the tests.
167 To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
170 =item * F<prove> can run under taint mode
172 F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
175 =item * F<prove> can shuffle tests
177 You can use F<prove>'s C<--shuffle> option to try to excite problems
178 that don't show up when tests are run in the same order every time.
180 =item * F<prove> doesn't rely on a make tool
182 Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
183 to do so. F<prove> has no external dependencies.
185 =item * Not everything is a module
187 More and more users are using Perl's testing tools outside the
188 context of a module distribution, and may not even use a makefile
193 =head1 COMMAND LINE OPTIONS
197 Adds blib/lib to the path for your tests, a la "use blib".
201 Include debug information about how F<prove> is being run. This
202 option doesn't show the output from the test scripts. That's handled
207 Dry run: Show the tests to run, but don't run them.
211 Add libraries to @INC, as Perl's -I.
215 Add C<lib> to @INC. Equivalent to C<-Ilib>.
219 Sets the C<HARNESS_PERL> environment variable, which controls what
220 Perl executable will run the tests.
224 Descends into subdirectories of any directories specified, looking for tests.
228 Sometimes tests are accidentally dependent on tests that have been
229 run before. This switch will shuffle the tests to be run prior to
230 running them, thus ensuring that hidden dependencies in the test
231 order are likely to be revealed. The author hopes the run the
232 algorithm on the preceding sentence to see if he can produce something
233 slightly less awkward.
237 Runs test programs under perl's -t taint warning mode.
241 Runs test programs under perl's -T taint mode.
245 Print elapsed time after each test file
249 Display standard output of test scripts while running them. Also sets
250 TEST_VERBOSE in case your tests rely on them.
254 Display version info.
258 Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
259 You can also mail bugs, fixes and enhancements to
260 C<< <bug-test-harness@rt.cpan.org> >>.
268 Shuffled tests must be recreatable
274 Andy Lester C<< <andy at petdance.com> >>
278 Copyright 2005 by Andy Lester C<< <andy at petdance.com> >>.
280 This program is free software; you can redistribute it and/or
281 modify it under the same terms as Perl itself.
283 See L<http://www.perl.com/perl/misc/Artistic.html>.