Bring ExtUtils::Install up to date with the latest on CPAN 1.50_04 and related test...
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / basic.pl
1 #!/usr/bin/perl -w
2
3 # *NOTE* This is executed by basic.t and is included in both ExtUtils-Install
4 # and ExtUtils-MakeMaker as well as Perl itself. Which bits of it execute depend
5 # on each given packages basic.t
6
7 # This test puts MakeMaker through the paces of a basic perl module
8 # build, test and installation of the Big::Fat::Dummy module.
9
10 use strict;
11 use Config;
12 use ExtUtils::MakeMaker;
13
14 use Test::More tests => $::TESTS;
15 use MakeMaker::Test::Utils;
16 use MakeMaker::Test::Setup::BFD;
17 use File::Find;
18 use File::Spec;
19 use File::Path;
20
21 # 'make disttest' sets a bunch of environment variables which interfere
22 # with our testing.
23 delete @ENV{qw(PREFIX LIB MAKEFLAGS)};
24
25 my $perl = which_perl();
26 my $Is_VMS = $^O eq 'VMS';
27
28 # GNV logical interferes with testing
29 $ENV{'bin'} = '[.bin]' if $Is_VMS;
30
31 chdir 't';
32
33 perl_lib;
34
35 my $Touch_Time = calibrate_mtime();
36
37 $| = 1;
38
39 ok( setup_recurs(), 'setup' );
40 END {
41     ok( chdir File::Spec->updir );
42     ok( teardown_recurs(), 'teardown' );
43 }
44
45 ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
46   diag("chdir failed: $!");
47
48 my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
49 END { rmtree '../dummy-install'; }
50
51 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
52   diag(@mpl_out);
53
54 my $makefile = makefile_name();
55 ok( grep(/^Writing $makefile for Big::Dummy/, 
56          @mpl_out) == 1,
57                                            'Makefile.PL output looks right');
58
59 ok( grep(/^Current package is: main$/,
60          @mpl_out) == 1,
61                                            'Makefile.PL run in package main');
62
63 ok( -e $makefile,       'Makefile exists' );
64
65 # -M is flakey on VMS
66 my $mtime = (stat($makefile))[9];
67 cmp_ok( $Touch_Time, '<=', $mtime,  '  its been touched' );
68
69 END { unlink makefile_name(), makefile_backup() }
70
71 my $make = make_run();
72
73 {
74     # Supress 'make manifest' noise
75     local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0;
76     my $manifest_out = run("$make manifest");
77     ok( -e 'MANIFEST',      'make manifest created a MANIFEST' );
78     ok( -s 'MANIFEST',      '  its not empty' );
79 }
80
81 END { unlink 'MANIFEST'; }
82
83 unless ($::TEST_INSTALL_ONLY) {
84     my $ppd_out = run("$make ppd");
85     is( $?, 0,                      '  exited normally' ) || diag $ppd_out;
86     ok( open(PPD, 'Big-Dummy.ppd'), '  .ppd file generated' );
87     my $ppd_html;
88     { local $/; $ppd_html = <PPD> }
89     close PPD;
90     like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0,01,0,0">}m, 
91                                                                '  <SOFTPKG>' );
92     like( $ppd_html, qr{^\s*<TITLE>Big-Dummy</TITLE>}m,        '  <TITLE>'   );
93     like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m, # Unconfuse highlighters: '
94                                                                '  <ABSTRACT>');
95     like( $ppd_html, 
96           qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
97                                                                '  <AUTHOR>'  );
98     like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m,          '  <IMPLEMENTATION>');
99     like( $ppd_html, qr{^\s*<DEPENDENCY NAME="strict" VERSION="0,0,0,0" />}m,
100                                                                '  <DEPENDENCY>' );
101     like( $ppd_html, qr{^\s*<OS NAME="$Config{osname}" />}m,
102                                                                '  <OS>'      );
103     my $archname = $Config{archname};
104     $archname .= "-". substr($Config{version},0,3) if $] >= 5.008;
105     like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$archname" />}m,
106                                                                '  <ARCHITECTURE>');
107     like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
108     like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
109     like( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
110     END { unlink 'Big-Dummy.ppd' }
111 }
112
113 my $test_out = run("$make test");
114 like( $test_out, qr/All tests successful/, 'make test' );
115 is( $?, 0,                                 '  exited normally' ) || 
116     diag $test_out;
117
118 # Test 'make test TEST_VERBOSE=1'
119 my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
120 $test_out = run("$make_test_verbose");
121 like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
122 like( $test_out, qr/All tests successful/,  '  successful' );
123 is( $?, 0,                                  '  exited normally' ) ||
124     diag $test_out;
125
126 # Test 'make install VERBINST=1'
127 my $make_install_verbinst = make_macro($make, 'install', VERBINST => 1);
128 my $install_out = run($make_install_verbinst);
129 is( $?, 0, 'install' ) || diag $install_out;
130 like( $install_out, qr/^Installing /m );
131 like( $install_out, qr/^Writing /m );
132
133 ok( -r '../dummy-install',     '  install dir created' );
134 my %files = ();
135 find( sub { 
136     # do it case-insensitive for non-case preserving OSs
137     my $file = lc $_;
138
139     # VMS likes to put dots on the end of things that don't have them.
140     $file =~ s/\.$// if $Is_VMS;
141
142     $files{$file} = $File::Find::name; 
143 }, '../dummy-install' );
144 ok( $files{'dummy.pm'},     '  Dummy.pm installed' );
145 ok( $files{'liar.pm'},      '  Liar.pm installed'  );
146 ok( $files{'program'},      '  program installed'  );
147 ok( $files{'.packlist'},    '  packlist created'   );
148 ok( $files{'perllocal.pod'},'  perllocal.pod created' );
149
150
151 SKIP: {
152     skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS;
153
154     $install_out = run("$make install PREFIX=elsewhere VERBINST=1");
155     is( $?, 0, 'install with PREFIX override' ) || diag $install_out;
156     like( $install_out, qr/^Installing /m );
157     like( $install_out, qr/^Writing /m );
158
159     ok( -r 'elsewhere',     '  install dir created' );
160     %files = ();
161     find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' );
162     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
163     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
164     ok( $files{'program'},      '  program installed'  );
165     ok( $files{'.packlist'},    '  packlist created'   );
166     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
167     rmtree('elsewhere');
168 }
169
170
171 SKIP: {
172     skip 'VMS install targets do not preserve $(DESTDIR)', 11 if $Is_VMS;
173
174     $install_out = run("$make install PREFIX= DESTDIR=other VERBINST=1");
175     is( $?, 0, 'install with DESTDIR' ) || 
176         diag $install_out;
177     like( $install_out, qr/^Installing /m );
178     like( $install_out, qr/^Writing /m );
179
180     ok( -d 'other',  '  destdir created' );
181     %files = ();
182     my $perllocal;
183     find( sub { 
184         $files{$_} = $File::Find::name;
185     }, 'other' );
186     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
187     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
188     ok( $files{'program'},      '  program installed'  );
189     ok( $files{'.packlist'},    '  packlist created'   );
190     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
191
192     ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) || 
193         diag("Can't open $files{'perllocal.pod'}: $!");
194     { local $/;
195       unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal');
196     }
197     close PERLLOCAL;
198
199 # TODO not available in the min version of Test::Harness we require
200 #    ok( open(PACKLIST, $files{'.packlist'} ) ) || 
201 #        diag("Can't open $files{'.packlist'}: $!");
202 #    { local $/;
203 #      local $TODO = 'DESTDIR still in .packlist';
204 #      unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist');
205 #    }
206 #    close PACKLIST;
207
208     rmtree('other');
209 }
210
211
212 SKIP: {
213     skip 'VMS install targets do not preserve $(PREFIX)', 10 if $Is_VMS;
214
215     $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/ VERBINST=1");
216     is( $?, 0, 'install with PREFIX override and DESTDIR' ) || 
217         diag $install_out;
218     like( $install_out, qr/^Installing /m );
219     like( $install_out, qr/^Writing /m );
220
221     ok( !-d 'elsewhere',       '  install dir not created' );
222     ok( -d 'other/elsewhere',  '  destdir created' );
223     %files = ();
224     find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' );
225     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
226     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
227     ok( $files{'program'},      '  program installed'  );
228     ok( $files{'.packlist'},    '  packlist created'   );
229     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
230     rmtree('other');
231 }