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