which_perl for safer $^Xing
authorMichael G. Schwern <schwern@pobox.com>
Thu, 6 Dec 2001 22:45:44 +0000 (17:45 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 7 Dec 2001 03:05:38 +0000 (03:05 +0000)
Message-ID: <20011207034544.GN22648@blackrider>

(plus op/ref tweak)

p4raw-id: //depot/perl@13506

t/comp/script.t
t/io/open.t
t/op/ref.t
t/op/stat.t
t/run/kill_perl.t
t/test.pl

index f925b59..d70b767 100755 (executable)
@@ -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";}
 
index 92e71ea..cb8aea3 100755 (executable)
@@ -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' );
     }
index 613c450..4b1d6e3 100755 (executable)
@@ -2,7 +2,7 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = qw(.);
+    @INC = qw(. ../lib);
 }
 
 print "1..62\n";
index 2673ef4..36ab149 100755 (executable)
@@ -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: {
index 499189a..e568afe 100644 (file)
 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 = $?;
 
index 5ed6c82..ca4af68 100644 (file)
--- 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;