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