Change 13506 by jhi@alpha on 2001/12/07 03:05:38
Subject: [PATCH t/test.pl ...] which_perl for safer $^Xing
From: Michael G Schwern <[EMAIL PROTECTED]>
Date: Thu, 6 Dec 2001 22:45:44 -0500
Message-ID: <20011207034544.GN22648@blackrider>
(plus op/ref tweak)
Affected files ...
.... //depot/perl/t/comp/script.t#11 edit
.... //depot/perl/t/io/open.t#22 edit
.... //depot/perl/t/op/ref.t#14 edit
.... //depot/perl/t/op/stat.t#41 edit
.... //depot/perl/t/run/kill_perl.t#20 edit
.... //depot/perl/t/test.pl#14 edit
Differences ...
==== //depot/perl/t/comp/script.t#11 (xtext) ====
Index: perl/t/comp/script.t
--- perl/t/comp/script.t.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/comp/script.t Thu Dec 6 20:15:05 2001
@@ -1,8 +1,16 @@
#!./perl
+BEGIN {
+ chdir 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+
+my $Perl = which_perl;
+
print "1..3\n";
-$x = `$^X -le "print 'ok';"`;
+$x = `$Perl -le "print 'ok';"`;
if ($x eq "ok\n") {print "ok 1\n";} else {print "not ok 1\n";}
@@ -10,11 +18,11 @@
print try 'print "ok\n";'; print try "\n";
close try;
-$x = `$^X Comp.script`;
+$x = `$Perl Comp.script`;
if ($x eq "ok\n") {print "ok 2\n";} else {print "not ok 2\n";}
-$x = `$^X <Comp.script`;
+$x = `$Perl <Comp.script`;
if ($x eq "ok\n") {print "ok 3\n";} else {print "not ok 3\n";}
==== //depot/perl/t/io/open.t#22 (xtext) ====
Index: perl/t/io/open.t
--- perl/t/io/open.t.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/io/open.t Thu Dec 6 20:15:05 2001
@@ -12,6 +12,8 @@
plan tests => 95;
+my $Perl = which_perl();
+
{
unlink("afile") if -f "afile";
@@ -76,7 +78,7 @@
skip "open -| busted and noisy on VMS", 3 if $Is_VMS;
ok( open(my $f, '-|', <<EOC), 'open -|' );
- $^X -e "print qq(a row\n); print qq(another row\n)"
+ $Perl -e "print qq(a row\n); print qq(another row\n)"
EOC
my @rows = <$f>;
@@ -86,7 +88,7 @@
{
ok( open(my $f, '|-', <<EOC), 'open |-' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
@@ -169,7 +171,7 @@
skip "open -| busted and noisy on VMS", 3 if $Is_VMS;
ok( open(local $f, '-|', <<EOC), 'open local $f, "-|", ...' );
- $^X -e "print qq(a row\n); print qq(another row\n)"
+ $Perl -e "print qq(a row\n); print qq(another row\n)"
EOC
my @rows = <$f>;
@@ -179,7 +181,7 @@
{
ok( open(local $f, '|-', <<EOC), 'open local $f, "|-", ...' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
@@ -203,13 +205,13 @@
{
local *F;
for (1..2) {
- ok( open(F, qq{$^X -le "print 'ok'"|}), 'open to pipe' );
+ ok( open(F, qq{$Perl -le "print 'ok'"|}), 'open to pipe' );
is(scalar <F>, "ok\n", ' readline');
ok( close F, ' close' );
}
for (1..2) {
- ok( open(F, "-|", qq{$^X -le "print 'ok'"}), 'open -|');
+ ok( open(F, "-|", qq{$Perl -le "print 'ok'"}), 'open -|');
is( scalar <F>, "ok\n", ' readline');
ok( close F, ' close' );
}
==== //depot/perl/t/op/ref.t#14 (xtext) ====
Index: perl/t/op/ref.t
--- perl/t/op/ref.t.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/op/ref.t Thu Dec 6 20:15:05 2001
@@ -2,7 +2,7 @@
BEGIN {
chdir 't' if -d 't';
- @INC = qw(.);
+ @INC = qw(. ../lib);
}
print "1..62\n";
==== //depot/perl/t/op/stat.t#41 (xtext) ====
Index: perl/t/op/stat.t
--- perl/t/op/stat.t.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/op/stat.t Thu Dec 6 20:15:05 2001
@@ -11,6 +11,8 @@
plan tests => 69;
+my $Perl = which_perl;
+
$Is_Amiga = $^O eq 'amigaos';
$Is_Cygwin = $^O eq 'cygwin';
$Is_Dos = $^O eq 'dos';
@@ -294,8 +296,8 @@
ok(-T 'op/stat.t', '-T');
ok(! -B 'op/stat.t', '!-B');
-ok(-B $^X, '-B');
-ok(! -T $^X, '!-T');
+ok(-B $Perl, '-B');
+ok(! -T $Perl, '!-T');
open(FOO,'op/stat.t');
SKIP: {
==== //depot/perl/t/run/kill_perl.t#20 (text) ====
Index: perl/t/run/kill_perl.t
--- perl/t/run/kill_perl.t.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/run/kill_perl.t Thu Dec 6 20:15:05 2001
@@ -22,10 +22,13 @@
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
+ require './test.pl';
}
use strict;
+my $Perl = which_perl;
+
$|=1;
my @prgs = ();
@@ -70,10 +73,10 @@
my $results;
if ($^O eq 'MacOS') {
- $results = `$^X -I::lib -MMac::err=unix $switch $tmpfile`;
+ $results = `$Perl -I::lib -MMac::err=unix $switch $tmpfile`;
}
else {
- $results = `$^X "-I../lib" $switch $tmpfile 2>&1`;
+ $results = `$Perl "-I../lib" $switch $tmpfile 2>&1`;
}
my $status = $?;
==== //depot/perl/t/test.pl#14 (text) ====
Index: perl/t/test.pl
--- perl/t/test.pl.~1~ Thu Dec 6 20:15:05 2001
+++ perl/t/test.pl Thu Dec 6 20:15:05 2001
@@ -263,4 +263,28 @@
}
+# A somewhat safer version of the sometimes wrong $^X.
+BEGIN: {
+ eval {
+ require File::Spec;
+ require Config;
+ Config->import;
+ };
+ warn "test.pl had problems loading other modules: $@" if $@;
+}
+
+# We do this at compile time before the test might have chdir'd around
+# and make sure its absolute in case they do later.
+my $Perl = $^X;
+$Perl = File::Spec->rel2abs(File::Spec->catfile(File::Spec->curdir(), $Perl))
+ if $^X eq "perl$Config{_exe}";
+warn "Can't generate which_perl from $^X" unless -f $Perl;
+
+# For subcommands to use.
+$ENV{PERLEXE} = $Perl;
+
+sub which_perl {
+ return $Perl;
+}
+
1;
End of Patch.