Hi all,

Long before prove came along, I used a program named "grind" to manage
my test suites.  One thing that grind had that prove does not was the
ability to specify *which* tests to run.  grind did it via shell
expansion and that was terrible.  Andy sensibly did not include that in
prove.

I want that back, however, so I've included a patch that allows prove
to run tests based upon a pattern.  So if you're heavily focused on
your "Customer" behavior and you want to just run those tests:

  prove -p '*cust*' t/
  prove --pattern='*cust*' t/

Patterns must be valid Perl regular expressions and prove will die if
an invalid pattern is supplied.

Comments welcome.

Cheers,
Ovid

=====
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
--- prove	2005-01-24 13:30:25.060298520 -0800
+++ prove.new	2005-01-24 13:31:05.120208488 -0800
@@ -11,7 +11,7 @@
 use File::Spec;
 
 use vars qw( $VERSION );
-$VERSION = "1.04";
+$VERSION = "1.05";
 
 my @ext = ();
 my $shuffle = 0;
@@ -21,6 +21,7 @@
 my $recurse = 0;
 my @includes = ();
 my @switches = ();
+my $pattern;
 
 # Allow cuddling the paths with the -I
 @ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
@@ -39,6 +40,7 @@
     'H|man'         => sub {pod2usage({-verbose => 2, -input => \*DATA}); exit},
     'I=s@'          => [EMAIL PROTECTED],
     'l|lib'         => \$lib,
+    'p|pattern=s'   => \$pattern,
     'r|recurse'     => \$recurse,
     's|shuffle'     => \$shuffle,
     't'             => sub { unshift @switches, "-t" }, # Always want -t up front
@@ -48,6 +50,11 @@
     'ext=s@'        => [EMAIL PROTECTED],
 ) or exit 1;
 
+if ($pattern) {
+    eval {"" =~ /$pattern/};
+    die "Bad pattern ($pattern): $@" if $@;
+}
+
 $ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
 
 # Build up extensions regex
@@ -80,6 +87,7 @@
 my @tests;
 @ARGV = File::Spec->curdir unless @ARGV;
 push( @tests, -d $_ ? all_in( $_ ) : $_ ) for map { glob } @ARGV;
[EMAIL PROTECTED] = grep /$pattern/ => @tests if $pattern;
 
 if ( @tests ) {
     shuffle(@tests) if $shuffle;
@@ -178,6 +186,7 @@
     -H, --man       Longer manpage for prove
     -I              Add libraries to @INC, as Perl's -I
     -l, --lib       Add lib to the path for your tests.
+    -p, --pattern   Only run tests whose filenames match the specified pattern.
     -r, --recurse   Recursively descend into directories.
     -s, --shuffle   Run the tests in a random order.
     -T              Enable tainting checks
@@ -274,6 +283,14 @@
 
 Add C<lib> to @INC.  Equivalent to C<-Ilib>.
 
+=head2 -p, --pattern
+
+Only run tests whose filenames match a given regular expression.  This regular
+expression must be a valid Perl regular expression or F<prove> will die.
+
+ prove -p 'cust.*\.t' t/
+ prove --pattern='cust.*\.t' t/
+
 =head2 -r, --recurse
 
 Descends into subdirectories of any directories specified, looking for tests.

Reply via email to