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