3 # Tests for Perl run-time environment variable settings
5 # $PERL5OPT, $PERL5LIB, etc.
10 unless ($Config{'d_fork'}) {
11 print "1..0 # Skip: no fork\n";
16 my $STDOUT = './results-0';
17 my $STDERR = './results-1';
19 my $FAILURE_CODE = 119;
23 # Run perl with specified environment and arguments returns a list.
24 # First element is true iff Perl's stdout and stderr match the
25 # supplied $stdout and $stderr argument strings exactly.
26 # second element is an explanation of the failure
29 my ($env, $args, $stdout, $stderr) = @_;
31 unshift @$args, '-I../lib';
33 $stdout = '' unless defined $stdout;
34 $stderr = '' unless defined $stderr;
36 return (0, "Couldn't fork: $!") unless defined $pid; # failure
38 my ($actual_stdout, $actual_stderr);
40 return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
42 open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file");
43 { local $/; $actual_stdout = <F> }
44 open F, "< $STDERR" or return (0, "Couldn't read $STDERR file");
45 { local $/; $actual_stderr = <F> }
47 if ($actual_stdout ne $stdout) {
48 return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]");
49 } elsif ($actual_stderr ne $stderr) {
50 return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]");
55 for my $k (keys %$env) {
56 $ENV{$k} = $env->{$k};
58 open STDOUT, "> $STDOUT" or exit $FAILURE_CODE;
59 open STDERR, "> $STDERR" or it_didnt_work();
60 { exec $PERL, @$args }
67 print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
73 my ($success, $reason) = runperl(@_);
77 $reason =~ s/\n/\\n/g;
78 print "not ok $testno # $reason\n";
82 # PERL5OPT Command-line options (switches). Switches in
83 # this variable are taken as if they were on
84 # every Perl command line. Only the -[DIMUdmw]
85 # switches are allowed. When running taint
86 # checks (because the program was running setuid
87 # or setgid, or the -T switch was used), this
88 # variable is ignored. If PERL5OPT begins with
89 # -T, tainting will be enabled, and any
90 # subsequent options ignored.
93 try($T++, {PERL5OPT => '-w'}, ['-e', 'print $::x'],
95 qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value in print at -e line 1.\n});
97 try($T++, {PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'],
100 try($T++, {PERL5OPT => '-Mstrict'}, ['-e', 'print $x'],
102 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
105 try($T++, {PERL5OPT => '-Mstrict -w'}, ['-e', 'print $x'],
107 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
110 try($T++, {PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
113 Name "main::x" used only once: possible typo at -e line 1.
114 Use of uninitialized value in print at -e line 1.
119 try($T++, {PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
122 Name "main::x" used only once: possible typo at -e line 1.
123 Use of uninitialized value in print at -e line 1.
127 try($T++, {PERL5OPT => '-MExporter'}, ['-e0'],
132 try($T++, {PERL5OPT => '-MExporter -MExporter'}, ['-e0'],
136 try($T++, {PERL5OPT => '-Mstrict -Mwarnings'},
137 ['-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
141 print "# ", $T-1, " tests total.\n";
144 1 while unlink $STDOUT;
145 1 while unlink $STDERR;