Upgrade to PathTools 3.07
[p5sagit/p5-mst-13.2.git] / lib / File / Spec / t / Spec.t
index 1c2dd6a..85d580c 100644 (file)
@@ -7,6 +7,7 @@ use File::Spec @File::Spec::EXPORT_OK ;
 
 require File::Spec::Unix ;
 require File::Spec::Win32 ;
+require Cwd;
 
 eval {
    require VMS::Filespec ;
@@ -117,6 +118,7 @@ if ($^O eq 'MacOS') {
 [ "Unix->rel2abs('/t1','/t1/t2/t3')",            '/t1'             ],
 
 [ "Win32->case_tolerant()",         '1'  ],
+[ "Win32->rootdir()",               '\\'  ],
 
 [ "Win32->splitpath('file')",                            ',,file'                            ],
 [ "Win32->splitpath('\\d1/d2\\d3/')",                    ',\\d1/d2\\d3/,'                    ],
@@ -226,14 +228,14 @@ if ($^O eq 'MacOS') {
 [ "Win32->canonpath('/..\\')",          '\\'                  ],
 [ "Win32->can('_cwd')",                 '/CODE/'              ],
 
-# FakeWin32 subclass (see below) just sets CWD to C:\one\two
+# FakeWin32 subclass (see below) just sets CWD to C:\one\two and getdcwd('D') to D:\alpha\beta
 
 [ "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('../t4','/t1/t2/t3')",         '..\\..\\..\\one\\t4'    ],  # Uses _cwd()
 [ "FakeWin32->abs2rel('/','/t1/t2/t3')",             '..\\..\\..'             ],
 [ "FakeWin32->abs2rel('///','/t1/t2/t3')",           '..\\..\\..'             ],
 [ "FakeWin32->abs2rel('/.','/t1/t2/t3')",            '..\\..\\..'             ],
@@ -295,6 +297,33 @@ if ($^O eq 'MacOS') {
 [ "VMS->canonpath('volume:[d1]file')",                     'volume:[d1]file'         ],
 [ "VMS->canonpath('volume:[d1.-.d2.][d3.d4.-]')",              'volume:[d2.d3]'          ],
 [ "VMS->canonpath('volume:[000000.d1]d2.dir;1')",                 'volume:[d1]d2.dir;1'   ],
+[ "VMS->canonpath('volume:[d1.d2.d3]file.txt')",       'volume:[d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('[d1.d2.d3]file.txt')",              '[d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('volume:[-.d1.d2.d3]file.txt')",     'volume:[-.d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('[-.d1.d2.d3]file.txt')",            '[-.d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('volume:[--.d1.d2.d3]file.txt')",    'volume:[--.d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('[--.d1.d2.d3]file.txt')",           '[--.d1.d2.d3]file.txt' ],
+[ "VMS->canonpath('volume:[d1.-.d2.d3]file.txt')",     'volume:[d2.d3]file.txt' ],
+[ "VMS->canonpath('[d1.-.d2.d3]file.txt')",            '[d2.d3]file.txt' ],
+[ "VMS->canonpath('volume:[d1.--.d2.d3]file.txt')",    'volume:[-.d2.d3]file.txt' ],
+[ "VMS->canonpath('[d1.--.d2.d3]file.txt')",           '[-.d2.d3]file.txt' ],
+[ "VMS->canonpath('volume:[d1.d2.-.d3]file.txt')",     'volume:[d1.d3]file.txt' ],
+[ "VMS->canonpath('[d1.d2.-.d3]file.txt')",            '[d1.d3]file.txt' ],
+[ "VMS->canonpath('volume:[d1.d2.--.d3]file.txt')",    'volume:[d3]file.txt' ],
+[ "VMS->canonpath('[d1.d2.--.d3]file.txt')",           '[d3]file.txt' ],
+[ "VMS->canonpath('volume:[d1.d2.d3.-]file.txt')",     'volume:[d1.d2]file.txt' ],
+[ "VMS->canonpath('[d1.d2.d3.-]file.txt')",            '[d1.d2]file.txt' ],
+[ "VMS->canonpath('volume:[d1.d2.d3.--]file.txt')",    'volume:[d1]file.txt' ],
+[ "VMS->canonpath('[d1.d2.d3.--]file.txt')",           '[d1]file.txt' ],
+[ "VMS->canonpath('volume:[d1.000000.][000000.][d3.--]file.txt')",     'volume:[d1]file.txt' ],
+[ "VMS->canonpath('[d1.000000.][000000.][d3.--]file.txt')",            '[d1]file.txt' ],
+[ "VMS->canonpath('volume:[d1.000000.][000000.][d2.000000]file.txt')", 'volume:[d1.000000.d2.000000]file.txt' ],
+[ "VMS->canonpath('[d1.000000.][000000.][d2.000000]file.txt')",        '[d1.000000.d2.000000]file.txt' ],
+[ "VMS->canonpath('volume:[d1.000000.][000000.][d3.--.000000]file.txt')",'volume:[d1.000000]file.txt' ],
+[ "VMS->canonpath('[d1.000000.][000000.][d3.--.000000]file.txt')",     '[d1.000000]file.txt' ],
+[ "VMS->canonpath('volume:[d1.000000.][000000.][-.-.000000]file.txt')",        'volume:[000000]file.txt' ],
+[ "VMS->canonpath('[d1.000000.][000000.][--.-.000000]file.txt')",      '[-.000000]file.txt' ],
+[ "VMS->canonpath('[d1.d2.--]file')",                                   '[000000]file'       ],
 
 [ "VMS->splitdir('')",            ''          ],
 [ "VMS->splitdir('[]')",          ''          ],
@@ -304,6 +333,12 @@ if ($^O eq 'MacOS') {
 [ "VMS->splitdir('[.d1.d2.d3]')", ',d1,d2,d3' ],
 [ "VMS->splitdir('.-.d2.d3')",    ',-,d2,d3'  ],
 [ "VMS->splitdir('[.-.d2.d3]')",  ',-,d2,d3'  ],
+[ "VMS->splitdir('[d1.d2]')",                  'd1,d2'  ],
+[ "VMS->splitdir('[d1-.--d2]')",       'd1-,--d2'  ],
+[ "VMS->splitdir('[d1---.-.d2]')",     'd1---,-,d2'  ],
+[ "VMS->splitdir('[d1.---.d2]')",      'd1,-,-,-,d2'  ],
+[ "VMS->splitdir('[d1---d2]')",        'd1---d2'  ],
+[ "VMS->splitdir('[d1.][000000.d2]')",  'd1,d2'  ],
 
 [ "VMS->catdir('')",                                                      ''                 ],
 [ "VMS->catdir('d1','d2','d3')",                                          '[.d1.d2.d3]'         ],
@@ -558,11 +593,37 @@ if ($^O eq 'MacOS') {
 
 ) ;
 
+if ($^O eq 'MSWin32') {
+  push @tests, [ "FakeWin32->rel2abs('D:foo.txt')", 'D:\\alpha\\beta\\foo.txt' ];
+}
+
+
 plan tests => scalar @tests;
 
 {
-    @File::Spec::FakeWin32::ISA = qw(File::Spec::Win32);
-    sub File::Spec::FakeWin32::_cwd { 'C:\\one\\two' }
+    package File::Spec::FakeWin32;
+    use vars qw(@ISA);
+    @ISA = qw(File::Spec::Win32);
+
+    sub _cwd { 'C:\\one\\two' }
+
+    # Some funky stuff to override Cwd::getdcwd() for testing purposes,
+    # in the limited scope of the rel2abs() method.
+    if ($Cwd::VERSION && $Cwd::VERSION gt '2.17') {  # Avoid a 'used only once' warning
+       local $^W;
+       *rel2abs = sub {
+           my $self = shift;
+           local $^W;
+           local *Cwd::getdcwd = sub {
+             return 'D:\alpha\beta' if $_[0] eq 'D:';
+             return 'C:\one\two'    if $_[0] eq 'C:';
+             return;
+           };
+           *Cwd::getdcwd = *Cwd::getdcwd; # Avoid a 'used only once' warning
+           return $self->SUPER::rel2abs(@_);
+       };
+       *rel2abs = *rel2abs; # Avoid a 'used only once' warning
+    }
 }