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