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