Here's my auto-prove script. The idea of it is that if you're working in "my-code/lib/Foo/Bar/", you don't want to chdir all the way back to "my-code/" before you run your test suite.
So auto-prove climbs back down your directory tree looking for a test suite, then runs "prove" on it.
#!/usr/bin/perl use 5.008; use strict; use Getopt::Long; my @booleans = qw{ recurse|r timer verbose|v color|c dry|D failures|f comments|o fork ignore-exit merge|m shuffle|s reverse normalize T t W w }; my %opts; GetOptions(\%opts, @booleans, 'jobs|j=i', 'xt', 'help|usage|h') or die("See '--help'.\n"); die "Unlike prove, $0 does not accept a list of test cases.\nSee '--he +lp'.\n" if @ARGV; if ($opts{help}) { # Please look away if you are easily offended. my $nice_booleans = join "\n", sort { lc$a cmp lc$b } q{ --jobs=N}, map { q{ }. join q{, }, map { length == 1 ? "-$_" : "--$_" } split m{\|}, $_; } @booleans; print eval 'qq{'.(do { local $/ = <DATA> }).'}' and exit; } require App::Prove; require Cwd; Cwd->import('cwd'); while (-d '..' and not -d 't') { chdir '..'; } unless (-d 't') { die "No suitable test suite found.\n"; } my $cwd = cwd(); print "Found suitable test suite within directory '$cwd'.\n"; my @args; foreach my $opt (@booleans) { my ($full, $short) = split m{\|}, $opt; if ($opts{$full}) { push @args, sprintf( (length($full) == 1 ? '-%s' : '--%s'), $full, ); } } push @args, sprintf('--jobs=%d', $opts{jobs}||1); foreach my $dir (qw{blib/lib inc lib}) { next unless -d $dir; push @args, sprintf('-I%s', $dir) } if ($opts{xt}) { push @args, 't', 'xt'; } else { push @args, 't'; } print join(q{ }, prove => @args), "\n" if $opts{verbose}; my $app = App::Prove->new; $app->process_args(@args); $app->run; __DATA__ Usage: $0 [OPTIONS] Searches this directory, the parent, and further up the directory tree for a subdirectory called "t". Once found, runs "prove t" there. Automatically adds "blib/lib", "inc" and "lib" to \@INC if those directories exist. Passes any of the following options through to prove: $nice_booleans Additionally supports options: --help Show this help --xt Also run "xt" tests.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Run tests with "auto-prove"
by jeffa (Bishop) on Feb 29, 2012 at 20:26 UTC | |
by tobyink (Canon) on Feb 29, 2012 at 23:07 UTC | |
by Anonymous Monk on Mar 01, 2012 at 18:27 UTC |