3 # This is a test checking various aspects of the optional argument
4 # MIN_PERL_VERSION to WriteMakefile.
7 if( $ENV{PERL_CORE} ) {
9 @INC = ('../lib', 'lib');
12 unshift @INC, 't/lib';
17 use Test::More tests => 33;
20 use MakeMaker::Test::Utils;
21 use MakeMaker::Test::Setup::MPV;
24 use ExtUtils::MakeMaker;
26 # avoid environment variables interfering with our make runs
27 delete @ENV{qw(LIB MAKEFLAGS)};
29 my $perl = which_perl();
30 my $make = make_run();
31 my $makefile = makefile_name();
37 ok( setup_recurs(), 'setup' );
39 ok( chdir(File::Spec->updir), 'leaving dir' );
40 ok( teardown_recurs(), 'teardown' );
43 ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) ||
44 diag("chdir failed: $!");
47 # ----- argument verification -----
49 my $stdout = tie *STDOUT, 'TieOut';
50 ok( $stdout, 'capturing stdout' );
52 local $SIG{__WARN__} = sub {
53 $warnings .= join '', @_;
58 NAME => 'Min::PerlVers',
59 MIN_PERL_VERSION => '5',
62 is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' );
63 is( $@, '', ' nor a hard failure' );
69 NAME => 'Min::PerlVers',
70 MIN_PERL_VERSION => '5.4.4',
73 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
74 is( $@, '', ' nor a hard failure' );
80 NAME => 'Min::PerlVers',
81 MIN_PERL_VERSION => '999999',
84 ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' );
86 "Warning: Perl version 999999 or higher required. We run $].\n",
87 ' with expected message text' );
88 is( $@, '', ' and without a hard failure' );
93 NAME => 'Min::PerlVers',
94 MIN_PERL_VERSION => '999999',
98 is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' );
99 is( $@, <<"END", ' correct exception' );
100 MakeMaker FATAL: perl version too low for this distribution.
101 Required is 999999. We run $].
107 NAME => 'Min::PerlVers',
108 MIN_PERL_VERSION => 'foobar',
111 ok( '' ne $warnings, 'MIN_PERL_VERSION=foobar triggers a warning' );
112 is( $warnings, <<'END', ' with expected message text' );
113 Warning: MIN_PERL_VERSION is not in a recognized format.
114 Recommended is a quoted numerical value like '5.005' or '5.008001'.
117 is( $@, '', ' and without a hard failure' );
121 # ----- PREREQ_PRINT output -----
123 my $prereq_out = run(qq{$perl Makefile.PL "PREREQ_PRINT=1"});
124 is( $?, 0, 'PREREQ_PRINT exiting normally' );
125 my $prereq_out_sane = $prereq_out =~ /^\s*\$PREREQ_PM\s*=/;
126 ok( $prereq_out_sane, ' and talking like we expect' ) ||
130 skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane;
132 package _Prereq::Print::WithMPV; ## no critic
133 use vars qw($PREREQ_PM $MIN_PERL_VERSION $ERR);
136 eval $prereq_out; ## no critic
139 ::is( $@ . $ERR, '', 'prereqs evaluable' );
140 ::is_deeply( $PREREQ_PM, { strict => 0 }, ' and looking correct' );
141 ::is( $MIN_PERL_VERSION, '5.005', 'min version also correct' );
146 # ----- PRINT_PREREQ output -----
148 my $prereq_out = run(qq{$perl Makefile.PL "PRINT_PREREQ=1"});
149 is( $?, 0, 'PRINT_PREREQ exiting normally' );
150 ok( $prereq_out !~ /^warning/i, ' and not complaining loudly' );
152 qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/x,
153 'dump has prereqs and perl version' );
157 # ----- generated files verification -----
160 my @mpl_out = run(qq{$perl Makefile.PL});
161 END { unlink $makefile, makefile_backup() }
163 cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out);
164 ok( -e $makefile, 'Makefile present' );
168 # ----- ppd output -----
170 my $ppd_file = 'Min-PerlVers.ppd';
171 my @make_out = run(qq{$make ppd});
172 END { unlink $ppd_file }
174 cmp_ok( $?, '==', 0, 'Make ppd exiting normally' ) || diag(@make_out);
176 my $ppd_html = slurp($ppd_file);
177 ok( defined($ppd_html), ' .ppd file present' );
179 like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m,
180 ' .ppd file content good' );
184 # ----- META.yml output -----
186 my $distdir = 'Min-PerlVers-0.05';
187 $distdir =~ s{\.}{_}g if $Is_VMS;
189 my $meta_yml = "$distdir/META.yml";
190 my @make_out = run(qq{$make metafile});
191 END { rmtree $distdir }
193 cmp_ok( $?, '==', 0, 'Make metafile exiting normally' ) || diag(@make_out);
194 my $meta = slurp($meta_yml);
195 ok( defined($meta), ' META.yml present' );
197 like( $meta, qr{\nrequires:[^\S\n]*\n\s+perl:\s+5\.005\n\s+strict:\s+0\n},
198 ' META.yml content good');