xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/meta_convert.t (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1BEGIN {
2    chdir '..' if -d '../t';
3    unshift @INC, 't/lib';
4    use lib 'lib';
5}
6
7use strict;
8use warnings;
9use Test::More 'no_plan';
10
11require ExtUtils::MM_Any;
12
13sub ExtUtils::MM_Any::quote_literal { $_[1] }
14
15my $new_mm = sub {
16    return bless { ARGS => {@_}, @_ }, 'ExtUtils::MM_Any';
17};
18
19my $warn_ok = sub {
20    my($code, $want, $name) = @_;
21
22    my @have;
23    my $ret;
24    {
25        local $SIG{__WARN__} = sub { push @have, @_ };
26        $ret = $code->();
27    }
28
29    like join("", @have), $want, $name;
30    return $ret;
31};
32
33my $version_regex = qr/version: ''/;
34my $version_action = "they're converted to empty string";
35
36
37note "Filename as version"; {
38    my $mm = $new_mm->(
39        DISTNAME => 'Net::FTP::Recursive',
40        VERSION  => 'Recursive.pm',
41    );
42
43    my $res = $warn_ok->(
44        sub { eval { $mm->metafile_target } },
45        qr{Can't parse version 'Recursive.pm'}
46    );
47    ok $res, 'we know how to deal with bogus versions defined in Makefile.PL';
48    like $res, $version_regex, $version_action;
49}
50
51
52note "'undef' version from parse_version"; {
53    my $mm = $new_mm->(
54        DISTNAME => 'Image::Imgur',
55        VERSION  => 'undef',
56    );
57    my $res = $warn_ok->(
58        sub { eval { $mm->metafile_target } },
59        qr{Can't parse version 'undef'}
60    );
61    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|;
62    like $res, $version_regex, $version_action;
63}
64
65
66note "x.y.z version"; {
67    my $mm = $new_mm->(
68        DISTNAME => 'SQL::Library',
69        VERSION  => 0.0.3,
70    );
71
72    # It would be more useful if the warning got translated to visible characters
73    my $res = $warn_ok->(
74        sub { eval { $mm->metafile_target } },
75        qr{Can't parse version '\x00\x00\x03'}
76    );
77    ok $res, q|we know how to deal with our $VERSION = 0.0.3; style versions defined in the module|;
78    like $res, $version_regex, $version_action;
79}
80
81
82note ".5 version"; {
83    my $mm = $new_mm->(
84        DISTNAME => 'Array::Suffix',
85        VERSION  => '.5',
86    );
87    my $res = $warn_ok->(
88        sub { eval { $mm->metafile_target } },
89        qr{Can't parse version '.5'}
90    );
91    ok $res, q|we know how to deal with our $VERSION = '.5'; style versions defined in the module|;
92    like $res, $version_regex, $version_action;
93}
94
95
96note "Non-camel case metadata"; {
97    my $mm = $new_mm->(
98        DISTNAME   => 'Attribute::Signature',
99        META_MERGE => {
100            resources => {
101                repository         => 'http://github.com/chorny/Attribute-Signature',
102                'Repository-clone' => 'git://github.com/chorny/Attribute-Signature.git',
103            },
104        },
105    );
106    my $res = eval { $mm->metafile_target };
107    ok $res, q|we know how to deal with non-camel-cased custom meta resource keys defined in Makefile.PL|;
108    like $res, qr/x_Repositoryclone/, "they're camel-cased";
109}
110
111
112note "version object in provides"; {
113    my $mm = $new_mm->(
114        DISTNAME   => 'CPAN::Testers::ParseReport',
115        VERSION    => '2.34',
116        META_ADD => {
117            provides => {
118                "CPAN::Testers::ParseReport" => {
119                    version => version->declare("v1.2.3"),
120                    file    => "lib/CPAN/Testers/ParseReport.pm"
121                }
122            }
123        },
124    );
125    my $res = eval { $mm->metafile_target };
126    like $res, qr{version: \s* v1.2.3}x;
127}
128