xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/min_perl_version.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1#!/usr/bin/perl -w
2
3# This is a test checking various aspects of the optional argument
4# MIN_PERL_VERSION to WriteMakefile.
5
6BEGIN {
7    unshift @INC, 't/lib';
8}
9
10use strict;
11use Test::More tests => 33;
12
13use TieOut;
14use MakeMaker::Test::Utils;
15use MakeMaker::Test::Setup::MPV;
16use File::Path;
17
18use ExtUtils::MakeMaker;
19
20# avoid environment variables interfering with our make runs
21delete @ENV{qw(LIB MAKEFLAGS)};
22
23my $perl     = which_perl();
24my $make     = make_run();
25my $makefile = makefile_name();
26
27chdir 't';
28
29perl_lib();
30
31ok( setup_recurs(), 'setup' );
32END {
33    ok( chdir(File::Spec->updir), 'leaving dir' );
34    ok( teardown_recurs(), 'teardown' );
35}
36
37ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) ||
38    diag("chdir failed: $!");
39
40{
41    # ----- argument verification -----
42
43    my $stdout = tie *STDOUT, 'TieOut';
44    ok( $stdout, 'capturing stdout' );
45    my $warnings = '';
46    local $SIG{__WARN__} = sub {
47        $warnings .= join '', @_;
48    };
49
50    eval {
51        WriteMakefile(
52            NAME             => 'Min::PerlVers',
53            MIN_PERL_VERSION => '5',
54        );
55    };
56    is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' );
57    is( $@, '',        '  nor a hard failure' );
58
59
60    $warnings = '';
61    eval {
62        WriteMakefile(
63            NAME             => 'Min::PerlVers',
64            MIN_PERL_VERSION => '5.4.4',
65        );
66    };
67    is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
68    is( $@, '',        '  nor a hard failure' );
69
70
71    $warnings = '';
72    eval {
73        WriteMakefile(
74            NAME             => 'Min::PerlVers',
75            MIN_PERL_VERSION => '999999',
76        );
77    };
78    ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' );
79    is( $warnings,
80        "Warning: Perl version 999999 or higher required. We run $].\n",
81                         '  with expected message text' );
82    is( $@, '',          '  and without a hard failure' );
83
84    $warnings = '';
85    eval {
86        WriteMakefile(
87            NAME             => 'Min::PerlVers',
88            MIN_PERL_VERSION => '999999',
89            PREREQ_FATAL     => 1,
90        );
91    };
92    is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' );
93    is( $@, <<"END",   '  correct exception' );
94MakeMaker FATAL: perl version too low for this distribution.
95Required is 999999. We run $].
96END
97
98    $warnings = '';
99    eval {
100        WriteMakefile(
101            NAME             => 'Min::PerlVers',
102            MIN_PERL_VERSION => 'foobar',
103        );
104    };
105    ok( '' ne $warnings,    'MIN_PERL_VERSION=foobar triggers a warning' );
106    is( $warnings, <<'END', '  with expected message text' );
107Warning: MIN_PERL_VERSION is not in a recognized format.
108Recommended is a quoted numerical value like '5.005' or '5.008001'.
109END
110
111    is( $@, '',             '  and without a hard failure' );
112}
113
114
115# ----- PREREQ_PRINT output -----
116{
117    my $prereq_out = run(qq{$perl Makefile.PL "PREREQ_PRINT=1"});
118    is( $?, 0,            'PREREQ_PRINT exiting normally' );
119    my $prereq_out_sane = $prereq_out =~ /^\s*\$PREREQ_PM\s*=/;
120    ok( $prereq_out_sane, '  and talking like we expect' ) ||
121        diag($prereq_out);
122
123    SKIP: {
124        skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane;
125
126        package _Prereq::Print::WithMPV;          ## no critic
127        our($PREREQ_PM, $BUILD_REQUIRES, $MIN_PERL_VERSION, $ERR);
128        $ERR = '';
129        eval {
130            eval $prereq_out;                     ## no critic
131            $ERR = $@;
132        };
133        ::is( $@ . $ERR, '',                      'prereqs evaluable' );
134        ::is_deeply( $PREREQ_PM, { strict => 0 }, '  and looking correct' );
135        ::is( $MIN_PERL_VERSION, '5.005',         'min version also correct' );
136    }
137}
138
139
140# ----- PRINT_PREREQ output -----
141{
142    my $prereq_out = run(qq{$perl Makefile.PL "PRINT_PREREQ=1"});
143    is( $?, 0,                      'PRINT_PREREQ exiting normally' );
144    ok( $prereq_out !~ /^warning/i, '  and not complaining loudly' );
145    like( $prereq_out,
146        qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/x,
147                                    'dump has prereqs and perl version' );
148}
149
150
151# ----- generated files verification -----
152{
153    unlink $makefile;
154    my @mpl_out = run(qq{$perl Makefile.PL});
155    END { unlink $makefile, makefile_backup() }
156
157    cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out);
158    ok( -e $makefile, 'Makefile present' );
159}
160
161
162# ----- ppd output -----
163{
164    my $ppd_file = 'Min-PerlVers.ppd';
165    my @make_out = run(qq{$make ppd});
166    END { unlink $ppd_file }
167
168    cmp_ok( $?, '==', 0,    'Make ppd exiting normally' ) || diag(@make_out);
169
170    my $ppd_html = slurp($ppd_file);
171    ok( defined($ppd_html), '  .ppd file present' );
172
173    like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m,
174                            '  .ppd file content good' );
175}
176
177
178# ----- META.yml output -----
179{
180    my $distdir  = 'Min-PerlVers-0.05';
181    $distdir =~ s{\.}{_}g if $Is_VMS;
182
183    my $meta_yml = "$distdir/META.yml";
184    my @make_out    = run(qq{$make metafile});
185    END { rmtree $distdir }
186
187    cmp_ok( $?, '==', 0, 'Make metafile exiting normally' ) || diag(@make_out);
188    my $meta = slurp($meta_yml);
189    ok( defined($meta),  '  META.yml present' );
190
191    like( $meta, qr{\nrequires:[^\S\n]*\n\s+perl:\s+5\.005\n\s+strict:\s+0\n},
192                         '  META.yml content good');
193}
194
195__END__
196