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 warnings; 12 13use TieOut; 14use MakeMaker::Test::Utils; 15use Config; 16use ExtUtils::MM; 17use Test::More 18 !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'} 19 ? (skip_all => "cross-compiling and make not available") 20 : (tests => 35); 21use File::Path; 22 23use ExtUtils::MakeMaker; 24my $CM = eval { require CPAN::Meta; }; 25 26my $DIRNAME = 'Min-PerlVers'; 27my %FILES = ( 28 'Makefile.PL' => <<'END', 29use ExtUtils::MakeMaker; 30WriteMakefile( 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', 36); 37END 38 39 'lib/Min/PerlVers.pm' => <<'END', 40package Min::PerlVers; 41$VERSION = 0.05; 42 43=head1 NAME 44 45Min::PerlVers - being picky about perl versions 46 47=cut 48 491; 50END 51 52); 53 54# avoid environment variables interfering with our make runs 55delete @ENV{qw(PERL_JSON_BACKEND CPAN_META_JSON_BACKEND PERL_YAML_BACKEND)} if $ENV{PERL_CORE}; 56delete @ENV{qw(LIB MAKEFLAGS PERL_CORE)}; 57 58my $perl = which_perl(); 59my $make = make_run(); 60my $makefile = makefile_name(); 61 62chdir 't'; 63 64perl_lib(); 65 66hash2files($DIRNAME, \%FILES); 67END { 68 ok( chdir(File::Spec->updir), 'leaving dir' ); 69 ok( rmtree($DIRNAME), 'teardown' ); 70} 71 72ok( chdir 'Min-PerlVers', 'entering dir Min-PerlVers' ) || 73 diag("chdir failed: $!"); 74 75note "Argument verification"; { 76 my $stdout = tie *STDOUT, 'TieOut'; 77 ok( $stdout, 'capturing stdout' ); 78 my $warnings = ''; 79 local $SIG{__WARN__} = sub { 80 $warnings .= join '', @_; 81 }; 82 83 eval { 84 WriteMakefile( 85 NAME => 'Min::PerlVers', 86 MIN_PERL_VERSION => '5', 87 ); 88 }; 89 is( $warnings, '', 'MIN_PERL_VERSION=5 does not trigger a warning' ); 90 is( $@, '', ' nor a hard failure' ); 91 92 93 $warnings = ''; 94 eval { 95 WriteMakefile( 96 NAME => 'Min::PerlVers', 97 MIN_PERL_VERSION => '5.4.4', 98 ); 99 }; 100 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' ); 101 is( $@, '', ' nor a hard failure' ); 102 103 104 $warnings = ''; 105 eval { 106 WriteMakefile( 107 NAME => 'Min::PerlVers', 108 MIN_PERL_VERSION => 5.4.4, 109 ); 110 }; 111 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' ); 112 is( $@, '', ' nor a hard failure' ); 113 114 115 $warnings = ''; 116 eval { 117 WriteMakefile( 118 NAME => 'Min::PerlVers', 119 MIN_PERL_VERSION => v5.4.4, 120 ); 121 }; 122 is( $warnings, '', 'MIN_PERL_VERSION=X.Y.Z does not trigger a warning' ); 123 is( $@, '', ' nor a hard failure' ); 124 125 126 $warnings = ''; 127 eval { 128 WriteMakefile( 129 NAME => 'Min::PerlVers', 130 MIN_PERL_VERSION => '999999', 131 ); 132 }; 133 ok( '' ne $warnings, 'MIN_PERL_VERSION=999999 triggers a warning' ); 134 is( $warnings, 135 "Warning: Perl version 999999 or higher required. We run $].\n", 136 ' with expected message text' ); 137 is( $@, '', ' and without a hard failure' ); 138 139 $warnings = ''; 140 eval { 141 WriteMakefile( 142 NAME => 'Min::PerlVers', 143 MIN_PERL_VERSION => '999999', 144 PREREQ_FATAL => 1, 145 ); 146 }; 147 is( $warnings, '', 'MIN_PERL_VERSION=999999 and PREREQ_FATAL: no warning' ); 148 is( $@, <<"END", ' correct exception' ); 149MakeMaker FATAL: perl version too low for this distribution. 150Required is 999999. We run $]. 151END 152 153 $warnings = ''; 154 eval { 155 WriteMakefile( 156 NAME => 'Min::PerlVers', 157 MIN_PERL_VERSION => 'foobar', 158 ); 159 }; 160 is( $@, <<'END', 'Invalid MIN_PERL_VERSION is fatal' ); 161Warning: MIN_PERL_VERSION is not in a recognized format. 162Recommended is a quoted numerical value like '5.005' or '5.008001'. 163END 164 165} 166 167 168note "PREREQ_PRINT output"; { 169 my $prereq_out = run(qq{$perl Makefile.PL "PREREQ_PRINT=1"}); 170 is( $?, 0, 'PREREQ_PRINT exiting normally' ); 171 $prereq_out =~ s/.*(\$PREREQ_PM\s*=)/$1/s; # strip off errors eg from chcp 172 my $prereq_out_sane = $prereq_out =~ /^\s*\$PREREQ_PM\s*=/; 173 ok( $prereq_out_sane, ' and talking like we expect' ) || 174 diag($prereq_out); 175 176 SKIP: { 177 skip 'not going to evaluate rubbish', 3 if !$prereq_out_sane; 178 179 package _Prereq::Print::WithMPV; ## no critic 180 our($PREREQ_PM, $BUILD_REQUIRES, $MIN_PERL_VERSION, $ERR); 181 $BUILD_REQUIRES = undef; # suppress "used only once" 182 $ERR = ''; 183 eval { 184 eval $prereq_out; ## no critic 185 $ERR = $@; 186 }; 187 ::is( $@ . $ERR, '', 'prereqs evaluable' ); 188 ::is_deeply( $PREREQ_PM, { strict => 0 }, ' and looking correct' ); 189 ::is( $MIN_PERL_VERSION, '5.005', 'min version also correct' ); 190 } 191} 192 193 194note "PRINT_PREREQ output"; { 195 my $prereq_out = run(qq{$perl Makefile.PL "PRINT_PREREQ=1"}); 196 is( $?, 0, 'PRINT_PREREQ exiting normally' ); 197 ok( $prereq_out !~ /^warning/i, ' and not complaining loudly' ); 198 like( $prereq_out, 199 qr/^perl\(perl\) \s* >= 5\.005 \s+ perl\(strict\) \s* >= \s* 0 \s*$/mx, 200 'dump has prereqs and perl version' ); 201} 202 203 204note "generated files verification"; { 205 unlink $makefile; 206 my @mpl_out = run(qq{$perl Makefile.PL}); 207 END { unlink $makefile, makefile_backup() } 208 209 cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out); 210 ok( -e $makefile, 'Makefile present' ); 211} 212 213 214note "ppd output"; { 215 my $ppd_file = 'Min-PerlVers.ppd'; 216 my @make_out = run(qq{$make ppd}); 217 END { unlink $ppd_file } 218 219 cmp_ok( $?, '==', 0, 'Make ppd exiting normally' ) || diag(@make_out); 220 221 my $ppd_html = slurp($ppd_file); 222 ok( defined($ppd_html), ' .ppd file present' ); 223 224 like( $ppd_html, qr{^\s*<PERLCORE VERSION="5,005,0,0" />}m, 225 ' .ppd file content good' ); 226} 227 228 229note "META.yml output"; SKIP: { 230 skip 'Failed to load CPAN::Meta', 4 unless $CM; 231 my $distdir = 'Min-PerlVers-0.05'; 232 $distdir =~ s{\.}{_}g if $Is_VMS; 233 234 my $meta_yml = "$distdir/META.yml"; 235 my $meta_json = "$distdir/META.json"; 236 my @make_out = run(qq{$make metafile}); 237 END { rmtree $distdir if defined $distdir } 238 239 for my $case ( 240 ['META.yml', $meta_yml], 241 ['META.json', $meta_json], 242 ) { 243 my ($label, $meta_name) = @$case; 244 ok( 245 my $obj = eval { 246 CPAN::Meta->load_file($meta_name, {lazy_validation => 0}) 247 }, 248 "$label validates" 249 ); 250 is( $obj->prereqs->{runtime}{requires}{perl}, '5.005', 251 "$label has runtime/requires perl 5.005" 252 ); 253 } 254} 255