Fix a2p manpage (from Debian)
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / INST_PREFIX.t
1 #!/usr/bin/perl -w
2
3 # Wherein we ensure the INST_* and INSTALL* variables are set correctly
4 # when various PREFIX variables are set.
5 #
6 # Essentially, this test is a Makefile.PL.
7
8 BEGIN {
9     if( $ENV{PERL_CORE} ) {
10         chdir 't' if -d 't';
11         @INC = ('../lib', 'lib');
12     }
13     else {
14         unshift @INC, 't/lib';
15     }
16 }
17
18 use strict;
19 use Test::More tests => 52;
20 use MakeMaker::Test::Utils;
21 use MakeMaker::Test::Setup::BFD;
22 use ExtUtils::MakeMaker;
23 use File::Spec;
24 use TieOut;
25 use Config;
26
27 my $Is_VMS = $^O eq 'VMS';
28
29 chdir 't';
30
31 perl_lib;
32
33 $| = 1;
34
35 my $Makefile = makefile_name;
36 my $Curdir = File::Spec->curdir;
37 my $Updir  = File::Spec->updir;
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 $stdout = tie *STDOUT, 'TieOut' or die;
49
50 my $mm = WriteMakefile(
51     NAME          => 'Big::Dummy',
52     VERSION_FROM  => 'lib/Big/Dummy.pm',
53     PREREQ_PM     => {},
54     PERL_CORE     => $ENV{PERL_CORE},
55 );
56
57 like( $stdout->read, qr{
58                         Writing\ $Makefile\ for\ Big::Liar\n
59                         Big::Liar's\ vars\n
60                         INST_LIB\ =\ \S+\n
61                         INST_ARCHLIB\ =\ \S+\n
62                         Writing\ $Makefile\ for\ Big::Dummy\n
63 }x );
64
65 is( $mm->{PREFIX}, '$(SITEPREFIX)', 'PREFIX set based on INSTALLDIRS' );
66
67 isa_ok( $mm, 'ExtUtils::MakeMaker' );
68
69 is( $mm->{NAME}, 'Big::Dummy',  'NAME' );
70 is( $mm->{VERSION}, 0.01,            'VERSION' );
71
72 foreach my $prefix (qw(PREFIX PERLPREFIX SITEPREFIX VENDORPREFIX)) {
73     unlike( $mm->{$prefix}, qr/\$\(PREFIX\)/ );
74 }
75
76
77 my $PREFIX = File::Spec->catdir('foo', 'bar');
78 $mm = WriteMakefile(
79     NAME          => 'Big::Dummy',
80     VERSION_FROM  => 'lib/Big/Dummy.pm',
81     PREREQ_PM     => {},
82     PERL_CORE     => $ENV{PERL_CORE},
83     PREFIX        => $PREFIX,
84 );
85 like( $stdout->read, qr{
86                         Writing\ $Makefile\ for\ Big::Liar\n
87                         Big::Liar's\ vars\n
88                         INST_LIB\ =\ \S+\n
89                         INST_ARCHLIB\ =\ \S+\n
90                         Writing\ $Makefile\ for\ Big::Dummy\n
91 }x );
92 undef $stdout;
93 untie *STDOUT;
94
95 is( $mm->{PREFIX}, $PREFIX,   'PREFIX' );
96
97 foreach my $prefix (qw(PERLPREFIX SITEPREFIX VENDORPREFIX)) {
98     is( $mm->{$prefix}, '$(PREFIX)', "\$(PREFIX) overrides $prefix" );
99 }
100
101 is( !!$mm->{PERL_CORE}, !!$ENV{PERL_CORE}, 'PERL_CORE' );
102
103 my($perl_src, $mm_perl_src);
104 if( $ENV{PERL_CORE} ) {
105     $perl_src = File::Spec->catdir($Updir, $Updir);
106     $perl_src = File::Spec->canonpath($perl_src);
107     $mm_perl_src = File::Spec->canonpath($mm->{PERL_SRC});
108 }
109 else {
110     $mm_perl_src = $mm->{PERL_SRC};
111 }
112
113 is( $mm_perl_src, $perl_src,     'PERL_SRC' );
114
115
116 # Every INSTALL* variable must start with some PREFIX.
117 my %Install_Vars = (
118  PERL   => [qw(archlib    privlib   bin       man1dir       man3dir   script)],
119  SITE   => [qw(sitearch   sitelib   sitebin   siteman1dir   siteman3dir)],
120  VENDOR => [qw(vendorarch vendorlib vendorbin vendorman1dir vendorman3dir)]
121 );
122
123 while( my($type, $vars) = each %Install_Vars) {
124     SKIP: {
125         skip "VMS must expand macros in INSTALL* vars", scalar @$vars 
126           if $Is_VMS;    
127         skip '$Config{usevendorprefix} not set', scalar @$vars
128           if $type eq 'VENDOR' and !$Config{usevendorprefix};
129
130         foreach my $var (@$vars) {
131             my $installvar = "install$var";
132             my $prefix = '$('.$type.'PREFIX)';
133
134             SKIP: {
135                 skip uc($installvar).' set to another INSTALL variable', 1
136                   if $mm->{uc $installvar} =~ /^\$\(INSTALL.*\)$/;
137
138                 # support for man page skipping
139                 $prefix = 'none' if $type eq 'PERL' && 
140                                     $var =~ /man/ && 
141                                     !$Config{$installvar};
142                 like( $mm->{uc $installvar}, qr/^\Q$prefix\E/, 
143                       "$prefix + $var" );
144             }
145         }
146     }
147 }
148
149 # Check that when installman*dir isn't set in Config no man pages
150 # are generated.
151 {
152     undef *ExtUtils::MM_Unix::Config;
153     undef *ExtUtils::MM_Unix::Config_Override;
154     %ExtUtils::MM_Unix::Config = %Config;
155     *ExtUtils::MM_VMS::Config = \%ExtUtils::MM_Unix::Config;
156
157     _set_config(installman1dir => '');
158     _set_config(installman3dir => '');
159
160     my $wibble = File::Spec->catdir(qw(wibble and such));
161     my $stdout = tie *STDOUT, 'TieOut' or die;
162     my $mm = WriteMakefile(
163                            NAME          => 'Big::Dummy',
164                            VERSION_FROM  => 'lib/Big/Dummy.pm',
165                            PREREQ_PM     => {},
166                            PERL_CORE     => $ENV{PERL_CORE},
167                            PREFIX        => $PREFIX,
168                            INSTALLMAN1DIR=> $wibble,
169                           );
170
171     is( $mm->{INSTALLMAN1DIR}, $wibble );
172     is( $mm->{INSTALLMAN3DIR}, 'none'  );
173 }
174
175 # Check that when installvendorman*dir is set in Config it is honored
176 # [rt.cpan.org 2949]
177 {
178     undef *ExtUtils::MM_Unix::Config;
179     undef *ExtUtils::MM_Unix::Config_Override;
180     undef *ExtUtils::MM_VMS::Config;
181
182     %ExtUtils::MM_Unix::Config = %Config;
183     *ExtUtils::MM_VMS::Config = \%ExtUtils::MM_Unix::Config;
184
185     _set_config(installvendorman1dir => File::Spec->catdir('foo','bar') );
186     _set_config(installvendorman3dir => '' );
187     _set_config(usevendorprefix => 1 );
188     _set_config(vendorprefixexp => 'something' );
189
190     my $stdout = tie *STDOUT, 'TieOut' or die;
191     my $mm = WriteMakefile(
192                    NAME          => 'Big::Dummy',
193                    VERSION_FROM  => 'lib/Big/Dummy.pm',
194                    PREREQ_PM     => {},
195                    PERL_CORE     => $ENV{PERL_CORE},
196
197                    # In case the local installation doesn't have man pages.
198                    INSTALLMAN1DIR=> 'foo/bar/baz',
199                    INSTALLMAN3DIR=> 'foo/bar/baz',
200                   );
201
202     is( $mm->{INSTALLVENDORMAN1DIR}, File::Spec->catdir('foo','bar'), 
203                       'installvendorman1dir (in %Config) not modified' );
204     isnt( $mm->{INSTALLVENDORMAN3DIR}, '', 
205                       'installvendorman3dir (not in %Config) set'  );
206 }
207
208 # Check that when installsiteman*dir isn't set in Config it falls back
209 # to installman*dir
210 {
211     undef *ExtUtils::MM_Unix::Config;
212     undef *ExtUtils::MM_Unix::Config_Override;
213     %ExtUtils::MM_Unix::Config = %Config;
214     *ExtUtils::MM_VMS::Config = \%ExtUtils::MM_Unix::Config;
215
216     _set_config(installman1dir => File::Spec->catdir('foo', 'bar') );
217     _set_config(installman3dir => File::Spec->catdir('foo', 'baz') );
218     _set_config(installsiteman1dir => '' );
219     _set_config(installsiteman3dir => '' );
220     _set_config(installvendorman1dir => '' );
221     _set_config(installvendorman3dir => '' );
222     _set_config(usevendorprefix => 'define' );
223     _set_config(vendorprefixexp => 'something' );
224
225     my $wibble = File::Spec->catdir(qw(wibble and such));
226     my $stdout = tie *STDOUT, 'TieOut' or die;
227     my $mm = WriteMakefile(
228                            NAME          => 'Big::Dummy',
229                            VERSION_FROM  => 'lib/Big/Dummy.pm',
230                            PERL_CORE     => $ENV{PERL_CORE},
231                           );
232
233     is( $mm->{INSTALLMAN1DIR}, File::Spec->catdir('foo', 'bar') );
234     is( $mm->{INSTALLMAN3DIR}, File::Spec->catdir('foo', 'baz') );
235     SKIP: {
236         skip "VMS must expand macros in INSTALL* vars", 4 if $Is_VMS;
237
238         is( $mm->{INSTALLSITEMAN1DIR},   '$(INSTALLMAN1DIR)' );
239         is( $mm->{INSTALLSITEMAN3DIR},   '$(INSTALLMAN3DIR)' );
240         is( $mm->{INSTALLVENDORMAN1DIR}, '$(INSTALLMAN1DIR)' );
241         is( $mm->{INSTALLVENDORMAN3DIR}, '$(INSTALLMAN3DIR)' );
242     }
243 }
244
245
246 # Check that when usevendoprefix and installvendorman*dir aren't set in 
247 # Config it leaves them unset.
248 {
249     undef *ExtUtils::MM_Unix::Config;
250     undef *ExtUtils::MM_Unix::Config_Override;
251     %ExtUtils::MM_Unix::Config = %Config;
252     *ExtUtils::MM_VMS::Config = \%ExtUtils::MM_Unix::Config;
253
254     _set_config(installman1dir => File::Spec->catdir('foo', 'bar') );
255     _set_config(installman3dir => File::Spec->catdir('foo', 'baz') );
256     _set_config(installsiteman1dir => '' );
257     _set_config(installsiteman3dir => '' );
258     _set_config(installvendorman1dir => '' );
259     _set_config(installvendorman3dir => '' );
260     _set_config(usevendorprefix => '' );
261     _set_config(vendorprefixexp => '' );
262
263     my $wibble = File::Spec->catdir(qw(wibble and such));
264     my $stdout = tie *STDOUT, 'TieOut' or die;
265     my $mm = WriteMakefile(
266                            NAME          => 'Big::Dummy',
267                            VERSION_FROM  => 'lib/Big/Dummy.pm',
268                            PERL_CORE     => $ENV{PERL_CORE},
269                           );
270
271     is( $mm->{INSTALLMAN1DIR}, File::Spec->catdir('foo', 'bar') );
272     is( $mm->{INSTALLMAN3DIR}, File::Spec->catdir('foo', 'baz') );
273     SKIP: {
274         skip "VMS must expand macros in INSTALL* vars", 2 if $Is_VMS;
275         is( $mm->{INSTALLSITEMAN1DIR},   '$(INSTALLMAN1DIR)' );
276         is( $mm->{INSTALLSITEMAN3DIR},   '$(INSTALLMAN3DIR)' );
277     }
278     is( $mm->{INSTALLVENDORMAN1DIR}, '' );
279     is( $mm->{INSTALLVENDORMAN3DIR}, '' );
280 }
281
282
283 sub _set_config {
284     my($k,$v) = @_;
285     (my $k_no_install = $k) =~ s/^install//i;
286     $ExtUtils::MM_Unix::Config{$k} = $v;
287
288     # Because VMS's config has traditionally been underpopulated, it will
289     # fall back to the install-less versions in desperation.
290     $ExtUtils::MM_Unix::Config{$k_no_install} = $v if $Is_VMS;
291     return;
292 }