This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to ExtUtils::MakeMaker 6.25
[perl5.git] / lib / ExtUtils / t / INST_PREFIX.t
CommitLineData
5c161494
MS
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
8BEGIN {
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
18use strict;
a7d1454b 19use Test::More tests => 52;
5c161494 20use MakeMaker::Test::Utils;
a7d1454b 21use MakeMaker::Test::Setup::BFD;
5c161494
MS
22use ExtUtils::MakeMaker;
23use File::Spec;
24use TieOut;
25use Config;
26
45bc4d3a
JH
27my $Is_VMS = $^O eq 'VMS';
28
29chdir 't';
5c161494
MS
30
31perl_lib;
32
33$| = 1;
34
35my $Makefile = makefile_name;
36my $Curdir = File::Spec->curdir;
37my $Updir = File::Spec->updir;
38
a7d1454b
RGS
39ok( setup_recurs(), 'setup' );
40END {
41 ok( chdir File::Spec->updir );
42 ok( teardown_recurs(), 'teardown' );
43}
44
45bc4d3a 45ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
5c161494
MS
46 diag("chdir failed: $!");
47
48my $stdout = tie *STDOUT, 'TieOut' or die;
479d2113 49
5c161494 50my $mm = WriteMakefile(
45bc4d3a
JH
51 NAME => 'Big::Dummy',
52 VERSION_FROM => 'lib/Big/Dummy.pm',
5c161494
MS
53 PREREQ_PM => {},
54 PERL_CORE => $ENV{PERL_CORE},
5c161494 55);
479d2113 56
5c161494 57like( $stdout->read, qr{
45bc4d3a
JH
58 Writing\ $Makefile\ for\ Big::Liar\n
59 Big::Liar's\ vars\n
5c161494
MS
60 INST_LIB\ =\ \S+\n
61 INST_ARCHLIB\ =\ \S+\n
45bc4d3a 62 Writing\ $Makefile\ for\ Big::Dummy\n
5c161494 63}x );
5c161494 64
a7d1454b
RGS
65is( $mm->{PREFIX}, '$(SITEPREFIX)', 'PREFIX set based on INSTALLDIRS' );
66
5c161494
MS
67isa_ok( $mm, 'ExtUtils::MakeMaker' );
68
45bc4d3a 69is( $mm->{NAME}, 'Big::Dummy', 'NAME' );
5c161494
MS
70is( $mm->{VERSION}, 0.01, 'VERSION' );
71
479d2113
MS
72foreach my $prefix (qw(PREFIX PERLPREFIX SITEPREFIX VENDORPREFIX)) {
73 unlike( $mm->{$prefix}, qr/\$\(PREFIX\)/ );
479d2113
MS
74}
75
76
77my $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);
85like( $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 );
92undef $stdout;
93untie *STDOUT;
94
5e719f03 95is( $mm->{PREFIX}, $PREFIX, 'PREFIX' );
479d2113
MS
96
97foreach my $prefix (qw(PERLPREFIX SITEPREFIX VENDORPREFIX)) {
5e719f03 98 is( $mm->{$prefix}, '$(PREFIX)', "\$(PREFIX) overrides $prefix" );
479d2113 99}
5c161494
MS
100
101is( !!$mm->{PERL_CORE}, !!$ENV{PERL_CORE}, 'PERL_CORE' );
102
103my($perl_src, $mm_perl_src);
104if( $ENV{PERL_CORE} ) {
45bc4d3a 105 $perl_src = File::Spec->catdir($Updir, $Updir);
5c161494
MS
106 $perl_src = File::Spec->canonpath($perl_src);
107 $mm_perl_src = File::Spec->canonpath($mm->{PERL_SRC});
108}
109else {
110 $mm_perl_src = $mm->{PERL_SRC};
111}
112
113is( $mm_perl_src, $perl_src, 'PERL_SRC' );
114
115
116# Every INSTALL* variable must start with some PREFIX.
479d2113
MS
117my %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);
5c161494 122
479d2113 123while( my($type, $vars) = each %Install_Vars) {
a7d1454b 124 SKIP: {
479d2113 125 skip "VMS must expand macros in INSTALL* vars", scalar @$vars
a7d1454b
RGS
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 }
479d2113 146 }
5c161494 147}
45bc4d3a 148
45bc4d3a
JH
149# Check that when installman*dir isn't set in Config no man pages
150# are generated.
151{
152 undef *ExtUtils::MM_Unix::Config;
5e719f03 153 undef *ExtUtils::MM_Unix::Config_Override;
45bc4d3a 154 %ExtUtils::MM_Unix::Config = %Config;
5e719f03
MS
155 *ExtUtils::MM_VMS::Config = \%ExtUtils::MM_Unix::Config;
156
a7d1454b
RGS
157 _set_config(installman1dir => '');
158 _set_config(installman3dir => '');
45bc4d3a
JH
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}
5e719f03
MS
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
a7d1454b
RGS
185 _set_config(installvendorman1dir => File::Spec->catdir('foo','bar') );
186 _set_config(installvendorman3dir => '' );
187 _set_config(usevendorprefix => 1 );
188 _set_config(vendorprefixexp => 'something' );
5e719f03
MS
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}
a7d1454b
RGS
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') );
1238c24d 235 SKIP: {
5dca256e
RGS
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)' );
1238c24d 242 }
a7d1454b
RGS
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') );
1238c24d 273 SKIP: {
5dca256e
RGS
274 skip "VMS must expand macros in INSTALL* vars", 2 if $Is_VMS;
275 is( $mm->{INSTALLSITEMAN1DIR}, '$(INSTALLMAN1DIR)' );
276 is( $mm->{INSTALLSITEMAN3DIR}, '$(INSTALLMAN3DIR)' );
1238c24d 277 }
a7d1454b
RGS
278 is( $mm->{INSTALLVENDORMAN1DIR}, '' );
279 is( $mm->{INSTALLVENDORMAN3DIR}, '' );
280}
281
282
283sub _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}