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