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