Adam,
Post by Adam KennedyEven if you do no other unit test scripts, at least you know there
aren't any killer syntax errors.
I agree whole heartedly.
I have been using this small script for a while now to create my
'smoke' tests with, it only attempts to load the .pm files and skips
any CVS or svn directories too. It also formats the output, putting
comments for each folder, and indenting as well. I basically just say
'perl create_smoke_test.pl lib/ > t/001_smoke_test.t' and I am good. It
basically saves me from having to bother doing this by hand.
- Steve
#!/usr/bin/perl
use strict;
use warnings;
my $directory = shift(@ARGV);
(defined($directory))
|| die "You must specify a directory to create a smoke test
for\nusage: create_smoke_test <directory>\n";
sub map_dir {
my ($dir, $dir_func, $file_func, $depth) = @_;
$depth ||= 0;
return map {
if (-d $_ && !/CVS|\.svn/) {
$dir_func->($_, $depth + 1);
map_dir($_, $dir_func, $file_func, $depth + 1);
}
elsif (-f $_ && /\.pm/) {
$file_func->($_, $depth);
}
} sort { ((-d $a) ? 1 : (-d $b) ? -1 : ($a cmp $b)) } <$dir/*>;
}
sub handle_dir {
my ($dir, $depth) = @_;
$depth ||= 1;
$dir =~ s/^$directory\///;
print("\n" . (" " x $depth) . "# $dir\n");
}
sub handle_file {
my ($file, $depth) = @_;
$depth ||= 1;
$file =~ s/^$directory\///;
my ($module_name) = ($file =~ /(.*?)\.pm/);
$module_name =~ s/\//\:\:/g;
print((" " x $depth) . "use_ok('$module_name');\n");
}
print <<HEADER;
#!/usr/bin/perl
use strict;
use warnings;
use Test::More no_plan => 1;
BEGIN {
HEADER
map_dir($directory, \&handle_dir, \&handle_file);
print <<FOOTER;
};
FOOTER
Post by Adam KennedyAnd in the other unit tests, you can just C< use Module; > normally,
without having to test it.
I've been doing this for about the last year now, and I've found it to
work quite well.
01_compile.t
------------
#!/usr/bin/perl -w
# Load testing for CGI::Capture
use strict;
use lib ();
use File::Spec::Functions ':ALL';
BEGIN {
$| = 1;
unless ( $ENV{HARNESS_ACTIVE} ) {
require FindBin;
chdir ($FindBin::Bin = $FindBin::Bin); # Avoid a warning
lib->import( catdir( updir(), updir(), 'modules') );
}
}
use Test::More tests => 2;
# Check their perl version
ok( $] >= 5.006, "Your perl is new enough" );
# Does the module load
use_ok('CGI::Capture');
exit(0);
----------------------------
That block at the top is to let the tests work inside my slightly
unusual CVS layout. (I have a build_module.pl script to assemble stuff
into the proper layout when releasing).
Adam
This is actually kinda cool. Are you planning on submitting RT
reports? *hint hint*
Rob
Post by Adam KennedyWell... there's Zanas, which has
file.html.pm
-------
<html></html>
-------
And don't get me started on
file.gif.pm
------------------
(binary gif file)
------------------
Still haven't worked out what the hell they are for... :)
It's partly my fault for making the "what is a module" regex wrong.
Paper::Specs has used a code generator that doesn't escape properly, so
half a dozen Paper::Specs::Avery::8XXX label modules die
description => "Avery 5 1/2" blah blah labels",
Of the ones that are my fault, we have gems like
tr [\$|\%|\&|\*] //g;
And one that got fixed...
$|=1;$::|=1;
Or the fact that <<1HERE1 is illegal per the docs, but does actually work.
Since it takes 4 or 5 minutes to nail down the exact fault location for
each file, I haven't had time to get details on the rest, but it's
mostly insanely ugly quote/regexs or fairly insane code in general that
is causing the problems now, and I never said I'd support every single
thing.
I've been uploading some autogenerated reports as well, to
http://ali.as/PPI/tinderbox/
So you can see there are a large number of modules uploaded with
corrupted tarballs, or who have started using Build.PL without keeping
the wrapper Makefile.PL for compatibility.
Adam
_______________________________________________
sw-design mailing list
http://metaperl.com/cgi-bin/mailman/listinfo/sw-design