Cleanup & fix of unsafe filename
[p5sagit/p5-mst-13.2.git] / vms / ext / filespec.t
1 #!./perl
2
3 BEGIN { unshift(@INC,'../lib') if -d '../lib'; }
4
5 use VMS::Filespec;
6
7 foreach (<DATA>) {
8   chomp;
9   s/\s*#.*//;
10   next if /^\s*$/;
11   push(@tests,$_);
12 }
13
14 require './test.pl';
15 plan(tests => scalar(2*@tests)+6);
16
17 foreach $test (@tests) {
18   ($arg,$func,$expect) = split(/\s+/,$test);
19
20   $rslt = eval "$func('$arg')";
21   is($@, '', "eval func('$arg')");
22   is($rslt, $expect, "  result");
23 }
24
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.
30 EOW
31
32 is(rmsexpand('[]'),       "\U$ENV{DEFAULT}", 'rmsexpand()') || print $defwarn;
33 is(rmsexpand('from.here'),"\L$ENV{DEFAULT}from.here") || print $defwarn;
34 is(rmsexpand('from'),     "\L$ENV{DEFAULT}from")      || print $defwarn;
35
36 is(rmsexpand('from.here','cant:[get.there];2'),
37    'cant:[get.there]from.here;2')                     || print $defwarn;
38
39
40 # Make sure we're using redirected mkdir, which strips trailing '/', since
41 # the CRTL's mkdir can't handle this.
42 ok(mkdir('testdir/',0777),      'using redirected mkdir()');
43 ok(rmdir('testdir/'),           '    rmdir()');
44
45 __DATA__
46
47 # Basic VMS to Unix filespecs
48 some_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/../
57 []      unixify         ./
58 [-]     unixify         ../
59 [--]    unixify         ../../
60 [...]   unixify         .../
61
62 # and back again
63 /some_logical_name_not_likely/where/over/the.rainbow    vmsify  some_logical_name_not_likely:[where.over]the.rainbow
64 some_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
66 some_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
68 some_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
70 some_logical_name_not_likely/where/...  vmsify  [.some_logical_name_not_likely.where...]
71 /where/...      vmsify  where:[...]
72 .       vmsify  []
73 ..      vmsify  [-]
74 ../..   vmsify  [--]
75 .../    vmsify  [...]
76 /       vmsify  sys$disk:[000000]
77
78 # Fileifying directory specs
79 down_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
83 down_logical_name_not_likely/the/garden/path    fileify down_logical_name_not_likely/the/garden/path.dir;1
84 down_logical_name_not_likely:[the.garden]path   fileify down_logical_name_not_likely:[the.garden]path.dir;1
85 down_logical_name_not_likely:[the.garden]path.  fileify # N.B. trailing . ==> null type
86 down_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 
89
90 # and pathifying them
91 down_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/
94 down_logical_name_not_likely/the/garden/path.dir        pathify down_logical_name_not_likely/the/garden/path/
95 down_logical_name_not_likely:[the.garden]path   pathify down_logical_name_not_likely:[the.garden.path]
96 down_logical_name_not_likely:[the.garden]path.  pathify # N.B. trailing . ==> null type
97 down_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 
100 down_logical_name_not_likely:[the.garden]path.dir;2     pathify #N.B. ;2
101 __path  pathify __path/
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/.../
105 path.notdir     pathify 
106
107 # Both VMS/Unix and file/path conversions
108 down_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]
110 down_logical_name_not_likely:[the.garden.path]  unixpath        /down_logical_name_not_likely/the/garden/path/
111 down_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/
114 down_logical_name_not_likely/the/garden/path    vmspath [.down_logical_name_not_likely.the.garden.path]
115 __path  vmspath [.__path]
116 /       vmspath sys$disk:[000000]
117
118 # Redundant characters in Unix paths
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
121 ..//../ vmspath [--]
122 ./././  vmspath []
123 ./../.  vmsify  [-]