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