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