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";
17 my $STDOUT = './results-0';
18 my $STDERR = './results-1';
20 my $FAILURE_CODE = 119;
24 # Run perl with specified environment and arguments returns a list.
25 # First element is true iff Perl's stdout and stderr match the
26 # supplied $stdout and $stderr argument strings exactly.
27 # second element is an explanation of the failure
30 my ($env, $args, $stdout, $stderr) = @_;
32 unshift @$args, '-I../lib';
34 $stdout = '' unless defined $stdout;
35 $stderr = '' unless defined $stderr;
37 return (0, "Couldn't fork: $!") unless defined $pid; # failure
39 my ($actual_stdout, $actual_stderr);
41 return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
43 open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file");
44 { local $/; $actual_stdout = <F> }
45 open F, "< $STDERR" or return (0, "Couldn't read $STDERR file");
46 { local $/; $actual_stderr = <F> }
48 if ($actual_stdout ne $stdout) {
49 return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]");
50 } elsif ($actual_stderr ne $stderr) {
51 return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]");
56 for my $k (keys %$env) {
57 $ENV{$k} = $env->{$k};
59 open STDOUT, "> $STDOUT" or exit $FAILURE_CODE;
60 open STDERR, "> $STDERR" or it_didnt_work();
61 { exec $PERL, @$args }
68 print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
74 my ($success, $reason) = runperl(@_);
78 $reason =~ s/\n/\\n/g;
79 print "not ok $testno # $reason\n";
83 # PERL5OPT Command-line options (switches). Switches in
84 # this variable are taken as if they were on
85 # every Perl command line. Only the -[DIMUdmw]
86 # switches are allowed. When running taint
87 # checks (because the program was running setuid
88 # or setgid, or the -T switch was used), this
89 # variable is ignored. If PERL5OPT begins with
90 # -T, tainting will be enabled, and any
91 # subsequent options ignored.
94 try($T++, {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($T++, {PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'],
101 try($T++, {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($T++, {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($T++, {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($T++, {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($T++, {PERL5OPT => '-MExporter'}, ['-e0'],
133 try($T++, {PERL5OPT => '-MExporter -MExporter'}, ['-e0'],
137 try($T++, {PERL5OPT => '-Mstrict -Mwarnings'},
138 ['-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
142 print "# ", $T-1, " tests total.\n";
145 1 while unlink $STDOUT;
146 1 while unlink $STDERR;