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