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