more complete File::Spec support for Mac and VMS, tests (from
Gurusamy Sarathy [Tue, 15 Feb 2000 16:17:36 +0000 (16:17 +0000)]
Barrie Slaymaker <barries@slaysys.com>)

p4raw-id: //depot/perl@5099

lib/File/Spec/Mac.pm
lib/File/Spec/Unix.pm
lib/File/Spec/VMS.pm
lib/File/Spec/Win32.pm
t/lib/filespec.t

index e1f3c17..14da25a 100644 (file)
@@ -218,6 +218,174 @@ sub path {
     return split(/,/, $ENV{Commands});
 }
 
+=item splitpath
+
+=cut
+
+sub splitpath {
+    my ($self,$path, $nofile) = @_;
+
+    my ($volume,$directory,$file) = ('','','');
+
+    if ( $nofile ) {
+        ( $volume, $directory ) = $path =~ m@((?:[^:]+(?::|$))?)(.*)@;
+    }
+    else {
+        $path =~ 
+            m@^( (?: [^:]+: )? ) 
+                ( (?: .*: )? )
+                ( .* )
+             @x;
+        $volume    = $1;
+        $directory = $2;
+        $file      = $3;
+    }
+
+    # Make sure non-empty volumes and directories end in ':'
+    $volume    .= ':' if $volume    =~ m@[^:]$@ ;
+    $directory .= ':' if $directory =~ m@[^:]$@ ;
+    return ($volume,$directory,$file);
+}
+
+
+=item splitdir
+
+=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@:$@ ) {
+        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 ;
+    }
+}
+
+
+=item catpath
+
+=cut
+
+sub catpath {
+    my $self = shift ;
+
+    my $result = shift ;
+    $result =~ s@^([^/])@/$1@ ;
+
+    my $segment ;
+    for $segment ( @_ ) {
+        if ( $result =~ m@[^/]$@ && $segment =~ m@^[^/]@ ) {
+            $result .= "/$segment" ;
+        }
+        elsif ( $result =~ m@/$@ && $segment =~ m@^/@ ) {
+            $result  =~ s@/+$@/@;
+            $segment =~ s@^/+@@;
+            $result  .= "$segment" ;
+        }
+        else {
+            $result  .= $segment ;
+        }
+    }
+
+    return $result ;
+}
+
+=item abs2rel
+
+=cut
+
+sub abs2rel {
+    my($self,$path,$base) = @_;
+
+    # Clean up $path
+    if ( ! $self->file_name_is_absolute( $path ) ) {
+        $path = $self->rel2abs( $path ) ;
+    }
+
+    # Figure out the effective $base and clean it up.
+    if ( !defined( $base ) || $base eq '' ) {
+        $base = cwd() ;
+    }
+    elsif ( ! $self->file_name_is_absolute( $base ) ) {
+        $base = $self->rel2abs( $base ) ;
+    }
+
+    # Now, remove all leading components that are the same
+    my @pathchunks = $self->splitdir( $path );
+    my @basechunks = $self->splitdir( $base );
+
+    while (@pathchunks && @basechunks && $pathchunks[0] eq $basechunks[0]) {
+        shift @pathchunks ;
+        shift @basechunks ;
+    }
+
+    $path = join( ':', @pathchunks );
+
+    # @basechunks now contains the number of directories to climb out of.
+    $base = ':' x @basechunks ;
+
+    return "$base:$path" ;
+}
+
+=item rel2abs
+
+Converts a relative path to an absolute path. 
+
+    $abs_path = $File::Spec->rel2abs( $destination ) ;
+    $abs_path = $File::Spec->rel2abs( $destination, $base ) ;
+
+If $base is not present or '', then L<cwd()> is used. If $base is relative, 
+then it is converted to absolute form using L</rel2abs()>. This means that it
+is taken to be relative to L<cwd()>.
+
+On systems with the concept of a volume, this assumes that both paths 
+are on the $base volume, and ignores the $destination volume. 
+
+On systems that have a grammar that indicates filenames, this ignores the 
+$base filename as well. Otherwise all path components are assumed to be
+directories.
+
+If $path is absolute, it is cleaned up and returned using L</canonpath()>.
+
+Based on code written by Shigio Yamaguchi.
+
+No checks against the filesystem are made. 
+
+=cut
+
+sub rel2abs($;$;) {
+    my ($self,$path,$base ) = @_;
+
+    if ( ! $self->file_name_is_absolute( $path ) ) {
+        if ( !defined( $base ) || $base eq '' ) {
+            $base = cwd() ;
+        }
+        elsif ( ! $self->file_name_is_absolute( $base ) ) {
+            $base = $self->rel2abs( $base ) ;
+        }
+        else {
+            $base = $self->canonpath( $base ) ;
+        }
+
+        $path = $self->canonpath("$base$path") ;
+    }
+
+    return $path ;
+}
+
+
 =back
 
 =head1 SEE ALSO
index 85df2c2..d47a60e 100644 (file)
@@ -26,28 +26,15 @@ No physical check on the filesystem, but a logical cleanup of a
 path. On UNIX eliminated successive slashes and successive "/.".
 
     $cpath = File::Spec->canonpath( $path ) ;
-    $cpath = File::Spec->canonpath( $path, $reduce_ricochet ) ;
-
-If $reduce_ricochet is present and true, then "dirname/.." 
-constructs are eliminated from the path. Without $reduce_ricochet,
-if dirname is a symbolic link, then "a/dirname/../b" will often 
-take you to someplace other than "a/b". This is sometimes desirable.
-If it's not, setting $reduce_ricochet causes the "dirname/.." to
-be removed from this path, resulting in "a/b".  This may make
-your perl more portable and robust, unless you want to
-ricochet (some scripts depend on it).
 
 =cut
 
 sub canonpath {
-    my ($self,$path,$reduce_ricochet) = @_;
+    my ($self,$path) = @_;
     $path =~ s|/+|/|g unless($^O eq 'cygwin');     # xx////xx  -> xx/xx
     $path =~ s|(/\.)+/|/|g;                        # xx/././xx -> xx/xx
     $path =~ s|^(\./)+|| unless $path eq "./";     # ./xx      -> xx
     $path =~ s|^/(\.\./)+|/|;                      # /../../xx -> xx
-    if ( $reduce_ricochet ) {
-        while ( $path =~ s@[^/]+/\.\.(?:/|$)@@ ) {}# xx/..     -> xx
-    }
     $path =~ s|/$|| unless $path eq "/";           # xx/       -> xx
     return $path;
 }
@@ -281,8 +268,8 @@ sub splitdir {
 =item catpath
 
 Takes volume, directory and file portions and returns an entire path. Under
-Unix, $volume is ignored, and this is just like catfile(). On other OSs,
-the $volume become significant.
+Unix, $volume is ignored, and directory and file are catenated.  A '/' is
+inserted if need be.  On other OSs, $volume is significant.
 
 =cut
 
index 7949146..71c38f2 100644 (file)
@@ -263,6 +263,220 @@ sub file_name_is_absolute {
                  $file =~ /:[^<\[]/);
 }
 
+=item splitpath
+
+    ($volume,$directories,$file) = File::Spec->splitpath( $path );
+    ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
+
+Splits a VMS path in to volume, directory, and filename portions.
+Ignores $no_file, if present, since VMS paths indicate the 'fileness' of a 
+file.
+
+The results can be passed to L</catpath()> to get back a path equivalent to
+(usually identical to) the original path.
+
+=cut
+
+sub splitpath {
+    my $self = shift ;
+    my ($path, $nofile) = @_;
+
+    my ($volume,$directory,$file) ;
+
+    if ( $path =~ m{/} ) {
+        $path =~ 
+            m{^ ( (?: /[^/]* )? )
+                ( (?: .*/(?:[^/]+.dir)? )? )
+                (.*)
+             }x;
+        $volume    = $1;
+        $directory = $2;
+        $file      = $3;
+    }
+    else {
+        $path =~ 
+            m{^ ( (?: (?: (?: [\w\$-]+ (?: "[^"]*")?:: )? [\w\$-]+: )? ) )
+                ( (?:\[.*\])? )
+                (.*)
+             }x;
+        $volume    = $1;
+        $directory = $2;
+        $file      = $3;
+    }
+
+    $directory = $1
+        if $directory =~ /^\[(.*)\]$/ ;
+
+    return ($volume,$directory,$file);
+}
+
+
+=item splitdir
+
+The opposite of L</catdir()>.
+
+    @dirs = File::Spec->splitdir( $directories );
+
+$directories must be only the directory portion of the path.
+
+'[' and ']' delimiters are optional. An empty string argument is
+equivalent to '[]': both return an array with no elements.
+
+=cut
+
+sub splitdir {
+    my $self = shift ;
+    my $directories = $_[0] ;
+
+    return File::Spec::Unix::splitdir( $self, @_ )
+        if ( $directories =~ m{/} ) ;
+
+    $directories =~ s/^\[(.*)\]$/$1/ ;
+
+    #
+    # 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{\.$} ) {
+        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 ;
+    }
+}
+
+
+sub catpath {
+    my $self = shift;
+
+    return File::Spec::Unix::catpath( $self, @_ )
+        if ( join( '', @_ ) =~ m{/} ) ;
+
+    my ($volume,$directory,$file) = @_;
+
+    $volume .= ':'
+        if $volume =~ /[^:]$/ ;
+
+    $directory = "[$directory"
+        if $directory =~ /^[^\[]/ ;
+
+    $directory .= ']'
+        if $directory =~ /[^\]]$/ ;
+
+    return "$volume$directory$file" ;
+}
+
+
+sub abs2rel {
+    my $self = shift;
+
+    return File::Spec::Unix::abs2rel( $self, @_ )
+        if ( join( '', @_ ) =~ m{/} ) ;
+
+    my($path,$base) = @_;
+
+    # Note: we use '/' to glue things together here, then let canonpath()
+    # clean them up at the end.
+
+    # Clean up $path
+    if ( ! $self->file_name_is_absolute( $path ) ) {
+        $path = $self->rel2abs( $path ) ;
+    }
+    else {
+        $path = $self->canonpath( $path ) ;
+    }
+
+    # Figure out the effective $base and clean it up.
+    if ( ! $self->file_name_is_absolute( $base ) ) {
+        $base = $self->rel2abs( $base ) ;
+    }
+    elsif ( !defined( $base ) || $base eq '' ) {
+        $base = cwd() ;
+    }
+    else {
+        $base = $self->canonpath( $base ) ;
+    }
+
+    # Split up paths
+    my ( undef, $path_directories, $path_file ) =
+        $self->splitpath( $path, 1 ) ;
+
+    $path_directories = $1
+        if $path_directories =~ /^\[(.*)\]$/ ;
+
+    my ( undef, $base_directories, undef ) =
+        $self->splitpath( $base, 1 ) ;
+
+    $base_directories = $1
+        if $base_directories =~ /^\[(.*)\]$/ ;
+
+    # Now, remove all leading components that are the same
+    my @pathchunks = $self->splitdir( $path_directories );
+    my @basechunks = $self->splitdir( $base_directories );
+
+    while ( @pathchunks && 
+            @basechunks && 
+            lc( $pathchunks[0] ) eq lc( $basechunks[0] ) 
+          ) {
+        shift @pathchunks ;
+        shift @basechunks ;
+    }
+
+    # @basechunks now contains the directories to climb out of,
+    # @pathchunks now has the directories to descend in to.
+    $path_directories = '-.' x @basechunks . join( '.', @pathchunks ) ;
+    $path_directories =~ s{\.$}{} ;
+    return $self->catpath( '', $path_directories, $path_file ) ;
+}
+
+
+sub rel2abs($;$;) {
+    my $self = shift ;
+    return File::Spec::Unix::rel2abs( $self, @_ )
+        if ( join( '', @_ ) =~ m{/} ) ;
+
+    my ($path,$base ) = @_;
+    # Clean up and split up $path
+    if ( ! $self->file_name_is_absolute( $path ) ) {
+        # Figure out the effective $base and clean it up.
+        if ( !defined( $base ) || $base eq '' ) {
+            $base = 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 ) ;
+
+        my ( $base_volume, $base_directories, undef ) =
+            $self->splitpath( $base ) ;
+
+        my $sep = '' ;
+        $sep = '.'
+            if ( $base_directories =~ m{[^.]$} &&
+                 $path_directories =~ m{^[^.]}
+            ) ;
+        $base_directories = "$base_directories$sep$path_directories" ;
+
+        $path = $self->catpath( $base_volume, $base_directories, $path_file );
+   }
+
+    return $self->canonpath( $path ) ;
+}
+
+
 =back
 
 =head1 SEE ALSO
index 120b799..f1c6ccf 100644 (file)
@@ -95,7 +95,7 @@ path. On UNIX eliminated successive slashes and successive "/.".
 =cut
 
 sub canonpath {
-    my ($self,$path,$reduce_ricochet) = @_;
+    my ($self,$path) = @_;
     $path =~ s/^([a-z]:)/\u$1/;
     $path =~ s|/|\\|g;
     $path =~ s|([^\\])\\+|$1\\|g;                  # xx////xx  -> xx/xx
@@ -120,7 +120,7 @@ Separators accepted are \ and /.
 
 Volumes can be drive letters or UNC sharenames (\\server\share).
 
-The results can be passed to L</catpath()> to get back a path equivalent to
+The results can be passed to L</catpath> to get back a path equivalent to
 (usually identical to) the original path.
 
 =cut
@@ -130,21 +130,21 @@ sub splitpath {
     my ($volume,$directory,$file) = ('','','');
     if ( $nofile ) {
         $path =~ 
-            m@^( (?:[a-zA-Z]:|(?:\\\\\\\\|//)[^\\\\/]+[\\\\/][^\\\\/]+)? ) 
+            m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? ) 
                  (.*)
-             @x;
+             }x;
         $volume    = $1;
         $directory = $2;
     }
     else {
         $path =~ 
-            m@^ ( (?: [a-zA-Z]: |
-                      (?:\\\\\\\\|//)[^\\\\/]+[\\\\/][^\\\\/]+
+            m{^ ( (?: [a-zA-Z]: |
+                      (?:\\\\|//)[^\\/]+[\\/][^\\/]+
                   )?
                 )
                 ( (?:.*[\\\\/](?:\.\.?$)?)? )
                 (.*)
-             @x;
+             }x;
         $volume    = $1;
         $directory = $2;
         $file      = $3;
@@ -221,8 +221,8 @@ sub catpath {
     # If the volume is not just A:, make sure the glue separator is 
     # there, reusing whatever separator is first in the $volume if possible.
     if ( $volume !~ m@^[a-zA-Z]:$@ &&
-         $volume !~ m@[\\/]$@      &&
-         $file   !~ m@^[\\/]@
+         $volume =~ m@[^\\/]$@      &&
+         $file   =~ m@[^\\/]@
        ) {
         $volume =~ m@([\\/])@ ;
         my $sep = $1 ? $1 : '\\' ;
@@ -248,7 +248,7 @@ then it is converted to absolute form using L</rel2abs()>. This means that it
 is taken to be relative to L<cwd()>.
 
 On systems with the concept of a volume, this assumes that both paths 
-are on the $destination volume, and ignores the $base volume. 
+are on the $destination volume, and ignores the $base volume.
 
 On systems that have a grammar that indicates filenames, this ignores the 
 $base filename as well. Otherwise all path components are assumed to be
@@ -325,8 +325,11 @@ sub abs2rel {
         $path_directories = "$base_directories$path_directories" ;
     }
 
+    # It makes no sense to add a relative path to a UNC volume
+    $path_volume = '' unless $path_volume =~ m{^[A-Z]:}i ;
+
     return $self->canonpath( 
-        $self->catpath( $path_volume, $path_directories, $path_file )
+        $self->catpath($path_volume, $path_directories, $path_file ) 
     ) ;
 }
 
@@ -359,10 +362,8 @@ No checks against the filesystem are made.
 sub rel2abs($;$;) {
     my ($self,$path,$base ) = @_;
 
-    # Clean up and split up $path
     if ( ! $self->file_name_is_absolute( $path ) ) {
 
-        # Figure out the effective $base and clean it up.
         if ( ! $self->file_name_is_absolute( $base ) ) {
             $base = $self->rel2abs( $base ) ;
         }
@@ -373,7 +374,6 @@ sub rel2abs($;$;) {
             $base = $self->canonpath( $base ) ;
         }
 
-        # Split up paths
         my ( undef, $path_directories, $path_file ) =
             $self->splitpath( $path, 1 ) ;
 
index 3aeed17..9c273d2 100755 (executable)
@@ -6,38 +6,378 @@ BEGIN {
     unshift @INC, '../lib';
 }
 
-print "1..4\n";
+# 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.
 
-use File::Spec;
+@tests = (
+# Function                      Expected
+[ "Unix->catfile('a','b','c')", 'a/b/c'  ],
 
+[ "Unix->splitpath('file')",            ',,file'            ],
+[ "Unix->splitpath('/d1/d2/d3/')",      ',/d1/d2/d3/,'      ],
+[ "Unix->splitpath('d1/d2/d3/')",       ',d1/d2/d3/,'       ],
+[ "Unix->splitpath('/d1/d2/d3/.')",     ',/d1/d2/d3/.,'     ],
+[ "Unix->splitpath('/d1/d2/d3/..')",    ',/d1/d2/d3/..,'    ],
+[ "Unix->splitpath('/d1/d2/d3/.file')", ',/d1/d2/d3/,.file' ],
+[ "Unix->splitpath('d1/d2/d3/file')",   ',d1/d2/d3/,file'   ],
+[ "Unix->splitpath('/../../d1/')",      ',/../../d1/,'      ],
+[ "Unix->splitpath('/././d1/')",        ',/././d1/,'        ],
 
-if (File::Spec->catfile('a','b','c') eq 'a/b/c') {
-       print "ok 1\n";
-} else {
-       print "not ok 1\n";
-}
+[ "Unix->catpath('','','file')",            'file'            ],
+[ "Unix->catpath('','/d1/d2/d3/','')",      '/d1/d2/d3/'      ],
+[ "Unix->catpath('','d1/d2/d3/','')",       'd1/d2/d3/'       ],
+[ "Unix->catpath('','/d1/d2/d3/.','')",     '/d1/d2/d3/.'     ],
+[ "Unix->catpath('','/d1/d2/d3/..','')",    '/d1/d2/d3/..'    ],
+[ "Unix->catpath('','/d1/d2/d3/','.file')", '/d1/d2/d3/.file' ],
+[ "Unix->catpath('','d1/d2/d3/','file')",   'd1/d2/d3/file'   ],
+[ "Unix->catpath('','/../../d1/','')",      '/../../d1/'      ],
+[ "Unix->catpath('','/././d1/','')",        '/././d1/'        ],
+[ "Unix->catpath('d1','d2/d3/','')",        'd2/d3/'          ],
+[ "Unix->catpath('d1','d2','d3/')",         'd2/d3/'          ],
 
-use File::Spec::OS2;
+[ "Unix->splitdir('')",           ''           ],
+[ "Unix->splitdir('/d1/d2/d3/')", ',d1,d2,d3,' ],
+[ "Unix->splitdir('d1/d2/d3/')",  'd1,d2,d3,'  ],
+[ "Unix->splitdir('/d1/d2/d3')",  ',d1,d2,d3'  ],
+[ "Unix->splitdir('d1/d2/d3')",   'd1,d2,d3'   ],
 
-if (File::Spec::OS2->catfile('a','b','c') eq 'a/b/c') {
-       print "ok 2\n";
-} else {
-       print "not ok 2\n";
-}
+[ "Unix->catdir()",                     ''          ],
+[ "Unix->catdir('/')",                  '/'         ],
+[ "Unix->catdir('','d1','d2','d3','')", '/d1/d2/d3' ],
+[ "Unix->catdir('d1','d2','d3','')",    'd1/d2/d3'  ],
+[ "Unix->catdir('','d1','d2','d3')",    '/d1/d2/d3' ],
+[ "Unix->catdir('d1','d2','d3')",       'd1/d2/d3'  ],
+
+[ "Unix->catfile('a','b','c')", 'a/b/c' ],
+
+[ "Unix->canonpath('')",                                      ''          ],
+[ "Unix->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
+[ "Unix->canonpath('/.')",                                    '/.'        ],
+
+[  "Unix->abs2rel('/t1/t2/t3','/t1/t2/t3')",          ''                   ],
+[  "Unix->abs2rel('/t1/t2/t4','/t1/t2/t3')",          '../t4'              ],
+[  "Unix->abs2rel('/t1/t2','/t1/t2/t3')",             '..'                 ],
+[  "Unix->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')",       't4'                 ],
+[  "Unix->abs2rel('/t4/t5/t6','/t1/t2/t3')",          '../../../t4/t5/t6'  ],
+#[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
+[  "Unix->abs2rel('/','/t1/t2/t3')",                  '../../..'           ],
+[  "Unix->abs2rel('///','/t1/t2/t3')",                '../../..'           ],
+[  "Unix->abs2rel('/.','/t1/t2/t3')",                 '../../../.'         ],
+[  "Unix->abs2rel('/./','/t1/t2/t3')",                '../../..'           ],
+#[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
+
+[ "Unix->rel2abs('t4','/t1/t2/t3')",             '/t1/t2/t3/t4'    ],
+[ "Unix->rel2abs('t4/t5','/t1/t2/t3')",          '/t1/t2/t3/t4/t5' ],
+[ "Unix->rel2abs('.','/t1/t2/t3')",              '/t1/t2/t3'       ],
+[ "Unix->rel2abs('..','/t1/t2/t3')",             '/t1/t2/t3/..'    ],
+[ "Unix->rel2abs('../t4','/t1/t2/t3')",          '/t1/t2/t3/../t4' ],
+[ "Unix->rel2abs('/t1','/t1/t2/t3')",            '/t1'             ],
+
+[ "Win32->splitpath('file')",                            ',,file'                            ],
+[ "Win32->splitpath('\\d1/d2\\d3/')",                    ',\\d1/d2\\d3/,'                    ],
+[ "Win32->splitpath('d1/d2\\d3/')",                      ',d1/d2\\d3/,'                      ],
+[ "Win32->splitpath('\\d1/d2\\d3/.')",                   ',\\d1/d2\\d3/.,'                   ],
+[ "Win32->splitpath('\\d1/d2\\d3/..')",                  ',\\d1/d2\\d3/..,'                  ],
+[ "Win32->splitpath('\\d1/d2\\d3/.file')",               ',\\d1/d2\\d3/,.file'               ],
+[ "Win32->splitpath('\\d1/d2\\d3/file')",                ',\\d1/d2\\d3/,file'                ],
+[ "Win32->splitpath('d1/d2\\d3/file')",                  ',d1/d2\\d3/,file'                  ],
+[ "Win32->splitpath('C:\\d1/d2\\d3/')",                  'C:,\\d1/d2\\d3/,'                  ],
+[ "Win32->splitpath('C:d1/d2\\d3/')",                    'C:,d1/d2\\d3/,'                    ],
+[ "Win32->splitpath('C:\\d1/d2\\d3/file')",              'C:,\\d1/d2\\d3/,file'              ],
+[ "Win32->splitpath('C:d1/d2\\d3/file')",                'C:,d1/d2\\d3/,file'                ],
+[ "Win32->splitpath('C:\\../d2\\d3/file')",              'C:,\\../d2\\d3/,file'              ],
+[ "Win32->splitpath('C:../d2\\d3/file')",                'C:,../d2\\d3/,file'                ],
+[ "Win32->splitpath('\\../..\\d1/')",                    ',\\../..\\d1/,'                    ],
+[ "Win32->splitpath('\\./.\\d1/')",                      ',\\./.\\d1/,'                      ],
+[ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/')",     '\\\\node\\share,\\d1/d2\\d3/,'     ],
+[ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/file')", '\\\\node\\share,\\d1/d2\\d3/,file' ],
+[ "Win32->splitpath('\\\\node\\share\\d1/d2\\file')",    '\\\\node\\share,\\d1/d2\\,file'    ],
+[ "Win32->splitpath('file',1)",                          ',file,'                            ],
+[ "Win32->splitpath('\\d1/d2\\d3/',1)",                  ',\\d1/d2\\d3/,'                    ],
+[ "Win32->splitpath('d1/d2\\d3/',1)",                    ',d1/d2\\d3/,'                      ],
+[ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/',1)",   '\\\\node\\share,\\d1/d2\\d3/,'     ],
+
+[ "Win32->catpath('','','file')",                            'file'                            ],
+[ "Win32->catpath('','\\d1/d2\\d3/','')",                    '\\d1/d2\\d3/'                    ],
+[ "Win32->catpath('','d1/d2\\d3/','')",                      'd1/d2\\d3/'                      ],
+[ "Win32->catpath('','\\d1/d2\\d3/.','')",                   '\\d1/d2\\d3/.'                   ],
+[ "Win32->catpath('','\\d1/d2\\d3/..','')",                  '\\d1/d2\\d3/..'                  ],
+[ "Win32->catpath('','\\d1/d2\\d3/','.file')",               '\\d1/d2\\d3/.file'               ],
+[ "Win32->catpath('','\\d1/d2\\d3/','file')",                '\\d1/d2\\d3/file'                ],
+[ "Win32->catpath('','d1/d2\\d3/','file')",                  'd1/d2\\d3/file'                  ],
+[ "Win32->catpath('C:','\\d1/d2\\d3/','')",                  'C:\\d1/d2\\d3/'                  ],
+[ "Win32->catpath('C:','d1/d2\\d3/','')",                    'C:d1/d2\\d3/'                    ],
+[ "Win32->catpath('C:','\\d1/d2\\d3/','file')",              'C:\\d1/d2\\d3/file'              ],
+[ "Win32->catpath('C:','d1/d2\\d3/','file')",                'C:d1/d2\\d3/file'                ],
+[ "Win32->catpath('C:','\\../d2\\d3/','file')",              'C:\\../d2\\d3/file'              ],
+[ "Win32->catpath('C:','../d2\\d3/','file')",                'C:../d2\\d3/file'                ],
+[ "Win32->catpath('','\\../..\\d1/','')",                    '\\../..\\d1/'                    ],
+[ "Win32->catpath('','\\./.\\d1/','')",                      '\\./.\\d1/'                      ],
+[ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','')",     '\\\\node\\share\\d1/d2\\d3/'     ],
+[ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','file')", '\\\\node\\share\\d1/d2\\d3/file' ],
+[ "Win32->catpath('\\\\node\\share','\\d1/d2\\','file')",    '\\\\node\\share\\d1/d2\\file'    ],
+
+[ "Win32->splitdir('')",             ''           ],
+[ "Win32->splitdir('\\d1/d2\\d3/')", ',d1,d2,d3,' ],
+[ "Win32->splitdir('d1/d2\\d3/')",   'd1,d2,d3,'  ],
+[ "Win32->splitdir('\\d1/d2\\d3')",  ',d1,d2,d3'  ],
+[ "Win32->splitdir('d1/d2\\d3')",    'd1,d2,d3'   ],
+
+[ "Win32->catdir()",                        ''                   ],
+[ "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','d3','')",    '\\d1\\d2\\d3'       ],
+[ "Win32->catdir('d1','d2','d3','')",       'd1\\d2\\d3'         ],
+[ "Win32->catdir('','d1','d2','d3')",       '\\d1\\d2\\d3'       ],
+[ "Win32->catdir('d1','d2','d3')",          'd1\\d2\\d3'         ],
+[ "Win32->catdir('A:/d1','d2','d3')",       'A:\\d1\\d2\\d3'     ],
+[ "Win32->catdir('A:/d1','d2','d3','')",    'A:\\d1\\d2\\d3'     ],
+#[ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\d2\\d3'     ],
+[ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\B:\\d2\\d3' ],
+[ "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->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->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:\\a\\..'                       ],
+[ "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\\..'       ],
+
+[ "VMS->splitpath('file')",                                       ',,file'                                   ],
+[ "VMS->splitpath('[d1.d2.d3]')",                                 ',d1.d2.d3,'                               ],
+[ "VMS->splitpath('[.d1.d2.d3]')",                                ',.d1.d2.d3,'                              ],
+[ "VMS->splitpath('[d1.d2.d3]file')",                             ',d1.d2.d3,file'                           ],
+[ "VMS->splitpath('d1/d2/d3/file')",                              ',d1/d2/d3/,file'                          ],
+[ "VMS->splitpath('/d1/d2/d3/file')",                             '/d1,/d2/d3/,file'                         ],
+[ "VMS->splitpath('[.d1.d2.d3]file')",                            ',.d1.d2.d3,file'                          ],
+[ "VMS->splitpath('node::volume:[d1.d2.d3]')",                    'node::volume:,d1.d2.d3,'                  ],
+[ "VMS->splitpath('node::volume:[d1.d2.d3]file')",                'node::volume:,d1.d2.d3,file'              ],
+[ "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('','','file')",                                       'file'                                     ],
+[ "VMS->catpath('','[d1.d2.d3]','')",                                 '[d1.d2.d3]'                               ],
+[ "VMS->catpath('','[.d1.d2.d3]','')",                                '[.d1.d2.d3]'                              ],
+[ "VMS->catpath('','[d1.d2.d3]','file')",                             '[d1.d2.d3]file'                           ],
+[ "VMS->catpath('','[.d1.d2.d3]','file')",                            '[.d1.d2.d3]file'                          ],
+[ "VMS->catpath('','d1/d2/d3','file')",                               'd1/d2/d3/file'                            ],
+[ "VMS->catpath('v','d1/d2/d3','file')",                              'd1/d2/d3/file'                            ],
+[ "VMS->catpath('node::volume:','[d1.d2.d3]','')",                    'node::volume:[d1.d2.d3]'                  ],
+[ "VMS->catpath('node::volume:','[d1.d2.d3]','file')",                'node::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('')",                                    ''                        ],
+# There's no VMS specific canonpath
+#[ "VMS->canonpath('volume:[d1]file')",                     'volume:[d1]file'         ],
+#[ "VMS->canonpath('LOGICAL:[LOGICAL]LOGICAL')",            'LOGICAL:[VULCAN]LOGICAL' ],
+#[ "VMS->canonpath('volume:[d1]d2.dir')",                   'volume:[d1.d2]'          ],
+#[ "VMS->canonpath('volume:[d1]d2.dir;1')",                 'volume:[d1.d2]'          ],
+#[ "VMS->canonpath('volume:[d1.d2.--]file')",               'volume:[d1.d2.-.-]file'  ],
+[ "VMS->canonpath('///../../..//./././a//b/.././c/././')", '/a/b/../c'               ],
+
+[ "VMS->splitdir('')",            ''          ],
+[ "VMS->splitdir('[]')",          ''          ],
+[ "VMS->splitdir('d1.d2.d3')",    'd1,d2,d3'  ],
+[ "VMS->splitdir('[d1.d2.d3]')",  'd1,d2,d3'  ],
+[ "VMS->splitdir('.d1.d2.d3')",   ',d1,d2,d3' ],
+[ "VMS->splitdir('[.d1.d2.d3]')", ',d1,d2,d3' ],
+[ "VMS->splitdir('.-.d2.d3')",    ',-,d2,d3'  ],
+[ "VMS->splitdir('[.-.d2.d3]')",  ',-,d2,d3'  ],
+
+[ "VMS->catdir('')",                                                      '[]'                 ],
+[ "VMS->catdir('d1','d2','d3')",                                          '[d1.d2.d3]'         ],
+[ "VMS->catdir('d1','d2/','d3')",                                         '[d1.d2.d3]'         ],
+[ "VMS->catdir('','d1','d2','d3')",                                       '[.d1.d2.d3]'        ],
+[ "VMS->catdir('','-','d2','d3')",                                        '[.-.d2.d3]'         ],
+[ "VMS->catdir('','-','d2','d3')",                                        '[.-.d2.d3]'         ],
+[ "VMS->catdir('','-','','d3')",                                          '[.-.d3]'            ],
+[ "VMS->catdir('[]','<->','[]','[d3]')",                                  '[.-.d3]'            ],
+[ "VMS->catdir('dir.dir','d2.dir','d3.dir')",                             '[dir.d2.d3]'        ],
+[ "VMS->catdir('[.name]')",                                               '[.name]'            ],
+[ "VMS->catdir('[.name]','[.name]')",                                     '[.name.name]'],    
+[ "VMS->catdir('a:[.name]','b:[.name]')",                                 '[.name.name]'],    
+[ "VMS->catdir('LOGICAL:[.LOGICAL]LOGICAL','LOGICAL:[.LOGICAL]LOGICAL')", '[.LOGICAL.LOGICAL]'],
+[ "VMS->catdir('LOGICAL','LOGICAL')",                                     '[VULCAN.VULCAN]'], 
+
+[  "VMS->abs2rel('node::volume:[t1.t2.t3]','[t1.t2.t3]')", ''                 ],
+[  "VMS->abs2rel('node::volume:[t1.t2.t4]','[t1.t2.t3]')", '[-.t4]'           ],
+[  "VMS->abs2rel('[t1.t2.t3]','[t1.t2.t3]')",              ''                 ],
+[  "VMS->abs2rel('[t1.t2.t3]file','[t1.t2.t3]')",          'file'             ],
+[  "VMS->abs2rel('[t1.t2.t4]','[t1.t2.t3]')",              '[-.t4]'           ],
+[  "VMS->abs2rel('[t1.t2]file','[t1.t2.t3]')",             '[-]file'          ],
+[  "VMS->abs2rel('[t1.t2.t3.t4]','[t1.t2.t3]')",           '[t4]'             ],
+[  "VMS->abs2rel('[t4.t5.t6]','[t1.t2.t3]')",              '[-.-.-.t4.t5.t6]' ],
+#[ "VMS->abs2rel('[]','[t1.t2.t3]')",                      '[-.-.-]'          ],
+#[ "VMS->abs2rel('[..]','[t1.t2.t3]')",                    '[-.-.-]'          ],
+#[ "VMS->abs2rel('[.]','[t1.t2.t3]')",                     '[-.-.-]'          ],
+#[ "VMS->abs2rel('[..]','[t1.t2.t3]')",                    '[-.-.-]'          ],
+#[ "VMS->abs2rel('a:[t1.t2.t4]','[t1.t2.t3]')",            '[-.t4]'           ],
+#[ "VMS->abs2rel('[a.-.b.c.-]','[t1.t2.t3]')",             '[-.-.-.b]'        ],
 
-use File::Spec::Win32;
+[ "VMS->rel2abs('[.t4]','[t1.t2.t3]')",          '[t1.t2.t3.t4]'    ],
+[ "VMS->rel2abs('[.t4.t5]','[t1.t2.t3]')",       '[t1.t2.t3.t4.t5]' ],
+[ "VMS->rel2abs('[]','[t1.t2.t3]')",             '[t1.t2.t3]'       ],
+[ "VMS->rel2abs('[-]','[t1.t2.t3]')",            '[t1.t2.t3.-]'     ],
+[ "VMS->rel2abs('[-.t4]','[t1.t2.t3]')",         '[t1.t2.t3.-.t4]'  ],
+[ "VMS->rel2abs('[t1]','[t1.t2.t3]')",           '[t1]'             ],
 
-if (File::Spec::Win32->catfile('a','b','c') eq 'a\b\c') {
-       print "ok 3\n";
-} else {
-       print "not ok 3\n";
+[ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
+[ "OS2->catfile('a','b','c')",            'a/b/c'          ],
+
+[ "Mac->splitpath('file')",          ',,file'          ],
+[ "Mac->splitpath(':file')",         ',:,file'         ],
+[ "Mac->splitpath(':d1',1)",         ',:d1:,'          ],
+[ "Mac->splitpath('d1',1)",          'd1:,,'           ],
+[ "Mac->splitpath('d1:d2:d3:')",     'd1:,d2:d3:,'     ],
+[ "Mac->splitpath('d1:d2:d3',1)",    'd1:,d2:d3:,'     ],
+[ "Mac->splitpath(':d1:d2:d3:')",    ',:d1:d2:d3:,'    ],
+[ "Mac->splitpath(':d1:d2:d3:',1)",  ',:d1:d2:d3:,'    ],
+[ "Mac->splitpath('d1:d2:d3:file')", 'd1:,d2:d3:,file' ],
+[ "Mac->splitpath('d1:d2:d3',1)",    'd1:,d2:d3:,'     ],
+
+[ "Mac->catdir('')",                ':'           ],
+[ "Mac->catdir('d1','d2','d3')",    'd1:d2:d3:'   ],
+[ "Mac->catdir('d1','d2/','d3')",   'd1:d2/:d3:'  ],
+[ "Mac->catdir('','d1','d2','d3')", ':d1:d2:d3:'  ],
+[ "Mac->catdir('','','d2','d3')",   '::d2:d3:'    ],
+[ "Mac->catdir('','','','d3')",     ':::d3:'      ],
+[ "Mac->catdir(':name')",           ':name:'      ],
+[ "Mac->catdir(':name',':name')",   ':name:name:' ],
+
+[ "Mac->catfile('a','b','c')", 'a:b:c' ],
+
+[ "Mac->canonpath('')",                   ''     ],
+[ "Mac->canonpath(':')",                  ':'    ],
+[ "Mac->canonpath('::')",                 '::'   ],
+[ "Mac->canonpath('a::')",                'a::'  ],
+[ "Mac->canonpath(':a::')",               ':a::' ],
+
+[ "Mac->abs2rel('t1:t2:t3','t1:t2:t3')",    ':'            ],
+[ "Mac->abs2rel('t1:t2','t1:t2:t3')",       '::'           ],
+[ "Mac->abs2rel('t1:t4','t1:t2:t3')",       ':::t4'        ],
+[ "Mac->abs2rel('t1:t2:t4','t1:t2:t3')",    '::t4'         ],
+[ "Mac->abs2rel('t1:t2:t3:t4','t1:t2:t3')", ':t4'          ],
+[ "Mac->abs2rel('t4:t5:t6','t1:t2:t3')",    '::::t4:t5:t6' ],
+[ "Mac->abs2rel('t1','t1:t2:t3')",          ':::'          ],
+
+[ "Mac->rel2abs(':t4','t1:t2:t3')",          't1:t2:t3:t4'    ],
+[ "Mac->rel2abs(':t4:t5','t1:t2:t3')",       't1:t2:t3:t4:t5' ],
+[ "Mac->rel2abs('','t1:t2:t3')",             ''               ],
+[ "Mac->rel2abs('::','t1:t2:t3')",           't1:t2:t3::'     ],
+[ "Mac->rel2abs('::t4','t1:t2:t3')",         't1:t2:t3::t4'   ],
+[ "Mac->rel2abs('t1','t1:t2:t3')",           't1'             ],
+) ;
+
+# 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 {
+      sub File::Spec::VMS::unixify { die "unixify() only provided on VMS" } ;
+      sub File::Spec::VMS::vmspath { die "vmspath() only provided on VMS" } ;
+   } ;
+   $INC{"VMS/Filespec.pm"} = 1 ;
 }
+require File::Spec::VMS ;
 
-use File::Spec::Mac;
+require File::Spec::OS2 ;
+require File::Spec::Mac ;
 
-if (File::Spec::Mac->catfile('a','b','c') eq 'a:b:c') {
-       print "ok 4\n";
-} else {
-       print "not ok 4\n";
+print "1..", scalar( @tests ), "\n" ;
+
+my $current_test= 1 ;
+
+# Set up for logical interpolation in ::VMS->canonpath() and ::VMS->catdir()
+%ENV = ( 'LOGICAL' => 'VULCAN' ) ;
+
+# 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 ;
+
+    $function =~ s#\\#\\\\#g ;
+
+    my $got ;
+    if ( $function =~ /^[^\$].*->/ ) {
+       $got = eval( "join( ',', File::Spec::$function )" ) ;
+    }
+    else {
+       $got = eval( "join( ',', $function )" ) ;
+    }
+
+    if ( $@ ) {
+       if ( $@ =~ /only provided on VMS/ ) {
+           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" ;
+    }
+    else {
+       print "ok $current_test # $function\n" ;
+    }
+    ++$current_test ;
+}