Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
I've probably posted this before, but it's just here so I google it later and find it easily. Note that one difference between this and some other Test::Class driver scripts is that this script assumes that all packages in TEST_DIR are test class packages which should be loaded. Thus, I don't have to have a bunch of "use" lines in this script and forget when I've added another class.
Also, note that the else condition allows me to put the following in my
noremap
,T :!perl t/test_class_tests.t %<cr>
That lets me run a test class while I'm editing it.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find::Rule;
use UNIVERSAL::require;
use constant TEST_DIR => 't/tests/';
use lib 'lib', 't/lib/', TEST_DIR;
sub file_to_module ($) {
my $file = shift;
$file =~ s/^@{[TEST_DIR]}//;
$file =~ s/\.pm$//;
$file =~ s{/}{::}g;
warn $file, $/;
return $file;
}
BEGIN {
# tests must be loaded in a begin block or they will not be run.
unless (@ARGV) {
foreach
my $file ( File::Find::Rule->file->name('*.pm')->in(TEST_DIR) )
{
( file_to_module $file )->require or die $@;
}
}
else {
my $file = shift;
unless ( -e $file ) {
die "Could not locate file ($file)";
}
( file_to_module $file )->require or die $@;
}
}
Test::Class->runtests;
Room for improvement (Score:1)
First of all: :)
unless ... else ...? What were you thinking?Secondly: sticking the
TEST_DIRremoval infile_to_moduleseems like a violation of separatation of concerns. Yeah, I know this script is small, but it still bugged me [perlmonks.org] when I did it in a small script of my own [perlmonks.org]. My suggestion would be to fix it the same way as I did: