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