expr: avoid memory leak due to shimmering
[jimtcl.git] / tests / file.test
blobfb5a555cca7cfb2e75e104bc8d92e1483a5b260c
1 source [file dirname [info script]]/testing.tcl
3 needs cmd file
5 test join-1.1 "One name" {
6         file join abc
7 } {abc}
9 test join-1.2 "One name with trailing slash" {
10         file join abc/
11 } {abc}
13 test join-1.3 "One name with leading slash" {
14         file join /abc
15 } {/abc}
17 test join-1.4 "One name with leading and trailing slash" {
18         file join /abc/
19 } {/abc}
21 test join-1.5 "Two names" {
22         file join abc def
23 } {abc/def}
25 test join-1.6 "Two names with dir trailing slash" {
26         file join abc/ def
27 } {abc/def}
29 test join-1.7 "Two names with dir leading slash" {
30         file join /abc def
31 } {/abc/def}
33 test join-1.8 "Two names with dir leading and trailing slash" {
34         file join /abc/ def
35 } {/abc/def}
37 test join-1.9 "Two names with file trailing slash" {
38         file join abc def/
39 } {abc/def}
41 test join-1.10 "Two names with file leading slash" {
42         file join abc /def
43 } {/def}
45 test join-1.11 "Two names with file leading and trailing slash" {
46         file join abc /def/
47 } {/def}
49 test join-1.12 "Two names with double slashes" {
50         file join abc/ /def
51 } {/def}
53 test join-1.13 "Join to root" {
54         file join / abc
55 } {/abc}
57 test join-1.14 "Join to root" {
58         set dir [file join / .]
59         # Either / or /. is OK here
60         expr {$dir in {/ /.}}
61 } 1
63 test join-1.15 "Join to root" {
64         file join / /
65 } {/}
67 test join-1.16 "Join to root" {
68         file join /abc /
69 } {/}
71 test join-1.17 "With trailing slash" {
72         file join /abc/def/ ghi/jkl
73 } {/abc/def/ghi/jkl}
75 test join-2.1 "Dir is empty string" {
76         file join "" def
77 } {def}
79 test join-2.2 "File is empty string" {
80         file join abc ""
81 } {abc}
83 test join-2.3 "Path too long" jim {
84         set components [string repeat {abcdefghi } 500]
85         list [catch [concat file join $components] msg] $msg
86 } {1 {Path too long}}
88 test tail-1.1 "One component" {
89         file tail abc
90 } {abc}
92 test tail-1.2 "Two components" {
93         file tail abc/def
94 } {def}
96 test tail-1.3 "Absolute one component" {
97         file tail /abc
98 } {abc}
100 test tail-1.4 "Trailing slash" {
101         file tail abc/
102 } {abc}
104 test dirname-1.1 "One component" {
105         file dirname abc
106 } {.}
108 test dirname-1.2 "Two components" {
109         file dirname abc/def
110 } {abc}
112 test dirname-1.3 "Absolute one component" {
113         file dirname /abc
114 } {/}
116 test dirname-1.4 "Trailing slash" {
117         file dirname abc/
118 } {.}
120 # These tests are courtesy of picol
122 test file.12.1 "picol test" {file dirname /foo/bar/grill.txt}  /foo/bar
123 test file.12.2 "picol test" {file dirname /foo/bar/baz/}       /foo/bar
124 test file.12.3 "picol test" {file dirname /foo/bar/baz///}     /foo/bar
125 test file.12.4 "picol test" {file dirname /foo/bar/baz///qux}  /foo/bar/baz
126 test file.12.5 "picol test" {file dirname foo/bar/grill.txt}   foo/bar
127 test file.12.6 "picol test" {file dirname foo/bar/baz/}        foo/bar
128 test file.12.7 "picol test" {file dirname {}}    .
129 test file.12.8 "picol test" {file dirname /}     /
130 test file.12.9 "picol test" {file dirname ///}   /
132 test file.13.1 "picol test" {file tail /foo/bar/grill.txt}   grill.txt
133 test file.13.2 "picol test" {file tail /foo/bar/baz/}        baz
134 test file.13.3 "picol test" {file tail /foo/bar/baz///}      baz
135 test file.13.4 "picol test" {file dirname /foo/bar/baz///qux}  /foo/bar/baz
136 test file.13.5 "picol test" {file tail foo/bar/grill.txt}    grill.txt
137 test file.13.6 "picol test" {file tail foo/bar/baz/}         baz
138 test file.13.7 "picol test" {file tail {}}    {}
139 test file.13.8 "picol test" {file tail /}     {}
140 test file.13.9 "picol test" {file tail ///}   {}
142 test file.14   "picol test" {file join foo}               foo
143 test file.15   "picol test" {file join foo bar}           foo/bar
144 test file.16   "picol test" {file join foo /bar}          /bar
146 if {$tcl_platform(platform) eq {windows}} {
147     test file.17  "picol test" {file join foo C:/bar grill}  C:/bar/grill
150 test file.18   "picol test" {file split {/foo/space station/bar}}  {/ foo {space station} bar}
151 test file.19   "picol test" {file split {/foo/space station/bar/}}  {/ foo {space station} bar}
152 test file.20   "picol test" {file split {foo/space station/bar}}  {foo {space station} bar}
153 test file.21   "picol test" {file split foo///bar}  {foo bar}
154 test file.22   "picol test" {file split foo}  foo
156 testreport