3 # This is a test checking various aspects of the optional argument
4 # MIN_PERL_VERSION to WriteMakefile.
11 use Test::More tests => 33;
14 use MakeMaker::Test::Utils;
15 use MakeMaker::Test::Setup::MPV;
18 use ExtUtils::MakeMaker;
20 # avoid environment variables interfering with our make runs
21 delete @ENV{qw(LIB MAKEFLAGS)};
23 my $perl = which_perl();
24 my $make = make_run();
25 my $makefile = makefile_name();
31 ok( setup_recurs(), 'setup' );
33 ok( chdir(File::Spec->updir), 'leaving dir' );
34 ok( teardown_recurs(), 'teardown' );
37 ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) ||
38 diag("chdir failed: $!");
41 # ----- argument verification -----
43 my $stdout = tie *STDOUT, 'TieOut';
44 ok( $stdout, 'capturing stdout' );
46 local $SIG{__WARN__} = sub {
47 $warnings .= join '', @_;
52 NAME => 'Min::PerlVers',
53 MIN_PERL_VERSION => '5',
56 is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' );
57 is( $@, '', ' nor a hard failure' );
63 NAME => 'Min::PerlVers',
64 MIN_PERL_VERSION => '5.4.4',
67 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' );
68 is( $@, '', ' nor a hard failure' );
74 NAME => 'Min::PerlVers',
75 MIN_PERL_VERSION => '999999',
78 ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' );
80 "Warning: Perl version 999999 or higher required. We run $].\n",
81 ' with expected message text' );
82 is( $@, '', ' and without a hard failure' );
87 NAME => 'Min::PerlVers',
88 MIN_PERL_VERSION => '999999',
92 is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' );
93 is( $@, <<"END", ' correct exception' );
94 MakeMaker FATAL: perl version too low for this distribution.
95 Required is 999999. We run $].
101 NAME => 'Min::PerlVers',
102 MIN_PERL_VERSION => 'foobar',
105 ok( '' ne $warnings, 'MIN_PERL_VERSION=foobar triggers a warning' );
106 is( $warnings, <<'END', ' with expected message text' );
107 Warning: MIN_PERL_VERSION is not in a recognized format.
108 Recommended is a quoted numerical value like '5.005' or '5.008001'.
111 is( $@, '', ' and without a hard failure' );
115 # ----- PREREQ_PRINT output -----
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' ) ||
124 skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane;
126 package _Prereq::Print::WithMPV; ## no critic
127 our($PREREQ_PM, $BUILD_REQUIRES, $MIN_PERL_VERSION, $ERR);
130 eval $prereq_out; ## no critic
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' );
140 # ----- PRINT_PREREQ output -----
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' );
146 qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/x,
147 'dump has prereqs and perl version' );
151 # ----- generated files verification -----
154 my @mpl_out = run(qq{$perl Makefile.PL});
155 END { unlink $makefile, makefile_backup() }
157 cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out);
158 ok( -e $makefile, 'Makefile present' );
162 # ----- ppd output -----
164 my $ppd_file = 'Min-PerlVers.ppd';
165 my @make_out = run(qq{$make ppd});
166 END { unlink $ppd_file }
168 cmp_ok( $?, '==', 0, 'Make ppd exiting normally' ) || diag(@make_out);
170 my $ppd_html = slurp($ppd_file);
171 ok( defined($ppd_html), ' .ppd file present' );
173 like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m,
174 ' .ppd file content good' );
178 # ----- META.yml output -----
180 my $distdir = 'Min-PerlVers-0.05';
181 $distdir =~ s{\.}{_}g if $Is_VMS;
183 my $meta_yml = "$distdir/META.yml";
184 my @make_out = run(qq{$make metafile});
185 END { rmtree $distdir }
187 cmp_ok( $?, '==', 0, 'Make metafile exiting normally' ) || diag(@make_out);
188 my $meta = slurp($meta_yml);
189 ok( defined($meta), ' META.yml present' );
191 like( $meta, qr{\nrequires:[^\S\n]*\n\s+perl:\s+5\.005\n\s+strict:\s+0\n},
192 ' META.yml content good');