1b39c5158Smillert#!/usr/bin/perl -w 2b39c5158Smillert 3b39c5158Smillert# This is a test of the verification of the arguments to 4b39c5158Smillert# WriteMakefile. 5b39c5158Smillert 6b39c5158SmillertBEGIN { 7b39c5158Smillert unshift @INC, 't/lib'; 8b39c5158Smillert} 9b39c5158Smillert 10b39c5158Smillertuse strict; 11*eac174f2Safresh1use warnings; 12b8851fccSafresh1use Config; 136fb12b70Safresh1use Test::More tests => 43; 14b39c5158Smillert 15b39c5158Smillertuse TieOut; 16b39c5158Smillertuse MakeMaker::Test::Utils; 17b39c5158Smillertuse MakeMaker::Test::Setup::BFD; 18b39c5158Smillert 19b39c5158Smillertuse ExtUtils::MakeMaker; 20b39c5158Smillert 219f11ffb7Safresh1chdir 't'; 229f11ffb7Safresh1perl_lib; # sets $ENV{PERL5LIB} relative to t/ 23b39c5158Smillert 249f11ffb7Safresh1use File::Temp qw[tempdir]; 259f11ffb7Safresh1my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 ); 269f11ffb7Safresh1use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup 279f11ffb7Safresh1chdir $tmpdir; 28b39c5158Smillert 29b39c5158Smillertok( setup_recurs(), 'setup' ); 30b39c5158SmillertEND { 31b39c5158Smillert ok( chdir File::Spec->updir ); 32b39c5158Smillert ok( teardown_recurs(), 'teardown' ); 33b39c5158Smillert} 34b39c5158Smillert 35b39c5158Smillertok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || 36b39c5158Smillert diag("chdir failed: $!"); 37b39c5158Smillert 38b39c5158Smillert{ 39b39c5158Smillert ok( my $stdout = tie *STDOUT, 'TieOut' ); 40b39c5158Smillert my $warnings = ''; 41b39c5158Smillert local $SIG{__WARN__} = sub { 42b8851fccSafresh1 if ( $Config{usecrosscompile} ) { 43b8851fccSafresh1 # libraries might not be present on the target system 44b8851fccSafresh1 # when cross-compiling 45b8851fccSafresh1 return if $_[0] =~ /\A\QWarning (mostly harmless): No library found for \E.+/ 46b8851fccSafresh1 } 47b39c5158Smillert $warnings .= join '', @_; 48b39c5158Smillert }; 49b39c5158Smillert 50b39c5158Smillert my $mm; 51b39c5158Smillert 52b39c5158Smillert eval { 53b39c5158Smillert $mm = WriteMakefile( 54b39c5158Smillert NAME => 'Big::Dummy', 55b39c5158Smillert VERSION_FROM => 'lib/Big/Dummy.pm', 56b39c5158Smillert MAN3PODS => ' ', # common mistake 57b39c5158Smillert ); 58b39c5158Smillert }; 59b39c5158Smillert 60b39c5158Smillert is( $warnings, <<VERIFY ); 61b39c5158SmillertWARNING: MAN3PODS takes a HASH reference not a string/number. 62b39c5158Smillert Please inform the author. 63b39c5158SmillertVERIFY 64b39c5158Smillert 65b39c5158Smillert $warnings = ''; 66b39c5158Smillert eval { 67b39c5158Smillert $mm = WriteMakefile( 68b39c5158Smillert NAME => 'Big::Dummy', 69b39c5158Smillert VERSION_FROM => 'lib/Big/Dummy.pm', 70b39c5158Smillert AUTHOR => sub {}, 71b39c5158Smillert ); 72b39c5158Smillert }; 73b39c5158Smillert 74b39c5158Smillert is( $warnings, <<VERIFY ); 75898184e3SsthenWARNING: AUTHOR takes a ARRAY reference not a CODE reference. 76b39c5158Smillert Please inform the author. 77b39c5158SmillertVERIFY 78b39c5158Smillert 79b39c5158Smillert # LIBS accepts *both* a string or an array ref. The first cut of 80b39c5158Smillert # our verification did not take this into account. 81b39c5158Smillert $warnings = ''; 82b39c5158Smillert $mm = WriteMakefile( 83b39c5158Smillert NAME => 'Big::Dummy', 84b39c5158Smillert VERSION_FROM => 'lib/Big/Dummy.pm', 85b39c5158Smillert LIBS => '-lwibble -lwobble', 86b39c5158Smillert ); 87b39c5158Smillert 88b39c5158Smillert # We'll get warnings about the bogus libs, that's ok. 89b39c5158Smillert unlike( $warnings, qr/WARNING: .* takes/ ); 90b39c5158Smillert is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'] ); 91b39c5158Smillert 92b39c5158Smillert $warnings = ''; 93b39c5158Smillert $mm = WriteMakefile( 94b39c5158Smillert NAME => 'Big::Dummy', 95b39c5158Smillert VERSION_FROM => 'lib/Big/Dummy.pm', 96b39c5158Smillert LIBS => ['-lwibble', '-lwobble'], 97b39c5158Smillert ); 98b39c5158Smillert 99b39c5158Smillert # We'll get warnings about the bogus libs, that's ok. 100b39c5158Smillert unlike( $warnings, qr/WARNING: .* takes/ ); 101b39c5158Smillert is_deeply( $mm->{LIBS}, ['-lwibble', '-lwobble'] ); 102b39c5158Smillert 103b39c5158Smillert $warnings = ''; 104b39c5158Smillert eval { 105b39c5158Smillert $mm = WriteMakefile( 106b39c5158Smillert NAME => 'Big::Dummy', 107b39c5158Smillert VERSION_FROM => 'lib/Big/Dummy.pm', 108b39c5158Smillert LIBS => { wibble => "wobble" }, 109b39c5158Smillert ); 110b39c5158Smillert }; 111b39c5158Smillert 112b39c5158Smillert # We'll get warnings about the bogus libs, that's ok. 113b39c5158Smillert like( $warnings, qr{^WARNING: LIBS takes a ARRAY reference or string/number not a HASH reference}m ); 114b39c5158Smillert 115b39c5158Smillert 116b39c5158Smillert $warnings = ''; 117b39c5158Smillert $mm = WriteMakefile( 118b39c5158Smillert NAME => 'Big::Dummy', 119b39c5158Smillert WIBBLE => 'something', 120b39c5158Smillert wump => { foo => 42 }, 121b39c5158Smillert ); 122b39c5158Smillert 123b39c5158Smillert like( $warnings, qr{^WARNING: WIBBLE is not a known parameter.\n}m ); 124b39c5158Smillert like( $warnings, qr{^WARNING: wump is not a known parameter.\n}m ); 125b39c5158Smillert 126b39c5158Smillert is( $mm->{WIBBLE}, 'something' ); 127b39c5158Smillert is_deeply( $mm->{wump}, { foo => 42 } ); 128b39c5158Smillert 129b39c5158Smillert 130b39c5158Smillert # Test VERSION 131b39c5158Smillert $warnings = ''; 132b39c5158Smillert eval { 133b39c5158Smillert $mm = WriteMakefile( 134b39c5158Smillert NAME => 'Big::Dummy', 135b39c5158Smillert VERSION => [1,2,3], 136b39c5158Smillert ); 137b39c5158Smillert }; 138b39c5158Smillert like( $warnings, qr{^WARNING: VERSION takes a version object or string/number} ); 139b39c5158Smillert 140b39c5158Smillert $warnings = ''; 141b39c5158Smillert eval { 142b39c5158Smillert $mm = WriteMakefile( 143b39c5158Smillert NAME => 'Big::Dummy', 144b39c5158Smillert VERSION => 1.002_003, 145b39c5158Smillert ); 146b39c5158Smillert }; 147b39c5158Smillert is( $warnings, '' ); 148b39c5158Smillert is( $mm->{VERSION}, '1.002003' ); 149b39c5158Smillert 150b39c5158Smillert $warnings = ''; 151b39c5158Smillert eval { 152b39c5158Smillert $mm = WriteMakefile( 153b39c5158Smillert NAME => 'Big::Dummy', 154b39c5158Smillert VERSION => '1.002_003', 155b39c5158Smillert ); 156b39c5158Smillert }; 157b39c5158Smillert is( $warnings, '' ); 158b39c5158Smillert is( $mm->{VERSION}, '1.002_003' ); 159b39c5158Smillert 160b39c5158Smillert 161b39c5158Smillert $warnings = ''; 162b39c5158Smillert eval { 163b39c5158Smillert $mm = WriteMakefile( 164b39c5158Smillert NAME => 'Big::Dummy', 165b39c5158Smillert VERSION => bless {}, "Some::Class", 166b39c5158Smillert ); 167b39c5158Smillert }; 168b39c5158Smillert like( $warnings, '/^WARNING: VERSION takes a version object or string/number not a Some::Class object/' ); 169b39c5158Smillert 170b39c5158Smillert 171b39c5158Smillert SKIP: { 172b39c5158Smillert skip("Can't test version objects", 8) unless eval { require version }; 173b39c5158Smillert version->import; 174b39c5158Smillert 175b39c5158Smillert my $version = version->new("1.2.3"); 176b39c5158Smillert $warnings = ''; 177b39c5158Smillert ok eval { 178b39c5158Smillert $mm = WriteMakefile( 179b39c5158Smillert NAME => 'Big::Dummy', 180b39c5158Smillert VERSION => $version, 181b39c5158Smillert ); 182b39c5158Smillert } || diag $@; 183b39c5158Smillert is( $warnings, '' ); 184b39c5158Smillert isa_ok( $mm->{VERSION}, 'version' ); 185b39c5158Smillert is( $mm->{VERSION}, $version ); 186b39c5158Smillert 187b39c5158Smillert $warnings = ''; 188b39c5158Smillert $version = qv('1.2.3'); 189b39c5158Smillert ok eval { 190b39c5158Smillert $mm = WriteMakefile( 191b39c5158Smillert NAME => 'Big::Dummy', 192b39c5158Smillert VERSION => $version, 193b39c5158Smillert ); 194b39c5158Smillert } || diag $@; 195b39c5158Smillert is( $warnings, '' ); 196b39c5158Smillert isa_ok( $mm->{VERSION}, 'version' ); 197b39c5158Smillert is( $mm->{VERSION}, $version ); 198b39c5158Smillert } 199b39c5158Smillert 200b39c5158Smillert 201b39c5158Smillert # DISTNAME 202b39c5158Smillert $warnings = ''; 203b39c5158Smillert eval { 204b39c5158Smillert $mm = WriteMakefile( 205b39c5158Smillert NAME => 'Big::Dummy', 206b39c5158Smillert VERSION => '1.00', 207b39c5158Smillert DISTNAME => "Hooballa", 208b39c5158Smillert ); 209b39c5158Smillert }; 210b39c5158Smillert is( $warnings, '' ); 211b39c5158Smillert is( $mm->{DISTNAME}, "Hooballa" ); 212b39c5158Smillert is( $mm->{DISTVNAME}, $Is_VMS ? "Hooballa-1_00" : "Hooballa-1.00" ); 213b39c5158Smillert 214b39c5158Smillert 215b39c5158Smillert # DISTVNAME (rt.cpan.org 43217) 216b39c5158Smillert $warnings = ''; 217b39c5158Smillert eval { 218b39c5158Smillert $mm = WriteMakefile( 219b39c5158Smillert NAME => 'Big::Dummy', 220b39c5158Smillert VERSION => 1.00, 221b39c5158Smillert DISTVNAME => "Hooballoo", 222b39c5158Smillert ); 223b39c5158Smillert }; 224b39c5158Smillert is( $warnings, '' ); 225b39c5158Smillert is( $mm->{DISTVNAME}, 'Hooballoo' ); 226898184e3Ssthen 227898184e3Ssthen 228898184e3Ssthen # AUTHOR / scalar 229898184e3Ssthen $warnings = ''; 230898184e3Ssthen eval { 231898184e3Ssthen $mm = WriteMakefile( 232898184e3Ssthen NAME => 'Big::Dummy', 233898184e3Ssthen VERSION => '1.00', 234898184e3Ssthen AUTHOR => "test", 235898184e3Ssthen ); 236898184e3Ssthen }; 237898184e3Ssthen is( $warnings, '' ); 238898184e3Ssthen is_deeply( $mm->{AUTHOR}, ["test"] ); 239898184e3Ssthen 240898184e3Ssthen 241898184e3Ssthen # AUTHOR / array 242898184e3Ssthen $warnings = ''; 243898184e3Ssthen eval { 244898184e3Ssthen $mm = WriteMakefile( 245898184e3Ssthen NAME => 'Big::Dummy', 246898184e3Ssthen VERSION => '1.00', 247898184e3Ssthen AUTHOR => ["test1", "test2"], 248898184e3Ssthen ); 249898184e3Ssthen }; 250898184e3Ssthen is( $warnings, '' ); 251898184e3Ssthen is_deeply( $mm->{AUTHOR}, ["test1","test2"] ); 252898184e3Ssthen 2536fb12b70Safresh1 # PERL_MM_OPT 2546fb12b70Safresh1 { 2556fb12b70Safresh1 local $ENV{PERL_MM_OPT} = 'CCFLAGS="-Wl,-rpath -Wl,/foo/bar/lib" LIBS="-lwibble -lwobble"'; 2566fb12b70Safresh1 $mm = WriteMakefile( 2576fb12b70Safresh1 NAME => 'Big::Dummy', 2586fb12b70Safresh1 VERSION => '1.00', 2596fb12b70Safresh1 ); 2606fb12b70Safresh1 2616fb12b70Safresh1 like( $mm->{CCFLAGS}, qr{-Wl,-rpath -Wl,/foo/bar/lib}, 'parse_args() splits like shell' ); 2626fb12b70Safresh1 is_deeply( $mm->{LIBS}, ['-lwibble -lwobble'], 'parse_args() splits like shell' ); 2636fb12b70Safresh1 } 2646fb12b70Safresh1 2656fb12b70Safresh1 # PERL_MM_OPT 2666fb12b70Safresh1 { 2676fb12b70Safresh1 local $ENV{PERL_MM_OPT} = 'INSTALL_BASE=/how/we/have/not/broken/local/lib'; 2686fb12b70Safresh1 $mm = WriteMakefile( 2696fb12b70Safresh1 NAME => 'Big::Dummy', 2706fb12b70Safresh1 VERSION => '1.00', 2716fb12b70Safresh1 ); 2726fb12b70Safresh1 2736fb12b70Safresh1 is( $mm->{INSTALL_BASE}, "/how/we/have/not/broken/local/lib", 'parse_args() splits like shell' ); 2746fb12b70Safresh1 } 2756fb12b70Safresh1 2766fb12b70Safresh1 # PERL_MM_OPT 2776fb12b70Safresh1 { 2786fb12b70Safresh1 local $ENV{PERL_MM_OPT} = 'INSTALL_BASE="/Users/miyagawa/tmp/car1 foo/foo bar"'; 2796fb12b70Safresh1 $mm = WriteMakefile( 2806fb12b70Safresh1 NAME => 'Big::Dummy', 2816fb12b70Safresh1 VERSION => '1.00', 2826fb12b70Safresh1 ); 2836fb12b70Safresh1 2846fb12b70Safresh1 is( $mm->{INSTALL_BASE}, "/Users/miyagawa/tmp/car1 foo/foo bar", 'parse_args() splits like shell' ); 2856fb12b70Safresh1 } 2866fb12b70Safresh1 287b39c5158Smillert} 288