1#!/usr/bin/perl -w 2 3# This test puts MakeMaker through the paces of a basic perl module 4# build, test and installation of the Big::Fat::Dummy module. 5 6BEGIN { 7 unshift @INC, 't/lib'; 8} 9 10use strict; 11use Config; 12use ExtUtils::MakeMaker; 13 14use Test::More 15 $ENV{PERL_CORE} && $Config{'usecrosscompile'} 16 ? (skip_all => "no toolchain installed when cross-compiling") 17 : (tests => 171); 18use MakeMaker::Test::Utils; 19use MakeMaker::Test::Setup::BFD; 20use File::Find; 21use File::Spec; 22use File::Path; 23use File::Temp qw[tempdir]; 24 25my $perl = which_perl(); 26my $Is_VMS = $^O eq 'VMS'; 27 28my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 ); 29chdir $tmpdir; 30 31perl_lib; 32 33my $Touch_Time = calibrate_mtime(); 34 35$| = 1; 36 37ok( setup_recurs(), 'setup' ); 38END { 39 ok chdir File::Spec->updir or die; 40 ok teardown_recurs, "teardown"; 41} 42 43ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) || 44 diag("chdir failed: $!"); 45 46my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"}); 47END { rmtree '../dummy-install'; } 48 49cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || 50 diag(@mpl_out); 51 52my $makefile = makefile_name(); 53ok( grep(/^Writing $makefile for Big::Dummy/, 54 @mpl_out) == 1, 55 'Makefile.PL output looks right'); 56 57ok( grep(/^Current package is: main$/, 58 @mpl_out) == 1, 59 'Makefile.PL run in package main'); 60 61ok( -e $makefile, 'Makefile exists' ); 62 63# -M is flakey on VMS 64my $mtime = (stat($makefile))[9]; 65cmp_ok( $Touch_Time, '<=', $mtime, ' its been touched' ); 66 67END { unlink makefile_name(), makefile_backup() } 68 69my $make = make_run(); 70 71{ 72 # Supress 'make manifest' noise 73 local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0; 74 my $manifest_out = run("$make manifest"); 75 ok( -e 'MANIFEST', 'make manifest created a MANIFEST' ); 76 ok( -s 'MANIFEST', ' its not empty' ); 77} 78 79END { unlink 'MANIFEST'; } 80 81my $ppd_out = run("$make ppd"); 82is( $?, 0, ' exited normally' ) || diag $ppd_out; 83ok( open(PPD, 'Big-Dummy.ppd'), ' .ppd file generated' ); 84my $ppd_html; 85{ local $/; $ppd_html = <PPD> } 86close PPD; 87like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0.01">}m, 88 ' <SOFTPKG>' ); 89like( $ppd_html, 90 qr{^\s*<ABSTRACT>Try "our" hot dog's, \$andwiche\$ and \$\(ub\)\$!</ABSTRACT>}m, 91 ' <ABSTRACT>'); 92like( $ppd_html, 93 qr{^\s*<AUTHOR>Michael G Schwern <schwern\@pobox.com></AUTHOR>}m, 94 ' <AUTHOR>' ); 95like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m, ' <IMPLEMENTATION>'); 96like( $ppd_html, qr{^\s*<REQUIRE NAME="strict::" />}m, ' <REQUIRE>' ); 97unlike( $ppd_html, qr{^\s*<REQUIRE NAME="warnings::" />}m, 'no <REQUIRE> for build_require' ); 98 99my $archname = $Config{archname}; 100if( $] >= 5.008 ) { 101 # XXX This is a copy of the internal logic, so it's not a great test 102 $archname .= "-$Config{PERL_REVISION}.$Config{PERL_VERSION}"; 103} 104like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$archname" />}m, 105 ' <ARCHITECTURE>'); 106like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m, ' <CODEBASE>'); 107like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m, ' </IMPLEMENTATION>'); 108like( $ppd_html, qr{^\s*</SOFTPKG>}m, ' </SOFTPKG>'); 109END { unlink 'Big-Dummy.ppd' } 110 111 112my $test_out = run("$make test"); 113like( $test_out, qr/All tests successful/, 'make test' ); 114is( $?, 0, ' exited normally' ) || 115 diag $test_out; 116 117# Test 'make test TEST_VERBOSE=1' 118my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1); 119$test_out = run("$make_test_verbose"); 120like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' ); 121like( $test_out, qr/All tests successful/, ' successful' ); 122is( $?, 0, ' exited normally' ) || 123 diag $test_out; 124 125 126my $install_out = run("$make install"); 127is( $?, 0, 'install' ) || diag $install_out; 128like( $install_out, qr/^Installing /m ); 129 130ok( -r '../dummy-install', ' install dir created' ); 131my %files = (); 132find( sub { 133 # do it case-insensitive for non-case preserving OSs 134 my $file = lc $_; 135 136 # VMS likes to put dots on the end of things that don't have them. 137 $file =~ s/\.$// if $Is_VMS; 138 139 $files{$file} = $File::Find::name; 140}, '../dummy-install' ); 141ok( $files{'dummy.pm'}, ' Dummy.pm installed' ); 142ok( $files{'liar.pm'}, ' Liar.pm installed' ); 143ok( $files{'program'}, ' program installed' ); 144ok( $files{'.packlist'}, ' packlist created' ); 145ok( $files{'perllocal.pod'},' perllocal.pod created' ); 146 147 148SKIP: { 149 skip 'VMS install targets do not preserve $(PREFIX)', 8 if $Is_VMS; 150 151 $install_out = run("$make install PREFIX=elsewhere"); 152 is( $?, 0, 'install with PREFIX override' ) || diag $install_out; 153 like( $install_out, qr/^Installing /m ); 154 155 ok( -r 'elsewhere', ' install dir created' ); 156 %files = (); 157 find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' ); 158 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 159 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 160 ok( $files{'program'}, ' program installed' ); 161 ok( $files{'.packlist'}, ' packlist created' ); 162 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 163 rmtree('elsewhere'); 164} 165 166 167SKIP: { 168 skip 'VMS install targets do not preserve $(DESTDIR)', 10 if $Is_VMS; 169 170 $install_out = run("$make install PREFIX= DESTDIR=other"); 171 is( $?, 0, 'install with DESTDIR' ) || 172 diag $install_out; 173 like( $install_out, qr/^Installing /m ); 174 175 ok( -d 'other', ' destdir created' ); 176 %files = (); 177 my $perllocal; 178 find( sub { 179 $files{$_} = $File::Find::name; 180 }, 'other' ); 181 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 182 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 183 ok( $files{'program'}, ' program installed' ); 184 ok( $files{'.packlist'}, ' packlist created' ); 185 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 186 187 ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) || 188 diag("Can't open $files{'perllocal.pod'}: $!"); 189 { local $/; 190 unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal'); 191 } 192 close PERLLOCAL; 193 194# TODO not available in the min version of Test::Harness we require 195# ok( open(PACKLIST, $files{'.packlist'} ) ) || 196# diag("Can't open $files{'.packlist'}: $!"); 197# { local $/; 198# local $TODO = 'DESTDIR still in .packlist'; 199# unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist'); 200# } 201# close PACKLIST; 202 203 rmtree('other'); 204} 205 206 207SKIP: { 208 skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS; 209 210 $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/"); 211 is( $?, 0, 'install with PREFIX override and DESTDIR' ) || 212 diag $install_out; 213 like( $install_out, qr/^Installing /m ); 214 215 ok( !-d 'elsewhere', ' install dir not created' ); 216 ok( -d 'other/elsewhere', ' destdir created' ); 217 %files = (); 218 find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' ); 219 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 220 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 221 ok( $files{'program'}, ' program installed' ); 222 ok( $files{'.packlist'}, ' packlist created' ); 223 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 224 rmtree('other'); 225} 226 227 228my $dist_test_out = run("$make disttest"); 229is( $?, 0, 'disttest' ) || diag($dist_test_out); 230 231# Test META.yml generation 232use ExtUtils::Manifest qw(maniread); 233 234my $distdir = 'Big-Dummy-0.01'; 235$distdir =~ s/\./_/g if $Is_VMS; 236my $meta_yml = "$distdir/META.yml"; 237my $mymeta_yml = "$distdir/MYMETA.yml"; 238my $meta_json = "$distdir/META.json"; 239my $mymeta_json = "$distdir/MYMETA.json"; 240 241note "META file validity"; { 242 require CPAN::Meta; 243 244 ok( !-f 'META.yml', 'META.yml not written to source dir' ); 245 ok( -f $meta_yml, 'META.yml written to dist dir' ); 246 ok( !-e "META_new.yml", 'temp META.yml file not left around' ); 247 248 ok( -f 'MYMETA.yml', 'MYMETA.yml is written to source dir' ); 249 ok( -f $mymeta_yml, 'MYMETA.yml is written to dist dir on disttest' ); 250 251 ok( !-f 'META.json', 'META.json not written to source dir' ); 252 ok( -f $meta_json, 'META.json written to dist dir' ); 253 ok( !-e "META_new.json", 'temp META.json file not left around' ); 254 255 ok( -f 'MYMETA.json', 'MYMETA.json is written to source dir' ); 256 ok( -f $mymeta_json, 'MYMETA.json is written to dist dir on disttest' ); 257 258 for my $case ( 259 ['META.yml', $meta_yml], 260 ['MYMETA.yml', $mymeta_yml], 261 ['META.json', $meta_json], 262 ['MYMETA.json', $mymeta_json], 263 ['MYMETA.yml', 'MYMETA.yml'], 264 ['MYMETA.json', 'MYMETA.json'], 265 ) { 266 my ($label, $meta_name) = @$case; 267 ok( 268 my $obj = eval { 269 CPAN::Meta->load_file($meta_name, {lazy_validation => 0}) 270 }, 271 "$label validates" 272 ); 273 my $is = sub { 274 my ($m,$e) = @_; 275 is($obj->$m, $e, "$label -> $m") 276 }; 277 my $is_list = sub { 278 my ($m,$e) = @_; 279 is_deeply([$obj->$m], $e, "$label -> $m") 280 }; 281 my $is_map = sub { 282 my ($m,$e) = @_; 283 is_deeply($obj->$m, $e, "$label -> $m") 284 }; 285 $is->( name => "Big-Dummy" ); 286 $is->( version => "0.01" ); 287 $is->( abstract => q{Try "our" hot dog's, $andwiche$ and $(ub)$!} ); 288 $is_list->( licenses => [q{unknown}] ); 289 $is_list->( authors => [ q{Michael G Schwern <schwern@pobox.com>} ] ); 290 $is_map->( prereqs => { 291 configure => { 292 requires => { 293 'ExtUtils::MakeMaker' => 0 294 }, 295 }, 296 build => { 297 requires => { 298 'warnings' => 0 299 } 300 }, 301 runtime => { 302 requires => { 303 'strict' => 0 304 } 305 }, 306 } 307 ); 308 $is_map->( 309 no_index => { 310 directory => [qw/t inc/], 311 } 312 ); 313 $is->( dynamic_config => ($label =~ /MYMETA/) ? 0 : 1 ); 314 } 315 316 my $manifest = maniread("$distdir/MANIFEST"); 317 # VMS is non-case preserving, so we can't know what the MANIFEST will 318 # look like. :( 319 _normalize($manifest); 320 is( $manifest->{'meta.yml'}, 'Module YAML meta-data (added by MakeMaker)', 321 "MANIFEST has META.yml" 322 ); 323 is( $manifest->{'meta.json'}, 'Module JSON meta-data (added by MakeMaker)', 324 "MANFIEST has META.json" 325 ); 326 327 # Test NO_META META.yml suppression 328 for my $f ( $meta_yml, $meta_json, 'MYMETA.yml', 'MYMETA.json' ) { 329 1 while unlink $f; 330 } 331 ok( !-f $meta_yml, 'META.yml deleted' ); 332 ok( !-f 'MYMETA.yml','MYMETA.yml deleted' ); 333 ok( !-f $meta_json, 'META.json deleted' ); 334 ok( !-f 'MYMETA.json','MYMETA.json deleted' ); 335 336 @mpl_out = run(qq{$perl Makefile.PL "NO_META=1"}); 337 ok( -f 'MYMETA.yml', 'MYMETA.yml generation not suppressed by NO_META' ); 338 ok( -f 'MYMETA.json', 'MYMETA.json generation not suppressed by NO_META' ); 339 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 340 ok( !-f $meta_yml, 'META.yml generation suppressed by NO_META' ); 341 ok( !-f $meta_json, 'META.json generation suppressed by NO_META' ); 342 my $distdir_out = run("$make distdir"); 343 is( $?, 0, 'distdir' ) || diag($distdir_out); 344 ok( !-f $meta_yml, 'META.yml generation suppressed by NO_META' ); 345 ok( !-f $meta_json, 'META.json generation suppressed by NO_META' ); 346 347 for my $f ( 'MYMETA.yml', 'MYMETA.json' ) { 348 1 while unlink $f; 349 } 350 ok( !-f 'MYMETA.yml','MYMETA.yml deleted' ); 351 ok( !-f 'MYMETA.json','MYMETA.json deleted' ); 352 353 @mpl_out = run(qq{$perl Makefile.PL "NO_MYMETA=1"}); 354 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 355 $distdir_out = run("$make distdir"); 356 is( $?, 0, 'distdir' ) || diag($distdir_out); 357 ok( !-f 'MYMETA.yml','MYMETA.yml generation suppressed by NO_MYMETA' ); 358 ok( !-f 'MYMETA.json','MYMETA.json generation suppressed by NO_MYMETA' ); 359 ok( -f $meta_yml, 'META.yml generation not suppressed by NO_MYMETA' ); 360 ok( -f $meta_json, 'META.json generation not suppressed by NO_MYMETA' ); 361 362 # Test MYMETA really comes from META except for prereqs 363 for my $f ( $meta_yml, $meta_json, 'MYMETA.yml', 'MYMETA.json' ) { 364 1 while unlink $f; 365 } 366 @mpl_out = run(qq{$perl Makefile.PL}); 367 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 368 $distdir_out = run("$make distdir"); 369 is( $?, 0, 'distdir' ) || diag($distdir_out); 370 ok( -f $meta_yml, 'META.yml generated in distdir' ); 371 ok( -f $meta_json, 'META.json generated in distdir' ); 372 ok( ! -f $mymeta_yml, 'MYMETA.yml not yet generated in distdir' ); 373 ok( ! -f $mymeta_json, 'MYMETA.json generated in distdir' ); 374 my $edit_meta = CPAN::Meta->load_file($meta_json)->as_struct; 375 $edit_meta->{abstract} = "New abstract"; 376 my $meta_obj = CPAN::Meta->new($edit_meta); 377 is( $meta_obj->abstract, "New abstract", "MYMETA abstract from META, not Makefile.PL"); 378 ok( $meta_obj->save($meta_json), "Saved edited META.json in distdir" ); 379 ok( $meta_obj->save($meta_yml, {version => 1.4}), "Saved edited META.yml in distdir"); 380 ok( chdir $distdir ); 381 ok( -f 'META.yml', 'META.yml confirmed in distdir' ); 382 ok( -f 'META.json', 'META.json confirmed in distdir' ); 383 @mpl_out = run(qq{$perl Makefile.PL}); 384 cmp_ok( $?, '==', 0, 'Makefile.PL in distdir exited with zero' ) || diag(@mpl_out); 385 ok( chdir File::Spec->updir ); 386 ok( -f $mymeta_yml, 'MYMETA.yml generated in distdir' ); 387 ok( -f $mymeta_json, 'MYMETA.json generated in distdir' ); 388 $meta_obj = CPAN::Meta->load_file($meta_json); 389 is( $meta_obj->abstract, "New abstract", "META abstract is same as was saved"); 390 $meta_obj = CPAN::Meta->load_file($mymeta_json); 391 is( $meta_obj->abstract, "New abstract", "MYMETA abstract from META, not Makefile.PL"); 392} 393 394 395 396# Make sure init_dirscan doesn't go into the distdir 397@mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"}); 398 399cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 400 401ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1, 402 'init_dirscan skipped distdir') || 403 diag(@mpl_out); 404 405# I know we'll get ignored errors from make here, that's ok. 406# Send STDERR off to oblivion. 407open(SAVERR, ">&STDERR") or die $!; 408open(STDERR, ">",File::Spec->devnull) or die $!; 409 410my $realclean_out = run("$make realclean"); 411is( $?, 0, 'realclean' ) || diag($realclean_out); 412 413open(STDERR, ">&SAVERR") or die $!; 414close SAVERR; 415 416 417sub _normalize { 418 my $hash = shift; 419 420 %$hash= map { lc($_) => $hash->{$_} } keys %$hash; 421} 422