source: for-distributions/trunk/bin/windows/perl/bin/prove.bat@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 9.4 KB
Line 
1@rem = '--*-Perl-*--
2@echo off
3if "%OS%" == "Windows_NT" goto WinNT
4perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
5goto endofperl
6:WinNT
7perl -x -S %0 %*
8if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
9if %errorlevel% == 9009 echo You do not have Perl in your PATH.
10if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
11goto 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
19use strict;
20
21use Test::Harness;
22use Getopt::Long;
23use Pod::Usage 1.12;
24use File::Spec;
25
26use vars qw( $VERSION );
27$VERSION = "1.04";
28
29my @ext = ();
30my $shuffle = 0;
31my $dry = 0;
32my $blib = 0;
33my $lib = 0;
34my $recurse = 0;
35my @includes = ();
36my @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.
43unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
44
45Getopt::Long::Configure( "no_ignore_case" );
46Getopt::Long::Configure( "bundling" );
47GetOptions(
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;
69s/^\.// foreach @ext;
70@ext = ("t") unless @ext;
71my $ext_regex = join( "|", map { quotemeta } @ext );
72$ext_regex = qr/\.($ext_regex)$/;
73
74# Handle blib includes
75if ( $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
85if ( $lib ) {
86 unshift @includes, "lib";
87}
88
89# Build up TH switches
90push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
91$Test::Harness::Switches = join( " ", @switches );
92print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
93
94my @tests;
95@ARGV = File::Spec->curdir unless @ARGV;
96push( @tests, -d $_ ? all_in( $_ ) : $_ ) for map { glob } @ARGV;
97
98if ( @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
108sub 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
136sub shuffle {
137 # Fisher-Yates shuffle
138 my $i = @_;
139 while ($i) {
140 my $j = rand $i--;
141 @_[$i, $j] = @_[$j, $i];
142 }
143}
144
145sub 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
151sub 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
181prove -- A command-line tool for running tests against Test::Harness
182
183=head1 SYNOPSIS
184
185prove [options] [files/directories]
186
187Options:
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
205Single-character options may be stacked. Default options may be set by
206specifying the PROVE_SWITCHES environment variable.
207
208=head1 OVERVIEW
209
210F<prove> is a command-line interface to the test-running functionality
211of C<Test::Harness>. With no arguments, it will run all tests in the
212current directory.
213
214Shell metacharacters may be used with command lines options and will be exanded
215via C<glob>.
216
217=head1 PROVE VS. "MAKE TEST"
218
219F<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
225Perl users typically run the test harness through a makefile via
226C<make test>. That's fine for module distributions, but it's
227suboptimal for a test/code/debug development cycle.
228
229=item * F<prove> is granular
230
231F<prove> lets your run against only the files you want to check.
232Running C<prove t/live/ t/master.t> checks every F<*.t> in F<t/live>,
233plus F<t/master.t>.
234
235=item * F<prove> has an easy verbose mode
236
237F<prove> has a C<-v> option to see the raw output from the tests.
238To do this with C<make test>, you must set C<HARNESS_VERBOSE=1> in
239the environment.
240
241=item * F<prove> can run under taint mode
242
243F<prove>'s C<-T> runs your tests under C<perl -T>, and C<-t> runs them
244under C<perl -t>.
245
246=item * F<prove> can shuffle tests
247
248You can use F<prove>'s C<--shuffle> option to try to excite problems
249that 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
253Not everyone wants to write a makefile, or use L<ExtUtils::MakeMaker>
254to do so. F<prove> has no external dependencies.
255
256=item * Not everything is a module
257
258More and more users are using Perl's testing tools outside the
259context of a module distribution, and may not even use a makefile
260at all.
261
262=back
263
264=head1 COMMAND LINE OPTIONS
265
266=head2 -b, --blib
267
268Adds blib/lib to the path for your tests, a la "use blib".
269
270=head2 -d, --debug
271
272Include debug information about how F<prove> is being run. This
273option doesn't show the output from the test scripts. That's handled
274by -v,--verbose.
275
276=head2 -D, --dry
277
278Dry run: Show the tests to run, but don't run them.
279
280=head2 --ext=extension
281
282Specify extensions of the test files to run. By default, these are .t,
283but you may have other non-.t test files, most likely .sh shell scripts.
284The --ext is repeatable.
285
286=head2 -I
287
288Add libraries to @INC, as Perl's -I.
289
290=head2 -l, --lib
291
292Add C<lib> to @INC. Equivalent to C<-Ilib>.
293
294=head2 -r, --recurse
295
296Descends into subdirectories of any directories specified, looking for tests.
297
298=head2 -s, --shuffle
299
300Sometimes tests are accidentally dependent on tests that have been
301run before. This switch will shuffle the tests to be run prior to
302running them, thus ensuring that hidden dependencies in the test
303order are likely to be revealed. The author hopes the run the
304algorithm on the preceding sentence to see if he can produce something
305slightly less awkward.
306
307=head2 -t
308
309Runs test programs under perl's -t taint warning mode.
310
311=head2 -T
312
313Runs test programs under perl's -T taint mode.
314
315=head2 --timer
316
317Print elapsed time after each test file
318
319=head2 -v, --verbose
320
321Display standard output of test scripts while running them. Also sets
322TEST_VERBOSE in case your tests rely on them.
323
324=head2 -V, --version
325
326Display version info.
327
328=head1 BUGS
329
330Please use the CPAN bug ticketing system at L<http://rt.cpan.org/>.
331You can also mail bugs, fixes and enhancements to
332C<< <[email protected]> >>.
333
334=head1 TODO
335
336=over 4
337
338=item *
339
340Shuffled tests must be recreatable
341
342=back
343
344=head1 AUTHORS
345
346Andy Lester C<< <[email protected]> >>
347
348=head1 COPYRIGHT
349
350Copyright 2005 by Andy Lester C<< <[email protected]> >>.
351
352This program is free software; you can redistribute it and/or
353modify it under the same terms as Perl itself.
354
355See L<http://www.perl.com/perl/misc/Artistic.html>.
356
357=cut
358
359__END__
360:endofperl
Note: See TracBrowser for help on using the repository browser.