3 # Tests for Perl run-time environment variable settings
5 # $PERL5OPT, $PERL5LIB, etc.
10 require Config; import Config;
11 unless ($Config{'d_fork'}) {
12 print "1..0 # Skip: no fork\n";
21 my $STDOUT = './results-0';
22 my $STDERR = './results-1';
24 my $FAILURE_CODE = 119;
27 delete $ENV{PERL5LIB};
28 delete $ENV{PERL5OPT};
30 # Run perl with specified environment and arguments returns a list.
31 # First element is true if Perl's stdout and stderr match the
32 # supplied $stdout and $stderr argument strings exactly.
33 # second element is an explanation of the failure
36 my ($env, $args, $stdout, $stderr) = @_;
38 unshift @$args, '-I../lib';
40 $stdout = '' unless defined $stdout;
41 $stderr = '' unless defined $stderr;
43 return (0, "Couldn't fork: $!") unless defined $pid; # failure
45 my ($actual_stdout, $actual_stderr);
47 return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
49 open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file");
50 { local $/; $actual_stdout = <F> }
51 open F, "< $STDERR" or return (0, "Couldn't read $STDERR file");
52 { local $/; $actual_stderr = <F> }
54 if ($actual_stdout ne $stdout) {
55 return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]");
56 } elsif ($actual_stderr ne $stderr) {
57 return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]");
62 for my $k (keys %$env) {
63 $ENV{$k} = $env->{$k};
65 open STDOUT, "> $STDOUT" or exit $FAILURE_CODE;
66 open STDERR, "> $STDERR" or it_didnt_work();
67 { exec $PERL, @$args }
74 print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
79 my ($success, $reason) = runperl(@_);
80 $reason =~ s/\n/\\n/g if defined $reason;
81 ok( !!$success, 1, $reason );
84 # PERL5OPT Command-line options (switches). Switches in
85 # this variable are taken as if they were on
86 # every Perl command line. Only the -[DIMUdmtw]
87 # switches are allowed. When running taint
88 # checks (because the program was running setuid
89 # or setgid, or the -T switch was used), this
90 # variable is ignored. If PERL5OPT begins with
91 # -T, tainting will be enabled, and any
92 # subsequent options ignored.
94 try({PERL5OPT => '-w'}, ['-e', 'print $::x'],
96 qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value in print at -e line 1.\n});
98 try({PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'],
101 try({PERL5OPT => '-Mstrict'}, ['-e', 'print $x'],
103 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
106 try({PERL5OPT => '-Mstrict -w'}, ['-e', 'print $x'],
108 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
111 try({PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
114 Name "main::x" used only once: possible typo at -e line 1.
115 Use of uninitialized value in print at -e line 1.
120 try({PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
123 Name "main::x" used only once: possible typo at -e line 1.
124 Use of uninitialized value in print at -e line 1.
128 try({PERL5OPT => '-MExporter'}, ['-e0'],
133 try({PERL5OPT => '-MExporter -MExporter'}, ['-e0'],
137 try({PERL5OPT => '-Mstrict -Mwarnings'},
138 ['-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
142 try({PERL5OPT => '-w -w'},
143 ['-e', 'print $ENV{PERL5OPT}'],
147 try({PERL5OPT => '-t'},
148 ['-e', 'print ${^TAINT}'],
152 try({PERLLIB => "foobar:42"},
153 ['-e', 'print grep { $_ eq "foobar" } @INC'],
157 try({PERLLIB => "foobar:42"},
158 ['-e', 'print grep { $_ eq "42" } @INC'],
162 try({PERL5LIB => "foobar:42"},
163 ['-e', 'print grep { $_ eq "foobar" } @INC'],
167 try({PERL5LIB => "foobar:42"},
168 ['-e', 'print grep { $_ eq "42" } @INC'],
172 try({PERL5LIB => "foo",
174 ['-e', 'print grep { $_ eq "foo" } @INC'],
178 try({PERL5LIB => "foo",
180 ['-e', 'print grep { $_ eq "bar" } @INC'],
184 # PERL5LIB tests with included arch directories still missing
187 1 while unlink $STDOUT;
188 1 while unlink $STDERR;