| 1 |
#!perl -w |
| 2 |
|
| 3 |
# Stolen from ChrisDolan on use.perl.org |
| 4 |
# http://use.perl.org/comments.pl?sid=29264&cid=44309 |
| 5 |
|
| 6 |
use warnings; |
| 7 |
use strict; |
| 8 |
use File::Find; |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
require './Makefile.PL'; |
| 12 |
# Loaded from Makefile.PL |
| 13 |
our %module = get_module_info(); |
| 14 |
|
| 15 |
my @files; |
| 16 |
my $blib = File::Spec->catfile(qw(blib lib)); |
| 17 |
find(\&wanted, grep { -d } ($blib)); |
| 18 |
|
| 19 |
if( my $exe = $module{EXE_FILES}) { |
| 20 |
push @files, @$exe; |
| 21 |
}; |
| 22 |
|
| 23 |
sub read_file { |
| 24 |
open my $fh, '<', $_[0] |
| 25 |
or die "Couldn't read '$_[0]': $!"; |
| 26 |
binmode $fh; |
| 27 |
local $/; |
| 28 |
<$fh> |
| 29 |
} |
| 30 |
|
| 31 |
sub wanted { |
| 32 |
push @files, $File::Find::name if /\.p(l|m|od)$/; |
| 33 |
} |
| 34 |
|
| 35 |
plan tests => 0+@files; |
| 36 |
|
| 37 |
my $last_version = undef; |
| 38 |
|
| 39 |
sub check { |
| 40 |
my $content = read_file($_); |
| 41 |
|
| 42 |
# only look at perl scripts, not sh scripts |
| 43 |
return if (m{blib/script/}xms && $content !~ m/\A \#![^\r\n]+?perl/xms); |
| 44 |
|
| 45 |
my @version_lines = $content =~ m/ ( [^\n]* \$VERSION \s* = [^=] [^\n]* ) /gxms; |
| 46 |
if (@version_lines == 0) { |
| 47 |
fail($_); |
| 48 |
} |
| 49 |
for my $line (@version_lines) { |
| 50 |
$line =~ s/^\s+//; |
| 51 |
$line =~ s/\s+$//; |
| 52 |
if (!defined $last_version) { |
| 53 |
$last_version = shift @version_lines; |
| 54 |
diag "Checking for $last_version"; |
| 55 |
pass($_); |
| 56 |
} else { |
| 57 |
is($line, $last_version, $_); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
for (@files) { |
| 63 |
check(); |
| 64 |
}; |
| 65 |
|
| 66 |
if (! defined $last_version) { |
| 67 |
fail('Failed to find any files with $VERSION'); |
| 68 |
} |