Move Cwd from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Cwd / t / rel2abs2rel.t
CommitLineData
e021ab8e 1#!/usr/bin/perl -w
3bb16ffc 2
e021ab8e 3# Here we make sure File::Spec can properly deal with executables.
4# VMS has some trouble with these.
5
99f36a73 6use File::Spec;
7use lib File::Spec->catdir('t', 'lib');
8
e021ab8e 9use Test::More (-x $^X
10 ? (tests => 5)
11 : (skip_all => "Can't find an executable file")
12 );
3bb16ffc 13
7ae32827 14BEGIN { # Set up a tiny script file
d7f1a795 15 local *F;
7ae32827 16 open(F, ">rel2abs2rel$$.pl")
17 or die "Can't open rel2abs2rel$$.pl file for script -- $!\n";
18 print F qq(print "ok\\n"\n);
19 close(F);
20}
21END {
98a392ec 22 1 while unlink("rel2abs2rel$$.pl");
23 1 while unlink("rel2abs2rel$$.tmp");
7ae32827 24}
3bb16ffc 25
f47fe535 26use Config;
b15a22ab 27
3bb16ffc 28
1be805e9 29# Change 'perl' to './perl' so the shell doesn't go looking through PATH.
30sub safe_rel {
7fad1f89 31 my($perl) = shift;
32 $perl = File::Spec->catfile(File::Spec->curdir, $perl) unless
33 File::Spec->file_name_is_absolute($perl);
34
35 return $perl;
1be805e9 36}
7ae32827 37# Make a putative perl binary say "ok\n". We have to do it this way
38# because the filespec of the binary may contain characters that a
39# command interpreter considers special, so we can't use the obvious
40# `$perl -le "print 'ok'"`. And, for portability, we can't use fork().
41sub sayok{
42 my $perl = shift;
43 open(STDOUTDUP, '>&STDOUT');
44 open(STDOUT, ">rel2abs2rel$$.tmp")
45 or die "Can't open scratch file rel2abs2rel$$.tmp -- $!\n";
46 system($perl, "rel2abs2rel$$.pl");
47 open(STDOUT, '>&STDOUTDUP');
48 close(STDOUTDUP);
d7f1a795 49
50 local *F;
7ae32827 51 open(F, "rel2abs2rel$$.tmp");
52 local $/ = undef;
53 my $output = <F>;
54 close(F);
55 return $output;
56}
1be805e9 57
a6133dd6 58print "# Checking manipulations of \$^X=$^X\n";
e021ab8e 59
7fad1f89 60my $perl = safe_rel($^X);
e021ab8e 61is( sayok($perl), "ok\n", "`$perl rel2abs2rel$$.pl` works" );
7fad1f89 62
63$perl = File::Spec->rel2abs($^X);
e021ab8e 64is( sayok($perl), "ok\n", "`$perl rel2abs2rel$$.pl` works" );
3bb16ffc 65
66$perl = File::Spec->canonpath($perl);
e021ab8e 67is( sayok($perl), "ok\n", "canonpath(rel2abs($^X)) = $perl" );
3bb16ffc 68
42873cec 69$perl = safe_rel(File::Spec->abs2rel($perl));
e021ab8e 70is( sayok($perl), "ok\n", "safe_rel(abs2rel(canonpath(rel2abs($^X)))) = $perl" );
3bb16ffc 71
7fad1f89 72$perl = safe_rel(File::Spec->canonpath($^X));
e021ab8e 73is( sayok($perl), "ok\n", "safe_rel(canonpath($^X)) = $perl" );