filespec.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
BEGIN {
$^O = '';
chdir 't' if -d 't';
}
# Each element in this array is a single test. Storing them this way makes
# maintenance easy, and should be OK since perl should be pretty functional
# before these tests are run.
@tests = (
# Function Expected
[ "Unix->catfile('a','b','c')", 'a/b/c' ],
[ "Unix->splitpath('file')", ',,file' ],
[ "Unix->splitpath('/../../d1/')", ',/../../d1/,' ],
[ "Unix->splitpath('/././d1/')", ',/././d1/,' ],
[ "Unix->catpath('','','file')", 'file' ],
[ "Unix->catpath('','/../../d1/','')", '/../../d1/' ],
[ "Unix->catpath('','/././d1/','')", '/././d1/' ],
[ "Unix->splitdir('')", '' ],
[ "Unix->catdir()", '' ],
[ "Unix->catdir('/')", '/' ],
[ "Unix->catfile('a','b','c')", 'a/b/c' ],
[ "Unix->canonpath('')", '' ],
[ "Unix->canonpath('///../../..//./././a//b/.././c/././')", '/a/b/../c' ],
[ "Unix->canonpath('/.')", '/.' ],
[ "Win32->splitpath('file')", ',,file' ],
[ "Win32->splitpath('\\../..\\d1/')", ',\\../..\\d1/,' ],
[ "Win32->splitpath('\\./.\\d1/')", ',\\./.\\d1/,' ],
[ "Win32->splitpath('file',1)", ',file,' ],
[ "Win32->catpath('','','file')", 'file' ],
[ "Win32->catpath('','\\../..\\d1/','')", '\\../..\\d1/' ],
[ "Win32->catpath('','\\./.\\d1/','')", '\\./.\\d1/' ],
[ "Win32->splitdir('')", '' ],
[ "Win32->catdir()", '' ],
[ "Win32->catdir('')", '\\' ],
[ "Win32->catdir('/')", '\\' ],
[ "Win32->catdir('A:/')", 'A:\\' ],
[ "Win32->catfile('a','b','c')", 'a\\b\\c' ],
[ "Win32->canonpath('')", '' ],
[ "Win32->canonpath('a:')", 'A:' ],
[ "Win32->canonpath('A:f')", 'A:f' ],
[ "Win32->canonpath('//a\\b//c')", '\\\\a\\b\\c' ],
[ "Win32->canonpath('/a/..../c')", '\\a\\....\\c' ],
[ "Win32->canonpath('//a/b\\c')", '\\\\a\\b\\c' ],
[ "Win32->canonpath('////')", '\\\\\\' ],
[ "Win32->canonpath('//')", '\\' ],
[ "Win32->canonpath('/.')", '\\.' ],
[ "Win32->canonpath('//a/b/../../c')", '\\\\a\\b\\..\\..\\c' ],
[ "Win32->canonpath('//a/../../c')", '\\\\a\\..\\..\\c' ],
[ "Win32->rel2abs('../','C:/')", 'C:\\..' ],
[ "Win32->rel2abs('../','C:/a')", 'C:\\a\\..' ],
[ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]')", 'node"access_spec"::volume:,[d1.d2.d3],' ],
[ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]file')", 'node"access_spec"::volume:,[d1.d2.d3],file' ],
[ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','')", 'node"access_spec"::volume:[d1.d2.d3]' ],
[ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','file')", 'node"access_spec"::volume:[d1.d2.d3]file' ],
[ "VMS->canonpath('')", '' ],
[ "VMS->splitdir('')", '' ],
[ "VMS->splitdir('[]')", '' ],
[ "VMS->catdir('')", '' ],
[ "OS2->catfile('a','b','c')", 'a/b/c' ],
[ "Mac->catdir('')", ':' ],
[ "Mac->catfile('a','b','c')", 'a:b:c' ],
[ "Mac->canonpath('')", '' ],
[ "Mac->canonpath(':')", ':' ],
[ "Mac->canonpath('::')", '::' ],
[ "Mac->canonpath('a::')", 'a::' ],
[ "Mac->canonpath(':a::')", ':a::' ],
) ;
# Grab all of the plain routines from File::Spec
use File::Spec @File::Spec::EXPORT_OK ;
require File::Spec::Unix ;
require File::Spec::Win32 ;
eval {
require VMS::Filespec ;
} ;
if ( $@ ) {
# Not pretty, but it allows testing of things not implemented soley
# on VMS. It might be better to change File::Spec::VMS to do this,
# making it more usable when running on (say) Unix but working with
# VMS paths.
eval qq-
sub File::Spec::VMS::vmsify { die "$skip_exception" }
sub File::Spec::VMS::unixify { die "$skip_exception" }
sub File::Spec::VMS::vmspath { die "$skip_exception" }
- ;
$INC{"VMS/Filespec.pm"} = 1 ;
}
require File::Spec::VMS ;
require File::Spec::OS2 ;
require File::Spec::Mac ;
print "1..", scalar( @tests ), "\n" ;
my $current_test= 1 ;
# Test out the class methods
for ( @tests ) {
tryfunc( @$_ ) ;
}
#
# Tries a named function with the given args and compares the result against
# an expected result. Works with functions that return scalars or arrays.
#
sub tryfunc {
my $function = shift ;
my $expected = shift ;
my $platform = shift ;
if ($platform && $^O ne $platform) {
print "ok $current_test # skipped: $function\n" ;
++$current_test ;
return;
}
$function =~ s#\\#\\\\#g ;
my $got ;
if ( $function =~ /^[^\$].*->/ ) {
$got = eval( "join( ',', File::Spec::$function )" ) ;
}
else {
$got = eval( "join( ',', $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 ) {
}
else {
print "ok $current_test # $function\n" ;
}
++$current_test ;
}