This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bcd0990651f3d711e41142b383f7a00464e17784
[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]','node::volume:[t1.t2.t3]')", ''                 ],
308 [  "VMS->abs2rel('node::volume:[t1.t2.t3]','[t1.t2.t3]')", 'node::volume:[t1.t2.t3]'                 ],
309 [  "VMS->abs2rel('node::volume:[t1.t2.t4]','node::volume:[t1.t2.t3]')", '[-.t4]'           ],
310 [  "VMS->abs2rel('node::volume:[t1.t2.t4]','[t1.t2.t3]')", 'node::volume:[t1.t2.t4]'           ],
311 [  "VMS->abs2rel('[t1.t2.t3]','[t1.t2.t3]')",              ''                 ],
312 [  "VMS->abs2rel('[t1.t2.t3]file','[t1.t2.t3]')",          'file'             ],
313 [  "VMS->abs2rel('[t1.t2.t4]','[t1.t2.t3]')",              '[-.t4]'           ],
314 [  "VMS->abs2rel('[t1.t2]file','[t1.t2.t3]')",             '[-]file'          ],
315 [  "VMS->abs2rel('[t1.t2.t3.t4]','[t1.t2.t3]')",           '[t4]'             ],
316 [  "VMS->abs2rel('[t4.t5.t6]','[t1.t2.t3]')",              '[---.t4.t5.t6]'   ],
317 [ "VMS->abs2rel('[000000]','[t1.t2.t3]')",                 '[---]'            ],
318 [ "VMS->abs2rel('a:[t1.t2.t4]','a:[t1.t2.t3]')",             '[-.t4]'           ],
319 [ "VMS->abs2rel('a:[t1.t2.t4]','[t1.t2.t3]')",             'a:[t1.t2.t4]'           ],
320 [ "VMS->abs2rel('[a.-.b.c.-]','[t1.t2.t3]')",              '[---.b]'          ],
321
322 [ "VMS->rel2abs('[.t4]','[t1.t2.t3]')",          '[t1.t2.t3.t4]'    ],
323 [ "VMS->rel2abs('[.t4.t5]','[t1.t2.t3]')",       '[t1.t2.t3.t4.t5]' ],
324 [ "VMS->rel2abs('[]','[t1.t2.t3]')",             '[t1.t2.t3]'       ],
325 [ "VMS->rel2abs('[-]','[t1.t2.t3]')",            '[t1.t2]'          ],
326 [ "VMS->rel2abs('[-.t4]','[t1.t2.t3]')",         '[t1.t2.t4]'       ],
327 [ "VMS->rel2abs('[t1]','[t1.t2.t3]')",           '[t1]'             ],
328
329 [ "OS2->case_tolerant()",         '1'  ],
330
331 [ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
332
333 [ "OS2->catfile('a','b','c')",            'a/b/c'          ],
334 [ "OS2->catfile('a','b','./c')",          'a/b/c'  ],
335 [ "OS2->catfile('./a','b','c')",          'a/b/c'  ],
336 [ "OS2->catfile('c')",                    'c' ],
337 [ "OS2->catfile('./c')",                  'c' ],
338
339 [ "Mac->case_tolerant()",         '1'  ],
340
341 [ "Mac->catpath('','','')",              ''                ],
342 [ "Mac->catpath('',':','')",             ':'               ],
343 [ "Mac->catpath('','::','')",            '::'              ],
344
345 [ "Mac->catpath('hd','','')",            'hd:'             ],
346 [ "Mac->catpath('hd:','','')",           'hd:'             ],
347 [ "Mac->catpath('hd:',':','')",          'hd:'             ],
348 [ "Mac->catpath('hd:','::','')",         'hd::'            ],
349
350 [ "Mac->catpath('hd','','file')",       'hd:file'          ],
351 [ "Mac->catpath('hd',':','file')",      'hd:file'          ],
352 [ "Mac->catpath('hd','::','file')",     'hd::file'         ],
353 [ "Mac->catpath('hd',':::','file')",    'hd:::file'        ],
354
355 [ "Mac->catpath('hd:','',':file')",      'hd:file'         ],
356 [ "Mac->catpath('hd:',':',':file')",     'hd:file'         ],
357 [ "Mac->catpath('hd:','::',':file')",    'hd::file'        ],
358 [ "Mac->catpath('hd:',':::',':file')",   'hd:::file'       ],
359
360 [ "Mac->catpath('hd:','d1','file')",     'hd:d1:file'      ],
361 [ "Mac->catpath('hd:',':d1:',':file')",  'hd:d1:file'      ],
362
363 [ "Mac->catpath('','d1','')",            ':d1:'            ],
364 [ "Mac->catpath('',':d1','')",           ':d1:'            ],
365 [ "Mac->catpath('',':d1:','')",          ':d1:'            ],
366
367 [ "Mac->catpath('','d1','file')",        ':d1:file'        ],
368 [ "Mac->catpath('',':d1:',':file')",     ':d1:file'        ],
369
370 [ "Mac->catpath('','','file')",          'file'            ],
371 [ "Mac->catpath('','',':file')",         'file'            ], # !
372 [ "Mac->catpath('',':',':file')",        ':file'           ], # !
373
374
375 [ "Mac->splitpath(':')",              ',:,'               ],
376 [ "Mac->splitpath('::')",             ',::,'              ],
377 [ "Mac->splitpath(':::')",            ',:::,'             ],
378
379 [ "Mac->splitpath('file')",           ',,file'            ],
380 [ "Mac->splitpath(':file')",          ',:,file'           ],
381
382 [ "Mac->splitpath('d1',1)",           ',:d1:,'            ], # dir, not volume
383 [ "Mac->splitpath(':d1',1)",          ',:d1:,'            ],
384 [ "Mac->splitpath(':d1:',1)",         ',:d1:,'            ],
385 [ "Mac->splitpath(':d1:')",           ',:d1:,'            ],
386 [ "Mac->splitpath(':d1:d2:d3:')",     ',:d1:d2:d3:,'      ],
387 [ "Mac->splitpath(':d1:d2:d3:',1)",   ',:d1:d2:d3:,'      ],
388 [ "Mac->splitpath(':d1:file')",       ',:d1:,file'        ],
389 [ "Mac->splitpath('::d1:file')",      ',::d1:,file'       ],
390
391 [ "Mac->splitpath('hd:', 1)",         'hd:,,'             ],
392 [ "Mac->splitpath('hd:')",            'hd:,,'             ],
393 [ "Mac->splitpath('hd:d1:d2:')",      'hd:,:d1:d2:,'      ],
394 [ "Mac->splitpath('hd:d1:d2',1)",     'hd:,:d1:d2:,'      ],
395 [ "Mac->splitpath('hd:d1:d2:file')",  'hd:,:d1:d2:,file'  ],
396 [ "Mac->splitpath('hd:d1:d2::file')", 'hd:,:d1:d2::,file' ],
397 [ "Mac->splitpath('hd::d1:d2:file')", 'hd:,::d1:d2:,file' ], # invalid path
398 [ "Mac->splitpath('hd:file')",        'hd:,,file'         ],
399
400 [ "Mac->splitdir()",                   ''            ],
401 [ "Mac->splitdir('')",                 ''            ],
402 [ "Mac->splitdir(':')",                ':'           ],
403 [ "Mac->splitdir('::')",               '::'          ],
404 [ "Mac->splitdir(':::')",              '::,::'       ],
405 [ "Mac->splitdir(':::d1:d2')",         '::,::,d1,d2' ],
406
407 [ "Mac->splitdir(':d1:d2:d3::')",      'd1,d2,d3,::'],
408 [ "Mac->splitdir(':d1:d2:d3:')",       'd1,d2,d3'   ],
409 [ "Mac->splitdir(':d1:d2:d3')",        'd1,d2,d3'   ],
410
411 # absolute paths in splitdir() work, but you'd better use splitpath()
412 [ "Mac->splitdir('hd:')",              'hd:'              ],
413 [ "Mac->splitdir('hd::')",             'hd:,::'           ], # invalid path, but it works
414 [ "Mac->splitdir('hd::d1:')",          'hd:,::,d1'        ], # invalid path, but it works
415 [ "Mac->splitdir('hd:d1:d2:::')",      'hd:,d1,d2,::,::'  ],
416 [ "Mac->splitdir('hd:d1:d2::')",       'hd:,d1,d2,::'     ],
417 [ "Mac->splitdir('hd:d1:d2:')",        'hd:,d1,d2'        ],
418 [ "Mac->splitdir('hd:d1:d2')",         'hd:,d1,d2'        ],
419 [ "Mac->splitdir('hd:d1::d2::')",      'hd:,d1,::,d2,::'  ],
420
421 [ "Mac->catdir()",                 ''             ],
422 [ "Mac->catdir('')",               $root, 'MacOS' ], # skipped on other OS
423 [ "Mac->catdir(':')",              ':'            ],
424
425 [ "Mac->catdir('', '')",           $root, 'MacOS' ], # skipped on other OS
426 [ "Mac->catdir('', ':')",          $root, 'MacOS' ], # skipped on other OS
427 [ "Mac->catdir(':', ':')",         ':'            ],
428 [ "Mac->catdir(':', '')",          ':'            ],
429
430 [ "Mac->catdir('', '::')",         $root, 'MacOS' ], # skipped on other OS
431 [ "Mac->catdir(':', '::')",        '::'           ],
432
433 [ "Mac->catdir('::', '')",         '::'           ],
434 [ "Mac->catdir('::', ':')",        '::'           ],
435
436 [ "Mac->catdir('::', '::')",       ':::'          ],
437
438 [ "Mac->catdir(':d1')",                    ':d1:'        ],
439 [ "Mac->catdir(':d1:')",                   ':d1:'        ],
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 [ "Mac->catdir('::','::',':d1',':d2')",    ':::d1:d2:'   ],
447 [ "Mac->catdir(':',':',':d1',':d2')",      ':d1:d2:'     ],
448 [ "Mac->catdir('::',':',':d1',':d2')",     '::d1:d2:'    ],
449
450 [ "Mac->catdir('d1')",                    ':d1:'         ],
451 [ "Mac->catdir('d1','d2','d3')",          ':d1:d2:d3:'   ],
452 [ "Mac->catdir('d1','d2/','d3')",         ':d1:d2/:d3:'  ],
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 [ "Mac->catdir('d1','d2','::','::')",     ':d1:d2:::'    ],
465 [ "Mac->catdir('d1',':d2')",              ':d1:d2:'      ],
466 [ "Mac->catdir('d1',':d2:')",             ':d1:d2:'      ],
467
468 [ "Mac->catdir('','d1','d2','d3')",        $root . 'd1:d2:d3:', '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 [ "Mac->catdir('',':','','d1')",           $root . 'd1:'      , 'MacOS' ], # skipped on other OS
472 [ "Mac->catdir('', ':d1',':d2')",          $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
473 [ "Mac->catdir('','',':d1',':d2')",        $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
474
475 [ "Mac->catdir('hd:',':d1')",       'hd:d1:'      ],
476 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
477 [ "Mac->catdir('hd:','d1')",        'hd:d1:'      ],
478 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
479 [ "Mac->catdir('hd:d1:',':d2:')",   'hd:d1:d2:'   ],
480
481 [ "Mac->catfile()",                      ''                      ],
482 [ "Mac->catfile('')",                    ''                      ],
483 [ "Mac->catfile('', '')",                $root         , 'MacOS' ], # skipped on other OS
484 [ "Mac->catfile('', 'file')",            $root . 'file', 'MacOS' ], # skipped on other OS
485 [ "Mac->catfile(':')",                   ':'                     ],
486 [ "Mac->catfile(':', '')",               ':'                     ],
487
488 [ "Mac->catfile('d1','d2','file')",      ':d1:d2:file' ],
489 [ "Mac->catfile('d1','d2',':file')",     ':d1:d2:file' ],
490 [ "Mac->catfile('file')",                'file'        ],
491 [ "Mac->catfile(':', 'file')",           ':file'       ],
492
493 [ "Mac->canonpath('')",                   ''     ],
494 [ "Mac->canonpath(':')",                  ':'    ],
495 [ "Mac->canonpath('::')",                 '::'   ],
496 [ "Mac->canonpath('a::')",                'a::'  ],
497 [ "Mac->canonpath(':a::')",               ':a::' ],
498
499 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:')",            ':'            ],
500 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:file')",        ':'            ], # ignore base's file portion
501 [ "Mac->abs2rel('hd:d1:d2:file','hd:d1:d2:')",        ':file'        ],
502 [ "Mac->abs2rel('hd:d1:','hd:d1:d2:')",               '::'           ],
503 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ],
504 [ "Mac->abs2rel('hd:d3:','hd:d1:d2::')",              '::d3:'        ],
505 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3::')",    '::d1:d4:d5:'  ],
506 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3:')",     ':::d1:d4:d5:' ], # first, resolve updirs in base
507 [ "Mac->abs2rel('hd:d1:d3:','hd:d1:d2:')",            '::d3:'        ],
508 [ "Mac->abs2rel('hd:d1::d3:','hd:d1:d2:')",           ':::d3:'       ],
509 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ], # same as above
510 [ "Mac->abs2rel('hd:d1:d2:d3:','hd:d1:d2:')",         ':d3:'         ],
511 [ "Mac->abs2rel('hd:d1:d2:d3::','hd:d1:d2:')",        ':d3::'        ],
512 [ "Mac->abs2rel('hd1:d3:d4:d5:','hd2:d1:d2:')",       ':::d3:d4:d5:' ], # ignore base's volume
513 [ "Mac->abs2rel('hd:','hd:d1:d2:')",                  ':::'          ],
514
515 [ "Mac->rel2abs(':d3:','hd:d1:d2:')",          'hd:d1:d2:d3:'     ],
516 [ "Mac->rel2abs(':d3:d4:','hd:d1:d2:')",       'hd:d1:d2:d3:d4:'  ],
517 [ "Mac->rel2abs('','hd:d1:d2:')",              ''                 ],
518 [ "Mac->rel2abs('::','hd:d1:d2:')",            'hd:d1:d2::'       ],
519 [ "Mac->rel2abs('::','hd:d1:d2:file')",        'hd:d1:d2::'       ],# ignore base's file portion
520 [ "Mac->rel2abs(':file','hd:d1:d2:')",         'hd:d1:d2:file'    ],
521 [ "Mac->rel2abs('::file','hd:d1:d2:')",        'hd:d1:d2::file'   ],
522 [ "Mac->rel2abs('::d3:','hd:d1:d2:')",         'hd:d1:d2::d3:'    ],
523 [ "Mac->rel2abs('hd:','hd:d1:d2:')",           'hd:'              ], # path already absolute
524 [ "Mac->rel2abs('hd:d3:file','hd:d1:d2:')",    'hd:d3:file'       ],
525 [ "Mac->rel2abs('hd:d3:','hd:d1:file')",       'hd:d3:'           ],
526
527 [ "Epoc->case_tolerant()",         '1'  ],
528
529 [ "Epoc->canonpath('')",                                      ''          ],
530 [ "Epoc->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
531 [ "Epoc->canonpath('/./')",                                   '/'         ],
532 [ "Epoc->canonpath('/a/./')",                                 '/a'        ],
533
534 # XXX Todo, copied from Unix, but fail. Should they? 2003-07-07 Tels
535 #[ "Epoc->canonpath('/a/.')",                                  '/a'        ],
536 #[ "Epoc->canonpath('/.')",                                    '/'         ],
537
538 [ "Cygwin->case_tolerant()",         '0'  ],
539
540 ) ;
541
542 plan tests => scalar @tests;
543
544 {
545     @File::Spec::FakeWin32::ISA = qw(File::Spec::Win32);
546     sub File::Spec::FakeWin32::_cwd { 'C:\\one\\two' }
547 }
548
549
550 # Test out the class methods
551 for ( @tests ) {
552    tryfunc( @$_ ) ;
553 }
554
555
556 #
557 # Tries a named function with the given args and compares the result against
558 # an expected result. Works with functions that return scalars or arrays.
559 #
560 sub tryfunc {
561     my $function = shift ;
562     my $expected = shift ;
563     my $platform = shift ;
564
565     if ($platform && $^O ne $platform) {
566         skip("skip $function", 1);
567         return;
568     }
569
570     $function =~ s#\\#\\\\#g ;
571     $function =~ s/^([^\$].*->)/File::Spec::$1/;
572     my $got = join ',', eval $function;
573
574     if ( $@ ) {
575       if ( $@ =~ /^\Q$skip_exception/ ) {
576         skip "skip $function: $skip_exception", 1;
577       }
578       else {
579         ok $@, '', $function;
580       }
581       return;
582     }
583
584     ok $got, $expected, $function;
585 }