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
    "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."

    Why? Just run two terminals -- one to run tests and run to edit. There are so many better ways to solve the problem of running your test suite while you "jump around" inside the source tree -- pushd and popd come to mind as well. I am curious as to how much time it took you to write this and contrast with how much time this actually saves you.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Who says I'm even running one terminal? I often run auto-prove straight from my text editor. Many text editors and IDEs allow you to launch external commands like compilers, syntax checkers, etc.

        alias autoprove="pushd /path/to/dist; prove -Ilib t; popd"