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