1842a1c839629029d00649d62805a5632468f0b0
[p5sagit/p5-mst-13.2.git] / cpan / 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 => 80;
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 unlike( $ppd_html, qr{^\s*<REQUIRE NAME="warnings::" />}m,  'no <REQUIRE> for build_require' );
93
94 my $archname = $Config{archname};
95 if( $] >= 5.008 ) {
96     # XXX This is a copy of the internal logic, so it's not a great test
97     $archname .= "-$Config{PERL_REVISION}.$Config{PERL_VERSION}";
98 }
99 like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$archname" />}m,
100                                                            '  <ARCHITECTURE>');
101 like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
102 like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
103 like( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
104 END { unlink 'Big-Dummy.ppd' }
105
106
107 my $test_out = run("$make test");
108 like( $test_out, qr/All tests successful/, 'make test' );
109 is( $?, 0,                                 '  exited normally' ) || 
110     diag $test_out;
111
112 # Test 'make test TEST_VERBOSE=1'
113 my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
114 $test_out = run("$make_test_verbose");
115 like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
116 like( $test_out, qr/All tests successful/,  '  successful' );
117 is( $?, 0,                                  '  exited normally' ) ||
118     diag $test_out;
119
120
121 my $install_out = run("$make install");
122 is( $?, 0, 'install' ) || diag $install_out;
123 like( $install_out, qr/^Installing /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     my $file = lc $_;
130
131     # VMS likes to put dots on the end of things that don't have them.
132     $file =~ s/\.$// if $Is_VMS;
133
134     $files{$file} = $File::Find::name; 
135 }, '../dummy-install' );
136 ok( $files{'dummy.pm'},     '  Dummy.pm installed' );
137 ok( $files{'liar.pm'},      '  Liar.pm installed'  );
138 ok( $files{'program'},      '  program installed'  );
139 ok( $files{'.packlist'},    '  packlist created'   );
140 ok( $files{'perllocal.pod'},'  perllocal.pod created' );
141
142
143 SKIP: {
144     skip 'VMS install targets do not preserve $(PREFIX)', 8 if $Is_VMS;
145
146     $install_out = run("$make install PREFIX=elsewhere");
147     is( $?, 0, 'install with PREFIX override' ) || diag $install_out;
148     like( $install_out, qr/^Installing /m );
149
150     ok( -r 'elsewhere',     '  install dir created' );
151     %files = ();
152     find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' );
153     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
154     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
155     ok( $files{'program'},      '  program installed'  );
156     ok( $files{'.packlist'},    '  packlist created'   );
157     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
158     rmtree('elsewhere');
159 }
160
161
162 SKIP: {
163     skip 'VMS install targets do not preserve $(DESTDIR)', 10 if $Is_VMS;
164
165     $install_out = run("$make install PREFIX= DESTDIR=other");
166     is( $?, 0, 'install with DESTDIR' ) || 
167         diag $install_out;
168     like( $install_out, qr/^Installing /m );
169
170     ok( -d 'other',  '  destdir created' );
171     %files = ();
172     my $perllocal;
173     find( sub { 
174         $files{$_} = $File::Find::name;
175     }, 'other' );
176     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
177     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
178     ok( $files{'program'},      '  program installed'  );
179     ok( $files{'.packlist'},    '  packlist created'   );
180     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
181
182     ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) || 
183         diag("Can't open $files{'perllocal.pod'}: $!");
184     { local $/;
185       unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal');
186     }
187     close PERLLOCAL;
188
189 # TODO not available in the min version of Test::Harness we require
190 #    ok( open(PACKLIST, $files{'.packlist'} ) ) || 
191 #        diag("Can't open $files{'.packlist'}: $!");
192 #    { local $/;
193 #      local $TODO = 'DESTDIR still in .packlist';
194 #      unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist');
195 #    }
196 #    close PACKLIST;
197
198     rmtree('other');
199 }
200
201
202 SKIP: {
203     skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS;
204
205     $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/");
206     is( $?, 0, 'install with PREFIX override and DESTDIR' ) || 
207         diag $install_out;
208     like( $install_out, qr/^Installing /m );
209
210     ok( !-d 'elsewhere',       '  install dir not created' );
211     ok( -d 'other/elsewhere',  '  destdir created' );
212     %files = ();
213     find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' );
214     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
215     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
216     ok( $files{'program'},      '  program installed'  );
217     ok( $files{'.packlist'},    '  packlist created'   );
218     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
219     rmtree('other');
220 }
221
222
223 my $dist_test_out = run("$make disttest");
224 is( $?, 0, 'disttest' ) || diag($dist_test_out);
225
226 # Test META.yml generation
227 use ExtUtils::Manifest qw(maniread);
228
229 my $distdir  = 'Big-Dummy-0.01';
230 $distdir =~ s/\./_/g if $Is_VMS;
231 my $meta_yml = "$distdir/META.yml";
232
233 ok( !-f 'META.yml',  'META.yml not written to source dir' );
234 ok( -f $meta_yml,    'META.yml written to dist dir' );
235 ok( !-e "META_new.yml", 'temp META.yml file not left around' );
236
237 SKIP: {
238     # META.yml spec 1.4 was added in 0.11
239     skip "Test::YAML::Meta >= 0.11 required", 2
240       unless eval { require Test::YAML::Meta }   and
241              Test::YAML::Meta->VERSION >= 0.11;
242
243     Test::YAML::Meta::meta_spec_ok($meta_yml);
244 }
245
246 ok open META, $meta_yml or diag $!;
247 my $meta = join '', <META>;
248 ok close META;
249
250 is $meta, <<"END";
251 --- #YAML:1.0
252 name:               Big-Dummy
253 version:            0.01
254 abstract:           Try "our" hot dog's
255 author:
256     - Michael G Schwern <schwern\@pobox.com>
257 license:            unknown
258 distribution_type:  module
259 configure_requires:
260     ExtUtils::MakeMaker:  0
261 build_requires:
262     warnings:  0
263 requires:
264     strict:  0
265 no_index:
266     directory:
267         - t
268         - inc
269 generated_by:       ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION
270 meta-spec:
271     url:      http://module-build.sourceforge.net/META-spec-v1.4.html
272     version:  1.4
273 END
274
275 my $manifest = maniread("$distdir/MANIFEST");
276 # VMS is non-case preserving, so we can't know what the MANIFEST will
277 # look like. :(
278 _normalize($manifest);
279 is( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' );
280
281
282 # Test NO_META META.yml suppression
283 unlink $meta_yml;
284 ok( !-f $meta_yml,   'META.yml deleted' );
285 @mpl_out = run(qq{$perl Makefile.PL "NO_META=1"});
286 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
287 my $distdir_out = run("$make distdir");
288 is( $?, 0, 'distdir' ) || diag($distdir_out);
289 ok( !-f $meta_yml,   'META.yml generation suppressed by NO_META' );
290
291
292 # Make sure init_dirscan doesn't go into the distdir
293 @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
294
295 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
296
297 ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1,
298                                 'init_dirscan skipped distdir') || 
299   diag(@mpl_out);
300
301 # I know we'll get ignored errors from make here, that's ok.
302 # Send STDERR off to oblivion.
303 open(SAVERR, ">&STDERR") or die $!;
304 open(STDERR, ">",File::Spec->devnull) or die $!;
305
306 my $realclean_out = run("$make realclean");
307 is( $?, 0, 'realclean' ) || diag($realclean_out);
308
309 open(STDERR, ">&SAVERR") or die $!;
310 close SAVERR;
311
312
313 sub _normalize {
314     my $hash = shift;
315
316     while(my($k,$v) = each %$hash) {
317         delete $hash->{$k};
318         $hash->{lc $k} = $v;
319     }
320 }