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