summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2001-12-06 17:45:44 -0500
committerJarkko Hietaniemi <jhi@iki.fi>2001-12-07 03:05:38 +0000
commitb5fe401bfa4db89e5f67b4efa27cfb15826a0dcc (patch)
tree6b62dc61e7583356a0d8ed4b8f4f31730ce1e7e9
parent394e6ffb59de984c27a7dce4842d9c594c141888 (diff)
downloadperl-b5fe401bfa4db89e5f67b4efa27cfb15826a0dcc.tar.gz
which_perl for safer $^Xing
Message-ID: <20011207034544.GN22648@blackrider> (plus op/ref tweak) p4raw-id: //depot/perl@13506
-rwxr-xr-xt/comp/script.t14
-rwxr-xr-xt/io/open.t14
-rwxr-xr-xt/op/ref.t2
-rwxr-xr-xt/op/stat.t6
-rw-r--r--t/run/kill_perl.t7
-rw-r--r--t/test.pl24
6 files changed, 53 insertions, 14 deletions
diff --git a/t/comp/script.t b/t/comp/script.t
index f925b59727..d70b767478 100755
--- a/t/comp/script.t
+++ b/t/comp/script.t
@@ -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 @@ open(try,">Comp.script") || (die "Can't open temp file.");
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";}
diff --git a/t/io/open.t b/t/io/open.t
index 92e71ea47a..cb8aea371f 100755
--- a/t/io/open.t
+++ b/t/io/open.t
@@ -12,6 +12,8 @@ $Is_VMS = $^O eq 'VMS';
plan tests => 95;
+my $Perl = which_perl();
+
{
unlink("afile") if -f "afile";
@@ -76,7 +78,7 @@ SKIP: {
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 @@ EOC
{
ok( open(my $f, '|-', <<EOC), 'open |-' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
@@ -169,7 +171,7 @@ SKIP: {
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 @@ EOC
{
ok( open(local $f, '|-', <<EOC), 'open local $f, "|-", ...' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
@@ -203,13 +205,13 @@ like( $@, qr/Bad filehandle:\s+afile/, ' right error' );
{
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' );
}
diff --git a/t/op/ref.t b/t/op/ref.t
index 613c4504e0..4b1d6e37a7 100755
--- a/t/op/ref.t
+++ b/t/op/ref.t
@@ -2,7 +2,7 @@
BEGIN {
chdir 't' if -d 't';
- @INC = qw(.);
+ @INC = qw(. ../lib);
}
print "1..62\n";
diff --git a/t/op/stat.t b/t/op/stat.t
index 2673ef45a9..36ab1490b4 100755
--- a/t/op/stat.t
+++ b/t/op/stat.t
@@ -11,6 +11,8 @@ use File::Spec;
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 @@ SKIP: {
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: {
diff --git a/t/run/kill_perl.t b/t/run/kill_perl.t
index 499189a350..e568afe1ed 100644
--- a/t/run/kill_perl.t
+++ b/t/run/kill_perl.t
@@ -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 @@ foreach my $prog (@prgs) {
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 = $?;
diff --git a/t/test.pl b/t/test.pl
index 5ed6c821b8..ca4af688dc 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -263,4 +263,28 @@ sub BAILOUT {
}
+# 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;