xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/ExtUtils/t/basic.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/perl -w
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# This test puts MakeMaker through the paces of a basic perl module
4*0Sstevel@tonic-gate# build, test and installation of the Big::Fat::Dummy module.
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gateBEGIN {
7*0Sstevel@tonic-gate    if( $ENV{PERL_CORE} ) {
8*0Sstevel@tonic-gate        chdir 't' if -d 't';
9*0Sstevel@tonic-gate        @INC = ('../lib', 'lib');
10*0Sstevel@tonic-gate    }
11*0Sstevel@tonic-gate    else {
12*0Sstevel@tonic-gate        unshift @INC, 't/lib';
13*0Sstevel@tonic-gate    }
14*0Sstevel@tonic-gate}
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gateuse strict;
17*0Sstevel@tonic-gateuse Config;
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gateuse Test::More tests => 73;
20*0Sstevel@tonic-gateuse MakeMaker::Test::Utils;
21*0Sstevel@tonic-gateuse File::Find;
22*0Sstevel@tonic-gateuse File::Spec;
23*0Sstevel@tonic-gateuse File::Path;
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate# 'make disttest' sets a bunch of environment variables which interfere
26*0Sstevel@tonic-gate# with our testing.
27*0Sstevel@tonic-gatedelete @ENV{qw(PREFIX LIB MAKEFLAGS)};
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gatemy $perl = which_perl();
30*0Sstevel@tonic-gatemy $Is_VMS = $^O eq 'VMS';
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gatechdir($Is_VMS ? 'BFD_TEST_ROOT:[t]' : 't');
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gateperl_lib;
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gatemy $Touch_Time = calibrate_mtime();
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate$| = 1;
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gateok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
42*0Sstevel@tonic-gate  diag("chdir failed: $!");
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gatemy @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
45*0Sstevel@tonic-gateEND { rmtree '../dummy-install'; }
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gatecmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
48*0Sstevel@tonic-gate  diag(@mpl_out);
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gatemy $makefile = makefile_name();
51*0Sstevel@tonic-gateok( grep(/^Writing $makefile for Big::Dummy/,
52*0Sstevel@tonic-gate         @mpl_out) == 1,
53*0Sstevel@tonic-gate                                           'Makefile.PL output looks right');
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gateok( grep(/^Current package is: main$/,
56*0Sstevel@tonic-gate         @mpl_out) == 1,
57*0Sstevel@tonic-gate                                           'Makefile.PL run in package main');
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gateok( -e $makefile,       'Makefile exists' );
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate# -M is flakey on VMS
62*0Sstevel@tonic-gatemy $mtime = (stat($makefile))[9];
63*0Sstevel@tonic-gatecmp_ok( $Touch_Time, '<=', $mtime,  '  its been touched' );
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gateEND { unlink makefile_name(), makefile_backup() }
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gatemy $make = make_run();
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate{
70*0Sstevel@tonic-gate    # Supress 'make manifest' noise
71*0Sstevel@tonic-gate    local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0;
72*0Sstevel@tonic-gate    my $manifest_out = run("$make manifest");
73*0Sstevel@tonic-gate    ok( -e 'MANIFEST',      'make manifest created a MANIFEST' );
74*0Sstevel@tonic-gate    ok( -s 'MANIFEST',      '  its not empty' );
75*0Sstevel@tonic-gate}
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gateEND { unlink 'MANIFEST'; }
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gatemy $ppd_out = run("$make ppd");
81*0Sstevel@tonic-gateis( $?, 0,                      '  exited normally' ) || diag $ppd_out;
82*0Sstevel@tonic-gateok( open(PPD, 'Big-Dummy.ppd'), '  .ppd file generated' );
83*0Sstevel@tonic-gatemy $ppd_html;
84*0Sstevel@tonic-gate{ local $/; $ppd_html = <PPD> }
85*0Sstevel@tonic-gateclose PPD;
86*0Sstevel@tonic-gatelike( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0,01,0,0">}m,
87*0Sstevel@tonic-gate                                                           '  <SOFTPKG>' );
88*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<TITLE>Big-Dummy</TITLE>}m,        '  <TITLE>'   );
89*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m,
90*0Sstevel@tonic-gate                                                           '  <ABSTRACT>');
91*0Sstevel@tonic-gatelike( $ppd_html,
92*0Sstevel@tonic-gate      qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
93*0Sstevel@tonic-gate                                                           '  <AUTHOR>'  );
94*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<IMPLEMENTATION>}m,          '  <IMPLEMENTATION>');
95*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<DEPENDENCY NAME="strict" VERSION="0,0,0,0" />}m,
96*0Sstevel@tonic-gate                                                           '  <DEPENDENCY>' );
97*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<OS NAME="$Config{osname}" />}m,
98*0Sstevel@tonic-gate                                                           '  <OS>'      );
99*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$Config{archname}" />}m,
100*0Sstevel@tonic-gate                                                           '  <ARCHITECTURE>');
101*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
102*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
103*0Sstevel@tonic-gatelike( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
104*0Sstevel@tonic-gateEND { unlink 'Big-Dummy.ppd' }
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gatemy $test_out = run("$make test");
108*0Sstevel@tonic-gatelike( $test_out, qr/All tests successful/, 'make test' );
109*0Sstevel@tonic-gateis( $?, 0,                                 '  exited normally' ) ||
110*0Sstevel@tonic-gate    diag $test_out;
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate# Test 'make test TEST_VERBOSE=1'
113*0Sstevel@tonic-gatemy $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
114*0Sstevel@tonic-gate$test_out = run("$make_test_verbose");
115*0Sstevel@tonic-gatelike( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
116*0Sstevel@tonic-gatelike( $test_out, qr/All tests successful/,  '  successful' );
117*0Sstevel@tonic-gateis( $?, 0,                                  '  exited normally' ) ||
118*0Sstevel@tonic-gate    diag $test_out;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gatemy $install_out = run("$make install");
122*0Sstevel@tonic-gateis( $?, 0, 'install' ) || diag $install_out;
123*0Sstevel@tonic-gatelike( $install_out, qr/^Installing /m );
124*0Sstevel@tonic-gatelike( $install_out, qr/^Writing /m );
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gateok( -r '../dummy-install',     '  install dir created' );
127*0Sstevel@tonic-gatemy %files = ();
128*0Sstevel@tonic-gatefind( sub {
129*0Sstevel@tonic-gate    # do it case-insensitive for non-case preserving OSs
130*0Sstevel@tonic-gate    $files{lc $_} = $File::Find::name;
131*0Sstevel@tonic-gate}, '../dummy-install' );
132*0Sstevel@tonic-gateok( $files{'dummy.pm'},     '  Dummy.pm installed' );
133*0Sstevel@tonic-gateok( $files{'liar.pm'},      '  Liar.pm installed'  );
134*0Sstevel@tonic-gateok( $files{'.packlist'},    '  packlist created'   );
135*0Sstevel@tonic-gateok( $files{'perllocal.pod'},'  perllocal.pod created' );
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gateSKIP: {
139*0Sstevel@tonic-gate    skip "VMS install targets do not preserve $(PREFIX)", 8 if $Is_VMS;
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate    $install_out = run("$make install PREFIX=elsewhere");
142*0Sstevel@tonic-gate    is( $?, 0, 'install with PREFIX override' ) || diag $install_out;
143*0Sstevel@tonic-gate    like( $install_out, qr/^Installing /m );
144*0Sstevel@tonic-gate    like( $install_out, qr/^Writing /m );
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate    ok( -r 'elsewhere',     '  install dir created' );
147*0Sstevel@tonic-gate    %files = ();
148*0Sstevel@tonic-gate    find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' );
149*0Sstevel@tonic-gate    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
150*0Sstevel@tonic-gate    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
151*0Sstevel@tonic-gate    ok( $files{'.packlist'},    '  packlist created'   );
152*0Sstevel@tonic-gate    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
153*0Sstevel@tonic-gate    rmtree('elsewhere');
154*0Sstevel@tonic-gate}
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gateSKIP: {
158*0Sstevel@tonic-gate    skip "VMS install targets do not preserve $(DESTDIR)", 10 if $Is_VMS;
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate    $install_out = run("$make install PREFIX= DESTDIR=other");
161*0Sstevel@tonic-gate    is( $?, 0, 'install with DESTDIR' ) ||
162*0Sstevel@tonic-gate        diag $install_out;
163*0Sstevel@tonic-gate    like( $install_out, qr/^Installing /m );
164*0Sstevel@tonic-gate    like( $install_out, qr/^Writing /m );
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate    ok( -d 'other',  '  destdir created' );
167*0Sstevel@tonic-gate    %files = ();
168*0Sstevel@tonic-gate    my $perllocal;
169*0Sstevel@tonic-gate    find( sub {
170*0Sstevel@tonic-gate        $files{$_} = $File::Find::name;
171*0Sstevel@tonic-gate    }, 'other' );
172*0Sstevel@tonic-gate    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
173*0Sstevel@tonic-gate    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
174*0Sstevel@tonic-gate    ok( $files{'.packlist'},    '  packlist created'   );
175*0Sstevel@tonic-gate    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate    ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) ||
178*0Sstevel@tonic-gate        diag("Can't open $files{'perllocal.pod'}: $!");
179*0Sstevel@tonic-gate    { local $/;
180*0Sstevel@tonic-gate      unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal');
181*0Sstevel@tonic-gate    }
182*0Sstevel@tonic-gate    close PERLLOCAL;
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate# TODO not available in the min version of Test::Harness we require
185*0Sstevel@tonic-gate#    ok( open(PACKLIST, $files{'.packlist'} ) ) ||
186*0Sstevel@tonic-gate#        diag("Can't open $files{'.packlist'}: $!");
187*0Sstevel@tonic-gate#    { local $/;
188*0Sstevel@tonic-gate#      local $TODO = 'DESTDIR still in .packlist';
189*0Sstevel@tonic-gate#      unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist');
190*0Sstevel@tonic-gate#    }
191*0Sstevel@tonic-gate#    close PACKLIST;
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate    rmtree('other');
194*0Sstevel@tonic-gate}
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gateSKIP: {
198*0Sstevel@tonic-gate    skip "VMS install targets do not preserve $(PREFIX)", 9 if $Is_VMS;
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gate    $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/");
201*0Sstevel@tonic-gate    is( $?, 0, 'install with PREFIX override and DESTDIR' ) ||
202*0Sstevel@tonic-gate        diag $install_out;
203*0Sstevel@tonic-gate    like( $install_out, qr/^Installing /m );
204*0Sstevel@tonic-gate    like( $install_out, qr/^Writing /m );
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate    ok( !-d 'elsewhere',       '  install dir not created' );
207*0Sstevel@tonic-gate    ok( -d 'other/elsewhere',  '  destdir created' );
208*0Sstevel@tonic-gate    %files = ();
209*0Sstevel@tonic-gate    find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' );
210*0Sstevel@tonic-gate    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
211*0Sstevel@tonic-gate    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
212*0Sstevel@tonic-gate    ok( $files{'.packlist'},    '  packlist created'   );
213*0Sstevel@tonic-gate    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
214*0Sstevel@tonic-gate    rmtree('other');
215*0Sstevel@tonic-gate}
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gatemy $dist_test_out = run("$make disttest");
219*0Sstevel@tonic-gateis( $?, 0, 'disttest' ) || diag($dist_test_out);
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate# Test META.yml generation
222*0Sstevel@tonic-gateuse ExtUtils::Manifest qw(maniread);
223*0Sstevel@tonic-gateok( -f 'META.yml',    'META.yml written' );
224*0Sstevel@tonic-gatemy $manifest = maniread();
225*0Sstevel@tonic-gate# VMS is non-case preserving, so we can't know what the MANIFEST will
226*0Sstevel@tonic-gate# look like. :(
227*0Sstevel@tonic-gate_normalize($manifest);
228*0Sstevel@tonic-gateis( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' );
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate# Test NO_META META.yml suppression
231*0Sstevel@tonic-gateunlink 'META.yml';
232*0Sstevel@tonic-gateok( !-f 'META.yml',   'META.yml deleted' );
233*0Sstevel@tonic-gate@mpl_out = run(qq{$perl Makefile.PL "NO_META=1"});
234*0Sstevel@tonic-gatecmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
235*0Sstevel@tonic-gatemy $metafile_out = run("$make metafile");
236*0Sstevel@tonic-gateis( $?, 0, 'metafile' ) || diag($metafile_out);
237*0Sstevel@tonic-gateok( !-f 'META.yml',   'META.yml generation suppressed by NO_META' );
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gate# Test if MANIFEST is read-only.
240*0Sstevel@tonic-gatechmod 0444, 'MANIFEST';
241*0Sstevel@tonic-gate@mpl_out = run(qq{$perl Makefile.PL});
242*0Sstevel@tonic-gatecmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
243*0Sstevel@tonic-gate$metafile_out = run("$make metafile_addtomanifest");
244*0Sstevel@tonic-gateis( $?, 0, q{metafile_addtomanifest didn't die with locked MANIFEST} ) ||
245*0Sstevel@tonic-gate    diag($metafile_out);
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gate# Make sure init_dirscan doesn't go into the distdir
249*0Sstevel@tonic-gate@mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gatecmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gateok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1,
254*0Sstevel@tonic-gate                                'init_dirscan skipped distdir') ||
255*0Sstevel@tonic-gate  diag(@mpl_out);
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate# I know we'll get ignored errors from make here, that's ok.
258*0Sstevel@tonic-gate# Send STDERR off to oblivion.
259*0Sstevel@tonic-gateopen(SAVERR, ">&STDERR") or die $!;
260*0Sstevel@tonic-gateopen(STDERR, ">".File::Spec->devnull) or die $!;
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gatemy $realclean_out = run("$make realclean");
263*0Sstevel@tonic-gateis( $?, 0, 'realclean' ) || diag($realclean_out);
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gateopen(STDERR, ">&SAVERR") or die $!;
266*0Sstevel@tonic-gateclose SAVERR;
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gatesub _normalize {
270*0Sstevel@tonic-gate    my $hash = shift;
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate    while(my($k,$v) = each %$hash) {
273*0Sstevel@tonic-gate        delete $hash->{$k};
274*0Sstevel@tonic-gate        $hash->{lc $k} = $v;
275*0Sstevel@tonic-gate    }
276*0Sstevel@tonic-gate}
277