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