OK. That's enough. On more than one large project I've been bitten by having bad version numbers of modules. I'm going to write tests for my code which automatically loads up a bunch of modules and then validates the version numbers of everything in @INC which I can load :/
Add a versiontest.t
ChrisDolan on 2005-11-03T03:37:25
I use the following test in all of my modules. It checks that all modules and scripts have the same version number. In conjunction with a Perl::Critic test that ensures every file has a $VERSION, it's nearly foolproof.
#!perl -w
use warnings;
use strict;
use File::Find;
use File::Slurp;
use Test::More qw(no_plan);
my $last_version = undef;
sub check {
return if (! m{blib/script/}xms && ! m{\.pm \z}xms);
my $content = read_file($_);
# only look at perl scripts, not sh scripts
return if (m{blib/script/}xms && $content !~ m/\A \#![^\r\n]+?perl/xms);
my @version_lines = $content =~ m/ ( [^\n]* \$VERSION [^\n]* )
/gxms;
if (@version_lines == 0) {
fail($_);
}
for my $line (@version_lines) {
if (!defined $last_version) {
$last_version = shift @version_lines;
pass($_);
} else {
is($line, $last_version, $_);
}
}
}
find({wanted => \&check, no_chdir => 1}, 'blib');
if (! defined $last_version) {
fail('Failed to find any files with $VERSION');
}