1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
#!./perl
#
# Tests for Perl run-time environment variable settings
#
# $PERL5OPT, $PERL5LIB, etc.
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require Config; import Config;
require './test.pl';
skip_all_without_config('d_fork');
}
plan tests => 84;
my $STDOUT = tempfile();
my $STDERR = tempfile();
my $PERL = $ENV{PERL} || './perl';
my $FAILURE_CODE = 119;
delete $ENV{PERLLIB};
delete $ENV{PERL5LIB};
delete $ENV{PERL5OPT};
# Run perl with specified environment and arguments, return (STDOUT, STDERR)
sub runperl_and_capture {
local *F;
my ($env, $args) = @_;
local %ENV = %ENV;
delete $ENV{PERLLIB};
delete $ENV{PERL5LIB};
delete $ENV{PERL5OPT};
my $pid = fork;
return (0, "Couldn't fork: $!") unless defined $pid; # failure
if ($pid) { # parent
wait;
return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
open my $stdout, '<', $STDOUT
or return (0, "Couldn't read $STDOUT file: $!");
open my $stderr, '<', $STDERR
or return (0, "Couldn't read $STDERR file: $!");
local $/;
# Empty file with <$stderr> returns nothing in list context
# (because there are no lines) Use scalar to force it to ''
return (scalar <$stdout>, scalar <$stderr>);
} else { # child
for my $k (keys %$env) {
$ENV{$k} = $env->{$k};
}
open STDOUT, '>', $STDOUT or exit $FAILURE_CODE;
open STDERR, '>', $STDERR and do { exec $PERL, @$args };
# it didn't_work:
print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
exit $FAILURE_CODE;
}
}
sub try {
my ($env, $args, $stdout, $stderr) = @_;
my ($actual_stdout, $actual_stderr) = runperl_and_capture($env, $args);
local $::Level = $::Level + 1;
is ($stdout, $actual_stdout);
is ($stderr, $actual_stderr);
}
# PERL5OPT Command-line options (switches). Switches in
# this variable are taken as if they were on
# every Perl command line. Only the -[DIMUdmtw]
# switches are allowed. When running taint
# checks (because the program was running setuid
# or setgid, or the -T switch was used), this
# variable is ignored. If PERL5OPT begins with
# -T, tainting will be enabled, and any
# subsequent options ignored.
try({PERL5OPT => '-w'}, ['-e', 'print $::x'],
"",
qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value \$x in print at -e line 1.\n});
try({PERL5OPT => '-Mstrict'}, ['-I../lib', '-e', 'print $::x'],
"", "");
try({PERL5OPT => '-Mstrict'}, ['-I../lib', '-e', 'print $x'],
"",
qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
# Fails in 5.6.0
try({PERL5OPT => '-Mstrict -w'}, ['-I../lib', '-e', 'print $x'],
"",
qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
# Fails in 5.6.0
try({PERL5OPT => '-w -Mstrict'}, ['-I../lib', '-e', 'print $::x'],
"",
<<ERROR
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value \$x in print at -e line 1.
ERROR
);
# Fails in 5.6.0
try({PERL5OPT => '-w -Mstrict'}, ['-I../lib', '-e', 'print $::x'],
"",
<<ERROR
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value \$x in print at -e line 1.
ERROR
);
try({PERL5OPT => '-MExporter'}, ['-I../lib', '-e0'],
"",
"");
# Fails in 5.6.0
try({PERL5OPT => '-MExporter -MExporter'}, ['-I../lib', '-e0'],
"",
"");
try({PERL5OPT => '-Mstrict -Mwarnings'},
['-I../lib', '-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
"ok",
"");
open my $fh, ">", "Oooof.pm" or die "Can't write Oooof.pm: $!";
print $fh "package Oooof; 1;\n";
close $fh;
END { 1 while unlink "Oooof.pm" }
try({PERL5OPT => '-I. -MOooof'},
['-e', 'print "ok" if $INC{"Oooof.pm"} eq "Oooof.pm"'],
"ok",
"");
try({PERL5OPT => '-I./ -MOooof'},
['-e', 'print "ok" if $INC{"Oooof.pm"} eq "Oooof.pm"'],
"ok",
"");
try({PERL5OPT => '-w -w'},
['-e', 'print $ENV{PERL5OPT}'],
'-w -w',
'');
try({PERL5OPT => '-t'},
['-e', 'print ${^TAINT}'],
'-1',
'');
try({PERL5OPT => '-W'},
['-I../lib','-e', 'local $^W = 0; no warnings; print $x'],
'',
<<ERROR
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value \$x in print at -e line 1.
ERROR
);
try({PERLLIB => "foobar$Config{path_sep}42"},
['-e', 'print grep { $_ eq "foobar" } @INC'],
'foobar',
'');
try({PERLLIB => "foobar$Config{path_sep}42"},
['-e', 'print grep { $_ eq "42" } @INC'],
'42',
'');
try({PERL5LIB => "foobar$Config{path_sep}42"},
['-e', 'print grep { $_ eq "foobar" } @INC'],
'foobar',
'');
try({PERL5LIB => "foobar$Config{path_sep}42"},
['-e', 'print grep { $_ eq "42" } @INC'],
'42',
'');
try({PERL5LIB => "foo",
PERLLIB => "bar"},
['-e', 'print grep { $_ eq "foo" } @INC'],
'foo',
'');
try({PERL5LIB => "foo",
PERLLIB => "bar"},
['-e', 'print grep { $_ eq "bar" } @INC'],
'',
'');
# Tests for S_incpush_use_sep():
my @dump_inc = ('-e', 'print "$_\n" foreach @INC');
my ($out, $err) = runperl_and_capture({}, [@dump_inc]);
is ($err, '', 'No errors when determining @INC');
my @default_inc = split /\n/, $out;
is ($default_inc[-1], '.', '. is last in @INC');
my $sep = $Config{path_sep};
foreach (['nothing', ''],
['something', 'zwapp', 'zwapp'],
['two things', "zwapp${sep}bam", 'zwapp', 'bam'],
['two things, ::', "zwapp${sep}${sep}bam", 'zwapp', 'bam'],
[': at start', "${sep}zwapp", 'zwapp'],
[': at end', "zwapp${sep}", 'zwapp'],
[':: sandwich ::', "${sep}${sep}zwapp${sep}${sep}", 'zwapp'],
[':', "${sep}"],
['::', "${sep}${sep}"],
[':::', "${sep}${sep}${sep}"],
['two things and :', "zwapp${sep}bam${sep}", 'zwapp', 'bam'],
[': and two things', "${sep}zwapp${sep}bam", 'zwapp', 'bam'],
[': two things :', "${sep}zwapp${sep}bam${sep}", 'zwapp', 'bam'],
['three things', "zwapp${sep}bam${sep}${sep}owww",
'zwapp', 'bam', 'owww'],
) {
my ($name, $lib, @expect) = @$_;
push @expect, @default_inc;
($out, $err) = runperl_and_capture({PERL5LIB => $lib}, [@dump_inc]);
is ($err, '', "No errors when determining \@INC for $name");
my @inc = split /\n/, $out;
is (scalar @inc, scalar @expect,
"expected number of elements in \@INC for $name");
is ("@inc", "@expect", "expected elements in \@INC for $name");
}
# PERL5LIB tests with included arch directories still missing
|