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 if( $ENV{PERL_CORE} ) { 8 chdir 't' if -d 't'; 9 @INC = ('../lib', 'lib'); 10 } 11 else { 12 unshift @INC, 't/lib'; 13 } 14} 15 16use strict; 17use Config; 18 19use Test::More tests => 80; 20use MakeMaker::Test::Utils; 21use MakeMaker::Test::Setup::BFD; 22use File::Find; 23use File::Spec; 24use File::Path; 25 26# 'make disttest' sets a bunch of environment variables which interfere 27# with our testing. 28delete @ENV{qw(PREFIX LIB MAKEFLAGS)}; 29 30my $perl = which_perl(); 31my $Is_VMS = $^O eq 'VMS'; 32 33chdir 't'; 34 35perl_lib; 36 37my $Touch_Time = calibrate_mtime(); 38 39$| = 1; 40 41ok( setup_recurs(), 'setup' ); 42END { 43 ok( chdir File::Spec->updir ); 44 ok( teardown_recurs(), 'teardown' ); 45} 46 47ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) || 48 diag("chdir failed: $!"); 49 50my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"}); 51END { rmtree '../dummy-install'; } 52 53cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || 54 diag(@mpl_out); 55 56my $makefile = makefile_name(); 57ok( grep(/^Writing $makefile for Big::Dummy/, 58 @mpl_out) == 1, 59 'Makefile.PL output looks right'); 60 61ok( grep(/^Current package is: main$/, 62 @mpl_out) == 1, 63 'Makefile.PL run in package main'); 64 65ok( -e $makefile, 'Makefile exists' ); 66 67# -M is flakey on VMS 68my $mtime = (stat($makefile))[9]; 69cmp_ok( $Touch_Time, '<=', $mtime, ' its been touched' ); 70 71END { unlink makefile_name(), makefile_backup() } 72 73my $make = make_run(); 74 75{ 76 # Supress 'make manifest' noise 77 local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0; 78 my $manifest_out = run("$make manifest"); 79 ok( -e 'MANIFEST', 'make manifest created a MANIFEST' ); 80 ok( -s 'MANIFEST', ' its not empty' ); 81} 82 83END { unlink 'MANIFEST'; } 84 85 86my $ppd_out = run("$make ppd"); 87is( $?, 0, ' exited normally' ) || diag $ppd_out; 88ok( open(PPD, 'Big-Dummy.ppd'), ' .ppd file generated' ); 89my $ppd_html; 90{ local $/; $ppd_html = <PPD> } 91close PPD; 92like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0,01,0,0">}m, 93 ' <SOFTPKG>' ); 94like( $ppd_html, qr{^\s*<TITLE>Big-Dummy</TITLE>}m, ' <TITLE>' ); 95like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m, 96 ' <ABSTRACT>'); 97like( $ppd_html, 98 qr{^\s*<AUTHOR>Michael G Schwern <schwern\@pobox.com></AUTHOR>}m, 99 ' <AUTHOR>' ); 100like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m, ' <IMPLEMENTATION>'); 101like( $ppd_html, qr{^\s*<DEPENDENCY NAME="strict" VERSION="0,0,0,0" />}m, 102 ' <DEPENDENCY>' ); 103like( $ppd_html, qr{^\s*<OS NAME="$Config{osname}" />}m, 104 ' <OS>' ); 105like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$Config{archname}" />}m, 106 ' <ARCHITECTURE>'); 107like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m, ' <CODEBASE>'); 108like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m, ' </IMPLEMENTATION>'); 109like( $ppd_html, qr{^\s*</SOFTPKG>}m, ' </SOFTPKG>'); 110END { unlink 'Big-Dummy.ppd' } 111 112 113my $test_out = run("$make test"); 114like( $test_out, qr/All tests successful/, 'make test' ); 115is( $?, 0, ' exited normally' ) || 116 diag $test_out; 117 118# Test 'make test TEST_VERBOSE=1' 119my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1); 120$test_out = run("$make_test_verbose"); 121like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' ); 122like( $test_out, qr/All tests successful/, ' successful' ); 123is( $?, 0, ' exited normally' ) || 124 diag $test_out; 125 126 127my $install_out = run("$make install"); 128is( $?, 0, 'install' ) || diag $install_out; 129like( $install_out, qr/^Installing /m ); 130like( $install_out, qr/^Writing /m ); 131 132ok( -r '../dummy-install', ' install dir created' ); 133my %files = (); 134find( sub { 135 # do it case-insensitive for non-case preserving OSs 136 my $file = lc $_; 137 138 # VMS likes to put dots on the end of things that don't have them. 139 $file =~ s/\.$// if $Is_VMS; 140 141 $files{$file} = $File::Find::name; 142}, '../dummy-install' ); 143ok( $files{'dummy.pm'}, ' Dummy.pm installed' ); 144ok( $files{'liar.pm'}, ' Liar.pm installed' ); 145ok( $files{'program'}, ' program installed' ); 146ok( $files{'.packlist'}, ' packlist created' ); 147ok( $files{'perllocal.pod'},' perllocal.pod created' ); 148 149 150SKIP: { 151 skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS; 152 153 $install_out = run("$make install PREFIX=elsewhere"); 154 is( $?, 0, 'install with PREFIX override' ) || diag $install_out; 155 like( $install_out, qr/^Installing /m ); 156 like( $install_out, qr/^Writing /m ); 157 158 ok( -r 'elsewhere', ' install dir created' ); 159 %files = (); 160 find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' ); 161 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 162 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 163 ok( $files{'program'}, ' program installed' ); 164 ok( $files{'.packlist'}, ' packlist created' ); 165 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 166 rmtree('elsewhere'); 167} 168 169 170SKIP: { 171 skip 'VMS install targets do not preserve $(DESTDIR)', 11 if $Is_VMS; 172 173 $install_out = run("$make install PREFIX= DESTDIR=other"); 174 is( $?, 0, 'install with DESTDIR' ) || 175 diag $install_out; 176 like( $install_out, qr/^Installing /m ); 177 like( $install_out, qr/^Writing /m ); 178 179 ok( -d 'other', ' destdir created' ); 180 %files = (); 181 my $perllocal; 182 find( sub { 183 $files{$_} = $File::Find::name; 184 }, 'other' ); 185 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 186 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 187 ok( $files{'program'}, ' program installed' ); 188 ok( $files{'.packlist'}, ' packlist created' ); 189 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 190 191 ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) || 192 diag("Can't open $files{'perllocal.pod'}: $!"); 193 { local $/; 194 unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal'); 195 } 196 close PERLLOCAL; 197 198# TODO not available in the min version of Test::Harness we require 199# ok( open(PACKLIST, $files{'.packlist'} ) ) || 200# diag("Can't open $files{'.packlist'}: $!"); 201# { local $/; 202# local $TODO = 'DESTDIR still in .packlist'; 203# unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist'); 204# } 205# close PACKLIST; 206 207 rmtree('other'); 208} 209 210 211SKIP: { 212 skip 'VMS install targets do not preserve $(PREFIX)', 10 if $Is_VMS; 213 214 $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/"); 215 is( $?, 0, 'install with PREFIX override and DESTDIR' ) || 216 diag $install_out; 217 like( $install_out, qr/^Installing /m ); 218 like( $install_out, qr/^Writing /m ); 219 220 ok( !-d 'elsewhere', ' install dir not created' ); 221 ok( -d 'other/elsewhere', ' destdir created' ); 222 %files = (); 223 find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' ); 224 ok( $files{'Dummy.pm'}, ' Dummy.pm installed' ); 225 ok( $files{'Liar.pm'}, ' Liar.pm installed' ); 226 ok( $files{'program'}, ' program installed' ); 227 ok( $files{'.packlist'}, ' packlist created' ); 228 ok( $files{'perllocal.pod'},' perllocal.pod created' ); 229 rmtree('other'); 230} 231 232 233my $dist_test_out = run("$make disttest"); 234is( $?, 0, 'disttest' ) || diag($dist_test_out); 235 236# Test META.yml generation 237use ExtUtils::Manifest qw(maniread); 238 239my $distdir = 'Big-Dummy-0.01'; 240$distdir =~ s/\./_/g if $Is_VMS; 241my $meta_yml = "$distdir/META.yml"; 242 243ok( !-f 'META.yml', 'META.yml not written to source dir' ); 244ok( -f $meta_yml, 'META.yml written to dist dir' ); 245ok( !-e "META_new.yml", 'temp META.yml file not left around' ); 246 247my $manifest = maniread("$distdir/MANIFEST"); 248# VMS is non-case preserving, so we can't know what the MANIFEST will 249# look like. :( 250_normalize($manifest); 251is( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' ); 252 253 254# Test NO_META META.yml suppression 255unlink $meta_yml; 256ok( !-f $meta_yml, 'META.yml deleted' ); 257@mpl_out = run(qq{$perl Makefile.PL "NO_META=1"}); 258cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 259my $distdir_out = run("$make distdir"); 260is( $?, 0, 'distdir' ) || diag($distdir_out); 261ok( !-f $meta_yml, 'META.yml generation suppressed by NO_META' ); 262 263 264# Make sure init_dirscan doesn't go into the distdir 265@mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"}); 266 267cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out); 268 269ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1, 270 'init_dirscan skipped distdir') || 271 diag(@mpl_out); 272 273# I know we'll get ignored errors from make here, that's ok. 274# Send STDERR off to oblivion. 275open(SAVERR, ">&STDERR") or die $!; 276open(STDERR, ">".File::Spec->devnull) or die $!; 277 278my $realclean_out = run("$make realclean"); 279is( $?, 0, 'realclean' ) || diag($realclean_out); 280 281open(STDERR, ">&SAVERR") or die $!; 282close SAVERR; 283 284 285sub _normalize { 286 my $hash = shift; 287 288 while(my($k,$v) = each %$hash) { 289 delete $hash->{$k}; 290 $hash->{lc $k} = $v; 291 } 292} 293