3 # This is a test checking various aspects of the optional argument
4 # MIN_PERL_VERSION to WriteMakefile.
14 use MakeMaker::Test::Utils;
18 !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}
19 ? (skip_all => "cross-compiling and make not available")
23 use ExtUtils::MakeMaker;
24 my $CM = eval { require CPAN::Meta; };
26 my $DIRNAME = 'Min-PerlVers';
28 'Makefile.PL' => <<'END',
29 use ExtUtils::MakeMaker;
31 NAME => 'Min::PerlVers',
32 AUTHOR => 'John Doe <jd@example.com>',
33 VERSION_FROM => 'lib/Min/PerlVers.pm',
34 PREREQ_PM => { strict => 0 },
35 MIN_PERL_VERSION => '5.005',
39 'lib/Min/PerlVers.pm' => <<'END',
40 package Min::PerlVers;
45 Min::PerlVers - being picky about perl versions
54 # avoid environment variables interfering with our make runs
55 delete @ENV{qw(LIB MAKEFLAGS PERL_CORE)};
57 my $perl = which_perl();
58 my $make = make_run();
59 my $makefile = makefile_name();
65 hash2files($DIRNAME, \%FILES);
67 ok( chdir(File::Spec->updir), 'leaving dir' );
68 ok( rmtree($DIRNAME), 'teardown' );
71 ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) ||
72 diag("chdir failed: $!");
74 note "Argument verification"; {
75 my $stdout = tie *STDOUT, 'TieOut';
76 ok( $stdout, 'capturing stdout' );
78 local $SIG{__WARN__} = sub {
79 $warnings .= join '', @_;
84 NAME => 'Min::PerlVers',
85 MIN_PERL_VERSION => '5',
88 is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' );
89 is( $@, '', ' nor a hard failure' );
95 NAME => 'Min::PerlVers',
96 MIN_PERL_VERSION => '5.4.4',
99 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
100 is( $@, '', ' nor a hard failure' );
106 NAME => 'Min::PerlVers',
107 MIN_PERL_VERSION => 5.4.4,
110 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
111 is( $@, '', ' nor a hard failure' );
117 NAME => 'Min::PerlVers',
118 MIN_PERL_VERSION => v5.4.4,
121 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
122 is( $@, '', ' nor a hard failure' );
128 NAME => 'Min::PerlVers',
129 MIN_PERL_VERSION => '999999',
132 ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' );
134 "Warning: Perl version 999999 or higher required. We run $].\n",
135 ' with expected message text' );
136 is( $@, '', ' and without a hard failure' );
141 NAME => 'Min::PerlVers',
142 MIN_PERL_VERSION => '999999',
146 is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' );
147 is( $@, <<"END", ' correct exception' );
148 MakeMaker FATAL: perl version too low for this distribution.
149 Required is 999999. We run $].
155 NAME => 'Min::PerlVers',
156 MIN_PERL_VERSION => 'foobar',
159 is( $@, <<'END', 'Invalid MIN_PERL_VERSION is fatal' );
160 Warning: MIN_PERL_VERSION is not in a recognized format.
161 Recommended is a quoted numerical value like '5.005' or '5.008001'.
167 note "PREREQ_PRINT output"; {
168 my $prereq_out = run(qq{$perl Makefile.PL "PREREQ_PRINT=1"});
169 is( $?, 0, 'PREREQ_PRINT exiting normally' );
170 $prereq_out =~ s/.*(\$PREREQ_PM\s*=)/$1/s; # strip off errors eg from chcp
171 my $prereq_out_sane = $prereq_out =~ /^\s*\$PREREQ_PM\s*=/;
172 ok( $prereq_out_sane, ' and talking like we expect' ) ||
176 skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane;
178 package _Prereq::Print::WithMPV; ## no critic
179 our($PREREQ_PM, $BUILD_REQUIRES, $MIN_PERL_VERSION, $ERR);
180 $BUILD_REQUIRES = undef; # suppress "used only once"
183 eval $prereq_out; ## no critic
186 ::is( $@ . $ERR, '', 'prereqs evaluable' );
187 ::is_deeply( $PREREQ_PM, { strict => 0 }, ' and looking correct' );
188 ::is( $MIN_PERL_VERSION, '5.005', 'min version also correct' );
193 note "PRINT_PREREQ output"; {
194 my $prereq_out = run(qq{$perl Makefile.PL "PRINT_PREREQ=1"});
195 is( $?, 0, 'PRINT_PREREQ exiting normally' );
196 ok( $prereq_out !~ /^warning/i, ' and not complaining loudly' );
198 qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/mx,
199 'dump has prereqs and perl version' );
203 note "generated files verification"; {
205 my @mpl_out = run(qq{$perl Makefile.PL});
206 END { unlink $makefile, makefile_backup() }
208 cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out);
209 ok( -e $makefile, 'Makefile present' );
214 my $ppd_file = 'Min-PerlVers.ppd';
215 my @make_out = run(qq{$make ppd});
216 END { unlink $ppd_file }
218 cmp_ok( $?, '==', 0, 'Make ppd exiting normally' ) || diag(@make_out);
220 my $ppd_html = slurp($ppd_file);
221 ok( defined($ppd_html), ' .ppd file present' );
223 like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m,
224 ' .ppd file content good' );
228 note "META.yml output"; SKIP: {
229 skip 'Failed to load CPAN::Meta', 4 unless $CM;
230 my $distdir = 'Min-PerlVers-0.05';
231 $distdir =~ s{\.}{_}g if $Is_VMS;
233 my $meta_yml = "$distdir/META.yml";
234 my $meta_json = "$distdir/META.json";
235 my @make_out = run(qq{$make metafile});
236 END { rmtree $distdir if defined $distdir }
239 ['META.yml', $meta_yml],
240 ['META.json', $meta_json],
242 my ($label, $meta_name) = @$case;
245 CPAN::Meta->load_file($meta_name, {lazy_validation => 0})
249 is( $obj->prereqs->{runtime}{requires}{perl}, '5.005',
250 "$label has runtime/requires perl 5.005"