summaryrefslogtreecommitdiff
path: root/cpan/ExtUtils-MakeMaker/t/meta_convert.t
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/ExtUtils-MakeMaker/t/meta_convert.t')
-rw-r--r--cpan/ExtUtils-MakeMaker/t/meta_convert.t211
1 files changed, 96 insertions, 115 deletions
diff --git a/cpan/ExtUtils-MakeMaker/t/meta_convert.t b/cpan/ExtUtils-MakeMaker/t/meta_convert.t
index 7053c33125..c99926dfad 100644
--- a/cpan/ExtUtils-MakeMaker/t/meta_convert.t
+++ b/cpan/ExtUtils-MakeMaker/t/meta_convert.t
@@ -1,127 +1,108 @@
-BEGIN {
- chdir '..' if -d '../t';
- unshift @INC, 't/lib';
- use lib 'lib';
-}
+#!perl -w
use strict;
use warnings;
-use Test::More 'no_plan';
+BEGIN { unshift @INC, 't/lib'; }
+use Test::More eval { require CPAN::Meta; CPAN::Meta->VERSION(2.143240) } ? ()
+ : (skip_all => 'CPAN::Meta 2.143240 required for this test');
+use File::Temp qw[tempdir];
require ExtUtils::MM_Any;
-sub ExtUtils::MM_Any::quote_literal { $_[1] }
-
-my $new_mm = sub {
- return bless { ARGS => {@_}, @_ }, 'ExtUtils::MM_Any';
-};
+my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
+use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
+chdir $tmpdir or die "chdir $tmpdir: $!";
+
+my $EMPTY = qr/['"]?version['"]?\s*:\s*['"]['"]/;
+my @DATA = (
+ [
+ [ DISTNAME => 'Net::FTP::Recursive', VERSION => 'Recursive.pm', ],
+ qr{Can't parse version 'Recursive.pm'},
+ 'VERSION => filename',
+ $EMPTY,
+ ],
+ [
+ [ DISTNAME => 'Image::Imgur', VERSION => 'undef', ],
+ qr{Can't parse version 'undef'},
+ 'no $VERSION in file -> VERSION=>"undef"',
+ $EMPTY,
+ ],
+ [
+ [ DISTNAME => 'SQL::Library', VERSION => 0.0.3, ],
+ qr{Can't parse version '\x00\x00\x03'},
+ "x.y.z version",
+ $EMPTY,
+ ],
+ [
+ [ DISTNAME => 'Array::Suffix', VERSION => '.5', ],
+ qr{Can't parse version '.5'},
+ ".5 version",
+ $EMPTY,
+ ],
+ [
+ [
+ DISTNAME => 'Attribute::Signature',
+ META_MERGE => {
+ resources => {
+ repository => 'http://github.com/chorny/Attribute-Signature',
+ 'Repository-clone' => 'git://github.com/chorny/Attribute-Signature.git',
+ },
+ },
+ ],
+ qr/^$/,
+ "Non-camel case metadata",
+ qr/x_Repositoryclone/,
+ ],
+ [
+ [
+ DISTNAME => 'CPAN::Testers::ParseReport',
+ VERSION => '2.34',
+ META_ADD => {
+ provides => {
+ "CPAN::Testers::ParseReport" => {
+ version => version->new("v1.2.3"),
+ file => "lib/CPAN/Testers/ParseReport.pm"
+ }
+ }
+ },
+ ],
+ qr/^$/,
+ "version object in provides",
+ qr/['"]?version['"]?\s*:\s*['"]v1\.2\.3['"]/,
+ ],
+ [
+ [
+ DISTNAME => 'Bad::License',
+ VERSION => '2.34',
+ LICENSE => 'death and retribution',
+ ],
+ qr/Invalid LICENSE value/,
+ "Bad licence warns",
+ qr/['"]?version['"]?\s*:\s*['"]2\.34['"]/,
+ ],
+);
+
+plan tests => 3 * @DATA;
+run_test(@$_) for @DATA;
-my $warn_ok = sub {
- my($code, $want, $name) = @_;
+sub ExtUtils::MM_Any::quote_literal { $_[1] }
- my @have;
+sub run_test {
+ my ($mmargs, $expected, $label, $metadata_re) = @_;
+ my $mm = bless { ARGS => {@$mmargs}, @$mmargs }, 'ExtUtils::MM_Any';
+ my @warnings;
my $ret;
{
- local $SIG{__WARN__} = sub { push @have, @_ };
- $ret = $code->();
+ local $SIG{__WARN__} = sub { push @warnings, @_ };
+ eval { $ret = $mm->metafile_target; };
+ }
+ SKIP: {
+ if ($@) {
+ diag $@;
+ skip "$label got exception", 3 if $@;
+ }
+ ok 1, "$label metafile_target";
+ like join("", @warnings), $expected, "$label right warning";
+ like $ret, $metadata_re, "$label metadata";
}
-
- like join("", @have), $want, $name;
- return $ret;
-};
-
-my $version_regex = qr/version: ''/;
-my $version_action = "they're converted to empty string";
-
-
-note "Filename as version"; {
- my $mm = $new_mm->(
- DISTNAME => 'Net::FTP::Recursive',
- VERSION => 'Recursive.pm',
- );
-
- my $res = $warn_ok->(
- sub { eval { $mm->metafile_target } },
- qr{Can't parse version 'Recursive.pm'}
- );
- ok $res, 'we know how to deal with bogus versions defined in Makefile.PL';
- like $res, $version_regex, $version_action;
-}
-
-
-note "'undef' version from parse_version"; {
- my $mm = $new_mm->(
- DISTNAME => 'Image::Imgur',
- VERSION => 'undef',
- );
- my $res = $warn_ok->(
- sub { eval { $mm->metafile_target } },
- qr{Can't parse version 'undef'}
- );
- ok $res, q|when there's no $VERSION in Module.pm, $self->{VERSION} = 'undef'; via MM_Unix::parse_version and we know how to deal with that|;
- like $res, $version_regex, $version_action;
-}
-
-
-note "x.y.z version"; {
- my $mm = $new_mm->(
- DISTNAME => 'SQL::Library',
- VERSION => 0.0.3,
- );
-
- # It would be more useful if the warning got translated to visible characters
- my $res = $warn_ok->(
- sub { eval { $mm->metafile_target } },
- qr{Can't parse version '\x00\x00\x03'}
- );
- ok $res, q|we know how to deal with our $VERSION = 0.0.3; style versions defined in the module|;
- like $res, $version_regex, $version_action;
-}
-
-
-note ".5 version"; {
- my $mm = $new_mm->(
- DISTNAME => 'Array::Suffix',
- VERSION => '.5',
- );
- my $res = $warn_ok->(
- sub { eval { $mm->metafile_target } },
- qr{Can't parse version '.5'}
- );
- ok $res, q|we know how to deal with our $VERSION = '.5'; style versions defined in the module|;
- like $res, $version_regex, $version_action;
-}
-
-
-note "Non-camel case metadata"; {
- my $mm = $new_mm->(
- DISTNAME => 'Attribute::Signature',
- META_MERGE => {
- resources => {
- repository => 'http://github.com/chorny/Attribute-Signature',
- 'Repository-clone' => 'git://github.com/chorny/Attribute-Signature.git',
- },
- },
- );
- my $res = eval { $mm->metafile_target };
- ok $res, q|we know how to deal with non-camel-cased custom meta resource keys defined in Makefile.PL|;
- like $res, qr/x_Repositoryclone/, "they're camel-cased";
-}
-
-
-note "version object in provides"; {
- my $mm = $new_mm->(
- DISTNAME => 'CPAN::Testers::ParseReport',
- VERSION => '2.34',
- META_ADD => {
- provides => {
- "CPAN::Testers::ParseReport" => {
- version => version->new("v1.2.3"),
- file => "lib/CPAN/Testers/ParseReport.pm"
- }
- }
- },
- );
- my $res = eval { $mm->metafile_target };
- like $res, qr{version: \s* v1.2.3}x;
}