1#!/usr/bin/perl -w 2 3# This is a test of the verification of the arguments to 4# WriteMakefile. 5 6BEGIN { 7 unshift @INC, 't/lib'; 8} 9 10use strict; 11use Config; 12use Test::More tests => 21; 13use File::Temp qw[tempdir]; 14 15use TieOut; 16use MakeMaker::Test::Utils; 17use MakeMaker::Test::Setup::BFD; 18 19use ExtUtils::MakeMaker; 20 21chdir 't'; 22perl_lib; # sets $ENV{PERL5LIB} relative to t/ 23 24my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 ); 25use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup 26chdir $tmpdir; 27 28ok( setup_recurs(), 'setup' ); 29END { 30 ok( chdir File::Spec->updir, 'chdir updir' ); 31 ok( teardown_recurs(), 'teardown' ); 32} 33 34ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || 35 diag("chdir failed: $!"); 36 37{ 38 ok my $stdout = tie(*STDOUT, 'TieOut'), 'tie STDOUT'; 39 my $warnings = ''; 40 local $SIG{__WARN__} = sub { 41 if ( $Config{usecrosscompile} ) { 42 # libraries might not be present on the target system 43 # when cross-compiling 44 return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/ 45 } 46 $warnings .= join '', @_; 47 }; 48 # prerequisite warnings are disabled while building the perl core: 49 local $ExtUtils::MakeMaker::UNDER_CORE = 0; 50 51 WriteMakefile( 52 NAME => 'Big::Dummy', 53 PREREQ_PM => { 54 strict => 0 55 } 56 ); 57 is $warnings, '', 'basic prereq'; 58 59 SKIP: { 60 skip 'No CMR, no version ranges', 1 61 unless ExtUtils::MakeMaker::_has_cpan_meta_requirements; 62 $warnings = ''; 63 WriteMakefile( 64 NAME => 'Big::Dummy', 65 PREREQ_PM => { 66 strict => '>= 0, <= 99999', 67 } 68 ); 69 is $warnings, '', 'version range'; 70 } 71 72 $warnings = ''; 73 WriteMakefile( 74 NAME => 'Big::Dummy', 75 PREREQ_PM => { 76 strict => 99999 77 } 78 ); 79 is $warnings, 80 sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n", 81 $strict::VERSION), 'strict 99999'; 82 83 $warnings = ''; 84 WriteMakefile( 85 NAME => 'Big::Dummy', 86 PREREQ_PM => { 87 "I::Do::Not::Exist" => 0, 88 } 89 ); 90 is $warnings, 91 "Warning: prerequisite I::Do::Not::Exist 0 not found.\n", 'non-exist prereq'; 92 93 $warnings = ''; 94 WriteMakefile( 95 NAME => 'Big::Dummy', 96 CONFIGURE_REQUIRES => { 97 "I::Do::Not::Configure" => 0, 98 } 99 ); 100 is $warnings, 101 "Warning: prerequisite I::Do::Not::Configure 0 not found.\n", 'non-exist prereq'; 102 103 $warnings = ''; 104 WriteMakefile( 105 NAME => 'Big::Dummy', 106 TEST_REQUIRES => { 107 "I::Do::Not::Test" => 0, 108 } 109 ); 110 is $warnings, 111 "Warning: prerequisite I::Do::Not::Test 0 not found.\n", 'non-exist prereq'; 112 113 114 $warnings = ''; 115 WriteMakefile( 116 NAME => 'Big::Dummy', 117 PREREQ_PM => { 118 "I::Do::Not::Exist" => "", 119 } 120 ); 121 my @warnings = split /\n/, $warnings; 122 is @warnings, 2, '2 warnings'; 123 like $warnings[0], qr{^Undefined requirement for I::Do::Not::Exist\b}, 'undef version warning'; 124 is $warnings[1], "Warning: prerequisite I::Do::Not::Exist 0 not found.", 'not found warning'; 125 126 127 $warnings = ''; 128 WriteMakefile( 129 NAME => 'Big::Dummy', 130 PREREQ_PM => { 131 "I::Do::Not::Exist" => 0, 132 "strict" => 99999, 133 } 134 ); 135 is $warnings, 136 "Warning: prerequisite I::Do::Not::Exist 0 not found.\n". 137 sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n", 138 $strict::VERSION), '2 bad prereq warnings'; 139 140 $warnings = ''; 141 eval { 142 WriteMakefile( 143 NAME => 'Big::Dummy', 144 PREREQ_PM => { 145 "I::Do::Not::Exist" => 0, 146 "Nor::Do::I" => 0, 147 "strict" => 99999, 148 }, 149 PREREQ_FATAL => 1, 150 ); 151 }; 152 153 is $warnings, '', 'no warnings on PREREQ_FATAL'; 154 is $@, <<'END', "PREREQ_FATAL"; 155MakeMaker FATAL: prerequisites not found. 156 I::Do::Not::Exist not installed 157 Nor::Do::I not installed 158 strict 99999 159 160Please install these modules first and rerun 'perl Makefile.PL'. 161END 162 163 164 $warnings = ''; 165 eval { 166 WriteMakefile( 167 NAME => 'Big::Dummy', 168 PREREQ_PM => { 169 "I::Do::Not::Exist" => 0, 170 }, 171 CONFIGURE => sub { 172 require I::Do::Not::Exist; 173 }, 174 PREREQ_FATAL => 1, 175 ); 176 }; 177 178 is $warnings, '', 'CONFIGURE sub non-exist req no warn'; 179 is $@, <<'END', "PREREQ_FATAL happens before CONFIGURE"; 180MakeMaker FATAL: prerequisites not found. 181 I::Do::Not::Exist not installed 182 183Please install these modules first and rerun 'perl Makefile.PL'. 184END 185 186 187 $warnings = ''; 188 @ARGV = 'PREREQ_FATAL=1'; 189 eval { 190 WriteMakefile( 191 NAME => 'Big::Dummy', 192 PREREQ_PM => { "I::Do::Not::Exist" => 0, }, 193 ); 194 }; 195 is $warnings, "Warning: prerequisite I::Do::Not::Exist 0 not found.\n", 196 'CLI PREREQ_FATAL warns'; 197 isnt $@, '', "CLI PREREQ_FATAL works"; 198 199} 200