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