Fix Some Pod Typos
[p5sagit/p5-mst-13.2.git] / lib / File / 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         $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->catfile('a','b','c')", 'a/b/c'  ],
51
52 [ "Unix->splitpath('file')",            ',,file'            ],
53 [ "Unix->splitpath('/d1/d2/d3/')",      ',/d1/d2/d3/,'      ],
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/.file')", ',/d1/d2/d3/,.file' ],
58 [ "Unix->splitpath('d1/d2/d3/file')",   ',d1/d2/d3/,file'   ],
59 [ "Unix->splitpath('/../../d1/')",      ',/../../d1/,'      ],
60 [ "Unix->splitpath('/././d1/')",        ',/././d1/,'        ],
61
62 [ "Unix->catpath('','','file')",            'file'            ],
63 [ "Unix->catpath('','/d1/d2/d3/','')",      '/d1/d2/d3/'      ],
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/','.file')", '/d1/d2/d3/.file' ],
68 [ "Unix->catpath('','d1/d2/d3/','file')",   'd1/d2/d3/file'   ],
69 [ "Unix->catpath('','/../../d1/','')",      '/../../d1/'      ],
70 [ "Unix->catpath('','/././d1/','')",        '/././d1/'        ],
71 [ "Unix->catpath('d1','d2/d3/','')",        'd2/d3/'          ],
72 [ "Unix->catpath('d1','d2','d3/')",         'd2/d3/'          ],
73
74 [ "Unix->splitdir('')",           ''           ],
75 [ "Unix->splitdir('/d1/d2/d3/')", ',d1,d2,d3,' ],
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
80 [ "Unix->catdir()",                     ''          ],
81 [ "Unix->catdir('/')",                  '/'         ],
82 [ "Unix->catdir('','d1','d2','d3','')", '/d1/d2/d3' ],
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
87 [ "Unix->catfile('a','b','c')", 'a/b/c' ],
88
89 [ "Unix->canonpath('')",                                      ''          ],
90 [ "Unix->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
91 [ "Unix->canonpath('/.')",                                    '/'         ],
92 [ "Unix->canonpath('/./')",                                   '/'         ],
93 [ "Unix->canonpath('/a/./')",                                 '/a'        ],
94 [ "Unix->canonpath('/a/.')",                                  '/a'        ],
95
96 [  "Unix->abs2rel('/t1/t2/t3','/t1/t2/t3')",          ''                   ],
97 [  "Unix->abs2rel('/t1/t2/t4','/t1/t2/t3')",          '../t4'              ],
98 [  "Unix->abs2rel('/t1/t2','/t1/t2/t3')",             '..'                 ],
99 [  "Unix->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')",       't4'                 ],
100 [  "Unix->abs2rel('/t4/t5/t6','/t1/t2/t3')",          '../../../t4/t5/t6'  ],
101 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
102 [  "Unix->abs2rel('/','/t1/t2/t3')",                  '../../..'           ],
103 [  "Unix->abs2rel('///','/t1/t2/t3')",                '../../..'           ],
104 [  "Unix->abs2rel('/.','/t1/t2/t3')",                 '../../..'           ],
105 [  "Unix->abs2rel('/./','/t1/t2/t3')",                '../../..'           ],
106 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
107
108 [ "Unix->rel2abs('t4','/t1/t2/t3')",             '/t1/t2/t3/t4'    ],
109 [ "Unix->rel2abs('t4/t5','/t1/t2/t3')",          '/t1/t2/t3/t4/t5' ],
110 [ "Unix->rel2abs('.','/t1/t2/t3')",              '/t1/t2/t3'       ],
111 [ "Unix->rel2abs('..','/t1/t2/t3')",             '/t1/t2/t3/..'    ],
112 [ "Unix->rel2abs('../t4','/t1/t2/t3')",          '/t1/t2/t3/../t4' ],
113 [ "Unix->rel2abs('/t1','/t1/t2/t3')",            '/t1'             ],
114
115 [ "Win32->splitpath('file')",                            ',,file'                            ],
116 [ "Win32->splitpath('\\d1/d2\\d3/')",                    ',\\d1/d2\\d3/,'                    ],
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/.file')",               ',\\d1/d2\\d3/,.file'               ],
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('C:\\d1/d2\\d3/')",                  'C:,\\d1/d2\\d3/,'                  ],
124 [ "Win32->splitpath('C:d1/d2\\d3/')",                    'C:,d1/d2\\d3/,'                    ],
125 [ "Win32->splitpath('C:\\d1/d2\\d3/file')",              'C:,\\d1/d2\\d3/,file'              ],
126 [ "Win32->splitpath('C:d1/d2\\d3/file')",                'C:,d1/d2\\d3/,file'                ],
127 [ "Win32->splitpath('C:\\../d2\\d3/file')",              'C:,\\../d2\\d3/,file'              ],
128 [ "Win32->splitpath('C:../d2\\d3/file')",                'C:,../d2\\d3/,file'                ],
129 [ "Win32->splitpath('\\../..\\d1/')",                    ',\\../..\\d1/,'                    ],
130 [ "Win32->splitpath('\\./.\\d1/')",                      ',\\./.\\d1/,'                      ],
131 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/')",     '\\\\node\\share,\\d1/d2\\d3/,'     ],
132 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/file')", '\\\\node\\share,\\d1/d2\\d3/,file' ],
133 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\file')",    '\\\\node\\share,\\d1/d2\\,file'    ],
134 [ "Win32->splitpath('file',1)",                          ',file,'                            ],
135 [ "Win32->splitpath('\\d1/d2\\d3/',1)",                  ',\\d1/d2\\d3/,'                    ],
136 [ "Win32->splitpath('d1/d2\\d3/',1)",                    ',d1/d2\\d3/,'                      ],
137 [ "Win32->splitpath('\\\\node\\share\\d1/d2\\d3/',1)",   '\\\\node\\share,\\d1/d2\\d3/,'     ],
138
139 [ "Win32->catpath('','','file')",                            'file'                            ],
140 [ "Win32->catpath('','\\d1/d2\\d3/','')",                    '\\d1/d2\\d3/'                    ],
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/','.file')",               '\\d1/d2\\d3/.file'               ],
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('C:','\\d1/d2\\d3/','')",                  'C:\\d1/d2\\d3/'                  ],
148 [ "Win32->catpath('C:','d1/d2\\d3/','')",                    'C:d1/d2\\d3/'                    ],
149 [ "Win32->catpath('C:','\\d1/d2\\d3/','file')",              'C:\\d1/d2\\d3/file'              ],
150 [ "Win32->catpath('C:','d1/d2\\d3/','file')",                'C:d1/d2\\d3/file'                ],
151 [ "Win32->catpath('C:','\\../d2\\d3/','file')",              'C:\\../d2\\d3/file'              ],
152 [ "Win32->catpath('C:','../d2\\d3/','file')",                'C:../d2\\d3/file'                ],
153 [ "Win32->catpath('','\\../..\\d1/','')",                    '\\../..\\d1/'                    ],
154 [ "Win32->catpath('','\\./.\\d1/','')",                      '\\./.\\d1/'                      ],
155 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','')",     '\\\\node\\share\\d1/d2\\d3/'     ],
156 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\d3/','file')", '\\\\node\\share\\d1/d2\\d3/file' ],
157 [ "Win32->catpath('\\\\node\\share','\\d1/d2\\','file')",    '\\\\node\\share\\d1/d2\\file'    ],
158
159 [ "Win32->splitdir('')",             ''           ],
160 [ "Win32->splitdir('\\d1/d2\\d3/')", ',d1,d2,d3,' ],
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
165 [ "Win32->catdir()",                        ''                   ],
166 [ "Win32->catdir('')",                      '\\'                 ],
167 [ "Win32->catdir('/')",                     '\\'                 ],
168 [ "Win32->catdir('//d1','d2')",             '\\\\d1\\d2'         ],
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','d3','')",    '\\d1\\d2\\d3'       ],
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('A:/d1','d2','d3')",       'A:\\d1\\d2\\d3'     ],
179 [ "Win32->catdir('A:/d1','d2','d3','')",    'A:\\d1\\d2\\d3'     ],
180 #[ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\d2\\d3'     ],
181 [ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\B:\\d2\\d3' ],
182 [ "Win32->catdir('A:/')",                   'A:\\'               ],
183
184 [ "Win32->catfile('a','b','c')", 'a\\b\\c' ],
185
186 [ "Win32->canonpath('')",               ''                    ],
187 [ "Win32->canonpath('a:')",             'A:'                  ],
188 [ "Win32->canonpath('A:f')",            'A:f'                 ],
189 [ "Win32->canonpath('//a\\b//c')",      '\\\\a\\b\\c'         ],
190 [ "Win32->canonpath('/a/..../c')",      '\\a\\....\\c'        ],
191 [ "Win32->canonpath('//a/b\\c')",       '\\\\a\\b\\c'         ],
192 [ "Win32->canonpath('////')",           '\\\\\\'              ],
193 [ "Win32->canonpath('//')",             '\\'                  ],
194 [ "Win32->canonpath('/.')",             '\\.'                 ],
195 [ "Win32->canonpath('//a/b/../../c')",  '\\\\a\\b\\..\\..\\c' ],
196 [ "Win32->canonpath('//a/../../c')",    '\\\\a\\..\\..\\c'    ],
197
198 [  "Win32->abs2rel('/t1/t2/t3','/t1/t2/t3')",    ''                       ],
199 [  "Win32->abs2rel('/t1/t2/t4','/t1/t2/t3')",    '..\\t4'                 ],
200 [  "Win32->abs2rel('/t1/t2','/t1/t2/t3')",       '..'                     ],
201 [  "Win32->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')", 't4'                     ],
202 [  "Win32->abs2rel('/t4/t5/t6','/t1/t2/t3')",    '..\\..\\..\\t4\\t5\\t6' ],
203 #[ "Win32->abs2rel('../t4','/t1/t2/t3')",        '\\t1\\t2\\t3\\..\\t4'   ],
204 [  "Win32->abs2rel('/','/t1/t2/t3')",            '..\\..\\..'             ],
205 [  "Win32->abs2rel('///','/t1/t2/t3')",          '..\\..\\..'             ],
206 [  "Win32->abs2rel('/.','/t1/t2/t3')",           '..\\..\\..\\.'          ],
207 [  "Win32->abs2rel('/./','/t1/t2/t3')",          '..\\..\\..'             ],
208 [  "Win32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')",  '..\\t4'                 ],
209 [  "Win32->abs2rel('//a/t1/t2/t4','/t2/t3')",    '..\\t4'                 ],
210
211 [ "Win32->rel2abs('temp','C:/')",                       'C:\\temp'                        ],
212 [ "Win32->rel2abs('temp','C:/a')",                      'C:\\a\\temp'                     ],
213 [ "Win32->rel2abs('temp','C:/a/')",                     'C:\\a\\temp'                     ],
214 [ "Win32->rel2abs('../','C:/')",                        'C:\\..'                          ],
215 [ "Win32->rel2abs('../','C:/a')",                       'C:\\a\\..'                       ],
216 [ "Win32->rel2abs('temp','//prague_main/work/')",       '\\\\prague_main\\work\\temp'     ],
217 [ "Win32->rel2abs('../temp','//prague_main/work/')",    '\\\\prague_main\\work\\..\\temp' ],
218 [ "Win32->rel2abs('temp','//prague_main/work')",        '\\\\prague_main\\work\\temp'     ],
219 [ "Win32->rel2abs('../','//prague_main/work')",         '\\\\prague_main\\work\\..'       ],
220
221 [ "VMS->splitpath('file')",                                       ',,file'                                   ],
222 [ "VMS->splitpath('[d1.d2.d3]')",                                 ',[d1.d2.d3],'                               ],
223 [ "VMS->splitpath('[.d1.d2.d3]')",                                ',[.d1.d2.d3],'                              ],
224 [ "VMS->splitpath('[d1.d2.d3]file')",                             ',[d1.d2.d3],file'                           ],
225 [ "VMS->splitpath('d1/d2/d3/file')",                              ',[.d1.d2.d3],file'                          ],
226 [ "VMS->splitpath('/d1/d2/d3/file')",                             'd1:,[d2.d3],file'                         ],
227 [ "VMS->splitpath('[.d1.d2.d3]file')",                            ',[.d1.d2.d3],file'                          ],
228 [ "VMS->splitpath('node::volume:[d1.d2.d3]')",                    'node::volume:,[d1.d2.d3],'                  ],
229 [ "VMS->splitpath('node::volume:[d1.d2.d3]file')",                'node::volume:,[d1.d2.d3],file'              ],
230 [ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]')",     'node"access_spec"::volume:,[d1.d2.d3],'     ],
231 [ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]file')", 'node"access_spec"::volume:,[d1.d2.d3],file' ],
232
233 [ "VMS->catpath('','','file')",                                       'file'                                     ],
234 [ "VMS->catpath('','[d1.d2.d3]','')",                                 '[d1.d2.d3]'                               ],
235 [ "VMS->catpath('','[.d1.d2.d3]','')",                                '[.d1.d2.d3]'                              ],
236 [ "VMS->catpath('','[d1.d2.d3]','file')",                             '[d1.d2.d3]file'                           ],
237 [ "VMS->catpath('','[.d1.d2.d3]','file')",                            '[.d1.d2.d3]file'                          ],
238 [ "VMS->catpath('','d1/d2/d3','file')",                               '[.d1.d2.d3]file'                            ],
239 [ "VMS->catpath('v','d1/d2/d3','file')",                              'v:[.d1.d2.d3]file'                            ],
240 [ "VMS->catpath('node::volume:','[d1.d2.d3]','')",                    'node::volume:[d1.d2.d3]'                  ],
241 [ "VMS->catpath('node::volume:','[d1.d2.d3]','file')",                'node::volume:[d1.d2.d3]file'              ],
242 [ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','')",     'node"access_spec"::volume:[d1.d2.d3]'     ],
243 [ "VMS->catpath('node\"access_spec\"::volume:','[d1.d2.d3]','file')", 'node"access_spec"::volume:[d1.d2.d3]file' ],
244
245 [ "VMS->canonpath('')",                                    ''                        ],
246 [ "VMS->canonpath('volume:[d1]file')",                     'volume:[d1]file'         ],
247 [ "VMS->canonpath('volume:[d1.-.d2.][d3.d4.-]')",              'volume:[d2.d3]'          ],
248 [ "VMS->canonpath('volume:[000000.d1]d2.dir;1')",                 'volume:[d1]d2.dir;1'   ],
249
250 [ "VMS->splitdir('')",            ''          ],
251 [ "VMS->splitdir('[]')",          ''          ],
252 [ "VMS->splitdir('d1.d2.d3')",    'd1,d2,d3'  ],
253 [ "VMS->splitdir('[d1.d2.d3]')",  'd1,d2,d3'  ],
254 [ "VMS->splitdir('.d1.d2.d3')",   ',d1,d2,d3' ],
255 [ "VMS->splitdir('[.d1.d2.d3]')", ',d1,d2,d3' ],
256 [ "VMS->splitdir('.-.d2.d3')",    ',-,d2,d3'  ],
257 [ "VMS->splitdir('[.-.d2.d3]')",  ',-,d2,d3'  ],
258
259 [ "VMS->catdir('')",                                                      ''                 ],
260 [ "VMS->catdir('d1','d2','d3')",                                          '[.d1.d2.d3]'         ],
261 [ "VMS->catdir('d1','d2/','d3')",                                         '[.d1.d2.d3]'         ],
262 [ "VMS->catdir('','d1','d2','d3')",                                       '[.d1.d2.d3]'        ],
263 [ "VMS->catdir('','-','d2','d3')",                                        '[-.d2.d3]'         ],
264 [ "VMS->catdir('','-','','d3')",                                          '[-.d3]'            ],
265 [ "VMS->catdir('dir.dir','d2.dir','d3.dir')",                             '[.dir.d2.d3]'        ],
266 [ "VMS->catdir('[.name]')",                                               '[.name]'            ],
267 [ "VMS->catdir('[.name]','[.name]')",                                     '[.name.name]'],    
268
269 [  "VMS->abs2rel('node::volume:[t1.t2.t3]','[t1.t2.t3]')", ''                 ],
270 [  "VMS->abs2rel('node::volume:[t1.t2.t4]','[t1.t2.t3]')", '[-.t4]'           ],
271 [  "VMS->abs2rel('[t1.t2.t3]','[t1.t2.t3]')",              ''                 ],
272 [  "VMS->abs2rel('[t1.t2.t3]file','[t1.t2.t3]')",          'file'             ],
273 [  "VMS->abs2rel('[t1.t2.t4]','[t1.t2.t3]')",              '[-.t4]'           ],
274 [  "VMS->abs2rel('[t1.t2]file','[t1.t2.t3]')",             '[-]file'          ],
275 [  "VMS->abs2rel('[t1.t2.t3.t4]','[t1.t2.t3]')",           '[t4]'             ],
276 [  "VMS->abs2rel('[t4.t5.t6]','[t1.t2.t3]')",              '[---.t4.t5.t6]'   ],
277 [ "VMS->abs2rel('[000000]','[t1.t2.t3]')",                 '[---]'            ],
278 [ "VMS->abs2rel('a:[t1.t2.t4]','[t1.t2.t3]')",             '[-.t4]'           ],
279 [ "VMS->abs2rel('[a.-.b.c.-]','[t1.t2.t3]')",              '[---.b]'          ],
280
281 [ "VMS->rel2abs('[.t4]','[t1.t2.t3]')",          '[t1.t2.t3.t4]'    ],
282 [ "VMS->rel2abs('[.t4.t5]','[t1.t2.t3]')",       '[t1.t2.t3.t4.t5]' ],
283 [ "VMS->rel2abs('[]','[t1.t2.t3]')",             '[t1.t2.t3]'       ],
284 [ "VMS->rel2abs('[-]','[t1.t2.t3]')",            '[t1.t2]'          ],
285 [ "VMS->rel2abs('[-.t4]','[t1.t2.t3]')",         '[t1.t2.t4]'       ],
286 [ "VMS->rel2abs('[t1]','[t1.t2.t3]')",           '[t1]'             ],
287
288 [ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
289 [ "OS2->catfile('a','b','c')",            'a/b/c'          ],
290
291
292 [ "Mac->catpath('','','')",              ''                ],
293 [ "Mac->catpath('',':','')",             ':'               ],
294 [ "Mac->catpath('','::','')",            '::'              ],
295
296 [ "Mac->catpath('hd','','')",            'hd:'             ],
297 [ "Mac->catpath('hd:','','')",           'hd:'             ],
298 [ "Mac->catpath('hd:',':','')",          'hd:'             ], 
299 [ "Mac->catpath('hd:','::','')",         'hd::'            ],
300
301 [ "Mac->catpath('hd','','file')",       'hd:file'          ],
302 [ "Mac->catpath('hd',':','file')",      'hd:file'          ],
303 [ "Mac->catpath('hd','::','file')",     'hd::file'         ],
304 [ "Mac->catpath('hd',':::','file')",    'hd:::file'        ],
305
306 [ "Mac->catpath('hd:','',':file')",      'hd:file'         ],
307 [ "Mac->catpath('hd:',':',':file')",     'hd:file'         ],
308 [ "Mac->catpath('hd:','::',':file')",    'hd::file'        ],
309 [ "Mac->catpath('hd:',':::',':file')",   'hd:::file'       ],
310
311 [ "Mac->catpath('hd:','d1','file')",     'hd:d1:file'      ],
312 [ "Mac->catpath('hd:',':d1:',':file')",  'hd:d1:file'      ],
313
314 [ "Mac->catpath('','d1','')",            ':d1:'            ],
315 [ "Mac->catpath('',':d1','')",           ':d1:'            ],
316 [ "Mac->catpath('',':d1:','')",          ':d1:'            ],
317
318 [ "Mac->catpath('','d1','file')",        ':d1:file'        ],
319 [ "Mac->catpath('',':d1:',':file')",     ':d1:file'        ],
320
321 [ "Mac->catpath('','','file')",          'file'            ],
322 [ "Mac->catpath('','',':file')",         'file'            ], # !
323 [ "Mac->catpath('',':',':file')",        ':file'           ], # !
324
325
326 [ "Mac->splitpath(':')",              ',:,'               ],
327 [ "Mac->splitpath('::')",             ',::,'              ],
328 [ "Mac->splitpath(':::')",            ',:::,'             ],
329
330 [ "Mac->splitpath('file')",           ',,file'            ],
331 [ "Mac->splitpath(':file')",          ',:,file'           ],
332
333 [ "Mac->splitpath('d1',1)",           ',:d1:,'            ], # dir, not volume
334 [ "Mac->splitpath(':d1',1)",          ',:d1:,'            ],
335 [ "Mac->splitpath(':d1:',1)",         ',:d1:,'            ],
336 [ "Mac->splitpath(':d1:')",           ',:d1:,'            ],
337 [ "Mac->splitpath(':d1:d2:d3:')",     ',:d1:d2:d3:,'      ],
338 [ "Mac->splitpath(':d1:d2:d3:',1)",   ',:d1:d2:d3:,'      ],
339 [ "Mac->splitpath(':d1:file')",       ',:d1:,file'        ],
340 [ "Mac->splitpath('::d1:file')",      ',::d1:,file'       ],
341
342 [ "Mac->splitpath('hd:', 1)",         'hd:,,'             ],
343 [ "Mac->splitpath('hd:')",            'hd:,,'             ],
344 [ "Mac->splitpath('hd:d1:d2:')",      'hd:,:d1:d2:,'      ],
345 [ "Mac->splitpath('hd:d1:d2',1)",     'hd:,:d1:d2:,'      ],
346 [ "Mac->splitpath('hd:d1:d2:file')",  'hd:,:d1:d2:,file'  ],
347 [ "Mac->splitpath('hd:d1:d2::file')", 'hd:,:d1:d2::,file' ],
348 [ "Mac->splitpath('hd::d1:d2:file')", 'hd:,::d1:d2:,file' ], # invalid path
349 [ "Mac->splitpath('hd:file')",        'hd:,,file'         ],
350
351 [ "Mac->splitdir()",                   ''            ],
352 [ "Mac->splitdir('')",                 ''            ],
353 [ "Mac->splitdir(':')",                ':'           ],
354 [ "Mac->splitdir('::')",               '::'          ],
355 [ "Mac->splitdir(':::')",              '::,::'       ],
356 [ "Mac->splitdir(':::d1:d2')",         '::,::,d1,d2' ],
357
358 [ "Mac->splitdir(':d1:d2:d3::')",      'd1,d2,d3,::'],
359 [ "Mac->splitdir(':d1:d2:d3:')",       'd1,d2,d3'   ],
360 [ "Mac->splitdir(':d1:d2:d3')",        'd1,d2,d3'   ],
361
362 # absolute paths in splitdir() work, but you'd better use splitpath()
363 [ "Mac->splitdir('hd:')",              'hd:'              ],
364 [ "Mac->splitdir('hd::')",             'hd:,::'           ], # invalid path, but it works
365 [ "Mac->splitdir('hd::d1:')",          'hd:,::,d1'        ], # invalid path, but it works
366 [ "Mac->splitdir('hd:d1:d2:::')",      'hd:,d1,d2,::,::'  ],
367 [ "Mac->splitdir('hd:d1:d2::')",       'hd:,d1,d2,::'     ],
368 [ "Mac->splitdir('hd:d1:d2:')",        'hd:,d1,d2'        ],
369 [ "Mac->splitdir('hd:d1:d2')",         'hd:,d1,d2'        ],
370 [ "Mac->splitdir('hd:d1::d2::')",      'hd:,d1,::,d2,::'  ],
371
372 [ "Mac->catdir()",                 ''             ],
373 [ "Mac->catdir('')",               $root, 'MacOS' ], # skipped on other OS
374 [ "Mac->catdir(':')",              ':'            ],
375
376 [ "Mac->catdir('', '')",           $root, 'MacOS' ], # skipped on other OS
377 [ "Mac->catdir('', ':')",          $root, 'MacOS' ], # skipped on other OS 
378 [ "Mac->catdir(':', ':')",         ':'            ],  
379 [ "Mac->catdir(':', '')",          ':'            ], 
380
381 [ "Mac->catdir('', '::')",         $root, 'MacOS' ], # skipped on other OS
382 [ "Mac->catdir(':', '::')",        '::'           ], 
383
384 [ "Mac->catdir('::', '')",         '::'           ],  
385 [ "Mac->catdir('::', ':')",        '::'           ], 
386
387 [ "Mac->catdir('::', '::')",       ':::'          ], 
388
389 [ "Mac->catdir(':d1')",                    ':d1:'        ],
390 [ "Mac->catdir(':d1:')",                   ':d1:'        ],
391 [ "Mac->catdir(':d1','d2')",               ':d1:d2:'     ],
392 [ "Mac->catdir(':d1',':d2')",              ':d1:d2:'     ],
393 [ "Mac->catdir(':d1',':d2:')",             ':d1:d2:'     ],
394 [ "Mac->catdir(':d1',':d2::')",            ':d1:d2::'     ],
395 [ "Mac->catdir(':',':d1',':d2')",          ':d1:d2:'     ],
396 [ "Mac->catdir('::',':d1',':d2')",         '::d1:d2:'    ],
397 [ "Mac->catdir('::','::',':d1',':d2')",    ':::d1:d2:'   ],
398 [ "Mac->catdir(':',':',':d1',':d2')",      ':d1:d2:'     ],
399 [ "Mac->catdir('::',':',':d1',':d2')",     '::d1:d2:'    ],
400
401 [ "Mac->catdir('d1')",                    ':d1:'         ],
402 [ "Mac->catdir('d1','d2','d3')",          ':d1:d2:d3:'   ],
403 [ "Mac->catdir('d1','d2/','d3')",         ':d1:d2/:d3:'  ],
404 [ "Mac->catdir('d1','',':d2')",           ':d1:d2:'      ],
405 [ "Mac->catdir('d1',':',':d2')",          ':d1:d2:'      ],
406 [ "Mac->catdir('d1','::',':d2')",         ':d1::d2:'     ],
407 [ "Mac->catdir('d1',':::',':d2')",        ':d1:::d2:'    ],
408 [ "Mac->catdir('d1','::','::',':d2')",    ':d1:::d2:'    ],
409 [ "Mac->catdir('d1','d2')",               ':d1:d2:'      ],
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
419 [ "Mac->catdir('','d1','d2','d3')",        $root . 'd1:d2:d3:', 'MacOS' ], # skipped on other OS
420 [ "Mac->catdir('',':','d1','d2')",         $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
421 [ "Mac->catdir('','::','d1','d2')",        $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
422 [ "Mac->catdir('',':','','d1')",           $root . 'd1:'      , 'MacOS' ], # skipped on other OS
423 [ "Mac->catdir('', ':d1',':d2')",          $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
424 [ "Mac->catdir('','',':d1',':d2')",        $root . 'd1:d2:'   , 'MacOS' ], # skipped on other OS
425
426 [ "Mac->catdir('hd:',':d1')",       'hd:d1:'      ],
427 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
428 [ "Mac->catdir('hd:','d1')",        'hd:d1:'      ],
429 [ "Mac->catdir('hd:d1:',':d2')",    'hd:d1:d2:'   ],
430 [ "Mac->catdir('hd:d1:',':d2:')",   'hd:d1:d2:'   ],
431
432 [ "Mac->catfile()",                      ''                      ], 
433 [ "Mac->catfile('')",                    ''                      ],
434 [ "Mac->catfile('', '')",                $root         , 'MacOS' ], # skipped on other OS 
435 [ "Mac->catfile('', 'file')",            $root . 'file', 'MacOS' ], # skipped on other OS
436 [ "Mac->catfile(':')",                   ':'                     ],
437 [ "Mac->catfile(':', '')",               ':'                     ],
438
439 [ "Mac->catfile('d1','d2','file')",      ':d1:d2:file' ],
440 [ "Mac->catfile('d1','d2',':file')",     ':d1:d2:file' ],
441 [ "Mac->catfile('file')",                'file'        ], 
442 [ "Mac->catfile(':', 'file')",           ':file'       ], 
443  
444 [ "Mac->canonpath('')",                   ''     ],
445 [ "Mac->canonpath(':')",                  ':'    ],
446 [ "Mac->canonpath('::')",                 '::'   ],
447 [ "Mac->canonpath('a::')",                'a::'  ],
448 [ "Mac->canonpath(':a::')",               ':a::' ],
449
450 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:')",            ':'            ],
451 [ "Mac->abs2rel('hd:d1:d2:','hd:d1:d2:file')",        ':'            ], # ignore base's file portion
452 [ "Mac->abs2rel('hd:d1:d2:file','hd:d1:d2:')",        ':file'        ], 
453 [ "Mac->abs2rel('hd:d1:','hd:d1:d2:')",               '::'           ],
454 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ],
455 [ "Mac->abs2rel('hd:d3:','hd:d1:d2::')",              '::d3:'        ],
456 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3::')",    '::d1:d4:d5:'  ],
457 [ "Mac->abs2rel('hd:d1:d4:d5:','hd:d1::d2:d3:')",     ':::d1:d4:d5:' ], # first, resolve updirs in base
458 [ "Mac->abs2rel('hd:d1:d3:','hd:d1:d2:')",            '::d3:'        ],
459 [ "Mac->abs2rel('hd:d1::d3:','hd:d1:d2:')",           ':::d3:'       ],
460 [ "Mac->abs2rel('hd:d3:','hd:d1:d2:')",               ':::d3:'       ], # same as above
461 [ "Mac->abs2rel('hd:d1:d2:d3:','hd:d1:d2:')",         ':d3:'         ],
462 [ "Mac->abs2rel('hd:d1:d2:d3::','hd:d1:d2:')",        ':d3::'        ],
463 [ "Mac->abs2rel('hd1:d3:d4:d5:','hd2:d1:d2:')",       ':::d3:d4:d5:' ], # ignore base's volume
464 [ "Mac->abs2rel('hd:','hd:d1:d2:')",                  ':::'          ],
465
466 [ "Mac->rel2abs(':d3:','hd:d1:d2:')",          'hd:d1:d2:d3:'     ], 
467 [ "Mac->rel2abs(':d3:d4:','hd:d1:d2:')",       'hd:d1:d2:d3:d4:'  ], 
468 [ "Mac->rel2abs('','hd:d1:d2:')",              ''                 ],
469 [ "Mac->rel2abs('::','hd:d1:d2:')",            'hd:d1:d2::'       ],
470 [ "Mac->rel2abs('::','hd:d1:d2:file')",        'hd:d1:d2::'       ],# ignore base's file portion
471 [ "Mac->rel2abs(':file','hd:d1:d2:')",         'hd:d1:d2:file'    ],
472 [ "Mac->rel2abs('::file','hd:d1:d2:')",        'hd:d1:d2::file'   ],
473 [ "Mac->rel2abs('::d3:','hd:d1:d2:')",         'hd:d1:d2::d3:'    ],
474 [ "Mac->rel2abs('hd:','hd:d1:d2:')",           'hd:'              ], # path already absolute
475 [ "Mac->rel2abs('hd:d3:file','hd:d1:d2:')",    'hd:d3:file'       ],
476 [ "Mac->rel2abs('hd:d3:','hd:d1:file')",       'hd:d3:'           ],
477 ) ;
478
479
480 print "1..", scalar( @tests ), "\n" ;
481
482 my $current_test= 1 ;
483
484 # Test out the class methods
485 for ( @tests ) {
486    tryfunc( @$_ ) ;
487 }
488
489
490 #
491 # Tries a named function with the given args and compares the result against
492 # an expected result. Works with functions that return scalars or arrays.
493 #
494 sub tryfunc {
495     my $function = shift ;
496     my $expected = shift ;
497     my $platform = shift ;
498
499     if ($platform && $^O ne $platform) {
500         print "ok $current_test # skipped: $function\n" ;
501         ++$current_test ;
502         return;
503     }
504
505     $function =~ s#\\#\\\\#g ;
506
507     my $got ;
508     if ( $function =~ /^[^\$].*->/ ) {
509         $got = eval( "join( ',', File::Spec::$function )" ) ;
510     }
511     else {
512         $got = eval( "join( ',', $function )" ) ;
513     }
514
515     if ( $@ ) {
516         if ( substr( $@, 0, length $skip_exception ) eq $skip_exception ) {
517             chomp $@ ;
518             print "ok $current_test # skip $function: $@\n" ;
519         }
520         else {
521             chomp $@ ;
522             print "not ok $current_test # $function: $@\n" ;
523         }
524     }
525     elsif ( !defined( $got ) || $got ne $expected ) {
526         print "not ok $current_test # $function: got '$got', expected '$expected'\n" ;
527     }
528     else {
529         print "ok $current_test # $function\n" ;
530     }
531     ++$current_test ;
532 }