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;
26 # Run perl with specified environment and arguments returns a list.
27 # First element is true if Perl's stdout and stderr match the
28 # supplied $stdout and $stderr argument strings exactly.
29 # second element is an explanation of the failure
32 my ($env, $args, $stdout, $stderr) = @_;
34 unshift @$args, '-I../lib';
36 $stdout = '' unless defined $stdout;
37 $stderr = '' unless defined $stderr;
39 return (0, "Couldn't fork: $!") unless defined $pid; # failure
41 my ($actual_stdout, $actual_stderr);
43 return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
45 open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file");
46 { local $/; $actual_stdout = <F> }
47 open F, "< $STDERR" or return (0, "Couldn't read $STDERR file");
48 { local $/; $actual_stderr = <F> }
50 if ($actual_stdout ne $stdout) {
51 return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]");
52 } elsif ($actual_stderr ne $stderr) {
53 return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]");
58 for my $k (keys %$env) {
59 $ENV{$k} = $env->{$k};
61 open STDOUT, "> $STDOUT" or exit $FAILURE_CODE;
62 open STDERR, "> $STDERR" or it_didnt_work();
63 { exec $PERL, @$args }
70 print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
75 my ($success, $reason) = runperl(@_);
76 $reason =~ s/\n/\\n/g if defined $reason;
77 ok( !!$success, 1, $reason );
80 # PERL5OPT Command-line options (switches). Switches in
81 # this variable are taken as if they were on
82 # every Perl command line. Only the -[DIMUdmtw]
83 # switches are allowed. When running taint
84 # checks (because the program was running setuid
85 # or setgid, or the -T switch was used), this
86 # variable is ignored. If PERL5OPT begins with
87 # -T, tainting will be enabled, and any
88 # subsequent options ignored.
90 try({PERL5OPT => '-w'}, ['-e', 'print $::x'],
92 qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value in print at -e line 1.\n});
94 try({PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'],
97 try({PERL5OPT => '-Mstrict'}, ['-e', 'print $x'],
99 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
102 try({PERL5OPT => '-Mstrict -w'}, ['-e', 'print $x'],
104 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
107 try({PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
110 Name "main::x" used only once: possible typo at -e line 1.
111 Use of uninitialized value in print at -e line 1.
116 try({PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
119 Name "main::x" used only once: possible typo at -e line 1.
120 Use of uninitialized value in print at -e line 1.
124 try({PERL5OPT => '-MExporter'}, ['-e0'],
129 try({PERL5OPT => '-MExporter -MExporter'}, ['-e0'],
133 try({PERL5OPT => '-Mstrict -Mwarnings'},
134 ['-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
138 try({PERL5OPT => '-w -w'},
139 ['-e', 'print $ENV{PERL5OPT}'],
143 try({PERL5OPT => '-t'},
144 ['-e', 'print ${^TAINT}'],
149 1 while unlink $STDOUT;
150 1 while unlink $STDERR;