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