From: Michael G. Schwern Date: Thu, 6 Dec 2001 22:45:44 +0000 (-0500) Subject: which_perl for safer $^Xing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5fe401bfa4db89e5f67b4efa27cfb15826a0dcc;p=p5sagit%2Fp5-mst-13.2.git which_perl for safer $^Xing Message-ID: <20011207034544.GN22648@blackrider> (plus op/ref tweak) p4raw-id: //depot/perl@13506 --- diff --git a/t/comp/script.t b/t/comp/script.t index f925b59..d70b767 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 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, '-|', <; @@ -86,7 +88,7 @@ EOC { ok( open(my $f, '|-', <; @@ -169,7 +171,7 @@ SKIP: { skip "open -| busted and noisy on VMS", 3 if $Is_VMS; ok( open(local $f, '-|', <; @@ -179,7 +181,7 @@ EOC { ok( open(local $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 , "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 , "ok\n", ' readline'); ok( close F, ' close' ); } diff --git a/t/op/ref.t b/t/op/ref.t index 613c450..4b1d6e3 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 2673ef4..36ab149 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 499189a..e568afe 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 5ed6c82..ca4af68 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;