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