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