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