3 # Tests for Perl run-time environment variable settings
5 # $PERL5OPT, $PERL5LIB, etc.
12 my $STDOUT = './results-0';
13 my $STDERR = './results-1';
15 my $FAILURE_CODE = 119;
19 # Run perl with specified environment and arguments returns a list.
20 # First element is true iff Perl's stdout and stderr match the
21 # supplied $stdout and $stderr argument strings exactly.
22 # second element is an explanation of the failure
25 my ($env, $args, $stdout, $stderr) = @_;
27 unshift @$args, '-I../lib';
29 $stdout = '' unless defined $stdout;
30 $stderr = '' unless defined $stderr;
32 return (0, "Couldn't fork: $!") unless defined $pid; # failure
34 my ($actual_stdout, $actual_stderr);
36 return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE;
38 open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file");
39 { local $/; $actual_stdout = <F> }
40 open F, "< $STDERR" or return (0, "Couldn't read $STDERR file");
41 { local $/; $actual_stderr = <F> }
43 if ($actual_stdout ne $stdout) {
44 return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]");
45 } elsif ($actual_stderr ne $stderr) {
46 return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]");
51 for my $k (keys %$env) {
52 $ENV{$k} = $env->{$k};
54 open STDOUT, "> $STDOUT" or exit $FAILURE_CODE;
55 open STDERR, "> $STDERR" or it_didnt_work();
56 { exec $PERL, @$args }
63 print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";
69 my ($success, $reason) = runperl(@_);
73 $reason =~ s/\n/\\n/g;
74 print "not ok $testno # $reason\n";
78 # PERL5OPT Command-line options (switches). Switches in
79 # this variable are taken as if they were on
80 # every Perl command line. Only the -[DIMUdmw]
81 # switches are allowed. When running taint
82 # checks (because the program was running setuid
83 # or setgid, or the -T switch was used), this
84 # variable is ignored. If PERL5OPT begins with
85 # -T, tainting will be enabled, and any
86 # subsequent options ignored.
89 try($T++, {PERL5OPT => '-w'}, ['-e', 'print $::x'],
91 qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value in print at -e line 1.\n});
93 try($T++, {PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'],
96 try($T++, {PERL5OPT => '-Mstrict'}, ['-e', 'print $x'],
98 qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n});
101 try($T++, {PERL5OPT => '-Mstrict -w'}, ['-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 => '-w -Mstrict'}, ['-e', 'print $::x'],
109 Name "main::x" used only once: possible typo at -e line 1.
110 Use of uninitialized value in print at -e line 1.
115 try($T++, {PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'],
118 Name "main::x" used only once: possible typo at -e line 1.
119 Use of uninitialized value in print at -e line 1.
123 try($T++, {PERL5OPT => '-MExporter'}, ['-e0'],
128 try($T++, {PERL5OPT => '-MExporter -MExporter'}, ['-e0'],
132 try($T++, {PERL5OPT => '-Mstrict -Mwarnings'},
133 ['-e', 'print "ok" if $INC{"strict.pm"} and $INC{"warnings.pm"}'],
137 print "# ", $T-1, " tests total.\n";