#!./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";}
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";}
plan tests => 95;
+my $Perl = which_perl();
+
{
unlink("afile") if -f "afile";
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>;
{
ok( open(my $f, '|-', <<EOC), 'open |-' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
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>;
{
ok( open(local $f, '|-', <<EOC), 'open local $f, "|-", ...' );
- $^X -pe "s/^not //"
+ $Perl -pe "s/^not //"
EOC
my @rows = <$f>;
{
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' );
}
}
+# 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;