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