CXUX_BROKEN_CONSTANT_CONVERT isn't used anymore.
[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 => 79;
20 use MakeMaker::Test::Utils;
21 use MakeMaker::Test::Setup::BFD;
22 use File::Find;
23 use File::Spec;
24 use File::Path;
25
26 # 'make disttest' sets a bunch of environment variables which interfere
27 # with our testing.
28 delete @ENV{qw(PREFIX LIB MAKEFLAGS)};
29
30 my $perl = which_perl();
31 my $Is_VMS = $^O eq 'VMS';
32
33 chdir($Is_VMS ? 'BFD_TEST_ROOT:[t]' : 't');
34
35
36 perl_lib;
37
38 my $Touch_Time = calibrate_mtime();
39
40 $| = 1;
41
42 ok( setup_recurs(), 'setup' );
43 END {
44     ok( chdir File::Spec->updir );
45     ok( teardown_recurs(), 'teardown' );
46 }
47
48 ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
49   diag("chdir failed: $!");
50
51 my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
52 END { rmtree '../dummy-install'; }
53
54 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
55   diag(@mpl_out);
56
57 my $makefile = makefile_name();
58 ok( grep(/^Writing $makefile for Big::Dummy/, 
59          @mpl_out) == 1,
60                                            'Makefile.PL output looks right');
61
62 ok( grep(/^Current package is: main$/,
63          @mpl_out) == 1,
64                                            'Makefile.PL run in package main');
65
66 ok( -e $makefile,       'Makefile exists' );
67
68 # -M is flakey on VMS
69 my $mtime = (stat($makefile))[9];
70 cmp_ok( $Touch_Time, '<=', $mtime,  '  its been touched' );
71
72 END { unlink makefile_name(), makefile_backup() }
73
74 my $make = make_run();
75
76 {
77     # Supress 'make manifest' noise
78     local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0;
79     my $manifest_out = run("$make manifest");
80     ok( -e 'MANIFEST',      'make manifest created a MANIFEST' );
81     ok( -s 'MANIFEST',      '  its not empty' );
82 }
83
84 END { unlink 'MANIFEST'; }
85
86
87 my $ppd_out = run("$make ppd");
88 is( $?, 0,                      '  exited normally' ) || diag $ppd_out;
89 ok( open(PPD, 'Big-Dummy.ppd'), '  .ppd file generated' );
90 my $ppd_html;
91 { local $/; $ppd_html = <PPD> }
92 close PPD;
93 like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0,01,0,0">}m, 
94                                                            '  <SOFTPKG>' );
95 like( $ppd_html, qr{^\s*<TITLE>Big-Dummy</TITLE>}m,        '  <TITLE>'   );
96 like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m,         
97                                                            '  <ABSTRACT>');
98 like( $ppd_html, 
99       qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
100                                                            '  <AUTHOR>'  );
101 like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m,          '  <IMPLEMENTATION>');
102 like( $ppd_html, qr{^\s*<DEPENDENCY NAME="strict" VERSION="0,0,0,0" />}m,
103                                                            '  <DEPENDENCY>' );
104 like( $ppd_html, qr{^\s*<OS NAME="$Config{osname}" />}m,
105                                                            '  <OS>'      );
106 like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$Config{archname}" />}m,  
107                                                            '  <ARCHITECTURE>');
108 like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
109 like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
110 like( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
111 END { unlink 'Big-Dummy.ppd' }
112
113
114 my $test_out = run("$make test");
115 like( $test_out, qr/All tests successful/, 'make test' );
116 is( $?, 0,                                 '  exited normally' ) || 
117     diag $test_out;
118
119 # Test 'make test TEST_VERBOSE=1'
120 my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
121 $test_out = run("$make_test_verbose");
122 like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
123 like( $test_out, qr/All tests successful/,  '  successful' );
124 is( $?, 0,                                  '  exited normally' ) ||
125     diag $test_out;
126
127
128 my $install_out = run("$make install");
129 is( $?, 0, 'install' ) || diag $install_out;
130 like( $install_out, qr/^Installing /m );
131 like( $install_out, qr/^Writing /m );
132
133 ok( -r '../dummy-install',     '  install dir created' );
134 my %files = ();
135 find( sub { 
136     # do it case-insensitive for non-case preserving OSs
137     $files{lc $_} = $File::Find::name; 
138 }, '../dummy-install' );
139 ok( $files{'dummy.pm'},     '  Dummy.pm installed' );
140 ok( $files{'liar.pm'},      '  Liar.pm installed'  );
141 ok( $files{'.packlist'},    '  packlist created'   );
142 ok( $files{'perllocal.pod'},'  perllocal.pod created' );
143
144
145 SKIP: {
146     skip "VMS install targets do not preserve $(PREFIX)", 8 if $Is_VMS;
147
148     $install_out = run("$make install PREFIX=elsewhere");
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' );
160     rmtree('elsewhere');
161 }
162
163
164 SKIP: {
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
204 SKIP: {
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');
222 }
223
224
225 my $dist_test_out = run("$make disttest");
226 is( $?, 0, 'disttest' ) || diag($dist_test_out);
227
228 # Test META.yml generation
229 use ExtUtils::Manifest qw(maniread);
230 ok( -f 'META.yml',    'META.yml written' );
231 my $manifest = maniread();
232 # VMS is non-case preserving, so we can't know what the MANIFEST will
233 # look like. :(
234 _normalize($manifest);
235 is( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' );
236 my $meta_mtime = (stat('META.yml'))[9];
237
238 sleep 1;
239 my $metafile_out = run("$make metafile");
240 is( $?, 0, 'metafile' ) || diag($metafile_out);
241 is( (stat('META.yml'))[9], $meta_mtime, 'META.yml untouched if not changed' );
242 ok( !-e 'META_new.yml', 'temp META.yml file not left around' );
243
244 # Test NO_META META.yml suppression
245 unlink 'META.yml';
246 ok( !-f 'META.yml',   'META.yml deleted' );
247 @mpl_out = run(qq{$perl Makefile.PL "NO_META=1"});
248 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
249 $metafile_out = run("$make metafile");
250 is( $?, 0, 'metafile' ) || diag($metafile_out);
251 ok( !-f 'META.yml',   'META.yml generation suppressed by NO_META' );
252
253 # Test if MANIFEST is read-only.
254 chmod 0444, 'MANIFEST';
255 @mpl_out = run(qq{$perl Makefile.PL});
256 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
257 $metafile_out = run("$make metafile_addtomanifest");
258 is( $?, 0, q{metafile_addtomanifest didn't die with locked MANIFEST} ) || 
259     diag($metafile_out);
260
261
262 # Make sure init_dirscan doesn't go into the distdir
263 @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
264
265 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
266
267 ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1,
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.
273 open(SAVERR, ">&STDERR") or die $!;
274 open(STDERR, ">".File::Spec->devnull) or die $!;
275
276 my $realclean_out = run("$make realclean");
277 is( $?, 0, 'realclean' ) || diag($realclean_out);
278
279 open(STDERR, ">&SAVERR") or die $!;
280 close SAVERR;
281
282
283 sub _normalize {
284     my $hash = shift;
285
286     while(my($k,$v) = each %$hash) {
287         delete $hash->{$k};
288         $hash->{lc $k} = $v;
289     }
290 }