Make the executable slightly smaller by using PL_hexdigit in
[p5sagit/p5-mst-13.2.git] / lib / Test / Harness / bin / prove
CommitLineData
e4fc8a1e 1#!/usr/bin/perl -w
2
3use strict;
4
5use Test::Harness;
20f9f807 6use Test::Harness::Util qw( all_in blibdirs shuffle );
7
e4fc8a1e 8use Getopt::Long;
9use Pod::Usage 1.12;
10use File::Spec;
11
12use vars qw( $VERSION );
13$VERSION = "1.04";
14
e4fc8a1e 15my $shuffle = 0;
16my $dry = 0;
17my $blib = 0;
60e33a80 18my $lib = 0;
e4fc8a1e 19my $recurse = 0;
20my @includes = ();
21my @switches = ();
22
23# Allow cuddling the paths with the -I
24@ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
25
26# Stick any default switches at the beginning, so they can be overridden
27# by the command line switches.
28unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
29
30Getopt::Long::Configure( "no_ignore_case" );
31Getopt::Long::Configure( "bundling" );
32GetOptions(
33 'b|blib' => \$blib,
42d29bac 34 'd|debug' => \$Test::Harness::debug,
e4fc8a1e 35 'D|dry' => \$dry,
73ea3450 36 'h|help|?' => sub {pod2usage({-verbose => 1}); exit},
37 'H|man' => sub {pod2usage({-verbose => 2}); exit},
e4fc8a1e 38 'I=s@' => \@includes,
42d29bac 39 'l|lib' => \$lib,
20f9f807 40 'perl' => \$ENV{HARNESS_PERL},
e4fc8a1e 41 'r|recurse' => \$recurse,
42 's|shuffle' => \$shuffle,
42d29bac 43 't' => sub { unshift @switches, "-t" }, # Always want -t up front
44 'T' => sub { unshift @switches, "-T" }, # Always want -T up front
20f9f807 45 'w' => sub { push @switches, '-w' },
46 'W' => sub { push @switches, '-W' },
43ef773b 47 'timer' => \$Test::Harness::Timer,
e4fc8a1e 48 'v|verbose' => \$Test::Harness::verbose,
49 'V|version' => sub { print_version(); exit; },
e4fc8a1e 50) or exit 1;
51
42d29bac 52$ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
53
e4fc8a1e 54# Handle blib includes
55if ( $blib ) {
56 my @blibdirs = blibdirs();
57 if ( @blibdirs ) {
42d29bac 58 unshift @includes, @blibdirs;
20f9f807 59 }
60 else {
42d29bac 61 warn "No blib directories found.\n";
e4fc8a1e 62 }
63}
64
60e33a80 65# Handle lib includes
66if ( $lib ) {
67 unshift @includes, "lib";
68}
69
e4fc8a1e 70# Build up TH switches
71push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
72$Test::Harness::Switches = join( " ", @switches );
73print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
74
e4fc8a1e 75@ARGV = File::Spec->curdir unless @ARGV;
20f9f807 76my @argv_globbed;
77my @tests;
ea5423ed 78if ( $] >= 5.006001 ) {
20f9f807 79 require File::Glob;
80 @argv_globbed = map { File::Glob::bsd_glob($_) } @ARGV;
81}
82else {
83 @argv_globbed = map { glob } @ARGV;
84}
85
86for ( @argv_globbed ) {
87 push( @tests, -d $_ ? all_in( { recurse => $recurse, start => $_ } ) : $_ )
88}
e4fc8a1e 89
90if ( @tests ) {
91 shuffle(@tests) if $shuffle;
92 if ( $dry ) {
93 print join( "\n", @tests, "" );
20f9f807 94 }
95 else {
42d29bac 96 print "# ", scalar @tests, " tests to run\n" if $Test::Harness::debug;
e4fc8a1e 97 runtests(@tests);
98 }
99}
100
e4fc8a1e 101sub print_version {
102 printf( "prove v%s, using Test::Harness v%s and Perl v%vd\n",
42d29bac 103 $VERSION, $Test::Harness::VERSION, $^V );
e4fc8a1e 104}
105
e4fc8a1e 106__END__
107
108=head1 NAME
109
110prove -- A command-line tool for running tests against Test::Harness
111
112=head1 SYNOPSIS
113
114prove [options] [files/directories]
115
20f9f807 116=head1 OPTIONS
e4fc8a1e 117
20f9f807 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
e4fc8a1e 121 -h, --help Display this help
122 -H, --man Longer manpage for prove
123 -I Add libraries to @INC, as Perl's -I
20f9f807 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
42d29bac 128 -T Enable tainting checks
129 -t Enable tainting warnings
43ef773b 130 --timer Print elapsed time after each test file
20f9f807 131 -v, --verbose Display standard output of test scripts while running them
e4fc8a1e 132 -V, --version Display version info
133
134Single-character options may be stacked. Default options may be set by
135specifying the PROVE_SWITCHES environment variable.
136
137=head1 OVERVIEW
138
139F<prove> is a command-line interface to the test-running functionality
140of C<Test::Harness>. With no arguments, it will run all tests in the
141current directory.
142
143Shell metacharacters may be used with command lines options and will be exanded
20f9f807 144via C<File::Glob::bsd_glob>.
e4fc8a1e 145
146=head1 PROVE VS. "MAKE TEST"
147
148F<prove> has a number of advantages over C<make test> when doing development.
149
150=over 4
151
152=item * F<prove> is designed as a development tool
153
154Perl users typically run the test harness through a makefile via
155C<make test>. That's fine for module distributions, but it's
156suboptimal for a test/code/debug development cycle.
157
158=item * F<prove> is granular
159
160F<prove> lets your run against only the files you want to check.
161Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
162plus F<t/master.t>.
163
164=item * F<prove> has an easy verbose mode
165
166F<prove> has a C<-v> option to see the raw output from the tests.
167To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
168the environment.
169
170=item * F<prove> can run under taint mode
171
172F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
173under C<perl -t>.
174
175=item * F<prove> can shuffle tests
176
177You can use F<prove>'s C<--shuffle> option to try to excite problems
178that don't show up when tests are run in the same order every time.
179
180=item * F<prove> doesn't rely on a make tool
181
182Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
183to do so. F<prove> has no external dependencies.
184
185=item * Not everything is a module
186
187More and more users are using Perl's testing tools outside the
188context of a module distribution, and may not even use a makefile
189at all.
190
191=back
192
193=head1 COMMAND LINE OPTIONS
194
195=head2 -b, --blib
196
197Adds blib/lib to the path for your tests, a la "use blib".
198
199=head2 -d, --debug
200
201Include debug information about how F<prove> is being run. This
202option doesn't show the output from the test scripts. That's handled
203by -v,--verbose.
204
205=head2 -D, --dry
206
207Dry run: Show the tests to run, but don't run them.
208
e4fc8a1e 209=head2 -I
210
60e33a80 211Add libraries to @INC, as Perl's -I.
212
213=head2 -l, --lib
214
215Add C<lib> to @INC. Equivalent to C<-Ilib>.
e4fc8a1e 216
20f9f807 217=head2 --perl
218
219Sets the C<HARNESS_PERL> environment variable, which controls what
220Perl executable will run the tests.
221
e4fc8a1e 222=head2 -r, --recurse
223
224Descends into subdirectories of any directories specified, looking for tests.
225
226=head2 -s, --shuffle
227
228Sometimes tests are accidentally dependent on tests that have been
229run before. This switch will shuffle the tests to be run prior to
230running them, thus ensuring that hidden dependencies in the test
231order are likely to be revealed. The author hopes the run the
232algorithm on the preceding sentence to see if he can produce something
233slightly less awkward.
234
235=head2 -t
236
237Runs test programs under perl's -t taint warning mode.
238
239=head2 -T
240
241Runs test programs under perl's -T taint mode.
242
43ef773b 243=head2 --timer
244
245Print elapsed time after each test file
246
e4fc8a1e 247=head2 -v, --verbose
248
42d29bac 249Display standard output of test scripts while running them. Also sets
250TEST_VERBOSE in case your tests rely on them.
e4fc8a1e 251
252=head2 -V, --version
253
254Display version info.
255
256=head1 BUGS
257
258Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
259You can also mail bugs, fixes and enhancements to
260C<< <bug-test-harness@rt.cpan.org> >>.
261
262=head1 TODO
263
264=over 4
265
266=item *
267
268Shuffled tests must be recreatable
269
e4fc8a1e 270=back
271
272=head1 AUTHORS
273
20f9f807 274Andy Lester C<< <andy at petdance.com> >>
e4fc8a1e 275
276=head1 COPYRIGHT
277
20f9f807 278Copyright 2005 by Andy Lester C<< <andy at petdance.com> >>.
e4fc8a1e 279
280This program is free software; you can redistribute it and/or
281modify it under the same terms as Perl itself.
282
283See L<http://www.perl.com/perl/misc/Artistic.html>.
284
285=cut