| 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 |
eval { |
| 12 |
#require Test::MinimumVersion::Fast; |
| 13 |
require Parse::CPAN::Meta; |
| 14 |
require CPAN::Meta::Validator; |
| 15 |
CPAN::Meta::Validator->VERSION(2.15); |
| 16 |
}; |
| 17 |
if ($@) { |
| 18 |
plan skip_all => "CPAN::Meta::Validator version 2.15 required for testing META files"; |
| 19 |
} |
| 20 |
else { |
| 21 |
plan tests => 4; |
| 22 |
} |
| 23 |
|
| 24 |
use lib '.'; |
| 25 |
our %module; |
| 26 |
require 'Makefile.PL'; |
| 27 |
# Loaded from Makefile.PL |
| 28 |
%module = get_module_info(); |
| 29 |
my $module = $module{NAME}; |
| 30 |
|
| 31 |
(my $file = $module) =~ s!::!/!g; |
| 32 |
require "$file.pm"; |
| 33 |
|
| 34 |
my $version = sprintf '%0.2f', $module->VERSION; |
| 35 |
|
| 36 |
for my $meta_file ('META.yml', 'META.json') { |
| 37 |
my $meta = Parse::CPAN::Meta->load_file($meta_file); |
| 38 |
|
| 39 |
my $cmv = CPAN::Meta::Validator->new( $meta ); |
| 40 |
|
| 41 |
if(! ok $cmv->is_valid, "$meta_file is valid" ) { |
| 42 |
diag $_ for $cmv->errors; |
| 43 |
}; |
| 44 |
|
| 45 |
# Also check that the declared version matches the version in META.* |
| 46 |
is $meta->{version}, $version, "$meta_file version matches module version ($version)"; |
| 47 |
}; |