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