ExtUtils::MakeMaker 6.55_02
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / basic.t
CommitLineData
75e2e551 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
6BEGIN {
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
1487aac6 16use strict;
17use Config;
18use ExtUtils::MakeMaker;
479d2113 19
5bdf71cc 20use Test::More tests => 79;
1487aac6 21use MakeMaker::Test::Utils;
22use MakeMaker::Test::Setup::BFD;
23use File::Find;
24use File::Spec;
25use File::Path;
26
1487aac6 27my $perl = which_perl();
28my $Is_VMS = $^O eq 'VMS';
29
1487aac6 30chdir 't';
31
32perl_lib;
33
34my $Touch_Time = calibrate_mtime();
35
36$| = 1;
37
38ok( setup_recurs(), 'setup' );
39END {
40 ok( chdir File::Spec->updir );
41 ok( teardown_recurs(), 'teardown' );
42}
43
44ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
45 diag("chdir failed: $!");
46
47my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
48END { rmtree '../dummy-install'; }
49
50cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
51 diag(@mpl_out);
52
53my $makefile = makefile_name();
54ok( grep(/^Writing $makefile for Big::Dummy/,
55 @mpl_out) == 1,
56 'Makefile.PL output looks right');
57
58ok( grep(/^Current package is: main$/,
59 @mpl_out) == 1,
60 'Makefile.PL run in package main');
61
62ok( -e $makefile, 'Makefile exists' );
63
64# -M is flakey on VMS
65my $mtime = (stat($makefile))[9];
66cmp_ok( $Touch_Time, '<=', $mtime, ' its been touched' );
67
68END { unlink makefile_name(), makefile_backup() }
69
70my $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
80END { unlink 'MANIFEST'; }
81
82
83my $ppd_out = run("$make ppd");
84is( $?, 0, ' exited normally' ) || diag $ppd_out;
85ok( open(PPD, 'Big-Dummy.ppd'), ' .ppd file generated' );
86my $ppd_html;
87{ local $/; $ppd_html = <PPD> }
88close PPD;
5bdf71cc 89like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0.01">}m,
1487aac6 90 ' <SOFTPKG>' );
1487aac6 91like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m,
92 ' <ABSTRACT>');
93like( $ppd_html,
94 qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
95 ' <AUTHOR>' );
96like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m, ' <IMPLEMENTATION>');
5bdf71cc 97like( $ppd_html, qr{^\s*<REQUIRE NAME="strict::" />}m, ' <REQUIRE>' );
98
1487aac6 99my $archname = $Config{archname};
5bdf71cc 100if( $] >= 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}
1487aac6 104like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$archname" />}m,
105 ' <ARCHITECTURE>');
106like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m, ' <CODEBASE>');
107like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m, ' </IMPLEMENTATION>');
108like( $ppd_html, qr{^\s*</SOFTPKG>}m, ' </SOFTPKG>');
109END { unlink 'Big-Dummy.ppd' }
110
111
112my $test_out = run("$make test");
113like( $test_out, qr/All tests successful/, 'make test' );
114is( $?, 0, ' exited normally' ) ||
115 diag $test_out;
116
117# Test 'make test TEST_VERBOSE=1'
118my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
119$test_out = run("$make_test_verbose");
120like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
121like( $test_out, qr/All tests successful/, ' successful' );
122is( $?, 0, ' exited normally' ) ||
123 diag $test_out;
124
125
126my $install_out = run("$make install");
127is( $?, 0, 'install' ) || diag $install_out;
128like( $install_out, qr/^Installing /m );
129
130ok( -r '../dummy-install', ' install dir created' );
131my %files = ();
132find( 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' );
141ok( $files{'dummy.pm'}, ' Dummy.pm installed' );
142ok( $files{'liar.pm'}, ' Liar.pm installed' );
143ok( $files{'program'}, ' program installed' );
144ok( $files{'.packlist'}, ' packlist created' );
145ok( $files{'perllocal.pod'},' perllocal.pod created' );
146
147
148SKIP: {
5bdf71cc 149 skip 'VMS install targets do not preserve $(PREFIX)', 8 if $Is_VMS;
1487aac6 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
167SKIP: {
5bdf71cc 168 skip 'VMS install targets do not preserve $(DESTDIR)', 10 if $Is_VMS;
1487aac6 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
207SKIP: {
5bdf71cc 208 skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS;
1487aac6 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
228my $dist_test_out = run("$make disttest");
229is( $?, 0, 'disttest' ) || diag($dist_test_out);
230
231# Test META.yml generation
232use ExtUtils::Manifest qw(maniread);
233
234my $distdir = 'Big-Dummy-0.01';
235$distdir =~ s/\./_/g if $Is_VMS;
236my $meta_yml = "$distdir/META.yml";
237
238ok( !-f 'META.yml', 'META.yml not written to source dir' );
239ok( -f $meta_yml, 'META.yml written to dist dir' );
240ok( !-e "META_new.yml", 'temp META.yml file not left around' );
241
242SKIP: {
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
251ok open META, $meta_yml or diag $!;
252my $meta = join '', <META>;
253ok close META;
254
255is $meta, <<"END";
256--- #YAML:1.0
257name: Big-Dummy
258version: 0.01
259abstract: Try "our" hot dog's
260author:
261 - Michael G Schwern <schwern\@pobox.com>
262license: unknown
263distribution_type: module
264configure_requires:
265 ExtUtils::MakeMaker: 0
266build_requires:
267 ExtUtils::MakeMaker: 0
268requires:
269 strict: 0
270no_index:
271 directory:
272 - t
273 - inc
274generated_by: ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION
275meta-spec:
276 url: http://module-build.sourceforge.net/META-spec-v1.4.html
277 version: 1.4
278END
279
280my $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);
284is( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' );
285
286
287# Test NO_META META.yml suppression
288unlink $meta_yml;
289ok( !-f $meta_yml, 'META.yml deleted' );
290@mpl_out = run(qq{$perl Makefile.PL "NO_META=1"});
291cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
292my $distdir_out = run("$make distdir");
293is( $?, 0, 'distdir' ) || diag($distdir_out);
294ok( !-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
300cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
301
302ok( 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.
308open(SAVERR, ">&STDERR") or die $!;
5bdf71cc 309open(STDERR, ">",File::Spec->devnull) or die $!;
1487aac6 310
311my $realclean_out = run("$make realclean");
312is( $?, 0, 'realclean' ) || diag($realclean_out);
313
314open(STDERR, ">&SAVERR") or die $!;
315close SAVERR;
316
317
318sub _normalize {
319 my $hash = shift;
320
321 while(my($k,$v) = each %$hash) {
322 delete $hash->{$k};
323 $hash->{lc $k} = $v;
324 }
325}