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