summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-07-27 16:12:44 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-07-27 16:12:44 +0000
commite021ab8eb33165472d1025d41b9f78226e0d90c7 (patch)
tree6afcf7b48a304478bbe5038866cf55b6a3376ea4 /lib
parent7996736c5ecb6da6273386229ce113837049152c (diff)
downloadperl-e021ab8eb33165472d1025d41b9f78226e0d90c7.tar.gz
Upgrade to File::Spec 0.85.
p4raw-id: //depot/perl@20225
Diffstat (limited to 'lib')
-rw-r--r--lib/File/Spec.pm4
-rw-r--r--lib/File/Spec/Epoc.pm14
-rw-r--r--lib/File/Spec/Functions.pm2
-rw-r--r--lib/File/Spec/Mac.pm4
-rw-r--r--lib/File/Spec/Unix.pm19
-rw-r--r--lib/File/Spec/Win32.pm121
-rw-r--r--lib/File/Spec/t/Functions.t21
-rw-r--r--lib/File/Spec/t/Spec.t147
-rw-r--r--lib/File/Spec/t/rel2abs2rel.t30
9 files changed, 170 insertions, 192 deletions
diff --git a/lib/File/Spec.pm b/lib/File/Spec.pm
index fd544cdec1..957216423c 100644
--- a/lib/File/Spec.pm
+++ b/lib/File/Spec.pm
@@ -3,7 +3,7 @@ package File::Spec;
use strict;
use vars qw(@ISA $VERSION);
-$VERSION = 0.84 ;
+$VERSION = '0.85';
my %module = (MacOS => 'Mac',
MSWin32 => 'Win32',
@@ -290,3 +290,5 @@ Mac support by Paul Schinder <schinder@pobox.com>, and Thomas Wegner
Yamaguchi <shigio@tamacom.com>, modified by Barrie Slaymaker
<barries@slaysys.com>. splitpath(), splitdir(), catpath() and
catdir() by Barrie Slaymaker.
+
+=cut
diff --git a/lib/File/Spec/Epoc.pm b/lib/File/Spec/Epoc.pm
index e3c90f0de4..91c3a1d7e8 100644
--- a/lib/File/Spec/Epoc.pm
+++ b/lib/File/Spec/Epoc.pm
@@ -24,20 +24,28 @@ there. This package overrides the implementation of these methods, not
the semantics.
This package is still work in progress ;-)
-o.flebbe@gmx.de
+=head1 AUTHORS
-=over 4
+o.flebbe@gmx.de
+
+=cut
sub case_tolerant {
return 1;
}
+=pod
+
+=over 4
+
=item canonpath()
No physical check on the filesystem, but a logical cleanup of a
path. On UNIX eliminated successive slashes and successive "/.".
+=back
+
=cut
sub canonpath {
@@ -51,8 +59,6 @@ sub canonpath {
return $path;
}
-=back
-
=head1 SEE ALSO
L<File::Spec>
diff --git a/lib/File/Spec/Functions.pm b/lib/File/Spec/Functions.pm
index 1a8c2aebe9..1c36e8b946 100644
--- a/lib/File/Spec/Functions.pm
+++ b/lib/File/Spec/Functions.pm
@@ -31,6 +31,7 @@ require Exporter;
catpath
abs2rel
rel2abs
+ case_tolerant
);
%EXPORT_TAGS = ( ALL => [ @EXPORT_OK, @EXPORT ] );
@@ -88,6 +89,7 @@ The following functions are exported only by request.
catpath
abs2rel
rel2abs
+ case_tolerant
All the functions may be imported using the C<:ALL> tag.
diff --git a/lib/File/Spec/Mac.pm b/lib/File/Spec/Mac.pm
index acf187ece0..513e837f14 100644
--- a/lib/File/Spec/Mac.pm
+++ b/lib/File/Spec/Mac.pm
@@ -8,11 +8,15 @@ $VERSION = '1.4';
@ISA = qw(File::Spec::Unix);
+use Cwd;
my $macfiles;
if ($^O eq 'MacOS') {
$macfiles = eval { require Mac::Files };
}
+sub case_tolerant { 1 }
+
+
=head1 NAME
File::Spec::Mac - File::Spec for Mac OS (Classic)
diff --git a/lib/File/Spec/Unix.pm b/lib/File/Spec/Unix.pm
index 904b6572e1..9e4ff7dc31 100644
--- a/lib/File/Spec/Unix.pm
+++ b/lib/File/Spec/Unix.pm
@@ -302,24 +302,7 @@ Yields:
=cut
sub splitdir {
- my ($self,$directories) = @_ ;
- #
- # split() likes to forget about trailing null fields, so here we
- # check to be sure that there will not be any before handling the
- # simple case.
- #
- if ( $directories !~ m|/\Z(?!\n)| ) {
- return split( m|/|, $directories );
- }
- else {
- #
- # since there was a trailing separator, add a file name to the end,
- # then do the split, then replace it with ''.
- #
- my( @directories )= split( m|/|, "${directories}dummy" ) ;
- $directories[ $#directories ]= '' ;
- return @directories ;
- }
+ return split m|/|, $_[1], -1; # Preserve trailing fields
}
diff --git a/lib/File/Spec/Win32.pm b/lib/File/Spec/Win32.pm
index 9e7bb39892..26d92bacc4 100644
--- a/lib/File/Spec/Win32.pm
+++ b/lib/File/Spec/Win32.pm
@@ -120,39 +120,40 @@ sub canonpath {
$path =~ s|(\\\.)+\\|\\|g; # xx\.\.\xx -> xx\xx
$path =~ s|^(\.\\)+||s unless $path eq ".\\"; # .\xx -> xx
$path =~ s|\\\Z(?!\n)||
- unless $path =~ m#^([A-Z]:)?\\\Z(?!\n)#s; # xx\ -> xx
- # xx1/xx2/xx3/../../xx -> xx1/xx
- $path =~ s|\\\.\.\.\\|\\\.\.\\\.\.\\|g; # \...\ is 2 levels up
- $path =~ s|^\.\.\.\\|\.\.\\\.\.\\|g; # ...\ is 2 levels up
- return $path if $path =~ m|^\.\.|; # skip relative paths
- return $path unless $path =~ /\.\./; # too few .'s to cleanup
- return $path if $path =~ /\.\.\.\./; # too many .'s to cleanup
- return $path if $orig_path =~ m|^\Q/../\E|
- and $orig_path =~ m|\/$|; # don't do /../dirs/
- # when called from rel2abs()
- # for ../dirs/
- my ($vol,$dirs,$file) = $self->splitpath($path);
- my @dirs = $self->splitdir($dirs);
- my (@base_dirs, @path_dirs);
- my $dest = \@base_dirs;
- for my $dir (@dirs){
- $dest = \@path_dirs if $dir eq $self->updir;
- push @$dest, $dir;
- }
- # for each .. in @path_dirs pop one item from
- # @base_dirs
- while (my $dir = shift @path_dirs){
- unless ($dir eq $self->updir){
- unshift @path_dirs, $dir;
- last;
- }
- pop @base_dirs;
+ unless $path =~ m{^([A-Z]:)?\\\Z(?!\n)}s; # xx\ -> xx
+ # xx1/xx2/xx3/../../xx -> xx1/xx
+ $path =~ s|\\\.\.\.\\|\\\.\.\\\.\.\\|g; # \...\ is 2 levels up
+ $path =~ s|^\.\.\.\\|\.\.\\\.\.\\|g; # ...\ is 2 levels up
+ return $path if $path =~ m|^\.\.|; # skip relative paths
+ return $path unless $path =~ /\.\./; # too few .'s to cleanup
+ return $path if $path =~ /\.\.\.\./; # too many .'s to cleanup
+ return $path if $orig_path =~ m|^\Q/../\E|
+ and $orig_path =~ m|\/$|; # don't do /../dirs/ when called
+ # from rel2abs() for ../dirs/
+ 1 while $path =~ s{^\\\.\.}{}; # \..\xx -> \xx
+
+ my ($vol,$dirs,$file) = $self->splitpath($path);
+ my @dirs = $self->splitdir($dirs);
+ my (@base_dirs, @path_dirs);
+ my $dest = \@base_dirs;
+ for my $dir (@dirs){
+ $dest = \@path_dirs if $dir eq $self->updir;
+ push @$dest, $dir;
+ }
+ # for each .. in @path_dirs pop one item from
+ # @base_dirs
+ while (my $dir = shift @path_dirs){
+ unless ($dir eq $self->updir){
+ unshift @path_dirs, $dir;
+ last;
}
- $path = $self->catpath(
- $vol,
- $self->catdir(@base_dirs, @path_dirs),
- $file
- );
+ pop @base_dirs;
+ }
+ $path = $self->catpath(
+ $vol,
+ $self->catdir(@base_dirs, @path_dirs),
+ $file
+ );
return $path;
}
@@ -287,31 +288,20 @@ sub catpath {
sub abs2rel {
my($self,$path,$base) = @_;
+ $base = $self->cwd() unless defined $base and length $base;
- # Clean up $path
- if ( ! $self->file_name_is_absolute( $path ) ) {
- $path = $self->rel2abs( $path ) ;
- }
- else {
- $path = $self->canonpath( $path ) ;
+ for ($path, $base) {
+ $_ = $self->canonpath($self->rel2abs($_));
}
+ my ($path_volume, $path_directories) = $self->splitpath($path, 1) ;
+ my ($base_volume, $base_directories) = $self->splitpath($base, 1);
- # Figure out the effective $base and clean it up.
- if ( !defined( $base ) || $base eq '' ) {
- $base = cwd() ;
+ if ($path_volume and not $base_volume) {
+ ($base_volume) = $self->splitpath($self->cwd);
}
- elsif ( ! $self->file_name_is_absolute( $base ) ) {
- $base = $self->rel2abs( $base ) ;
- }
- else {
- $base = $self->canonpath( $base ) ;
- }
-
- # Split up paths
- my ( undef, $path_directories, $path_file ) =
- $self->splitpath( $path, 1 ) ;
- my $base_directories = ($self->splitpath( $base, 1 ))[1] ;
+ # Can't relativize across volumes
+ return $path unless $path_volume eq $base_volume;
# Now, remove all leading components that are the same
my @pathchunks = $self->splitdir( $path_directories );
@@ -325,30 +315,9 @@ sub abs2rel {
shift @basechunks ;
}
- # No need to catdir, we know these are well formed.
- $path_directories = CORE::join( '\\', @pathchunks );
- $base_directories = CORE::join( '\\', @basechunks );
-
- # $base_directories now contains the directories the resulting relative
- # path must ascend out of before it can descend to $path_directory. So,
- # replace all names with $parentDir
-
- #FA Need to replace between backslashes...
- $base_directories =~ s|[^\\]+|..|g ;
-
- # Glue the two together, using a separator if necessary, and preventing an
- # empty result.
-
- #FA Must check that new directories are not empty.
- if ( $path_directories ne '' && $base_directories ne '' ) {
- $path_directories = "$base_directories\\$path_directories" ;
- } else {
- $path_directories = "$base_directories$path_directories" ;
- }
+ my $result_dirs = $self->catdir( ($self->updir) x @basechunks, @pathchunks );
- return $self->canonpath(
- $self->catpath( "", $path_directories, $path_file )
- ) ;
+ return $self->canonpath( $self->catpath('', $result_dirs, '') );
}
@@ -358,7 +327,7 @@ sub rel2abs {
if ( ! $self->file_name_is_absolute( $path ) ) {
if ( !defined( $base ) || $base eq '' ) {
- $base = cwd() ;
+ $base = $self->cwd() ;
}
elsif ( ! $self->file_name_is_absolute( $base ) ) {
$base = $self->rel2abs( $base ) ;
diff --git a/lib/File/Spec/t/Functions.t b/lib/File/Spec/t/Functions.t
index 926812248c..457f53cb6f 100644
--- a/lib/File/Spec/t/Functions.t
+++ b/lib/File/Spec/t/Functions.t
@@ -1,17 +1,10 @@
-#!./perl
+#!/usr/bin/perl -w
-BEGIN {
- $^O = '';
- chdir 't' if -d 't';
- @INC = '../lib';
-}
+use Test;
+use File::Spec::Functions qw/:ALL/;
+plan tests => 2;
-print "1..1\n";
+ok catfile('a','b','c'), File::Spec->catfile('a','b','c');
-use File::Spec::Functions;
-
-if (catfile('a','b','c') eq 'a/b/c') {
- print "ok 1\n";
-} else {
- print "not ok 1\n";
-}
+# seems to return 0 or 1, so see if we can call it - 2003-07-07 tels
+ok case_tolerant(), '/^0|1$/';
diff --git a/lib/File/Spec/t/Spec.t b/lib/File/Spec/t/Spec.t
index b6331cec66..847d9010ca 100644
--- a/lib/File/Spec/t/Spec.t
+++ b/lib/File/Spec/t/Spec.t
@@ -1,12 +1,7 @@
-#!./perl
+#!/usr/bin/perl -w
+
+use Test;
-BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
- if ($^O eq 'MacOS') {
- push @INC, "::lib:$MacPerl::Architecture";
- }
-}
# Grab all of the plain routines from File::Spec
use File::Spec @File::Spec::EXPORT_OK ;
@@ -35,10 +30,12 @@ require File::Spec::VMS ;
require File::Spec::OS2 ;
require File::Spec::Mac ;
+require File::Spec::Epoc ;
+require File::Spec::Cygwin ;
# $root is only needed by Mac OS tests; these particular
# tests are skipped on other OSs
-my $root;
+my $root = '';
if ($^O eq 'MacOS') {
$root = File::Spec::Mac->rootdir();
}
@@ -50,6 +47,8 @@ if ($^O eq 'MacOS') {
@tests = (
# [ Function , Expected , Platform ]
+[ "Unix->case_tolerant()", '0' ],
+
[ "Unix->catfile('a','b','c')", 'a/b/c' ],
[ "Unix->catfile('a','b','./c')", 'a/b/c' ],
[ "Unix->catfile('./a','b','c')", 'a/b/c' ],
@@ -117,6 +116,8 @@ if ($^O eq 'MacOS') {
[ "Unix->rel2abs('../t4','/t1/t2/t3')", '/t1/t2/t3/../t4' ],
[ "Unix->rel2abs('/t1','/t1/t2/t3')", '/t1' ],
+[ "Win32->case_tolerant()", '1' ],
+
[ "Win32->splitpath('file')", ',,file' ],
[ "Win32->splitpath('\\d1/d2\\d3/')", ',\\d1/d2\\d3/,' ],
[ "Win32->splitpath('d1/d2\\d3/')", ',d1/d2\\d3/,' ],
@@ -171,6 +172,10 @@ if ($^O eq 'MacOS') {
[ "Win32->catdir('')", '\\' ],
[ "Win32->catdir('/')", '\\' ],
[ "Win32->catdir('//d1','d2')", '\\\\d1\\d2' ],
+[ "Win32->catdir('\\d1\\','d2')", '\\d1\\d2' ],
+[ "Win32->catdir('\\d1','d2')", '\\d1\\d2' ],
+[ "Win32->catdir('\\d1','\\d2')", '\\d1\\d2' ],
+[ "Win32->catdir('\\d1','\\d2\\')", '\\d1\\d2' ],
[ "Win32->catdir('','/d1','d2')", '\\\\d1\\d2' ],
[ "Win32->catdir('','','/d1','d2')", '\\\\\\d1\\d2' ],
[ "Win32->catdir('','//d1','d2')", '\\\\\\d1\\d2' ],
@@ -208,34 +213,41 @@ if ($^O eq 'MacOS') {
[ "Win32->canonpath('//a/b/c/.../d')", '\\\\a\\b\\d' ],
[ "Win32->canonpath('/a/b/c/../../d')", '\\a\\d' ],
[ "Win32->canonpath('/a/b/c/.../d')", '\\a\\d' ],
-
-## Hmmm, we should test missing and relative base paths some day...
-## would need to cd to a known place, get the cwd() and use it I
-## think.
-[ "Win32->abs2rel('/t1/t2/t3','/t1/t2/t3')", '' ],
-[ "Win32->abs2rel('/t1/t2/t4','/t1/t2/t3')", '..\\t4' ],
-[ "Win32->abs2rel('/t1/t2','/t1/t2/t3')", '..' ],
-[ "Win32->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')", 't4' ],
-[ "Win32->abs2rel('/t4/t5/t6','/t1/t2/t3')", '..\\..\\..\\t4\\t5\\t6' ],
-#[ "Win32->abs2rel('../t4','/t1/t2/t3')", '\\t1\\t2\\t3\\..\\t4' ],
-[ "Win32->abs2rel('/','/t1/t2/t3')", '..\\..\\..' ],
-[ "Win32->abs2rel('///','/t1/t2/t3')", '..\\..\\..' ],
-[ "Win32->abs2rel('/.','/t1/t2/t3')", '..\\..\\..\\.' ],
-[ "Win32->abs2rel('/./','/t1/t2/t3')", '..\\..\\..' ],
-[ "Win32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')", '..\\t4' ],
-[ "Win32->abs2rel('//a/t1/t2/t4','/t2/t3')", '..\\t4' ],
-[ "Win32->abs2rel('A:/t1/t2/t3','B:/t1/t2/t3')",'' ],
-[ "Win32->abs2rel('A:/t1/t2/t3/t4','B:/t1/t2/t3')",'t4' ],
-
-[ "Win32->rel2abs('temp','C:/')", 'C:\\temp' ],
-[ "Win32->rel2abs('temp','C:/a')", 'C:\\a\\temp' ],
-[ "Win32->rel2abs('temp','C:/a/')", 'C:\\a\\temp' ],
-[ "Win32->rel2abs('../','C:/')", 'C:\\' ],
-[ "Win32->rel2abs('../','C:/a')", 'C:\\' ],
-[ "Win32->rel2abs('temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
-[ "Win32->rel2abs('../temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
-[ "Win32->rel2abs('temp','//prague_main/work')", '\\\\prague_main\\work\\temp' ],
-[ "Win32->rel2abs('../','//prague_main/work')", '\\\\prague_main\\work' ],
+[ "Win32->canonpath('\\../temp\\')", '\\temp' ],
+
+# FakeWin32 subclass (see below) just sets CWD to C:\one\two
+
+[ "FakeWin32->abs2rel('/t1/t2/t3','/t1/t2/t3')", '' ],
+[ "FakeWin32->abs2rel('/t1/t2/t4','/t1/t2/t3')", '..\\t4' ],
+[ "FakeWin32->abs2rel('/t1/t2','/t1/t2/t3')", '..' ],
+[ "FakeWin32->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')", 't4' ],
+[ "FakeWin32->abs2rel('/t4/t5/t6','/t1/t2/t3')", '..\\..\\..\\t4\\t5\\t6' ],
+[ "FakeWin32->abs2rel('../t4','/t1/t2/t3')", '..\\..\\..\\one\\t4' ],
+[ "FakeWin32->abs2rel('/','/t1/t2/t3')", '..\\..\\..' ],
+[ "FakeWin32->abs2rel('///','/t1/t2/t3')", '..\\..\\..' ],
+[ "FakeWin32->abs2rel('/.','/t1/t2/t3')", '..\\..\\..' ],
+[ "FakeWin32->abs2rel('/./','/t1/t2/t3')", '..\\..\\..' ],
+[ "FakeWin32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')", '\\\\a\\t1\\t2\\t4' ],
+[ "FakeWin32->abs2rel('//a/t1/t2/t4','/t2/t3')", '\\\\a\\t1\\t2\\t4' ],
+[ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3')", '' ],
+[ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','A:/t1/t2/t3')", 't4' ],
+[ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3/t4')", '..' ],
+[ "FakeWin32->abs2rel('A:/t1/t2/t3','B:/t1/t2/t3')", 'A:\\t1\\t2\\t3' ],
+[ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','B:/t1/t2/t3')", 'A:\\t1\\t2\\t3\\t4' ],
+[ "FakeWin32->abs2rel('E:/foo/bar/baz')", 'E:\\foo\\bar\\baz' ],
+[ "FakeWin32->abs2rel('C:/one/two/three')", 'three' ],
+
+[ "FakeWin32->rel2abs('temp','C:/')", 'C:\\temp' ],
+[ "FakeWin32->rel2abs('temp','C:/a')", 'C:\\a\\temp' ],
+[ "FakeWin32->rel2abs('temp','C:/a/')", 'C:\\a\\temp' ],
+[ "FakeWin32->rel2abs('../','C:/')", 'C:\\' ],
+[ "FakeWin32->rel2abs('../','C:/a')", 'C:\\' ],
+[ "FakeWin32->rel2abs('temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
+[ "FakeWin32->rel2abs('../temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
+[ "FakeWin32->rel2abs('temp','//prague_main/work')", '\\\\prague_main\\work\\temp' ],
+[ "FakeWin32->rel2abs('../','//prague_main/work')", '\\\\prague_main\\work' ],
+
+[ "VMS->case_tolerant()", '1' ],
[ "VMS->catfile('a','b','c')", '[.a.b]c' ],
[ "VMS->catfile('a','b','[]c')", '[.a.b]c' ],
@@ -310,6 +322,8 @@ if ($^O eq 'MacOS') {
[ "VMS->rel2abs('[-.t4]','[t1.t2.t3]')", '[t1.t2.t4]' ],
[ "VMS->rel2abs('[t1]','[t1.t2.t3]')", '[t1]' ],
+[ "OS2->case_tolerant()", '1' ],
+
[ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
[ "OS2->catfile('a','b','c')", 'a/b/c' ],
@@ -318,6 +332,7 @@ if ($^O eq 'MacOS') {
[ "OS2->catfile('c')", 'c' ],
[ "OS2->catfile('./c')", 'c' ],
+[ "Mac->case_tolerant()", '1' ],
[ "Mac->catpath('','','')", '' ],
[ "Mac->catpath('',':','')", ':' ],
@@ -504,12 +519,29 @@ if ($^O eq 'MacOS') {
[ "Mac->rel2abs('hd:','hd:d1:d2:')", 'hd:' ], # path already absolute
[ "Mac->rel2abs('hd:d3:file','hd:d1:d2:')", 'hd:d3:file' ],
[ "Mac->rel2abs('hd:d3:','hd:d1:file')", 'hd:d3:' ],
+
+[ "Epoc->case_tolerant()", '1' ],
+
+[ "Epoc->canonpath('')", '' ],
+[ "Epoc->canonpath('///../../..//./././a//b/.././c/././')", '/a/b/../c' ],
+[ "Epoc->canonpath('/./')", '/' ],
+[ "Epoc->canonpath('/a/./')", '/a' ],
+
+# XXX Todo, copied from Unix, but fail. Should they? 2003-07-07 Tels
+#[ "Epoc->canonpath('/a/.')", '/a' ],
+#[ "Epoc->canonpath('/.')", '/' ],
+
+[ "Cygwin->case_tolerant()", '0' ],
+
) ;
+plan tests => scalar @tests;
-print "1..", scalar( @tests ), "\n" ;
+{
+ @File::Spec::FakeWin32::ISA = qw(File::Spec::Win32);
+ sub File::Spec::FakeWin32::cwd { 'C:\\one\\two' }
+}
-my $current_test= 1 ;
# Test out the class methods
for ( @tests ) {
@@ -527,36 +559,23 @@ sub tryfunc {
my $platform = shift ;
if ($platform && $^O ne $platform) {
- print "ok $current_test # skipped: $function\n" ;
- ++$current_test ;
+ skip("skip $function", 1);
return;
}
$function =~ s#\\#\\\\#g ;
-
- my $got ;
- if ( $function =~ /^[^\$].*->/ ) {
- $got = eval( "join( ',', File::Spec::$function )" ) ;
- }
- else {
- $got = eval( "join( ',', $function )" ) ;
- }
+ $function =~ s/^([^\$].*->)/File::Spec::$1/;
+ my $got = join ',', eval $function;
if ( $@ ) {
- if ( substr( $@, 0, length $skip_exception ) eq $skip_exception ) {
- chomp $@ ;
- print "ok $current_test # skip $function: $@\n" ;
- }
- else {
- chomp $@ ;
- print "not ok $current_test # $function: $@\n" ;
- }
- }
- elsif ( !defined( $got ) || $got ne $expected ) {
- print "not ok $current_test # $function: got '$got', expected '$expected'\n" ;
+ if ( $@ =~ /^\Q$skip_exception/ ) {
+ skip "skip $function: $skip_exception", 1;
+ }
+ else {
+ ok $@, '', $function;
+ }
+ return;
}
- else {
- print "ok $current_test # $function\n" ;
- }
- ++$current_test ;
+
+ ok $got, $expected, $function;
}
diff --git a/lib/File/Spec/t/rel2abs2rel.t b/lib/File/Spec/t/rel2abs2rel.t
index 34f313c4dc..dbfb57ca5a 100644
--- a/lib/File/Spec/t/rel2abs2rel.t
+++ b/lib/File/Spec/t/rel2abs2rel.t
@@ -1,12 +1,13 @@
-#!./perl -w
+#!/usr/bin/perl -w
-# Herein we apply abs2rel, rel2abs and canonpath against various real
-# world files and make sure it all actually works.
+# Here we make sure File::Spec can properly deal with executables.
+# VMS has some trouble with these.
+
+use Test::More (-x $^X
+ ? (tests => 5)
+ : (skip_all => "Can't find an executable file")
+ );
-BEGIN {
- chdir 't';
- @INC = '../lib';
-}
BEGIN { # Set up a tiny script file
open(F, ">rel2abs2rel$$.pl")
or die "Can't open rel2abs2rel$$.pl file for script -- $!\n";
@@ -20,7 +21,6 @@ END {
use Config;
-use Test::More tests => 5;
use File::Spec;
# Change 'perl' to './perl' so the shell doesn't go looking through PATH.
@@ -50,19 +50,19 @@ sub sayok{
return $output;
}
-# Here we make sure File::Spec can properly deal with executables.
-# VMS has some trouble with these.
+print "Checking manipulations of \$^X=$^X\n";
+
my $perl = safe_rel($^X);
-is( sayok($perl), "ok\n", '`` works' );
+is( sayok($perl), "ok\n", "`$perl rel2abs2rel$$.pl` works" );
$perl = File::Spec->rel2abs($^X);
-is( sayok($perl), "ok\n", '`` works' );
+is( sayok($perl), "ok\n", "`$perl rel2abs2rel$$.pl` works" );
$perl = File::Spec->canonpath($perl);
-is( sayok($perl), "ok\n", 'rel2abs($^X)' );
+is( sayok($perl), "ok\n", "canonpath(rel2abs($^X)) = $perl" );
$perl = safe_rel(File::Spec->abs2rel($perl));
-is( sayok($perl), "ok\n", 'canonpath on abs executable' );
+is( sayok($perl), "ok\n", "safe_rel(abs2rel(canonpath(rel2abs($^X)))) = $perl" );
$perl = safe_rel(File::Spec->canonpath($^X));
-is(sayok($perl), "ok\n", 'canonpath on rel executable' );
+is( sayok($perl), "ok\n", "safe_rel(canonpath($^X)) = $perl" );