This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix ext/VMS-Filespec/t/filespec.t after move in 2d11a7e9678a88.
[perl5.git] / ext / VMS-Filespec / t / filespec.t
1 #!./perl
2
3 use VMS::Filespec;
4 use File::Spec;
5
6 foreach (<DATA>) {
7   chomp;
8   s/\s*#.*//;
9   next if /^\s*$/;
10   push(@tests,$_);
11 }
12
13 require 'test.pl';
14 plan(tests => scalar(2*@tests)+6);
15
16 my $vms_unix_rpt;
17 my $vms_efs;
18
19 if ($^O eq 'VMS') {
20     if (eval 'require VMS::Feature') {
21         $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
22         $vms_efs = VMS::Feature::current("efs_charset");
23     } else {
24         my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
25         my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
26         $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i; 
27         $vms_efs = $efs_charset =~ /^[ET1]/i; 
28     }
29 }
30
31
32
33 foreach $test (@tests) {
34   ($arg,$func,$expect2,$expect5) = split(/\s+/,$test);
35
36   $expect2 = undef if $expect2 eq 'undef';
37   $expect2 = undef if $expect2 eq '^';
38   $expect5 = undef if $expect5 eq 'undef';
39   $expect5 = $expect2 if $expect5 eq '^';
40
41   if ($vms_efs) {
42         $expect = $expect5;
43   }
44   else {
45         $expect = $expect2;
46   }
47
48   $rslt = eval "$func('$arg')";
49   is($@, '', "eval ${func}('$arg')");
50   if ($expect ne '^*') {
51     is(lc($rslt), lc($expect), "${func}('$arg'): '$rslt'");
52   }
53   else {
54     is(lc($rslt), lc($expect), "${func}('$arg'): '$rslt' # TODO fix ODS-5 test");
55   }
56 }
57
58 $defwarn = <<'EOW';
59 # Note: This failure may have occurred because your default device
60 # was set using a non-concealed logical name.  If this is the case,
61 # you will need to determine by inspection that the two resultant
62 # file specifications shown above are in fact equivalent.
63 EOW
64
65 is(uc(rmsexpand('[]')),   "\U$ENV{DEFAULT}", 'rmsexpand()') || print $defwarn;
66 is(lc(rmsexpand('from.here')),"\L$ENV{DEFAULT}from.here") || print $defwarn;
67 is(lc(rmsexpand('from')),     "\L$ENV{DEFAULT}from")      || print $defwarn;
68
69 is(lc(rmsexpand('from.here','cant:[get.there];2')),
70    'cant:[get.there]from.here;2')                     || print $defwarn;
71
72
73 # Make sure we're using redirected mkdir, which strips trailing '/', since
74 # the CRTL's mkdir can't handle this.
75 ok(mkdir('testdir/',0777),      'using redirected mkdir()');
76 ok(rmdir('testdir/'),           '    rmdir()');
77
78 __DATA__
79
80 # Column definitions:
81 #
82 #  Column 1: Argument (path spec to be transformed)
83 #  Column 2: Function that is to do the transformation
84 #  Column 3: Expected result when DECC$EFS_CHARSET is not in effect
85 #  Column 4: Expected result when DECC$EFS_CHARSET is in effect
86 #            ^ means expect same result for EFS as for non-EFS
87 #            ^* means TODO when EFS is in effect
88
89 # lots of underscores used to minimize collision with existing logical names
90
91 # Basic VMS to Unix filespecs
92 __some_:[__where_.__over_]__the_.__rainbow_    unixify /__some_/__where_/__over_/__the_.__rainbow_ ^
93 __some_:<__where_.__over_>__the_.__rainbow_    unixify /__some_/__where_/__over_/__the_.__rainbow_ ^
94 [.__some_.__where_.__over_]__the_.__rainbow_   unixify __some_/__where_/__over_/__the_.__rainbow_ ^
95 [-.__some_.__where_.__over_]__the_.__rainbow_  unixify ../__some_/__where_/__over_/__the_.__rainbow_ ^
96 [.__some_.--.__where_.__over_]__the_.__rainbow_        unixify __some_/../../__where_/__over_/__the_.__rainbow_ ^
97 [.__some_...__where_.__over_]__the_.__rainbow_ unixify __some_/.../__where_/__over_/__the_.__rainbow_ ^
98 [...__some_.__where_.__over_]__the_.__rainbow_ unixify .../__some_/__where_/__over_/__the_.__rainbow_ ^
99 [.__some_.__where_.__over_...]__the_.__rainbow_        unixify __some_/__where_/__over_/.../__the_.__rainbow_ ^
100 [.__some_.__where_.__over_...] unixify __some_/__where_/__over_/.../ ^
101 [.__some_.__where_.__over_.-]  unixify __some_/__where_/__over_/../ ^
102 []      unixify         ./      ^
103 [-]     unixify         ../     ^
104 [--]    unixify         ../../  ^
105 [...]   unixify         .../    ^
106 __lyrics_:[__are_.__very_^.__sappy_]__but_^.__rhymes_^.__are_.__true_    unixify   /__lyrics_/__are_/__very_.__sappy_/__but_.__rhymes_.__are_.__true_ ^
107 [.$(macro)]     unixify $(macro)/ ^
108
109 # and back again
110 /__some_/__where_/__over_/__the_.__rainbow_    vmsify  __some_:[__where_.__over_]__the_.__rainbow_ ^
111 __some_/__where_/__over_/__the_.__rainbow_     vmsify  [.__some_.__where_.__over_]__the_.__rainbow_ ^
112 ../__some_/__where_/__over_/__the_.__rainbow_  vmsify  [-.__some_.__where_.__over_]__the_.__rainbow_ ^
113 __some_/../../__where_/__over_/__the_.__rainbow_       vmsify  [.__some_.--.__where_.__over_]__the_.__rainbow_ ^
114 .../__some_/__where_/__over_/__the_.__rainbow_ vmsify  [...__some_.__where_.__over_]__the_.__rainbow_ ^
115 __some_/.../__where_/__over_/__the_.__rainbow_ vmsify  [.__some_...__where_.__over_]__the_.__rainbow_  ^
116 /__some_/.../__where_/__over_/__the_.__rainbow_        vmsify  __some_:[...__where_.__over_]__the_.__rainbow_ ^
117 __some_/__where_/...   vmsify  [.__some_.__where_...] ^
118 /__where_/...  vmsify  __where_:[...] ^
119 .       vmsify  []      ^
120 ..      vmsify  [-]     ^
121 ../..   vmsify  [--]    ^
122 .../    vmsify  [...]   ^
123 /       vmsify  sys$disk:[000000] ^
124 ./$(macro)/     vmsify  [.$(macro)] ^
125 ./$(macro)      vmsify  []$(macro) ^
126 ./$(m+  vmsify  []$^(m^+        ^
127 foo-bar-0^.01/  vmsify [.foo-bar-0_01] [.foo-bar-0^.01]
128 # Fileifying directory specs
129 __down_:[__the_.__garden_.__path_]     fileify __down_:[__the_.__garden_]__path_.dir;1 ^
130 [.__down_.__the_.__garden_.__path_]    fileify [.__down_.__the_.__garden_]__path_.dir;1 ^
131 /__down_/__the_/__garden_/__path_      fileify /__down_/__the_/__garden_/__path_.dir;1 ^
132 /__down_/__the_/__garden_/__path_/     fileify /__down_/__the_/__garden_/__path_.dir;1 ^
133 __down_/__the_/__garden_/__path_       fileify __down_/__the_/__garden_/__path_.dir;1 ^
134 __down_:[__the_.__garden_]__path_      fileify __down_:[__the_.__garden_]__path_.dir;1 ^
135 __down_:[__the_.__garden_]__path_.     fileify ^ __down_:[__the_.__garden_]__path_^..dir;1 # N.B. trailing . ==> null type
136 __down_:[__the_]__garden_.__path_      fileify ^ __down_:[__the_]__garden_^.__path_.dir;1 #undef
137 /__down_/__the_/__garden_/__path_.     fileify ^ /__down_/__the_/__garden_/__path_..dir;1 # N.B. trailing . ==> null type
138 /__down_/__the_/__garden_.__path_      fileify ^ /__down_/__the_/__garden_.__path_.dir;1
139
140 # and pathifying them
141 __down_:[__the_.__garden_]__path_.dir;1        pathify __down_:[__the_.__garden_.__path_] ^
142 [.__down_.__the_.__garden_]__path_.dir pathify [.__down_.__the_.__garden_.__path_] ^
143 /__down_/__the_/__garden_/__path_.dir  pathify /__down_/__the_/__garden_/__path_/ ^
144 __down_/__the_/__garden_/__path_.dir   pathify __down_/__the_/__garden_/__path_/ ^
145 __down_:[__the_.__garden_]__path_      pathify __down_:[__the_.__garden_.__path_] ^
146 __down_:[__the_.__garden_]__path_.     pathify ^ __down_:[__the_.__garden_.__path_^.] # N.B. trailing . ==> null type
147 __down_:[__the_]__garden_.__path_      pathify ^ __down_:[__the_.__garden_^.__path_] # undef
148 /__down_/__the_/__garden_/__path_.     pathify /__down_/__the_/__garden_/__path__/ /__down_/__the_/__garden_/__path_./ # N.B. trailing . ==> null type
149 /__down_/__the_/__garden_.__path_      pathify /__down_/__the_/__garden____path_/ /__down_/__the_/__garden_.__path_/
150 __down_:[__the_.__garden_]__path_.dir;2        pathify ^ #N.B. ;2
151 __path_        pathify __path_/ ^
152 /__down_/__the_/__garden_/.    pathify /__down_/__the_/__garden_/./ ^
153 /__down_/__the_/__garden_/..   pathify /__down_/__the_/__garden_/../ ^
154 /__down_/__the_/__garden_/...  pathify /__down_/__the_/__garden_/.../ ^ 
155 __path_.notdir pathify __path__notdir/ __path_.notdir/
156
157 # Both VMS/Unix and file/path conversions
158 __down_:[__the_.__garden_]__path_.dir;1        unixpath        /__down_/__the_/__garden_/__path_/ ^
159 /__down_/__the_/__garden_/__path_      vmspath __down_:[__the_.__garden_.__path_] ^
160 __down_:[__the_.__garden_.__path_]     unixpath        /__down_/__the_/__garden_/__path_/ ^
161 __down_:[__the_.__garden_.__path_...]  unixpath        /__down_/__the_/__garden_/__path_/.../ ^
162 /__down_/__the_/__garden_/__path_.dir  vmspath __down_:[__the_.__garden_.__path_] ^
163 [.__down_.__the_.__garden_]__path_.dir unixpath        __down_/__the_/__garden_/__path_/ ^
164 __down_/__the_/__garden_/__path_       vmspath [.__down_.__the_.__garden_.__path_] ^
165 __path_        vmspath [.__path_] ^
166 /       vmspath sys$disk:[000000] ^
167 /sys$scratch    vmspath sys$scratch: ^
168
169 # Redundant characters in Unix paths
170 //__some_/__where_//__over_/../__the_.__rainbow_       vmsify  __some_:[__where_.__over_.-]__the_.__rainbow_ ^
171 /__some_/__where_//__over_/./__the_.__rainbow_ vmsify  __some_:[__where_.__over_]__the_.__rainbow_ ^
172 ..//../ vmspath [--] ^
173 ./././  vmspath [] ^
174 ./../.  vmsify  [-] ^
175
176 # Our override of File::Spec->canonpath can do some strange things
177 __dev:[__dir.000000]__foo     File::Spec->canonpath   __dev:[__dir.000000]__foo ^
178 __dev:[__dir.][000000]__foo   File::Spec->canonpath   __dev:[__dir]__foo ^