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