1 | @rem = '--*-Perl-*--
|
---|
2 | @echo off
|
---|
3 | if "%OS%" == "Windows_NT" goto WinNT
|
---|
4 | perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
---|
5 | goto endofperl
|
---|
6 | :WinNT
|
---|
7 | perl -x -S %0 %*
|
---|
8 | if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
|
---|
9 | if %errorlevel% == 9009 echo You do not have Perl in your PATH.
|
---|
10 | if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
|
---|
11 | goto endofperl
|
---|
12 | @rem ';
|
---|
13 | #!perl
|
---|
14 | #line 15
|
---|
15 | eval 'exec c:\shaoqunWu\perl\bin\perl.exe -S $0 ${1+"$@"}'
|
---|
16 | if $running_under_some_shell;
|
---|
17 | #!/usr/bin/perl -w
|
---|
18 |
|
---|
19 | use strict;
|
---|
20 |
|
---|
21 | use Test::Harness;
|
---|
22 | use Getopt::Long;
|
---|
23 | use Pod::Usage 1.12;
|
---|
24 | use File::Spec;
|
---|
25 |
|
---|
26 | use vars qw( $VERSION );
|
---|
27 | $VERSION = "1.04";
|
---|
28 |
|
---|
29 | my @ext = ();
|
---|
30 | my $shuffle = 0;
|
---|
31 | my $dry = 0;
|
---|
32 | my $blib = 0;
|
---|
33 | my $lib = 0;
|
---|
34 | my $recurse = 0;
|
---|
35 | my @includes = ();
|
---|
36 | my @switches = ();
|
---|
37 |
|
---|
38 | # Allow cuddling the paths with the -I
|
---|
39 | @ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
|
---|
40 |
|
---|
41 | # Stick any default switches at the beginning, so they can be overridden
|
---|
42 | # by the command line switches.
|
---|
43 | unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
|
---|
44 |
|
---|
45 | Getopt::Long::Configure( "no_ignore_case" );
|
---|
46 | Getopt::Long::Configure( "bundling" );
|
---|
47 | GetOptions(
|
---|
48 | 'b|blib' => \$blib,
|
---|
49 | 'd|debug' => \$Test::Harness::debug,
|
---|
50 | 'D|dry' => \$dry,
|
---|
51 | 'h|help|?' => sub {pod2usage({-verbose => 1}); exit},
|
---|
52 | 'H|man' => sub {pod2usage({-verbose => 2}); exit},
|
---|
53 | 'I=s@' => \@includes,
|
---|
54 | 'l|lib' => \$lib,
|
---|
55 | 'r|recurse' => \$recurse,
|
---|
56 | 's|shuffle' => \$shuffle,
|
---|
57 | 't' => sub { unshift @switches, "-t" }, # Always want -t up front
|
---|
58 | 'T' => sub { unshift @switches, "-T" }, # Always want -T up front
|
---|
59 | 'timer' => \$Test::Harness::Timer,
|
---|
60 | 'v|verbose' => \$Test::Harness::verbose,
|
---|
61 | 'V|version' => sub { print_version(); exit; },
|
---|
62 | 'ext=s@' => \@ext,
|
---|
63 | ) or exit 1;
|
---|
64 |
|
---|
65 | $ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
|
---|
66 |
|
---|
67 | # Build up extensions regex
|
---|
68 | @ext = map { split /,/ } @ext;
|
---|
69 | s/^\.// foreach @ext;
|
---|
70 | @ext = ("t") unless @ext;
|
---|
71 | my $ext_regex = join( "|", map { quotemeta } @ext );
|
---|
72 | $ext_regex = qr/\.($ext_regex)$/;
|
---|
73 |
|
---|
74 | # Handle blib includes
|
---|
75 | if ( $blib ) {
|
---|
76 | my @blibdirs = blibdirs();
|
---|
77 | if ( @blibdirs ) {
|
---|
78 | unshift @includes, @blibdirs;
|
---|
79 | } else {
|
---|
80 | warn "No blib directories found.\n";
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | # Handle lib includes
|
---|
85 | if ( $lib ) {
|
---|
86 | unshift @includes, "lib";
|
---|
87 | }
|
---|
88 |
|
---|
89 | # Build up TH switches
|
---|
90 | push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
|
---|
91 | $Test::Harness::Switches = join( " ", @switches );
|
---|
92 | print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
|
---|
93 |
|
---|
94 | my @tests;
|
---|
95 | @ARGV = File::Spec->curdir unless @ARGV;
|
---|
96 | push( @tests, -d $_ ? all_in( $_ ) : $_ ) for map { glob } @ARGV;
|
---|
97 |
|
---|
98 | if ( @tests ) {
|
---|
99 | shuffle(@tests) if $shuffle;
|
---|
100 | if ( $dry ) {
|
---|
101 | print join( "\n", @tests, "" );
|
---|
102 | } else {
|
---|
103 | print "# ", scalar @tests, " tests to run\n" if $Test::Harness::debug;
|
---|
104 | runtests(@tests);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | sub all_in {
|
---|
109 | my $start = shift;
|
---|
110 |
|
---|
111 | my @hits = ();
|
---|
112 |
|
---|
113 | local *DH;
|
---|
114 | if ( opendir( DH, $start ) ) {
|
---|
115 | my @files = sort readdir DH;
|
---|
116 | closedir DH;
|
---|
117 | for my $file ( @files ) {
|
---|
118 | next if $file eq File::Spec->updir || $file eq File::Spec->curdir;
|
---|
119 | next if $file eq ".svn";
|
---|
120 | next if $file eq "CVS";
|
---|
121 |
|
---|
122 | my $currfile = File::Spec->catfile( $start, $file );
|
---|
123 | if ( -d $currfile ) {
|
---|
124 | push( @hits, all_in( $currfile ) ) if $recurse;
|
---|
125 | } else {
|
---|
126 | push( @hits, $currfile ) if $currfile =~ $ext_regex;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | } else {
|
---|
130 | warn "$start: $!\n";
|
---|
131 | }
|
---|
132 |
|
---|
133 | return @hits;
|
---|
134 | }
|
---|
135 |
|
---|
136 | sub shuffle {
|
---|
137 | # Fisher-Yates shuffle
|
---|
138 | my $i = @_;
|
---|
139 | while ($i) {
|
---|
140 | my $j = rand $i--;
|
---|
141 | @_[$i, $j] = @_[$j, $i];
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | sub print_version {
|
---|
146 | printf( "prove v%s, using Test::Harness v%s and Perl v%vd\n",
|
---|
147 | $VERSION, $Test::Harness::VERSION, $^V );
|
---|
148 | }
|
---|
149 |
|
---|
150 | # Stolen directly from blib.pm
|
---|
151 | sub blibdirs {
|
---|
152 | my $dir = File::Spec->curdir;
|
---|
153 | if ($^O eq 'VMS') {
|
---|
154 | ($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--;
|
---|
155 | }
|
---|
156 | my $archdir = "arch";
|
---|
157 | if ( $^O eq "MacOS" ) {
|
---|
158 | # Double up the MP::A so that it's not used only once.
|
---|
159 | $archdir = $MacPerl::Architecture = $MacPerl::Architecture;
|
---|
160 | }
|
---|
161 |
|
---|
162 | my $i = 5;
|
---|
163 | while ($i--) {
|
---|
164 | my $blib = File::Spec->catdir( $dir, "blib" );
|
---|
165 | my $blib_lib = File::Spec->catdir( $blib, "lib" );
|
---|
166 | my $blib_arch = File::Spec->catdir( $blib, $archdir );
|
---|
167 |
|
---|
168 | if ( -d $blib && -d $blib_arch && -d $blib_lib ) {
|
---|
169 | return ($blib_arch,$blib_lib);
|
---|
170 | }
|
---|
171 | $dir = File::Spec->catdir($dir, File::Spec->updir);
|
---|
172 | }
|
---|
173 | warn "$0: Cannot find blib\n";
|
---|
174 | return;
|
---|
175 | }
|
---|
176 |
|
---|
177 | __END__
|
---|
178 |
|
---|
179 | =head1 NAME
|
---|
180 |
|
---|
181 | prove -- A command-line tool for running tests against Test::Harness
|
---|
182 |
|
---|
183 | =head1 SYNOPSIS
|
---|
184 |
|
---|
185 | prove [options] [files/directories]
|
---|
186 |
|
---|
187 | Options:
|
---|
188 |
|
---|
189 | -b, --blib Adds blib/lib to the path for your tests, a la "use blib".
|
---|
190 | -d, --debug Includes extra debugging information.
|
---|
191 | -D, --dry Dry run: Show the tests to run, but don't run them.
|
---|
192 | --ext=x Extensions (defaults to .t)
|
---|
193 | -h, --help Display this help
|
---|
194 | -H, --man Longer manpage for prove
|
---|
195 | -I Add libraries to @INC, as Perl's -I
|
---|
196 | -l, --lib Add lib to the path for your tests.
|
---|
197 | -r, --recurse Recursively descend into directories.
|
---|
198 | -s, --shuffle Run the tests in a random order.
|
---|
199 | -T Enable tainting checks
|
---|
200 | -t Enable tainting warnings
|
---|
201 | --timer Print elapsed time after each test file
|
---|
202 | -v, --verbose Display standard output of test scripts while running them.
|
---|
203 | -V, --version Display version info
|
---|
204 |
|
---|
205 | Single-character options may be stacked. Default options may be set by
|
---|
206 | specifying the PROVE_SWITCHES environment variable.
|
---|
207 |
|
---|
208 | =head1 OVERVIEW
|
---|
209 |
|
---|
210 | F<prove> is a command-line interface to the test-running functionality
|
---|
211 | of C<Test::Harness>. With no arguments, it will run all tests in the
|
---|
212 | current directory.
|
---|
213 |
|
---|
214 | Shell metacharacters may be used with command lines options and will be exanded
|
---|
215 | via C<glob>.
|
---|
216 |
|
---|
217 | =head1 PROVE VS. "MAKE TEST"
|
---|
218 |
|
---|
219 | F<prove> has a number of advantages over C<make test> when doing development.
|
---|
220 |
|
---|
221 | =over 4
|
---|
222 |
|
---|
223 | =item * F<prove> is designed as a development tool
|
---|
224 |
|
---|
225 | Perl users typically run the test harness through a makefile via
|
---|
226 | C<make test>. That's fine for module distributions, but it's
|
---|
227 | suboptimal for a test/code/debug development cycle.
|
---|
228 |
|
---|
229 | =item * F<prove> is granular
|
---|
230 |
|
---|
231 | F<prove> lets your run against only the files you want to check.
|
---|
232 | Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
|
---|
233 | plus F<t/master.t>.
|
---|
234 |
|
---|
235 | =item * F<prove> has an easy verbose mode
|
---|
236 |
|
---|
237 | F<prove> has a C<-v> option to see the raw output from the tests.
|
---|
238 | To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
|
---|
239 | the environment.
|
---|
240 |
|
---|
241 | =item * F<prove> can run under taint mode
|
---|
242 |
|
---|
243 | F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
|
---|
244 | under C<perl -t>.
|
---|
245 |
|
---|
246 | =item * F<prove> can shuffle tests
|
---|
247 |
|
---|
248 | You can use F<prove>'s C<--shuffle> option to try to excite problems
|
---|
249 | that don't show up when tests are run in the same order every time.
|
---|
250 |
|
---|
251 | =item * F<prove> doesn't rely on a make tool
|
---|
252 |
|
---|
253 | Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
|
---|
254 | to do so. F<prove> has no external dependencies.
|
---|
255 |
|
---|
256 | =item * Not everything is a module
|
---|
257 |
|
---|
258 | More and more users are using Perl's testing tools outside the
|
---|
259 | context of a module distribution, and may not even use a makefile
|
---|
260 | at all.
|
---|
261 |
|
---|
262 | =back
|
---|
263 |
|
---|
264 | =head1 COMMAND LINE OPTIONS
|
---|
265 |
|
---|
266 | =head2 -b, --blib
|
---|
267 |
|
---|
268 | Adds blib/lib to the path for your tests, a la "use blib".
|
---|
269 |
|
---|
270 | =head2 -d, --debug
|
---|
271 |
|
---|
272 | Include debug information about how F<prove> is being run. This
|
---|
273 | option doesn't show the output from the test scripts. That's handled
|
---|
274 | by -v,--verbose.
|
---|
275 |
|
---|
276 | =head2 -D, --dry
|
---|
277 |
|
---|
278 | Dry run: Show the tests to run, but don't run them.
|
---|
279 |
|
---|
280 | =head2 --ext=extension
|
---|
281 |
|
---|
282 | Specify extensions of the test files to run. By default, these are .t,
|
---|
283 | but you may have other non-.t test files, most likely .sh shell scripts.
|
---|
284 | The --ext is repeatable.
|
---|
285 |
|
---|
286 | =head2 -I
|
---|
287 |
|
---|
288 | Add libraries to @INC, as Perl's -I.
|
---|
289 |
|
---|
290 | =head2 -l, --lib
|
---|
291 |
|
---|
292 | Add C<lib> to @INC. Equivalent to C<-Ilib>.
|
---|
293 |
|
---|
294 | =head2 -r, --recurse
|
---|
295 |
|
---|
296 | Descends into subdirectories of any directories specified, looking for tests.
|
---|
297 |
|
---|
298 | =head2 -s, --shuffle
|
---|
299 |
|
---|
300 | Sometimes tests are accidentally dependent on tests that have been
|
---|
301 | run before. This switch will shuffle the tests to be run prior to
|
---|
302 | running them, thus ensuring that hidden dependencies in the test
|
---|
303 | order are likely to be revealed. The author hopes the run the
|
---|
304 | algorithm on the preceding sentence to see if he can produce something
|
---|
305 | slightly less awkward.
|
---|
306 |
|
---|
307 | =head2 -t
|
---|
308 |
|
---|
309 | Runs test programs under perl's -t taint warning mode.
|
---|
310 |
|
---|
311 | =head2 -T
|
---|
312 |
|
---|
313 | Runs test programs under perl's -T taint mode.
|
---|
314 |
|
---|
315 | =head2 --timer
|
---|
316 |
|
---|
317 | Print elapsed time after each test file
|
---|
318 |
|
---|
319 | =head2 -v, --verbose
|
---|
320 |
|
---|
321 | Display standard output of test scripts while running them. Also sets
|
---|
322 | TEST_VERBOSE in case your tests rely on them.
|
---|
323 |
|
---|
324 | =head2 -V, --version
|
---|
325 |
|
---|
326 | Display version info.
|
---|
327 |
|
---|
328 | =head1 BUGS
|
---|
329 |
|
---|
330 | Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
|
---|
331 | You can also mail bugs, fixes and enhancements to
|
---|
332 | C<< <[email protected]> >>.
|
---|
333 |
|
---|
334 | =head1 TODO
|
---|
335 |
|
---|
336 | =over 4
|
---|
337 |
|
---|
338 | =item *
|
---|
339 |
|
---|
340 | Shuffled tests must be recreatable
|
---|
341 |
|
---|
342 | =back
|
---|
343 |
|
---|
344 | =head1 AUTHORS
|
---|
345 |
|
---|
346 | Andy Lester C<< <[email protected]> >>
|
---|
347 |
|
---|
348 | =head1 COPYRIGHT
|
---|
349 |
|
---|
350 | Copyright 2005 by Andy Lester C<< <[email protected]> >>.
|
---|
351 |
|
---|
352 | This program is free software; you can redistribute it and/or
|
---|
353 | modify it under the same terms as Perl itself.
|
---|
354 |
|
---|
355 | See L<http://www.perl.com/perl/misc/Artistic.html>.
|
---|
356 |
|
---|
357 | =cut
|
---|
358 |
|
---|
359 | __END__
|
---|
360 | :endofperl
|
---|