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
CommitLineData
acbb349e
PP
1#!./perl
2
3use VMS::Filespec;
0e9538e6 4use File::Spec;
acbb349e
PP
5
6foreach (<DATA>) {
7 chomp;
8 s/\s*#.*//;
9 next if /^\s*$/;
10 push(@tests,$_);
11}
cd5cd3a3 12
0d8e2021 13require 'test.pl';
cd5cd3a3 14plan(tests => scalar(2*@tests)+6);
acbb349e 15
1fe570cc
JM
16my $vms_unix_rpt;
17my $vms_efs;
18
19if ($^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
acbb349e 33foreach $test (@tests) {
1fe570cc
JM
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 }
cd5cd3a3 47
acbb349e 48 $rslt = eval "$func('$arg')";
9ba1b7d2 49 is($@, '', "eval ${func}('$arg')");
1fe570cc
JM
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 }
acbb349e
PP
56}
57
17f28c40
CB
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
9ba1b7d2 62# file specifications shown above are in fact equivalent.
17f28c40
CB
63EOW
64
b4558e59 65is(uc(rmsexpand('[]')), "\U$ENV{DEFAULT}", 'rmsexpand()') || print $defwarn;
51078f7b
CB
66is(lc(rmsexpand('from.here')),"\L$ENV{DEFAULT}from.here") || print $defwarn;
67is(lc(rmsexpand('from')), "\L$ENV{DEFAULT}from") || print $defwarn;
cd5cd3a3 68
51078f7b 69is(lc(rmsexpand('from.here','cant:[get.there];2')),
cd5cd3a3
MS
70 'cant:[get.there]from.here;2') || print $defwarn;
71
acbb349e 72
09b7f37c
CB
73# Make sure we're using redirected mkdir, which strips trailing '/', since
74# the CRTL's mkdir can't handle this.
cd5cd3a3
MS
75ok(mkdir('testdir/',0777), 'using redirected mkdir()');
76ok(rmdir('testdir/'), ' rmdir()');
09b7f37c 77
acbb349e
PP
78__DATA__
79
3a1de379
CB
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
0e9538e6
CB
89# lots of underscores used to minimize collision with existing logical names
90
acbb349e 91# Basic VMS to Unix filespecs
1fe570cc 92__some_:[__where_.__over_]__the_.__rainbow_ unixify /__some_/__where_/__over_/__the_.__rainbow_ ^
5ad5b34c 93__some_:<__where_.__over_>__the_.__rainbow_ unixify /__some_/__where_/__over_/__the_.__rainbow_ ^
1fe570cc
JM
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_ ^
d3a16da4
CB
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_/.../ ^
1fe570cc
JM
101[.__some_.__where_.__over_.-] unixify __some_/__where_/__over_/../ ^
102[] unixify ./ ^
103[-] unixify ../ ^
104[--] unixify ../../ ^
d3a16da4
CB
105[...] unixify .../ ^
106__lyrics_:[__are_.__very_^.__sappy_]__but_^.__rhymes_^.__are_.__true_ unixify /__lyrics_/__are_/__very_.__sappy_/__but_.__rhymes_.__are_.__true_ ^
1fe570cc 107[.$(macro)] unixify $(macro)/ ^
acbb349e
PP
108
109# and back again
1fe570cc
JM
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_ ^
4ab1eb56 113__some_/../../__where_/__over_/__the_.__rainbow_ vmsify [.__some_.--.__where_.__over_]__the_.__rainbow_ ^
7cae3803
CB
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_ ^
06099f79
CB
117__some_/__where_/... vmsify [.__some_.__where_...] ^
118/__where_/... vmsify __where_:[...] ^
1fe570cc
JM
119. vmsify [] ^
120.. vmsify [-] ^
121../.. vmsify [--] ^
7cae3803 122.../ vmsify [...] ^
9e1c5566 123/ vmsify sys$disk:[000000] ^
1fe570cc
JM
124./$(macro)/ vmsify [.$(macro)] ^
125./$(macro) vmsify []$(macro) ^
9e1c5566 126./$(m+ vmsify []$^(m^+ ^
b7bc7afb 127foo-bar-0^.01/ vmsify [.foo-bar-0_01] [.foo-bar-0^.01]
acbb349e 128# Fileifying directory specs
1fe570cc
JM
129__down_:[__the_.__garden_.__path_] fileify __down_:[__the_.__garden_]__path_.dir;1 ^
130[.__down_.__the_.__garden_.__path_] fileify [.__down_.__the_.__garden_]__path_.dir;1 ^
839e16da
CB
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 ^
1fe570cc
JM
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
839e16da
CB
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
acbb349e
PP
139
140# and pathifying them
1fe570cc
JM
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_] ^
9e1c5566 146__down_:[__the_.__garden_]__path_. pathify ^ __down_:[__the_.__garden_.__path_^.] # N.B. trailing . ==> null type
1fe570cc
JM
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/
acbb349e
PP
156
157# Both VMS/Unix and file/path conversions
1fe570cc
JM
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_/ ^
7cae3803 161__down_:[__the_.__garden_.__path_...] unixpath /__down_/__the_/__garden_/__path_/.../ ^
1fe570cc
JM
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_] ^
9e1c5566 166/ vmspath sys$disk:[000000] ^
50255d58 167/sys$scratch vmspath sys$scratch: ^
acbb349e
PP
168
169# Redundant characters in Unix paths
4ab1eb56 170//__some_/__where_//__over_/../__the_.__rainbow_ vmsify __some_:[__where_.__over_.-]__the_.__rainbow_ ^
1fe570cc
JM
171/__some_/__where_//__over_/./__the_.__rainbow_ vmsify __some_:[__where_.__over_]__the_.__rainbow_ ^
172..//../ vmspath [--] ^
173./././ vmspath [] ^
174./../. vmsify [-] ^
0e9538e6
CB
175
176# Our override of File::Spec->canonpath can do some strange things
1fe570cc
JM
177__dev:[__dir.000000]__foo File::Spec->canonpath __dev:[__dir.000000]__foo ^
178__dev:[__dir.][000000]__foo File::Spec->canonpath __dev:[__dir]__foo ^