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 warnings; 12use Config; 13use Test::More tests => 43; 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 24use File::Temp qw[tempdir]; 25my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 ); 26use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup 27chdir $tmpdir; 28 29ok( setup_recurs(), 'setup' ); 30END { 31 ok( chdir File::Spec->updir ); 32 ok( teardown_recurs(), 'teardown' ); 33} 34 35ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || 36 diag("chdir failed: $!"); 37 38{ 39 ok( my $stdout = tie *STDOUT, 'TieOut' ); 40 my $warnings = ''; 41 local $SIG{__WARN__} = sub { 42 if ( $Config{usecrosscompile} ) { 43 # libraries might not be present on the target system 44 # when cross-compiling 45 return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/ 46 } 47 $warnings .= join '', @_; 48 }; 49 50 my $mm; 51 52 eval { 53 $mm = WriteMakefile( 54 NAME => 'Big::Dummy', 55 VERSION_FROM => 'lib/Big/Dummy.pm', 56 MAN3PODS => ' ', # common mistake 57 ); 58 }; 59 60 is( $warnings, <<VERIFY ); 61WARNING: MAN3PODS takes a HASH reference not a string/number. 62 Please inform the author. 63VERIFY 64 65 $warnings = ''; 66 eval { 67 $mm = WriteMakefile( 68 NAME => 'Big::Dummy', 69 VERSION_FROM => 'lib/Big/Dummy.pm', 70 AUTHOR => sub {}, 71 ); 72 }; 73 74 is( $warnings, <<VERIFY ); 75WARNING: AUTHOR takes a ARRAY reference not a CODE reference. 76 Please inform the author. 77VERIFY 78 79 # LIBS accepts *both* a string or an array ref. The first cut of 80 # our verification did not take this into account. 81 $warnings = ''; 82 $mm = WriteMakefile( 83 NAME => 'Big::Dummy', 84 VERSION_FROM => 'lib/Big/Dummy.pm', 85 LIBS => '-lwibble -lwobble', 86 ); 87 88 # We'll get warnings about the bogus libs, that's ok. 89 unlike( $warnings, qr/WARNING: .* takes/ ); 90 is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'] ); 91 92 $warnings = ''; 93 $mm = WriteMakefile( 94 NAME => 'Big::Dummy', 95 VERSION_FROM => 'lib/Big/Dummy.pm', 96 LIBS => ['-lwibble', '-lwobble'], 97 ); 98 99 # We'll get warnings about the bogus libs, that's ok. 100 unlike( $warnings, qr/WARNING: .* takes/ ); 101 is_deeply( $mm->{LIBS}, ['-lwibble', '-lwobble'] ); 102 103 $warnings = ''; 104 eval { 105 $mm = WriteMakefile( 106 NAME => 'Big::Dummy', 107 VERSION_FROM => 'lib/Big/Dummy.pm', 108 LIBS => { wibble => "wobble" }, 109 ); 110 }; 111 112 # We'll get warnings about the bogus libs, that's ok. 113 like( $warnings, qr{^WARNING: LIBS takes a ARRAY reference or string/number not a HASH reference}m ); 114 115 116 $warnings = ''; 117 $mm = WriteMakefile( 118 NAME => 'Big::Dummy', 119 WIBBLE => 'something', 120 wump => { foo => 42 }, 121 ); 122 123 like( $warnings, qr{^WARNING: WIBBLE is not a known parameter.\n}m ); 124 like( $warnings, qr{^WARNING: wump is not a known parameter.\n}m ); 125 126 is( $mm->{WIBBLE}, 'something' ); 127 is_deeply( $mm->{wump}, { foo => 42 } ); 128 129 130 # Test VERSION 131 $warnings = ''; 132 eval { 133 $mm = WriteMakefile( 134 NAME => 'Big::Dummy', 135 VERSION => [1,2,3], 136 ); 137 }; 138 like( $warnings, qr{^WARNING: VERSION takes a version object or string/number} ); 139 140 $warnings = ''; 141 eval { 142 $mm = WriteMakefile( 143 NAME => 'Big::Dummy', 144 VERSION => 1.002_003, 145 ); 146 }; 147 is( $warnings, '' ); 148 is( $mm->{VERSION}, '1.002003' ); 149 150 $warnings = ''; 151 eval { 152 $mm = WriteMakefile( 153 NAME => 'Big::Dummy', 154 VERSION => '1.002_003', 155 ); 156 }; 157 is( $warnings, '' ); 158 is( $mm->{VERSION}, '1.002_003' ); 159 160 161 $warnings = ''; 162 eval { 163 $mm = WriteMakefile( 164 NAME => 'Big::Dummy', 165 VERSION => bless {}, "Some::Class", 166 ); 167 }; 168 like( $warnings, '/^WARNING: VERSION takes a version object or string/number not a Some::Class object/' ); 169 170 171 SKIP: { 172 skip("Can't test version objects", 8) unless eval { require version }; 173 version->import; 174 175 my $version = version->new("1.2.3"); 176 $warnings = ''; 177 ok eval { 178 $mm = WriteMakefile( 179 NAME => 'Big::Dummy', 180 VERSION => $version, 181 ); 182 } || diag $@; 183 is( $warnings, '' ); 184 isa_ok( $mm->{VERSION}, 'version' ); 185 is( $mm->{VERSION}, $version ); 186 187 $warnings = ''; 188 $version = qv('1.2.3'); 189 ok eval { 190 $mm = WriteMakefile( 191 NAME => 'Big::Dummy', 192 VERSION => $version, 193 ); 194 } || diag $@; 195 is( $warnings, '' ); 196 isa_ok( $mm->{VERSION}, 'version' ); 197 is( $mm->{VERSION}, $version ); 198 } 199 200 201 # DISTNAME 202 $warnings = ''; 203 eval { 204 $mm = WriteMakefile( 205 NAME => 'Big::Dummy', 206 VERSION => '1.00', 207 DISTNAME => "Hooballa", 208 ); 209 }; 210 is( $warnings, '' ); 211 is( $mm->{DISTNAME}, "Hooballa" ); 212 is( $mm->{DISTVNAME}, $Is_VMS ? "Hooballa-1_00" : "Hooballa-1.00" ); 213 214 215 # DISTVNAME (rt.cpan.org 43217) 216 $warnings = ''; 217 eval { 218 $mm = WriteMakefile( 219 NAME => 'Big::Dummy', 220 VERSION => 1.00, 221 DISTVNAME => "Hooballoo", 222 ); 223 }; 224 is( $warnings, '' ); 225 is( $mm->{DISTVNAME}, 'Hooballoo' ); 226 227 228 # AUTHOR / scalar 229 $warnings = ''; 230 eval { 231 $mm = WriteMakefile( 232 NAME => 'Big::Dummy', 233 VERSION => '1.00', 234 AUTHOR => "test", 235 ); 236 }; 237 is( $warnings, '' ); 238 is_deeply( $mm->{AUTHOR}, ["test"] ); 239 240 241 # AUTHOR / array 242 $warnings = ''; 243 eval { 244 $mm = WriteMakefile( 245 NAME => 'Big::Dummy', 246 VERSION => '1.00', 247 AUTHOR => ["test1", "test2"], 248 ); 249 }; 250 is( $warnings, '' ); 251 is_deeply( $mm->{AUTHOR}, ["test1","test2"] ); 252 253 # PERL_MM_OPT 254 { 255 local $ENV{PERL_MM_OPT} = 'CCFLAGS="-Wl,-rpath -Wl,/foo/bar/lib" LIBS="-lwibble -lwobble"'; 256 $mm = WriteMakefile( 257 NAME => 'Big::Dummy', 258 VERSION => '1.00', 259 ); 260 261 like( $mm->{CCFLAGS}, qr{-Wl,-rpath -Wl,/foo/bar/lib}, 'parse_args() splits like shell' ); 262 is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'], 'parse_args() splits like shell' ); 263 } 264 265 # PERL_MM_OPT 266 { 267 local $ENV{PERL_MM_OPT} = 'INSTALL_BASE=/how/we/have/not/broken/local/lib'; 268 $mm = WriteMakefile( 269 NAME => 'Big::Dummy', 270 VERSION => '1.00', 271 ); 272 273 is( $mm->{INSTALL_BASE}, "/how/we/have/not/broken/local/lib", 'parse_args() splits like shell' ); 274 } 275 276 # PERL_MM_OPT 277 { 278 local $ENV{PERL_MM_OPT} = 'INSTALL_BASE="/Users/miyagawa/tmp/car1 foo/foo bar"'; 279 $mm = WriteMakefile( 280 NAME => 'Big::Dummy', 281 VERSION => '1.00', 282 ); 283 284 is( $mm->{INSTALL_BASE}, "/Users/miyagawa/tmp/car1 foo/foo bar", 'parse_args() splits like shell' ); 285 } 286 287} 288