(was Re: [PATCH perl@13462]] VMS-only File::Spec->canonpath fix)
[perl.git] / vms / ext / filespec.t
1 #!./perl
2
3 BEGIN { unshift(@INC,'../lib') if -d '../lib'; }
4
5 use VMS::Filespec;
6 use File::Spec;
7
8 foreach (<DATA>) {
9   chomp;
10   s/\s*#.*//;
11   next if /^\s*$/;
12   push(@tests,$_);
13 }
14
15 require './test.pl';
16 plan(tests => scalar(2*@tests)+6);
17
18 foreach $test (@tests) {
19   ($arg,$func,$expect) = split(/\s+/,$test);
20
21   $rslt = eval "$func('$arg')";
22   is($@, '', "eval func('$arg')");
23   is($rslt, $expect, "  result");
24 }
25
26 $defwarn = <<'EOW';
27 # Note: This failure may have occurred because your default device
28 # was set using a non-concealed logical name.  If this is the case,
29 # you will need to determine by inspection that the two resultant
30 # file specifications shwn above are in fact equivalent.
31 EOW
32
33 is(rmsexpand('[]'),       "\U$ENV{DEFAULT}", 'rmsexpand()') || print $defwarn;
34 is(rmsexpand('from.here'),"\L$ENV{DEFAULT}from.here") || print $defwarn;
35 is(rmsexpand('from'),     "\L$ENV{DEFAULT}from")      || print $defwarn;
36
37 is(rmsexpand('from.here','cant:[get.there];2'),
38    'cant:[get.there]from.here;2')                     || print $defwarn;
39
40
41 # Make sure we're using redirected mkdir, which strips trailing '/', since
42 # the CRTL's mkdir can't handle this.
43 ok(mkdir('testdir/',0777),      'using redirected mkdir()');
44 ok(rmdir('testdir/'),           '    rmdir()');
45
46 __DATA__
47
48 # lots of underscores used to minimize collision with existing logical names
49
50 # Basic VMS to Unix filespecs
51 __some_:[__where_.__over_]__the_.__rainbow_    unixify /__some_/__where_/__over_/__the_.__rainbow_
52 [.__some_.__where_.__over_]__the_.__rainbow_   unixify __some_/__where_/__over_/__the_.__rainbow_
53 [-.__some_.__where_.__over_]__the_.__rainbow_  unixify ../__some_/__where_/__over_/__the_.__rainbow_
54 [.__some_.--.__where_.__over_]__the_.__rainbow_        unixify __some_/../../__where_/__over_/__the_.__rainbow_
55 [.__some_...__where_.__over_]__the_.__rainbow_ unixify __some_/.../__where_/__over_/__the_.__rainbow_
56 [...__some_.__where_.__over_]__the_.__rainbow_ unixify .../__some_/__where_/__over_/__the_.__rainbow_
57 [.__some_.__where_.__over_...]__the_.__rainbow_        unixify __some_/__where_/__over_/.../__the_.__rainbow_
58 [.__some_.__where_.__over_...] unixify __some_/__where_/__over_/.../
59 [.__some_.__where_.__over_.-]  unixify __some_/__where_/__over_/../
60 []      unixify         ./
61 [-]     unixify         ../
62 [--]    unixify         ../../
63 [...]   unixify         .../
64
65 # and back again
66 /__some_/__where_/__over_/__the_.__rainbow_    vmsify  __some_:[__where_.__over_]__the_.__rainbow_
67 __some_/__where_/__over_/__the_.__rainbow_     vmsify  [.__some_.__where_.__over_]__the_.__rainbow_
68 ../__some_/__where_/__over_/__the_.__rainbow_  vmsify  [-.__some_.__where_.__over_]__the_.__rainbow_
69 __some_/../../__where_/__over_/__the_.__rainbow_       vmsify  [-.__where_.__over_]__the_.__rainbow_
70 .../__some_/__where_/__over_/__the_.__rainbow_ vmsify  [...__some_.__where_.__over_]__the_.__rainbow_
71 __some_/.../__where_/__over_/__the_.__rainbow_ vmsify  [.__some_...__where_.__over_]__the_.__rainbow_
72 /__some_/.../__where_/__over_/__the_.__rainbow_        vmsify  __some_:[...__where_.__over_]__the_.__rainbow_
73 __some_/__where_/...   vmsify  [.__some_.__where_...]
74 /__where_/...  vmsify  __where_:[...]
75 .       vmsify  []
76 ..      vmsify  [-]
77 ../..   vmsify  [--]
78 .../    vmsify  [...]
79 /       vmsify  sys$disk:[000000]
80
81 # Fileifying directory specs
82 __down_:[__the_.__garden_.__path_]     fileify __down_:[__the_.__garden_]__path_.dir;1
83 [.__down_.__the_.__garden_.__path_]    fileify [.__down_.__the_.__garden_]__path_.dir;1
84 /__down_/__the_/__garden_/__path_      fileify /__down_/__the_/__garden_/__path_.dir;1
85 /__down_/__the_/__garden_/__path_/     fileify /__down_/__the_/__garden_/__path_.dir;1
86 __down_/__the_/__garden_/__path_       fileify __down_/__the_/__garden_/__path_.dir;1
87 __down_:[__the_.__garden_]__path_      fileify __down_:[__the_.__garden_]__path_.dir;1
88 __down_:[__the_.__garden_]__path_.     fileify # N.B. trailing . ==> null type
89 __down_:[__the_]__garden_.__path_      fileify 
90 /__down_/__the_/__garden_/__path_.     fileify # N.B. trailing . ==> null type
91 /__down_/__the_/__garden_.__path_      fileify 
92
93 # and pathifying them
94 __down_:[__the_.__garden_]__path_.dir;1        pathify __down_:[__the_.__garden_.__path_]
95 [.__down_.__the_.__garden_]__path_.dir pathify [.__down_.__the_.__garden_.__path_]
96 /__down_/__the_/__garden_/__path_.dir  pathify /__down_/__the_/__garden_/__path_/
97 __down_/__the_/__garden_/__path_.dir   pathify __down_/__the_/__garden_/__path_/
98 __down_:[__the_.__garden_]__path_      pathify __down_:[__the_.__garden_.__path_]
99 __down_:[__the_.__garden_]__path_.     pathify # N.B. trailing . ==> null type
100 __down_:[__the_]__garden_.__path_      pathify 
101 /__down_/__the_/__garden_/__path_.     pathify # N.B. trailing . ==> null type
102 /__down_/__the_/__garden_.__path_      pathify 
103 __down_:[__the_.__garden_]__path_.dir;2        pathify #N.B. ;2
104 __path_        pathify __path_/
105 /__down_/__the_/__garden_/.    pathify /__down_/__the_/__garden_/./
106 /__down_/__the_/__garden_/..   pathify /__down_/__the_/__garden_/../
107 /__down_/__the_/__garden_/...  pathify /__down_/__the_/__garden_/.../
108 __path_.notdir pathify 
109
110 # Both VMS/Unix and file/path conversions
111 __down_:[__the_.__garden_]__path_.dir;1        unixpath        /__down_/__the_/__garden_/__path_/
112 /__down_/__the_/__garden_/__path_      vmspath __down_:[__the_.__garden_.__path_]
113 __down_:[__the_.__garden_.__path_]     unixpath        /__down_/__the_/__garden_/__path_/
114 __down_:[__the_.__garden_.__path_...]  unixpath        /__down_/__the_/__garden_/__path_/.../
115 /__down_/__the_/__garden_/__path_.dir  vmspath __down_:[__the_.__garden_.__path_]
116 [.__down_.__the_.__garden_]__path_.dir unixpath        __down_/__the_/__garden_/__path_/
117 __down_/__the_/__garden_/__path_       vmspath [.__down_.__the_.__garden_.__path_]
118 __path_        vmspath [.__path_]
119 /       vmspath sys$disk:[000000]
120
121 # Redundant characters in Unix paths
122 //__some_/__where_//__over_/../__the_.__rainbow_       vmsify  __some_:[__where_]__the_.__rainbow_
123 /__some_/__where_//__over_/./__the_.__rainbow_ vmsify  __some_:[__where_.__over_]__the_.__rainbow_
124 ..//../ vmspath [--]
125 ./././  vmspath []
126 ./../.  vmsify  [-]
127
128 # Our override of File::Spec->canonpath can do some strange things
129 __dev:[__dir.000000]__foo     File::Spec->canonpath   __dev:[__dir]__foo
130 __dev:[__dir.][000000]__foo   File::Spec->canonpath   __dev:[__dir]__foo