This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
No more public cwd(), use private _cwd().
[perl5.git] / lib / File / Spec / t / Spec.t
1 #!/usr/bin/perl -w
2
3 use Test;
4
5 # Grab all of the plain routines from File::Spec
6 use File::Spec @File::Spec::EXPORT_OK ;
7
8 require File::Spec::Unix ;
9 require File::Spec::Win32 ;
10
11 eval {
12    require VMS::Filespec ;
13 } ;
14
15 my $skip_exception = "Install VMS::Filespec (from vms/ext)" ;
16
17 if ( $@ ) {
18    # Not pretty, but it allows testing of things not implemented soley
19    # on VMS.  It might be better to change File::Spec::VMS to do this,
20    # making it more usable when running on (say) Unix but working with
21    # VMS paths.
22    eval qq-
23       sub File::Spec::VMS::vmsify  { die "$skip_exception" }
24       sub File::Spec::VMS::unixify { die "$skip_exception" }
25       sub File::Spec::VMS::vmspath { die "$skip_exception" }
26    - ;
27    $INC{"VMS/Filespec.pm"} = 1 ;
28 }
29 require File::Spec::VMS ;
30
31 require File::Spec::OS2 ;
32 require File::Spec::Mac ;
33 require File::Spec::Epoc ;
34 require File::Spec::Cygwin ;
35
36 # $root is only needed by Mac OS tests; these particular
37 # tests are skipped on other OSs
38 my $root = '';
39 if ($^O eq 'MacOS') {
40         $root = File::Spec::Mac->rootdir();
41 }
42
43 # Each element in this array is a single test. Storing them this way makes
44 # maintenance easy, and should be OK since perl should be pretty functional
45 # before these tests are run.
46
47 @tests = (
48 # [ Function          ,            Expected          ,         Platform ]
49
50 [ "Unix->case_tolerant()",         '0'  ],
51
52 [ "Unix->catfile('a','b','c')",         'a/b/c'  ],
53 [ "Unix->catfile('a','b','./c')",       'a/b/c'  ],
54 [ "Unix->catfile('./a','b','c')",       'a/b/c'  ],
55 [ "Unix->catfile('c')",                 'c' ],
56 [ "Unix->catfile('./c')",               'c' ],
57
58 [ "Unix->splitpath('file')",            ',,file'            ],
59 [ "Unix->splitpath('/d1/d2/d3/')",      ',/d1/d2/d3/,'      ],
60 [ "Unix->splitpath('d1/d2/d3/')",       ',d1/d2/d3/,'       ],
61 [ "Unix->splitpath('/d1/d2/d3/.')",     ',/d1/d2/d3/.,'     ],
62 [ "Unix->splitpath('/d1/d2/d3/..')",    ',/d1/d2/d3/..,'    ],
63 [ "Unix->splitpath('/d1/d2/d3/.file')", ',/d1/d2/d3/,.file' ],
64 [ "Unix->splitpath('d1/d2/d3/file')",   ',d1/d2/d3/,file'   ],
65 [ "Unix->splitpath('/../../d1/')",      ',/../../d1/,'      ],
66 [ "Unix->splitpath('/././d1/')",        ',/././d1/,'        ],
67
68 [ "Unix->catpath('','','file')",            'file'            ],
69 [ "Unix->catpath('','/d1/d2/d3/','')",      '/d1/d2/d3/'      ],
70 [ "Unix->catpath('','d1/d2/d3/','')",       'd1/d2/d3/'       ],
71 [ "Unix->catpath('','/d1/d2/d3/.','')",     '/d1/d2/d3/.'     ],
72 [ "Unix->catpath('','/d1/d2/d3/..','')",    '/d1/d2/d3/..'    ],
73 [ "Unix->catpath('','/d1/d2/d3/','.file')", '/d1/d2/d3/.file' ],
74 [ "Unix->catpath('','d1/d2/d3/','file')",   'd1/d2/d3/file'   ],
75 [ "Unix->catpath('','/../../d1/','')",      '/../../d1/'      ],
76 [ "Unix->catpath('','/././d1/','')",        '/././d1/'        ],
77 [ "Unix->catpath('d1','d2/d3/','')",        'd2/d3/'          ],
78 [ "Unix->catpath('d1','d2','d3/')",         'd2/d3/'          ],
79
80 [ "Unix->splitdir('')",           ''           ],
81 [ "Unix->splitdir('/d1/d2/d3/')", ',d1,d2,d3,' ],
82 [ "Unix->splitdir('d1/d2/d3/')",  'd1,d2,d3,'  ],
83 [ "Unix->splitdir('/d1/d2/d3')",  ',d1,d2,d3'  ],
84 [ "Unix->splitdir('d1/d2/d3')",   'd1,d2,d3'   ],
85
86 [ "Unix->catdir()",                     ''          ],
87 [ "Unix->catdir('/')",                  '/'         ],
88 [ "Unix->catdir('','d1','d2','d3','')", '/d1/d2/d3' ],
89 [ "Unix->catdir('d1','d2','d3','')",    'd1/d2/d3'  ],
90 [ "Unix->catdir('','d1','d2','d3')",    '/d1/d2/d3' ],
91 [ "Unix->catdir('d1','d2','d3')",       'd1/d2/d3'  ],
92
93 [ "Unix->canonpath('')",                                      ''          ],
94 [ "Unix->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
95 [ "Unix->canonpath('/.')",                                    '/'         ],
96 [ "Unix->canonpath('/./')",                                   '/'         ],
97 [ "Unix->canonpath('/a/./')",                                 '/a'        ],
98 [ "Unix->canonpath('/a/.')",                                  '/a'        ],
99
100 [  "Unix->abs2rel('/t1/t2/t3','/t1/t2/t3')",          ''                   ],
101 [  "Unix->abs2rel('/t1/t2/t4','/t1/t2/t3')",          '../t4'              ],
102 [  "Unix->abs2rel('/t1/t2','/t1/t2/t3')",             '..'                 ],
103 [  "Unix->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')",       't4'                 ],
104 [  "Unix->abs2rel('/t4/t5/t6','/t1/t2/t3')",          '../../../t4/t5/t6'  ],
105 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
106 [  "Unix->abs2rel('/','/t1/t2/t3')",                  '../../..'           ],
107 [  "Unix->abs2rel('///','/t1/t2/t3')",                '../../..'           ],
108 [  "Unix->abs2rel('/.','/t1/t2/t3')",                 '../../..'           ],
109 [  "Unix->abs2rel('/./','/t1/t2/t3')",                '../../..'           ],
110 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
111
112 [ "Unix->rel2abs('t4','/t1/t2/t3')",             '/t1/t2/t3/t4'    ],
113 [ "Unix->rel2abs('t4/t5','/t1/t2/t3')",          '/t1/t2/t3/t4/t5' ],
114 [ "Unix->rel2abs('.','/t1/t2/t3')",              '/t1/t2/t3'       ],
115 [ "Unix->rel2abs('..','/t1/t2/t3')",             '/t1/t2/t3/..'    ],
116 [ "Unix->rel2abs('../t4','/t1/t2/t3')",          '/t1/t2/t3/../t4' ],
117 [ "Unix->rel2abs('/t1','/t1/t2/t3')",            '/t1'             ],
118
119 [ "Win32->case_tolerant()",         '1'  ],
120
121 [ "Win32->splitpath('file')",                            ',,file'                            ],
122 [ "Win32->splitpath('\\d1/d2\\d3/')",                    ',\\d1/d2\\d3/,'                    ],
123 [ "Win32->splitpath('d1/d2\\d3/')",                      ',d1/d2\\d3/,'                      ],
124 [ "Win32->splitpath('\\d1/d2\\d3/.')",                   ',\\d1/d2\\d3/.,'                   ],
125 [ "Win32->splitpath('\\d1/d2\\d3/..')",                  ',\\d1/d2\\d3/..,'                  ],
126 [ "Win32->splitpath('\\d1/d2\\d3/.file')",               ',\\d1/d2\\d3/,.file'               ],
127 [ "Win32->splitpath('\\d1/d2\\d3/file')",                ',\\d1/d2\\d3/,file'                ],
128 [ "Win32->splitpath('d1/d2\\d3/file')",                  ',d1/d2\\d3/,file'                  ],
129 [ "Win32->splitpath('C:\\d1/d2\\d3/')",                  'C:,\\d1/d2\\d3/,'                  ],
130 [ "Win32->splitpath('C:d1/d2\\d3/')",                    'C:,d1/d2\\d3/,'                    ],
131 [ "Win32->splitpath('C:\\d1/d2\\d3/file')",              'C:,\\d1/d2\\d3/,file'              ],
132 [ "Win32->splitpath('C:d1/d2\\d3/file')",                'C:,d1/d2\\d3/,file'                ],
133 [ "Win32->splitpath('C:\\../d2\\d3/file')",              'C:,\\../d2\\d3/,file'              ],
134 [ "Win32->splitpath('C:../d2\\d3/file')",                'C:,../d2\\d3/,file'                ],
135 [ "Win32->splitpath('\\../..\\d1/')",                    ',\\../..\\d1/,'                    ],
136 [ "Win32->splitpath('\\./.\\d1/')",                      ',\\./.\\d1/,'                      ],
137 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/')",     '\\\\node\\share,\\d1/d2\\d3/,'     ],
138 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/file')", '\\\\node\\share,\\d1/d2\\d3/,file' ],
139 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\file')",    '\\\\node\\share,\\d1/d2\\,file'    ],
140 [ "Win32->splitpath('file',1)",                          ',file,'                            ],
141 [ "Win32->splitpath('\\d1/d2\\d3/',1)",                  ',\\d1/d2\\d3/,'                    ],
142 [ "Win32->splitpath('d1/d2\\d3/',1)",                    ',d1/d2\\d3/,'                      ],
143 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/',1)",   '\\\\node\\share,\\d1/d2\\d3/,'     ],
144
145 [ "Win32->catpath('','','file')",                            'file'                            ],
146 [ "Win32->catpath('','\\d1/d2\\d3/','')",                    '\\d1/d2\\d3/'                    ],
147 [ "Win32->catpath('','d1/d2\\d3/','')",                      'd1/d2\\d3/'                      ],
148 [ "Win32->catpath('','\\d1/d2\\d3/.','')",                   '\\d1/d2\\d3/.'                   ],
149 [ "Win32->catpath('','\\d1/d2\\d3/..','')",                  '\\d1/d2\\d3/..'                  ],
150 [ "Win32->catpath('','\\d1/d2\\d3/','.file')",               '\\d1/d2\\d3/.file'               ],
151 [ "Win32->catpath('','\\d1/d2\\d3/','file')",                '\\d1/d2\\d3/file'                ],
152 [ "Win32->catpath('','d1/d2\\d3/','file')",                  'd1/d2\\d3/file'                  ],
153 [ "Win32->catpath('C:','\\d1/d2\\d3/','')",                  'C:\\d1/d2\\d3/'                  ],
154 [ "Win32->catpath('C:','d1/d2\\d3/','')",                    'C:d1/d2\\d3/'                    ],
155 [ "Win32->catpath('C:','\\d1/d2\\d3/','file')",              'C:\\d1/d2\\d3/file'              ],
156 [ "Win32->catpath('C:','d1/d2\\d3/','file')",                'C:d1/d2\\d3/file'                ],
157 [ "Win32->catpath('C:','\\../d2\\d3/','file')",              'C:\\../d2\\d3/file'              ],
158 [ "Win32->catpath('C:','../d2\\d3/','file')",                'C:../d2\\d3/file'                ],
159 [ "Win32->catpath('','\\../..\\d1/','')",                    '\\../..\\d1/'                    ],
160 [ "Win32->catpath('','\\./.\\d1/','')",                      '\\./.\\d1/'                      ],
161 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','')",     '\\\\node\\share\\d1/d2\\d3/'     ],
162 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','file')", '\\\\node\\share\\d1/d2\\d3/file' ],
163 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\','file')",    '\\\\node\\share\\d1/d2\\file'    ],
164
165 [ "Win32->splitdir('')",             ''           ],
166 [ "Win32->splitdir('\\d1/d2\\d3/')", ',d1,d2,d3,' ],
167 [ "Win32->splitdir('d1/d2\\d3/')",   'd1,d2,d3,'  ],
168 [ "Win32->splitdir('\\d1/d2\\d3')",  ',d1,d2,d3'  ],
169 [ "Win32->splitdir('d1/d2\\d3')",    'd1,d2,d3'   ],
170
171 [ "Win32->catdir()",                        ''                   ],
172 [ "Win32->catdir('')",                      '\\'                 ],
173 [ "Win32->catdir('/')",                     '\\'                 ],
174 [ "Win32->catdir('//d1','d2')",             '\\\\d1\\d2'         ],
175 [ "Win32->catdir('\\d1\\','d2')",           '\\d1\\d2'         ],
176 [ "Win32->catdir('\\d1','d2')",             '\\d1\\d2'         ],
177 [ "Win32->catdir('\\d1','\\d2')",           '\\d1\\d2'         ],
178 [ "Win32->catdir('\\d1','\\d2\\')",         '\\d1\\d2'         ],
179 [ "Win32->catdir('','/d1','d2')",           '\\\\d1\\d2'         ],
180 [ "Win32->catdir('','','/d1','d2')",        '\\\\\\d1\\d2'       ],
181 [ "Win32->catdir('','//d1','d2')",          '\\\\\\d1\\d2'       ],
182 [ "Win32->catdir('','','//d1','d2')",       '\\\\\\\\d1\\d2'     ],
183 [ "Win32->catdir('','d1','','d2','')",      '\\d1\\d2'           ],
184 [ "Win32->catdir('','d1','d2','d3','')",    '\\d1\\d2\\d3'       ],
185 [ "Win32->catdir('d1','d2','d3','')",       'd1\\d2\\d3'         ],
186 [ "Win32->catdir('','d1','d2','d3')",       '\\d1\\d2\\d3'       ],
187 [ "Win32->catdir('d1','d2','d3')",          'd1\\d2\\d3'         ],
188 [ "Win32->catdir('A:/d1','d2','d3')",       'A:\\d1\\d2\\d3'     ],
189 [ "Win32->catdir('A:/d1','d2','d3','')",    'A:\\d1\\d2\\d3'     ],
190 #[ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\d2\\d3'     ],
191 [ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\B:\\d2\\d3' ],
192 [ "Win32->catdir('A:/')",                   'A:\\'               ],
193
194 [ "Win32->catfile('a','b','c')",        'a\\b\\c' ],
195 [ "Win32->catfile('a','b','.\\c')",      'a\\b\\c'  ],
196 [ "Win32->catfile('.\\a','b','c')",      'a\\b\\c'  ],
197 [ "Win32->catfile('c')",                'c' ],
198 [ "Win32->catfile('.\\c')",              'c' ],
199
200
201 [ "Win32->canonpath('')",               ''                    ],
202 [ "Win32->canonpath('a:')",             'A:'                  ],
203 [ "Win32->canonpath('A:f')",            'A:f'                 ],
204 [ "Win32->canonpath('//a\\b//c')",      '\\\\a\\b\\c'         ],
205 [ "Win32->canonpath('/a/..../c')",      '\\a\\....\\c'        ],
206 [ "Win32->canonpath('//a/b\\c')",       '\\\\a\\b\\c'         ],
207 [ "Win32->canonpath('////')",           '\\\\\\'              ],
208 [ "Win32->canonpath('//')",             '\\'                  ],
209 [ "Win32->canonpath('/.')",             '\\.'                 ],
210 [ "Win32->canonpath('//a/b/../../c')",  '\\\\a\\b\\c'         ],
211 [ "Win32->canonpath('//a/b/c/../d')",   '\\\\a\\b\\d'         ],
212 [ "Win32->canonpath('//a/b/c/../../d')",'\\\\a\\b\\d'         ],
213 [ "Win32->canonpath('//a/b/c/.../d')",  '\\\\a\\b\\d'         ],
214 [ "Win32->canonpath('/a/b/c/../../d')", '\\a\\d'              ],
215 [ "Win32->canonpath('/a/b/c/.../d')",   '\\a\\d'              ],
216 [ "Win32->canonpath('\\../temp\\')",    '\\temp'              ],
217 [ "Win32->can('_cwd')",                 qr/CODE/              ],
218
219 # FakeWin32 subclass (see below) just sets CWD to C:\one\two
220
221 [ "FakeWin32->abs2rel('/t1/t2/t3','/t1/t2/t3')",     ''                       ],
222 [ "FakeWin32->abs2rel('/t1/t2/t4','/t1/t2/t3')",     '..\\t4'                 ],
223 [ "FakeWin32->abs2rel('/t1/t2','/t1/t2/t3')",        '..'                     ],
224 [ "FakeWin32->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')",  't4'                     ],
225 [ "FakeWin32->abs2rel('/t4/t5/t6','/t1/t2/t3')",     '..\\..\\..\\t4\\t5\\t6' ],
226 [ "FakeWin32->abs2rel('../t4','/t1/t2/t3')",         '..\\..\\..\\one\\t4'    ],
227 [ "FakeWin32->abs2rel('/','/t1/t2/t3')",             '..\\..\\..'             ],
228 [ "FakeWin32->abs2rel('///','/t1/t2/t3')",           '..\\..\\..'             ],
229 [ "FakeWin32->abs2rel('/.','/t1/t2/t3')",            '..\\..\\..'             ],
230 [ "FakeWin32->abs2rel('/./','/t1/t2/t3')",           '..\\..\\..'             ],
231 [ "FakeWin32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')",   '\\\\a\\t1\\t2\\t4'      ],
232 [ "FakeWin32->abs2rel('//a/t1/t2/t4','/t2/t3')",     '\\\\a\\t1\\t2\\t4'      ],
233 [ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3')",     ''                   ],
234 [ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','A:/t1/t2/t3')",  't4'                 ],
235 [ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3/t4')",  '..'                 ],
236 [ "FakeWin32->abs2rel('A:/t1/t2/t3','B:/t1/t2/t3')",     'A:\\t1\\t2\\t3'     ],
237 [ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','B:/t1/t2/t3')",  'A:\\t1\\t2\\t3\\t4' ],
238 [ "FakeWin32->abs2rel('E:/foo/bar/baz')",            'E:\\foo\\bar\\baz'      ],
239 [ "FakeWin32->abs2rel('C:/one/two/three')",          'three'                  ],
240
241 [ "FakeWin32->rel2abs('temp','C:/')",                       'C:\\temp'                        ],
242 [ "FakeWin32->rel2abs('temp','C:/a')",                      'C:\\a\\temp'                     ],
243 [ "FakeWin32->rel2abs('temp','C:/a/')",                     'C:\\a\\temp'                     ],
244 [ "FakeWin32->rel2abs('../','C:/')",                        'C:\\'                            ],
245 [ "FakeWin32->rel2abs('../','C:/a')",                       'C:\\'                            ],
246 [ "FakeWin32->rel2abs('temp','//prague_main/work/')",       '\\\\prague_main\\work\\temp'     ],
247 [ "FakeWin32->rel2abs('../temp','//prague_main/work/')",    '\\\\prague_main\\work\\temp'     ],
248 [ "FakeWin32->rel2abs('temp','//prague_main/work')",        '\\\\prague_main\\work\\temp'     ],
249 [ "FakeWin32->rel2abs('../','//prague_main/work')",         '\\\\prague_main\\work'           ],
250
251 [ "VMS->case_tolerant()",         '1'  ],
252
253 [ "VMS->catfile('a','b','c')",         '[.a.b]c'  ],
254 [ "VMS->catfile('a','b','[]c')",       '[.a.b]c'  ],
255 [ "VMS->catfile('[.a]','b','c')",       '[.a.b]c'  ],
256 [ "VMS->catfile('c')",                 'c' ],
257 [ "VMS->catfile('[]c')",               'c' ],
258
259 [ "VMS->splitpath('file')",                                       ',,file'                                   ],
260 [ "VMS->splitpath('[d1.d2.d3]')",                                 ',[d1.d2.d3],'                               ],
261 [ "VMS->splitpath('[.d1.d2.d3]')",                                ',[.d1.d2.d3],'                              ],
262 [ "VMS->splitpath('[d1.d2.d3]file')",                             ',[d1.d2.d3],file'                           ],
263 [ "VMS->splitpath('d1/d2/d3/file')",                              ',[.d1.d2.d3],file'                          ],
264 [ "VMS->splitpath('/d1/d2/d3/file')",                             'd1:,[d2.d3],file'                         ],
265 [ "VMS->splitpath('[.d1.d2.d3]file')",                            ',[.d1.d2.d3],file'                          ],
266 [ "VMS->splitpath('node::volume:[d1.d2.d3]')",                    'node::volume:,[d1.d2.d3],'                  ],
267 [ "VMS->splitpath('node::volume:[d1.d2.d3]file')",                'node::volume:,[d1.d2.d3],file'              ],
268 [ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]')",     'node"access_spec"::volume:,[d1.d2.d3],'     ],
269 [ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]file')", 'node"access_spec"::volume:,[d1.d2.d3],file' ],
270
271 [ "VMS->catpath('','','file')",                                       'file'                                     ],
272 [ "VMS->catpath('','[d1.d2.d3]','')",                                 '[d1.d2.d3]'                               ],
273 [ "VMS->catpath('','[.d1.d2.d3]','')",                                '[.d1.d2.d3]'                              ],
274 [ "VMS->catpath('','[d1.d2.d3]','file')",                             '[d1.d2.d3]file'                           ],
275 [ "VMS->catpath('','[.d1.d2.d3]','file')",                            '[.d1.d2.d3]file'                          ],
276 [ "VMS->catpath('','d1/d2/d3','file')",                               '[.d1.d2.d3]file'                            ],
277 [ "VMS->catpath('v','d1/d2/d3','file')",                              'v:[.d1.d2.d3]file'                            ],
278 [ "VMS->catpath('node::volume:','[d1.d2.d3]','')",                    'node::volume:[d1.d2.d3]'                  ],
279 [ "VMS->catpath('node::volume:','[d1.d2.d3]','file')",                'node::volume:[d1.d2.d3]file'              ],
280 [ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','')",     'node"access_spec"::volume:[d1.d2.d3]'     ],
281 [ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','file')", 'node"access_spec"::volume:[d1.d2.d3]file' ],
282
283 [ "VMS->canonpath('')",                                    ''                        ],
284 [ "VMS->canonpath('volume:[d1]file')",                     'volume:[d1]file'         ],
285 [ "VMS->canonpath('volume:[d1.-.d2.][d3.d4.-]')",              'volume:[d2.d3]'          ],
286 [ "VMS->canonpath('volume:[000000.d1]d2.dir;1')",                 'volume:[d1]d2.dir;1'   ],
287
288 [ "VMS->splitdir('')",            ''          ],
289 [ "VMS->splitdir('[]')",          ''          ],
290 [ "VMS->splitdir('d1.d2.d3')",    'd1,d2,d3'  ],
291 [ "VMS->splitdir('[d1.d2.d3]')",  'd1,d2,d3'  ],
292 [ "VMS->splitdir('.d1.d2.d3')",   ',d1,d2,d3' ],
293 [ "VMS->splitdir('[.d1.d2.d3]')", ',d1,d2,d3' ],
294 [ "VMS->splitdir('.-.d2.d3')",    ',-,d2,d3'  ],
295 [ "VMS->splitdir('[.-.d2.d3]')",  ',-,d2,d3'  ],
296
297 [ "VMS->catdir('')",                                                      ''                 ],
298 [ "VMS->catdir('d1','d2','d3')",                                          '[.d1.d2.d3]'         ],
299 [ "VMS->catdir('d1','d2/','d3')",                                         '[.d1.d2.d3]'         ],
300 [ "VMS->catdir('','d1','d2','d3')",                                       '[.d1.d2.d3]'        ],
301 [ "VMS->catdir('','-','d2','d3')",                                        '[-.d2.d3]'         ],
302 [ "VMS->catdir('','-','','d3')",                                          '[-.d3]'            ],
303 [ "VMS->catdir('dir.dir','d2.dir','d3.dir')",                             '[.dir.d2.d3]'        ],
304 [ "VMS->catdir('[.name]')",                                               '[.name]'            ],
305 [ "VMS->catdir('[.name]','[.name]')",                                     '[.name.name]'],
306
307 [  "VMS->abs2rel('node::volume:[t1.t2.t3]','[t1.t2.t3]')", ''                 ],
308 [  "VMS->abs2rel('node::volume:[t1.t2.t4]','[t1.t2.t3]')", '[-.t4]'           ],
309 [  "VMS->abs2rel('[t1.t2.t3]','[t1.t2.t3]')",              ''                 ],
310 [  "VMS->abs2rel('[t1.t2.t3]file','[t1.t2.t3]')",          'file'             ],
311 [  "VMS->abs2rel('[t1.t2.t4]','[t1.t2.t3]')",              '[-.t4]'           ],
312 [  "VMS->abs2rel('[t1.t2]file','[t1.t2.t3]')",             '[-]file'          ],
313 [  "VMS->abs2rel('[t1.t2.t3.t4]','[t1.t2.t3]')",           '[t4]'             ],
314 [  "VMS->abs2rel('[t4.t5.t6]','[t1.t2.t3]')",              '[---.t4.t5.t6]'   ],
315 [ "VMS->abs2rel('[000000]','[t1.t2.t3]')",                 '[---]'            ],
316 [ "VMS->abs2rel('a:[t1.t2.t4]','[t1.t2.t3]')",             '[-.t4]'           ],
317 [ "VMS->abs2rel('[a.-.b.c.-]','[t1.t2.t3]')",              '[---.b]'          ],
318
319 [ "VMS->rel2abs('[.t4]','[t1.t2.t3]')",          '[t1.t2.t3.t4]'    ],
320 [ "VMS->rel2abs('[.t4.t5]','[t1.t2.t3]')",       '[t1.t2.t3.t4.t5]' ],
321 [ "VMS->rel2abs('[]','[t1.t2.t3]')",             '[t1.t2.t3]'       ],
322 [ "VMS->rel2abs('[-]','[t1.t2.t3]')",            '[t1.t2]'          ],
323 [ "VMS->rel2abs('[-.t4]','[t1.t2.t3]')",         '[t1.t2.t4]'       ],
324 [ "VMS->rel2abs('[t1]','[t1.t2.t3]')",           '[t1]'             ],
325
326 [ "OS2->case_tolerant()",         '1'  ],
327
328 [ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
329
330 [ "OS2->catfile('a','b','c')",            'a/b/c'          ],
331 [ "OS2->catfile('a','b','./c')",          'a/b/c'  ],
332 [ "OS2->catfile('./a','b','c')",          'a/b/c'  ],
333 [ "OS2->catfile('c')",                    'c' ],
334 [ "OS2->catfile('./c')",                  'c' ],
335
336 [ "Mac->case_tolerant()",         '1'  ],
337
338 [ "Mac->catpath('','','')",              ''                ],
339 [ "Mac->catpath('',':','')",             ':'               ],
340 [ "Mac->catpath('','::','')",            '::'              ],
341
342 [ "Mac->catpath('hd','','')",            'hd:'             ],
343 [ "Mac->catpath('hd:','','')",           'hd:'             ],
344 [ "Mac->catpath('hd:',':','')",          'hd:'             ],
345 [ "Mac->catpath('hd:','::','')",         'hd::'            ],
346
347 [ "Mac->catpath('hd','','file')",       'hd:file'          ],
348 [ "Mac->catpath('hd',':','file')",      'hd:file'          ],
349 [ "Mac->catpath('hd','::','file')",     'hd::file'         ],
350 [ "Mac->catpath('hd',':::','file')",    'hd:::file'        ],
351
352 [ "Mac->catpath('hd:','',':file')",      'hd:file'         ],
353 [ "Mac->catpath('hd:',':',':file')",     'hd:file'         ],
354 [ "Mac->catpath('hd:','::',':file')",    'hd::file'        ],
355 [ "Mac->catpath('hd:',':::',':file')",   'hd:::file'       ],
356
357 [ "Mac->catpath('hd:','d1','file')",     'hd:d1:file'      ],
358 [ "Mac->catpath('hd:',':d1:',':file')",  'hd:d1:file'      ],
359
360 [ "Mac->catpath('','d1','')",            ':d1:'            ],
361 [ "Mac->catpath('',':d1','')",           ':d1:'            ],
362 [ "Mac->catpath('',':d1:','')",          ':d1:'            ],
363
364 [ "Mac->catpath('','d1','file')",        ':d1:file'        ],
365 [ "Mac->catpath('',':d1:',':file')",     ':d1:file'        ],
366
367 [ "Mac->catpath('','','file')",          'file'            ],
368 [ "Mac->catpath('','',':file')",         'file'            ], # !
369 [ "Mac->catpath('',':',':file')",        ':file'           ], # !
370
371
372 [ "Mac->splitpath(':')",              ',:,'               ],
373 [ "Mac->splitpath('::')",             ',::,'              ],
374 [ "Mac->splitpath(':::')",            ',:::,'             ],
375
376 [ "Mac->splitpath('file')",           ',,file'            ],
377 [ "Mac->splitpath(':file')",          ',:,file'           ],
378
379 [ "Mac->splitpath('d1',1)",           ',:d1:,'            ], # dir, not volume
380 [ "Mac->splitpath(':d1',1)",          ',:d1:,'            ],
381 [ "Mac->splitpath(':d1:',1)",         ',:d1:,'            ],
382 [ "Mac->splitpath(':d1:')",           ',:d1:,'            ],
383 [ "Mac->splitpath(':d1:d2:d3:')",     ',:d1:d2:d3:,'      ],
384 [ "Mac->splitpath(':d1:d2:d3:',1)",   ',:d1:d2:d3:,'      ],
385 [ "Mac->splitpath(':d1:file')",       ',:d1:,file'        ],
386 [ "Mac->splitpath('::d1:file')",      ',::d1:,file'       ],
387
388 [ "Mac->splitpath('hd:', 1)",         'hd:,,'             ],
389 [ "Mac->splitpath('hd:')",            'hd:,,'             ],
390 [ "Mac->splitpath('hd:d1:d2:')",      'hd:,:d1:d2:,'      ],
391 [ "Mac->splitpath('hd:d1:d2',1)",     'hd:,:d1:d2:,'      ],
392 [ "Mac->splitpath('hd:d1:d2:file')",  'hd:,:d1:d2:,file'  ],
393 [ "Mac->splitpath('hd:d1:d2::file')", 'hd:,:d1:d2::,file' ],
394 [ "Mac->splitpath('hd::d1:d2:file')", 'hd:,::d1:d2:,file' ], # invalid path
395 [ "Mac->splitpath('hd:file')",        'hd:,,file'         ],
396
397 [ "Mac->splitdir()",                   ''            ],
398 [ "Mac->splitdir('')",                 ''            ],
399 [ "Mac->splitdir(':')",                ':'           ],
400 [ "Mac->splitdir('::')",               '::'          ],
401 [ "Mac->splitdir(':::')",              '::,::'       ],
402 [ "Mac->splitdir(':::d1:d2')",         '::,::,d1,d2' ],
403
404 [ "Mac->splitdir(':d1:d2:d3::')",      'd1,d2,d3,::'],
405 [ "Mac->splitdir(':d1:d2:d3:')",       'd1,d2,d3'   ],
406 [ "Mac->splitdir(':d1:d2:d3')",        'd1,d2,d3'   ],
407
408 # absolute paths in splitdir() work, but you'd better use splitpath()
409 [ "Mac->splitdir('hd:')",              'hd:'              ],
410 [ "Mac->splitdir('hd::')",             'hd:,::'           ], # invalid path, but it works
411 [ "Mac->splitdir('hd::d1:')",          'hd:,::,d1'        ], # invalid path, but it works
412 [ "Mac->splitdir('hd:d1:d2:::')",      'hd:,d1,d2,::,::'  ],
413 [ "Mac->splitdir('hd:d1:d2::')",       'hd:,d1,d2,::'     ],
414 [ "Mac->splitdir('hd:d1:d2:')",        'hd:,d1,d2'        ],
415 [ "Mac->splitdir('hd:d1:d2')",         'hd:,d1,d2'        ],
416 [ "Mac->splitdir('hd:d1::d2::')",      'hd:,d1,::,d2,::'  ],
417
418 [ "Mac->catdir()",                 ''             ],
419 [ "Mac->catdir('')",               $root, 'MacOS' ], # skipped on other OS
420 [ "Mac->catdir(':')",              ':'            ],
421
422 [ "Mac->catdir('', '')",           $root, 'MacOS' ], # skipped on other OS
423 [ "Mac->catdir('', ':')",          $root, 'MacOS' ], # skipped on other OS
424 [ "Mac->catdir(':', ':')",         ':'            ],
425 [ "Mac->catdir(':', '')",          ':'            ],
426
427 [ "Mac->catdir('', '::')",         $root, 'MacOS' ], # skipped on other OS
428 [ "Mac->catdir(':', '::')",        '::'           ],
429
430 [ "Mac->catdir('::', '')",         '::'           ],
431 [ "Mac->catdir('::', ':')",        '::'           ],
432
433 [ "Mac->catdir('::', '::')",       ':::'          ],
434
435 [ "Mac->catdir(':d1')",                    ':d1:'        ],
436 [ "Mac->catdir(':d1:')",                   ':d1:'        ],
437 [ "Mac->catdir(':d1','d2')",               ':d1:d2:'     ],
438 [ "Mac->catdir(':d1',':d2')",              ':d1:d2:'     ],
439 [ "Mac->catdir(':d1',':d2:')",             ':d1:d2:'     ],
440 [ "Mac->catdir(':d1',':d2::')",            ':d1:d2::'     ],
441 [ "Mac->catdir(':',':d1',':d2')",          ':d1:d2:'     ],
442 [ "Mac->catdir('::',':d1',':d2')",         '::d1:d2:'    ],
443 [ "Mac->catdir('::','::',':d1',':d2')",    ':::d1:d2:'   ],
444 [ "Mac->catdir(':',':',':d1',':d2')",      ':d1:d2:'     ],
445 [ "Mac->catdir('::',':',':d1',':d2')",     '::d1:d2:'    ],
446
447 [ "Mac->catdir('d1')",                    ':d1:'         ],
448 [ "Mac->catdir('d1','d2','d3')",          ':d1:d2:d3:'   ],
449 [ "Mac->catdir('d1','d2/','d3')",         ':d1:d2/:d3:'  ],
450 [ "Mac->catdir('d1','',':d2')",           ':d1:d2:'      ],
451 [ "Mac->catdir('d1',':',':d2')",          ':d1:d2:'      ],
452 [ "Mac->catdir('d1','::',':d2')",         ':d1::d2:'     ],
453 [ "Mac->catdir('d1',':::',':d2')",        ':d1:::d2:'    ],
454 [ "Mac->catdir('d1','::','::',':d2')",    ':d1:::d2:'    ],
455 [ "Mac->catdir('d1','d2')",               ':d1:d2:'      ],
456 [ "Mac->catdir('d1','d2', '')",           ':d1:d2:'      ],
457 [ "Mac->catdir('d1','d2', ':')",          ':d1:d2:'      ],
458 [ "Mac->catdir('d1','d2', '::')",         ':d1:d2::'     ],
459 [ "Mac->catdir('d1','d2','','')",         ':d1:d2:'      ],
460 [ "Mac->catdir('d1','d2',':','::')",      ':d1:d2::'     ],
461 [ "Mac->catdir('d1','d2','::','::')",     ':d1:d2:::'    ],
462 [ "Mac->catdir('d1',':d2')",              ':d1:d2:'      ],
463 [ "Mac->catdir('d1',':d2:')",             ':d1:d2:'      ],
464
465 [ "Mac->catdir('','d1','d2','d3')",        $root . 'd1:d2:d3:', 'MacOS' ], # skipped on other OS
466 [ "Mac->catdir('',':','d1','d2')",         $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
467 [ "Mac->catdir('','::','d1','d2')",        $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
468 [ "Mac->catdir('',':','','d1')",           $root . 'd1:'      , 'MacOS' ], # skipped on other OS
469 [ "Mac->catdir('', ':d1',':d2')",          $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
470 [ "Mac->catdir('','',':d1',':d2')",        $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
471
472 [ "Mac->catdir('hd:',':d1')",       'hd:d1:'      ],
473 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
474 [ "Mac->catdir('hd:','d1')",        'hd:d1:'      ],
475 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
476 [ "Mac->catdir('hd:d1:',':d2:')",   'hd:d1:d2:'   ],
477
478 [ "Mac->catfile()",                      ''                      ],
479 [ "Mac->catfile('')",                    ''                      ],
480 [ "Mac->catfile('', '')",                $root         , 'MacOS' ], # skipped on other OS
481 [ "Mac->catfile('', 'file')",            $root . 'file', 'MacOS' ], # skipped on other OS
482 [ "Mac->catfile(':')",                   ':'                     ],
483 [ "Mac->catfile(':', '')",               ':'                     ],
484
485 [ "Mac->catfile('d1','d2','file')",      ':d1:d2:file' ],
486 [ "Mac->catfile('d1','d2',':file')",     ':d1:d2:file' ],
487 [ "Mac->catfile('file')",                'file'        ],
488 [ "Mac->catfile(':', 'file')",           ':file'       ],
489
490 [ "Mac->canonpath('')",                   ''     ],
491 [ "Mac->canonpath(':')",                  ':'    ],
492 [ "Mac->canonpath('::')",                 '::'   ],
493 [ "Mac->canonpath('a::')",                'a::'  ],
494 [ "Mac->canonpath(':a::')",               ':a::' ],
495
496 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:')",            ':'            ],
497 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:file')",        ':'            ], # ignore base's file portion
498 [ "Mac->abs2rel('hd:d1:d2:file','hd:d1:d2:')",        ':file'        ],
499 [ "Mac->abs2rel('hd:d1:','hd:d1:d2:')",               '::'           ],
500 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ],
501 [ "Mac->abs2rel('hd:d3:','hd:d1:d2::')",              '::d3:'        ],
502 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3::')",    '::d1:d4:d5:'  ],
503 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3:')",     ':::d1:d4:d5:' ], # first, resolve updirs in base
504 [ "Mac->abs2rel('hd:d1:d3:','hd:d1:d2:')",            '::d3:'        ],
505 [ "Mac->abs2rel('hd:d1::d3:','hd:d1:d2:')",           ':::d3:'       ],
506 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ], # same as above
507 [ "Mac->abs2rel('hd:d1:d2:d3:','hd:d1:d2:')",         ':d3:'         ],
508 [ "Mac->abs2rel('hd:d1:d2:d3::','hd:d1:d2:')",        ':d3::'        ],
509 [ "Mac->abs2rel('hd1:d3:d4:d5:','hd2:d1:d2:')",       ':::d3:d4:d5:' ], # ignore base's volume
510 [ "Mac->abs2rel('hd:','hd:d1:d2:')",                  ':::'          ],
511
512 [ "Mac->rel2abs(':d3:','hd:d1:d2:')",          'hd:d1:d2:d3:'     ],
513 [ "Mac->rel2abs(':d3:d4:','hd:d1:d2:')",       'hd:d1:d2:d3:d4:'  ],
514 [ "Mac->rel2abs('','hd:d1:d2:')",              ''                 ],
515 [ "Mac->rel2abs('::','hd:d1:d2:')",            'hd:d1:d2::'       ],
516 [ "Mac->rel2abs('::','hd:d1:d2:file')",        'hd:d1:d2::'       ],# ignore base's file portion
517 [ "Mac->rel2abs(':file','hd:d1:d2:')",         'hd:d1:d2:file'    ],
518 [ "Mac->rel2abs('::file','hd:d1:d2:')",        'hd:d1:d2::file'   ],
519 [ "Mac->rel2abs('::d3:','hd:d1:d2:')",         'hd:d1:d2::d3:'    ],
520 [ "Mac->rel2abs('hd:','hd:d1:d2:')",           'hd:'              ], # path already absolute
521 [ "Mac->rel2abs('hd:d3:file','hd:d1:d2:')",    'hd:d3:file'       ],
522 [ "Mac->rel2abs('hd:d3:','hd:d1:file')",       'hd:d3:'           ],
523
524 [ "Epoc->case_tolerant()",         '1'  ],
525
526 [ "Epoc->canonpath('')",                                      ''          ],
527 [ "Epoc->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
528 [ "Epoc->canonpath('/./')",                                   '/'         ],
529 [ "Epoc->canonpath('/a/./')",                                 '/a'        ],
530
531 # XXX Todo, copied from Unix, but fail. Should they? 2003-07-07 Tels
532 #[ "Epoc->canonpath('/a/.')",                                  '/a'        ],
533 #[ "Epoc->canonpath('/.')",                                    '/'         ],
534
535 [ "Cygwin->case_tolerant()",         '0'  ],
536
537 ) ;
538
539 plan tests => scalar @tests;
540
541 {
542     @File::Spec::FakeWin32::ISA = qw(File::Spec::Win32);
543     sub File::Spec::FakeWin32::_cwd { 'C:\\one\\two' }
544 }
545
546
547 # Test out the class methods
548 for ( @tests ) {
549    tryfunc( @$_ ) ;
550 }
551
552
553 #
554 # Tries a named function with the given args and compares the result against
555 # an expected result. Works with functions that return scalars or arrays.
556 #
557 sub tryfunc {
558     my $function = shift ;
559     my $expected = shift ;
560     my $platform = shift ;
561
562     if ($platform && $^O ne $platform) {
563         skip("skip $function", 1);
564         return;
565     }
566
567     $function =~ s#\\#\\\\#g ;
568     $function =~ s/^([^\$].*->)/File::Spec::$1/;
569     my $got = join ',', eval $function;
570
571     if ( $@ ) {
572       if ( $@ =~ /^\Q$skip_exception/ ) {
573         skip "skip $function: $skip_exception", 1;
574       }
575       else {
576         ok $@, '', $function;
577       }
578       return;
579     }
580
581     ok $got, $expected, $function;
582 }