Re: [Module-build-general] RFC: Build test test_dirs=(list)
Status: Beta
Brought to you by:
kwilliams
|
From: Michael G S. <sc...@po...> - 2003-08-13 01:21:05
|
On Tue, Aug 12, 2003 at 11:51:16PM +0100, Steve Purkis wrote:
> >If I want to test only the methods in the parent class Foo::Bar::One,
> >I run "Build test test_dirs=t/Foo/Bar/One/t". If I want to run
> >the tests for that class and all it's children, I run
> >"Build test test_dirs=t/Foo/Bar/One". If I'm fixing a bug in
> >Foo::Bar::One::B,
> >I run "Build test test_dirs=t/Foo/Bar/One/B/t" over and over, and then
> >when I'm
> >satisfied I run a full regression test with "Build test".
>
> That works fine if you organize tests by directory, but a lot of
> authors like to group their tests by function in the /t directory -
This may be a habit formed from MakeMaker's limitation on directory
depth.
> Using regexps on the path to the test script would let you specify a
> subset of tests to run in all of these scenarios:
>
> ./Build test matching=t/Foo/Bar/One
> ./Build test matching=runthrough
> ./Build test matching=t/0*
>
> Which could be handy.
I presume you mean globs, not regexes?
What might be a lot simpler is semantics like this:
# run only foo.t
Build test test_files=t/foo.t
# run all .t files in t/
Build test test_files=t/*.t
so rather than having "test_files" and "matching" as seperate beasts, just
run the test_files arguments through glob().
Additionally, one can add this shorthand.
# equivalent to t/*.t
build test test_files=t/
This is handy because if/when we get the "look for test files recursively"
option, the above would go recursive. Otherwise there's no easy
way to say "test everything in this directory and what's below it".
This patch implements both.
--- lib/Module/Build/Base.pm 2003/08/12 23:53:00 1.2
+++ lib/Module/Build/Base.pm 2003/08/12 23:58:27
@@ -875,13 +875,27 @@
my @tests;
if ($self->{args}{test_files}) { # XXX use 'properties'
- @tests = $self->split_like_shell($self->{args}{test_files});
+ @tests = map { glob $_ }
+ map { -d $_ ? $self->expand_test_dir($_) : $_ }
+ $self->split_like_shell($self->{args}{test_files});
} else {
# Find all possible tests in t/ or test.pl
push @tests, 'test.pl' if -e 'test.pl';
push @tests, @{$self->rscan_dir('t', qr{\.t$})} if -e 't' and -d _;
}
return [sort @tests];
+}
+
+sub expand_test_dir {
+ my($self, $dir) = @_;
+
+ opendir(DIR, $dir) or die "Can't open $dir: $!";
+ my @tests = map { File::Spec->catfile($dir, $_) }
+ grep { /\.t$/ }
+ readdir DIR;
+ closedir DIR;
+
+ return @tests;
}
sub ACTION_testdb {
--
Michael G Schwern sc...@po... http://www.pobox.com/~schwern/
Do not try comedy at home! Milk & Cheese are advanced experts! Attempts at
comedy can be dangerously unfunny!
|