1 | # The file tests the tclCmdAH.c file. |
---|
2 | # |
---|
3 | # This file contains a collection of tests for one or more of the Tcl |
---|
4 | # built-in commands. Sourcing this file into Tcl runs the tests and |
---|
5 | # generates output for errors. No output means no errors were found. |
---|
6 | # |
---|
7 | # Copyright (c) 1996-1998 by Sun Microsystems, Inc. |
---|
8 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
9 | # |
---|
10 | # See the file "license.terms" for information on usage and redistribution |
---|
11 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
12 | # |
---|
13 | # RCS: @(#) $Id: cmdAH.test,v 1.57 2007/12/13 15:26:06 dgp Exp $ |
---|
14 | |
---|
15 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
16 | package require tcltest 2.1 |
---|
17 | namespace import -force ::tcltest::* |
---|
18 | } |
---|
19 | |
---|
20 | testConstraint testchmod [llength [info commands testchmod]] |
---|
21 | testConstraint testsetplatform [llength [info commands testsetplatform]] |
---|
22 | testConstraint testvolumetype [llength [info commands testvolumetype]] |
---|
23 | testConstraint linkDirectory [expr { |
---|
24 | ![testConstraint win] || |
---|
25 | ([string index $tcl_platform(osVersion) 0] >= 5 |
---|
26 | && [lindex [file system [temporaryDirectory]] 1] eq "NTFS") |
---|
27 | }] |
---|
28 | |
---|
29 | global env |
---|
30 | set cmdAHwd [pwd] |
---|
31 | catch {set platform [testgetplatform]} |
---|
32 | |
---|
33 | test cmdAH-0.1 {Tcl_BreakObjCmd, errors} { |
---|
34 | list [catch {break foo} msg] $msg |
---|
35 | } {1 {wrong # args: should be "break"}} |
---|
36 | test cmdAH-0.2 {Tcl_BreakObjCmd, success} { |
---|
37 | list [catch {break} msg] $msg |
---|
38 | } {3 {}} |
---|
39 | |
---|
40 | # Tcl_CaseObjCmd is tested in case.test |
---|
41 | |
---|
42 | test cmdAH-1.1 {Tcl_CatchObjCmd, errors} { |
---|
43 | list [catch {catch} msg] $msg |
---|
44 | } {1 {wrong # args: should be "catch script ?resultVarName? ?optionVarName?"}} |
---|
45 | test cmdAH-1.2 {Tcl_CatchObjCmd, errors} { |
---|
46 | list [catch {catch foo bar baz} msg] $msg |
---|
47 | } {0 1} |
---|
48 | test cmdAH-1.3 {Tcl_CatchObjCmd, errors} { |
---|
49 | list [catch {catch foo bar baz spaz} msg] $msg |
---|
50 | } {1 {wrong # args: should be "catch script ?resultVarName? ?optionVarName?"}} |
---|
51 | |
---|
52 | test cmdAH-2.1 {Tcl_CdObjCmd} { |
---|
53 | list [catch {cd foo bar} msg] $msg |
---|
54 | } {1 {wrong # args: should be "cd ?dirName?"}} |
---|
55 | set foodir [file join [temporaryDirectory] foo] |
---|
56 | test cmdAH-2.2 {Tcl_CdObjCmd} { |
---|
57 | file delete -force $foodir |
---|
58 | file mkdir $foodir |
---|
59 | cd $foodir |
---|
60 | set result [file tail [pwd]] |
---|
61 | cd .. |
---|
62 | file delete $foodir |
---|
63 | set result |
---|
64 | } foo |
---|
65 | test cmdAH-2.3 {Tcl_CdObjCmd} { |
---|
66 | global env |
---|
67 | set oldpwd [pwd] |
---|
68 | set temp $env(HOME) |
---|
69 | set env(HOME) $oldpwd |
---|
70 | file delete -force $foodir |
---|
71 | file mkdir $foodir |
---|
72 | cd $foodir |
---|
73 | cd ~ |
---|
74 | set result [string equal [pwd] $oldpwd] |
---|
75 | file delete $foodir |
---|
76 | set env(HOME) $temp |
---|
77 | set result |
---|
78 | } 1 |
---|
79 | test cmdAH-2.4 {Tcl_CdObjCmd} { |
---|
80 | global env |
---|
81 | set oldpwd [pwd] |
---|
82 | set temp $env(HOME) |
---|
83 | set env(HOME) $oldpwd |
---|
84 | file delete -force $foodir |
---|
85 | file mkdir $foodir |
---|
86 | cd $foodir |
---|
87 | cd |
---|
88 | set result [string equal [pwd] $oldpwd] |
---|
89 | file delete $foodir |
---|
90 | set env(HOME) $temp |
---|
91 | set result |
---|
92 | } 1 |
---|
93 | test cmdAH-2.5 {Tcl_CdObjCmd} { |
---|
94 | list [catch {cd ~~} msg] $msg |
---|
95 | } {1 {user "~" doesn't exist}} |
---|
96 | test cmdAH-2.6 {Tcl_CdObjCmd} { |
---|
97 | list [catch {cd _foobar} msg] $msg |
---|
98 | } {1 {couldn't change working directory to "_foobar": no such file or directory}} |
---|
99 | test cmdAH-2.6.1 {Tcl_CdObjCmd} { |
---|
100 | list [catch {cd ""} msg] $msg |
---|
101 | } {1 {couldn't change working directory to "": no such file or directory}} |
---|
102 | |
---|
103 | test cmdAH-2.7 {Tcl_ConcatObjCmd} { |
---|
104 | concat |
---|
105 | } {} |
---|
106 | test cmdAH-2.8 {Tcl_ConcatObjCmd} { |
---|
107 | concat a |
---|
108 | } a |
---|
109 | test cmdAH-2.9 {Tcl_ConcatObjCmd} { |
---|
110 | concat a {b c} |
---|
111 | } {a b c} |
---|
112 | |
---|
113 | test cmdAH-3.1 {Tcl_ContinueObjCmd, errors} { |
---|
114 | list [catch {continue foo} msg] $msg |
---|
115 | } {1 {wrong # args: should be "continue"}} |
---|
116 | test cmdAH-3.2 {Tcl_ContinueObjCmd, success} { |
---|
117 | list [catch {continue} msg] $msg |
---|
118 | } {4 {}} |
---|
119 | |
---|
120 | test cmdAH-4.1 {Tcl_EncodingObjCmd} { |
---|
121 | list [catch {encoding} msg] $msg |
---|
122 | } {1 {wrong # args: should be "encoding option ?arg ...?"}} |
---|
123 | test cmdAH-4.2 {Tcl_EncodingObjCmd} { |
---|
124 | list [catch {encoding foo} msg] $msg |
---|
125 | } {1 {bad option "foo": must be convertfrom, convertto, dirs, names, or system}} |
---|
126 | test cmdAH-4.3 {Tcl_EncodingObjCmd} { |
---|
127 | list [catch {encoding convertto} msg] $msg |
---|
128 | } {1 {wrong # args: should be "encoding convertto ?encoding? data"}} |
---|
129 | test cmdAH-4.4 {Tcl_EncodingObjCmd} { |
---|
130 | list [catch {encoding convertto foo bar} msg] $msg |
---|
131 | } {1 {unknown encoding "foo"}} |
---|
132 | test cmdAH-4.5 {Tcl_EncodingObjCmd} { |
---|
133 | set system [encoding system] |
---|
134 | encoding system jis0208 |
---|
135 | set x [encoding convertto \u4e4e] |
---|
136 | encoding system $system |
---|
137 | set x |
---|
138 | } 8C |
---|
139 | test cmdAH-4.6 {Tcl_EncodingObjCmd} { |
---|
140 | set system [encoding system] |
---|
141 | encoding system identity |
---|
142 | set x [encoding convertto jis0208 \u4e4e] |
---|
143 | encoding system $system |
---|
144 | set x |
---|
145 | } 8C |
---|
146 | test cmdAH-4.7 {Tcl_EncodingObjCmd} { |
---|
147 | list [catch {encoding convertfrom} msg] $msg |
---|
148 | } {1 {wrong # args: should be "encoding convertfrom ?encoding? data"}} |
---|
149 | test cmdAH-4.8 {Tcl_EncodingObjCmd} { |
---|
150 | list [catch {encoding convertfrom foo bar} msg] $msg |
---|
151 | } {1 {unknown encoding "foo"}} |
---|
152 | test cmdAH-4.9 {Tcl_EncodingObjCmd} { |
---|
153 | set system [encoding system] |
---|
154 | encoding system jis0208 |
---|
155 | set x [encoding convertfrom 8C] |
---|
156 | encoding system $system |
---|
157 | set x |
---|
158 | } \u4e4e |
---|
159 | test cmdAH-4.10 {Tcl_EncodingObjCmd} { |
---|
160 | set system [encoding system] |
---|
161 | encoding system identity |
---|
162 | set x [encoding convertfrom jis0208 8C] |
---|
163 | encoding system $system |
---|
164 | set x |
---|
165 | } \u4e4e |
---|
166 | test cmdAH-4.11 {Tcl_EncodingObjCmd} { |
---|
167 | list [catch {encoding names foo} msg] $msg |
---|
168 | } {1 {wrong # args: should be "encoding names"}} |
---|
169 | test cmdAH-4.12 {Tcl_EncodingObjCmd} { |
---|
170 | list [catch {encoding system foo bar} msg] $msg |
---|
171 | } {1 {wrong # args: should be "encoding system ?encoding?"}} |
---|
172 | test cmdAH-4.13 {Tcl_EncodingObjCmd} { |
---|
173 | set system [encoding system] |
---|
174 | encoding system identity |
---|
175 | set x [encoding system] |
---|
176 | encoding system $system |
---|
177 | set x |
---|
178 | } identity |
---|
179 | |
---|
180 | test cmdAH-5.1 {Tcl_FileObjCmd} { |
---|
181 | list [catch file msg] $msg |
---|
182 | } {1 {wrong # args: should be "file option ?arg ...?"}} |
---|
183 | test cmdAH-5.2 {Tcl_FileObjCmd} { |
---|
184 | list [catch {file x} msg] $msg |
---|
185 | } {1 {bad option "x": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
186 | test cmdAH-5.3 {Tcl_FileObjCmd} { |
---|
187 | list [catch {file exists} msg] $msg |
---|
188 | } {1 {wrong # args: should be "file exists name"}} |
---|
189 | test cmdAH-5.4 {Tcl_FileObjCmd} { |
---|
190 | list [catch {file exists ""} msg] $msg |
---|
191 | } {0 0} |
---|
192 | |
---|
193 | #volume |
---|
194 | |
---|
195 | test cmdAH-6.1 {Tcl_FileObjCmd: volumes} { |
---|
196 | list [catch {file volumes x} msg] $msg |
---|
197 | } {1 {wrong # args: should be "file volumes"}} |
---|
198 | test cmdAH-6.2 {Tcl_FileObjCmd: volumes} { |
---|
199 | set volumeList [file volumes] |
---|
200 | if { [llength $volumeList] == 0 } { |
---|
201 | set result 0 |
---|
202 | } else { |
---|
203 | set result 1 |
---|
204 | } |
---|
205 | } {1} |
---|
206 | test cmdAH-6.3 {Tcl_FileObjCmd: volumes} {unix} { |
---|
207 | set volumeList [file volumes] |
---|
208 | catch [list glob -nocomplain [lindex $volumeList 0]*] |
---|
209 | } {0} |
---|
210 | test cmdAH-6.4 {Tcl_FileObjCmd: volumes} win { |
---|
211 | set volumeList [string tolower [file volumes]] |
---|
212 | list [catch {lsearch $volumeList "c:/"} element] [expr $element != -1] [catch {list glob -nocomplain [lindex $volumeList $element]*}] |
---|
213 | } {0 1 0} |
---|
214 | |
---|
215 | test cmdAH-6.5 {cd} {unix nonPortable} { |
---|
216 | set dir [pwd] |
---|
217 | cd / |
---|
218 | set res [pwd] |
---|
219 | cd $dir |
---|
220 | set res |
---|
221 | } {/} |
---|
222 | |
---|
223 | # attributes |
---|
224 | |
---|
225 | test cmdAH-7.1 {Tcl_FileObjCmd - file attrs} { |
---|
226 | set foofile [makeFile abcde foo.file] |
---|
227 | catch {file delete -force $foofile} |
---|
228 | close [open $foofile w] |
---|
229 | set res [catch {file attributes $foofile}] |
---|
230 | # We used [makeFile] so we undo with [removeFile] |
---|
231 | removeFile $foofile |
---|
232 | set res |
---|
233 | } {0} |
---|
234 | |
---|
235 | # dirname |
---|
236 | |
---|
237 | test cmdAH-8.1 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
238 | testsetplatform unix |
---|
239 | list [catch {file dirname a b} msg] $msg |
---|
240 | } {1 {wrong # args: should be "file dirname name"}} |
---|
241 | test cmdAH-8.2 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
242 | testsetplatform unix |
---|
243 | file dirname /a/b |
---|
244 | } /a |
---|
245 | test cmdAH-8.3 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
246 | testsetplatform unix |
---|
247 | file dirname {} |
---|
248 | } . |
---|
249 | test cmdAH-8.5 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
250 | testsetplatform win |
---|
251 | file dirname {} |
---|
252 | } . |
---|
253 | test cmdAH-8.6 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
254 | testsetplatform unix |
---|
255 | file dirname .def |
---|
256 | } . |
---|
257 | test cmdAH-8.8 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
258 | testsetplatform win |
---|
259 | file dirname a |
---|
260 | } . |
---|
261 | test cmdAH-8.9 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
262 | testsetplatform unix |
---|
263 | file dirname a/b/c.d |
---|
264 | } a/b |
---|
265 | test cmdAH-8.10 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
266 | testsetplatform unix |
---|
267 | file dirname a/b.c/d |
---|
268 | } a/b.c |
---|
269 | test cmdAH-8.11 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
270 | testsetplatform unix |
---|
271 | file dirname /. |
---|
272 | } / |
---|
273 | test cmdAH-8.12 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
274 | testsetplatform unix |
---|
275 | list [catch {file dirname /} msg] $msg |
---|
276 | } {0 /} |
---|
277 | test cmdAH-8.13 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
278 | testsetplatform unix |
---|
279 | list [catch {file dirname /foo} msg] $msg |
---|
280 | } {0 /} |
---|
281 | test cmdAH-8.14 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
282 | testsetplatform unix |
---|
283 | list [catch {file dirname //foo} msg] $msg |
---|
284 | } {0 /} |
---|
285 | test cmdAH-8.15 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
286 | testsetplatform unix |
---|
287 | list [catch {file dirname //foo/bar} msg] $msg |
---|
288 | } {0 /foo} |
---|
289 | test cmdAH-8.16 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
290 | testsetplatform unix |
---|
291 | list [catch {file dirname {//foo\/bar/baz}} msg] $msg |
---|
292 | } {0 {/foo\/bar}} |
---|
293 | test cmdAH-8.17 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
294 | testsetplatform unix |
---|
295 | list [catch {file dirname {//foo\/bar/baz/blat}} msg] $msg |
---|
296 | } {0 {/foo\/bar/baz}} |
---|
297 | test cmdAH-8.18 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
298 | testsetplatform unix |
---|
299 | list [catch {file dirname /foo//} msg] $msg |
---|
300 | } {0 /} |
---|
301 | test cmdAH-8.19 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
302 | testsetplatform unix |
---|
303 | list [catch {file dirname ./a} msg] $msg |
---|
304 | } {0 .} |
---|
305 | test cmdAH-8.20 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
306 | testsetplatform unix |
---|
307 | list [catch {file dirname a/.a} msg] $msg |
---|
308 | } {0 a} |
---|
309 | test cmdAH-8.21 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
310 | testsetplatform windows |
---|
311 | list [catch {file dirname c:foo} msg] $msg |
---|
312 | } {0 c:} |
---|
313 | test cmdAH-8.22 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
314 | testsetplatform windows |
---|
315 | list [catch {file dirname c:} msg] $msg |
---|
316 | } {0 c:} |
---|
317 | test cmdAH-8.23 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
318 | testsetplatform windows |
---|
319 | list [catch {file dirname c:/} msg] $msg |
---|
320 | } {0 c:/} |
---|
321 | test cmdAH-8.24 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
322 | testsetplatform windows |
---|
323 | list [catch {file dirname {c:\foo}} msg] $msg |
---|
324 | } {0 c:/} |
---|
325 | test cmdAH-8.25 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
326 | testsetplatform windows |
---|
327 | list [catch {file dirname {//foo/bar/baz}} msg] $msg |
---|
328 | } {0 //foo/bar} |
---|
329 | test cmdAH-8.26 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
330 | testsetplatform windows |
---|
331 | list [catch {file dirname {//foo/bar}} msg] $msg |
---|
332 | } {0 //foo/bar} |
---|
333 | test cmdAH-8.38 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
334 | testsetplatform unix |
---|
335 | list [catch {file dirname ~/foo} msg] $msg |
---|
336 | } {0 ~} |
---|
337 | test cmdAH-8.39 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
338 | testsetplatform unix |
---|
339 | list [catch {file dirname ~bar/foo} msg] $msg |
---|
340 | } {0 ~bar} |
---|
341 | test cmdAH-8.43 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
342 | global env |
---|
343 | set temp $env(HOME) |
---|
344 | set env(HOME) "/homewontexist/test" |
---|
345 | testsetplatform unix |
---|
346 | set result [list [catch {file dirname ~} msg] $msg] |
---|
347 | set env(HOME) $temp |
---|
348 | set result |
---|
349 | } {0 /homewontexist} |
---|
350 | test cmdAH-8.44 {Tcl_FileObjCmd: dirname} testsetplatform { |
---|
351 | global env |
---|
352 | set temp $env(HOME) |
---|
353 | set env(HOME) "~" |
---|
354 | testsetplatform unix |
---|
355 | set result [list [catch {file dirname ~} msg] $msg] |
---|
356 | set env(HOME) $temp |
---|
357 | set result |
---|
358 | } {0 ~} |
---|
359 | test cmdAH-8.45 {Tcl_FileObjCmd: dirname} { |
---|
360 | -constraints {win testsetplatform} |
---|
361 | -match regexp |
---|
362 | -setup { |
---|
363 | set temp $::env(HOME) |
---|
364 | } |
---|
365 | -body { |
---|
366 | set ::env(HOME) "/homewontexist/test" |
---|
367 | testsetplatform windows |
---|
368 | file dirname ~ |
---|
369 | } |
---|
370 | -cleanup { |
---|
371 | set ::env(HOME) $temp |
---|
372 | } |
---|
373 | -result {([a-zA-Z]:?)/homewontexist} |
---|
374 | } |
---|
375 | test cmdAH-8.46 {Tcl_FileObjCmd: dirname} { |
---|
376 | set f [file normalize [info nameof]] |
---|
377 | file exists $f |
---|
378 | set res1 [file dirname [file join $f foo/bar]] |
---|
379 | set res2 [file dirname "${f}/foo/bar"] |
---|
380 | if {$res1 eq $res2} { |
---|
381 | set res "ok" |
---|
382 | } else { |
---|
383 | set res "file dirname problem, $res1, $res2 not equal" |
---|
384 | } |
---|
385 | set res |
---|
386 | } {ok} |
---|
387 | |
---|
388 | # tail |
---|
389 | |
---|
390 | test cmdAH-9.1 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
391 | testsetplatform unix |
---|
392 | list [catch {file tail a b} msg] $msg |
---|
393 | } {1 {wrong # args: should be "file tail name"}} |
---|
394 | test cmdAH-9.2 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
395 | testsetplatform unix |
---|
396 | file tail /a/b |
---|
397 | } b |
---|
398 | test cmdAH-9.3 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
399 | testsetplatform unix |
---|
400 | file tail {} |
---|
401 | } {} |
---|
402 | test cmdAH-9.5 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
403 | testsetplatform win |
---|
404 | file tail {} |
---|
405 | } {} |
---|
406 | test cmdAH-9.6 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
407 | testsetplatform unix |
---|
408 | file tail .def |
---|
409 | } .def |
---|
410 | test cmdAH-9.8 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
411 | testsetplatform win |
---|
412 | file tail a |
---|
413 | } a |
---|
414 | test cmdAH-9.9 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
415 | testsetplatform unix |
---|
416 | file ta a/b/c.d |
---|
417 | } c.d |
---|
418 | test cmdAH-9.10 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
419 | testsetplatform unix |
---|
420 | file tail a/b.c/d |
---|
421 | } d |
---|
422 | test cmdAH-9.11 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
423 | testsetplatform unix |
---|
424 | file tail /. |
---|
425 | } . |
---|
426 | test cmdAH-9.12 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
427 | testsetplatform unix |
---|
428 | file tail / |
---|
429 | } {} |
---|
430 | test cmdAH-9.13 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
431 | testsetplatform unix |
---|
432 | file tail /foo |
---|
433 | } foo |
---|
434 | test cmdAH-9.14 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
435 | testsetplatform unix |
---|
436 | file tail //foo |
---|
437 | } foo |
---|
438 | test cmdAH-9.15 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
439 | testsetplatform unix |
---|
440 | file tail //foo/bar |
---|
441 | } bar |
---|
442 | test cmdAH-9.16 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
443 | testsetplatform unix |
---|
444 | file tail {//foo\/bar/baz} |
---|
445 | } baz |
---|
446 | test cmdAH-9.17 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
447 | testsetplatform unix |
---|
448 | file tail {//foo\/bar/baz/blat} |
---|
449 | } blat |
---|
450 | test cmdAH-9.18 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
451 | testsetplatform unix |
---|
452 | file tail /foo// |
---|
453 | } foo |
---|
454 | test cmdAH-9.19 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
455 | testsetplatform unix |
---|
456 | file tail ./a |
---|
457 | } a |
---|
458 | test cmdAH-9.20 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
459 | testsetplatform unix |
---|
460 | file tail a/.a |
---|
461 | } .a |
---|
462 | test cmdAH-9.21 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
463 | testsetplatform windows |
---|
464 | file tail c:foo |
---|
465 | } foo |
---|
466 | test cmdAH-9.22 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
467 | testsetplatform windows |
---|
468 | file tail c: |
---|
469 | } {} |
---|
470 | test cmdAH-9.23 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
471 | testsetplatform windows |
---|
472 | file tail c:/ |
---|
473 | } {} |
---|
474 | test cmdAH-9.24 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
475 | testsetplatform windows |
---|
476 | file tail {c:\foo} |
---|
477 | } foo |
---|
478 | test cmdAH-9.25 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
479 | testsetplatform windows |
---|
480 | file tail {//foo/bar/baz} |
---|
481 | } baz |
---|
482 | test cmdAH-9.26 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
483 | testsetplatform windows |
---|
484 | file tail {//foo/bar} |
---|
485 | } {} |
---|
486 | test cmdAH-9.42 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
487 | global env |
---|
488 | set temp $env(HOME) |
---|
489 | set env(HOME) "/home/test" |
---|
490 | testsetplatform unix |
---|
491 | set result [file tail ~] |
---|
492 | set env(HOME) $temp |
---|
493 | set result |
---|
494 | } test |
---|
495 | test cmdAH-9.43 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
496 | global env |
---|
497 | set temp $env(HOME) |
---|
498 | set env(HOME) "~" |
---|
499 | testsetplatform unix |
---|
500 | set result [file tail ~] |
---|
501 | set env(HOME) $temp |
---|
502 | set result |
---|
503 | } {} |
---|
504 | test cmdAH-9.44 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
505 | global env |
---|
506 | set temp $env(HOME) |
---|
507 | set env(HOME) "/home/test" |
---|
508 | testsetplatform windows |
---|
509 | set result [file tail ~] |
---|
510 | set env(HOME) $temp |
---|
511 | set result |
---|
512 | } test |
---|
513 | test cmdAH-9.46 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
514 | testsetplatform unix |
---|
515 | file tail {f.oo\bar/baz.bat} |
---|
516 | } baz.bat |
---|
517 | test cmdAH-9.47 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
518 | testsetplatform windows |
---|
519 | file tail c:foo |
---|
520 | } foo |
---|
521 | test cmdAH-9.48 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
522 | testsetplatform windows |
---|
523 | file tail c: |
---|
524 | } {} |
---|
525 | test cmdAH-9.49 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
526 | testsetplatform windows |
---|
527 | file tail c:/foo |
---|
528 | } foo |
---|
529 | test cmdAH-9.50 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
530 | testsetplatform windows |
---|
531 | file tail {c:/foo\bar} |
---|
532 | } bar |
---|
533 | test cmdAH-9.51 {Tcl_FileObjCmd: tail} testsetplatform { |
---|
534 | testsetplatform windows |
---|
535 | file tail {foo\bar} |
---|
536 | } bar |
---|
537 | |
---|
538 | # rootname |
---|
539 | |
---|
540 | test cmdAH-10.1 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
541 | testsetplatform unix |
---|
542 | list [catch {file rootname a b} msg] $msg |
---|
543 | } {1 {wrong # args: should be "file rootname name"}} |
---|
544 | test cmdAH-10.2 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
545 | testsetplatform unix |
---|
546 | file rootname {} |
---|
547 | } {} |
---|
548 | test cmdAH-10.3 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
549 | testsetplatform unix |
---|
550 | file ro foo |
---|
551 | } foo |
---|
552 | test cmdAH-10.4 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
553 | testsetplatform unix |
---|
554 | file rootname foo. |
---|
555 | } foo |
---|
556 | test cmdAH-10.5 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
557 | testsetplatform unix |
---|
558 | file rootname .foo |
---|
559 | } {} |
---|
560 | test cmdAH-10.6 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
561 | testsetplatform unix |
---|
562 | file rootname abc.def |
---|
563 | } abc |
---|
564 | test cmdAH-10.7 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
565 | testsetplatform unix |
---|
566 | file rootname abc.def.ghi |
---|
567 | } abc.def |
---|
568 | test cmdAH-10.8 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
569 | testsetplatform unix |
---|
570 | file rootname a/b/c.d |
---|
571 | } a/b/c |
---|
572 | test cmdAH-10.9 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
573 | testsetplatform unix |
---|
574 | file rootname a/b.c/d |
---|
575 | } a/b.c/d |
---|
576 | test cmdAH-10.10 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
577 | testsetplatform unix |
---|
578 | file rootname a/b.c/ |
---|
579 | } a/b.c/ |
---|
580 | test cmdAH-10.23 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
581 | testsetplatform windows |
---|
582 | file rootname {} |
---|
583 | } {} |
---|
584 | test cmdAH-10.24 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
585 | testsetplatform windows |
---|
586 | file ro foo |
---|
587 | } foo |
---|
588 | test cmdAH-10.25 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
589 | testsetplatform windows |
---|
590 | file rootname foo. |
---|
591 | } foo |
---|
592 | test cmdAH-10.26 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
593 | testsetplatform windows |
---|
594 | file rootname .foo |
---|
595 | } {} |
---|
596 | test cmdAH-10.27 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
597 | testsetplatform windows |
---|
598 | file rootname abc.def |
---|
599 | } abc |
---|
600 | test cmdAH-10.28 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
601 | testsetplatform windows |
---|
602 | file rootname abc.def.ghi |
---|
603 | } abc.def |
---|
604 | test cmdAH-10.29 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
605 | testsetplatform windows |
---|
606 | file rootname a/b/c.d |
---|
607 | } a/b/c |
---|
608 | test cmdAH-10.30 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
609 | testsetplatform windows |
---|
610 | file rootname a/b.c/d |
---|
611 | } a/b.c/d |
---|
612 | test cmdAH-10.31 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
613 | testsetplatform windows |
---|
614 | file rootname a\\b.c\\ |
---|
615 | } a\\b.c\\ |
---|
616 | test cmdAH-10.32 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
617 | testsetplatform windows |
---|
618 | file rootname a\\b\\c.d |
---|
619 | } a\\b\\c |
---|
620 | test cmdAH-10.33 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
621 | testsetplatform windows |
---|
622 | file rootname a\\b.c\\d |
---|
623 | } a\\b.c\\d |
---|
624 | test cmdAH-10.34 {Tcl_FileObjCmd: rootname} testsetplatform { |
---|
625 | testsetplatform windows |
---|
626 | file rootname a\\b.c\\ |
---|
627 | } a\\b.c\\ |
---|
628 | set num 35 |
---|
629 | foreach outer { {} a .a a. a.a } { |
---|
630 | foreach inner { {} a .a a. a.a } { |
---|
631 | set thing [format %s/%s $outer $inner] |
---|
632 | ;test cmdAH-10.$num {Tcl_FileObjCmd: rootname and extension options} testsetplatform " |
---|
633 | testsetplatform unix |
---|
634 | [list format %s%s [file rootname $thing] [file ext $thing]] |
---|
635 | " $thing |
---|
636 | incr num |
---|
637 | } |
---|
638 | } |
---|
639 | |
---|
640 | # extension |
---|
641 | |
---|
642 | test cmdAH-11.1 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
643 | testsetplatform unix |
---|
644 | list [catch {file extension a b} msg] $msg |
---|
645 | } {1 {wrong # args: should be "file extension name"}} |
---|
646 | test cmdAH-11.2 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
647 | testsetplatform unix |
---|
648 | file extension {} |
---|
649 | } {} |
---|
650 | test cmdAH-11.3 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
651 | testsetplatform unix |
---|
652 | file ext foo |
---|
653 | } {} |
---|
654 | test cmdAH-11.4 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
655 | testsetplatform unix |
---|
656 | file extension foo. |
---|
657 | } . |
---|
658 | test cmdAH-11.5 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
659 | testsetplatform unix |
---|
660 | file extension .foo |
---|
661 | } .foo |
---|
662 | test cmdAH-11.6 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
663 | testsetplatform unix |
---|
664 | file extension abc.def |
---|
665 | } .def |
---|
666 | test cmdAH-11.7 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
667 | testsetplatform unix |
---|
668 | file extension abc.def.ghi |
---|
669 | } .ghi |
---|
670 | test cmdAH-11.8 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
671 | testsetplatform unix |
---|
672 | file extension a/b/c.d |
---|
673 | } .d |
---|
674 | test cmdAH-11.9 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
675 | testsetplatform unix |
---|
676 | file extension a/b.c/d |
---|
677 | } {} |
---|
678 | test cmdAH-11.10 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
679 | testsetplatform unix |
---|
680 | file extension a/b.c/ |
---|
681 | } {} |
---|
682 | test cmdAH-11.23 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
683 | testsetplatform windows |
---|
684 | file extension {} |
---|
685 | } {} |
---|
686 | test cmdAH-11.24 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
687 | testsetplatform windows |
---|
688 | file ext foo |
---|
689 | } {} |
---|
690 | test cmdAH-11.25 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
691 | testsetplatform windows |
---|
692 | file extension foo. |
---|
693 | } . |
---|
694 | test cmdAH-11.26 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
695 | testsetplatform windows |
---|
696 | file extension .foo |
---|
697 | } .foo |
---|
698 | test cmdAH-11.27 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
699 | testsetplatform windows |
---|
700 | file extension abc.def |
---|
701 | } .def |
---|
702 | test cmdAH-11.28 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
703 | testsetplatform windows |
---|
704 | file extension abc.def.ghi |
---|
705 | } .ghi |
---|
706 | test cmdAH-11.29 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
707 | testsetplatform windows |
---|
708 | file extension a/b/c.d |
---|
709 | } .d |
---|
710 | test cmdAH-11.30 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
711 | testsetplatform windows |
---|
712 | file extension a/b.c/d |
---|
713 | } {} |
---|
714 | test cmdAH-11.31 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
715 | testsetplatform windows |
---|
716 | file extension a\\b.c\\ |
---|
717 | } {} |
---|
718 | test cmdAH-11.32 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
719 | testsetplatform windows |
---|
720 | file extension a\\b\\c.d |
---|
721 | } .d |
---|
722 | test cmdAH-11.33 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
723 | testsetplatform windows |
---|
724 | file extension a\\b.c\\d |
---|
725 | } {} |
---|
726 | test cmdAH-11.34 {Tcl_FileObjCmd: extension} testsetplatform { |
---|
727 | testsetplatform windows |
---|
728 | file extension a\\b.c\\ |
---|
729 | } {} |
---|
730 | set num 35 |
---|
731 | foreach value {a..b a...b a.c..b ..b} result {.b .b .b .b} { |
---|
732 | foreach p {unix windows} { |
---|
733 | ;test cmdAH-11.$num {Tcl_FileObjCmd: extension} testsetplatform " |
---|
734 | testsetplatform $p |
---|
735 | file extension $value |
---|
736 | " $result |
---|
737 | incr num |
---|
738 | } |
---|
739 | } |
---|
740 | |
---|
741 | # pathtype |
---|
742 | |
---|
743 | test cmdAH-12.1 {Tcl_FileObjCmd: pathtype} testsetplatform { |
---|
744 | testsetplatform unix |
---|
745 | list [catch {file pathtype a b} msg] $msg |
---|
746 | } {1 {wrong # args: should be "file pathtype name"}} |
---|
747 | test cmdAH-12.2 {Tcl_FileObjCmd: pathtype} testsetplatform { |
---|
748 | testsetplatform unix |
---|
749 | file pathtype /a |
---|
750 | } absolute |
---|
751 | test cmdAH-12.3 {Tcl_FileObjCmd: pathtype} testsetplatform { |
---|
752 | testsetplatform unix |
---|
753 | file p a |
---|
754 | } relative |
---|
755 | test cmdAH-12.4 {Tcl_FileObjCmd: pathtype} testsetplatform { |
---|
756 | testsetplatform windows |
---|
757 | file pathtype c:a |
---|
758 | } volumerelative |
---|
759 | |
---|
760 | # split |
---|
761 | |
---|
762 | test cmdAH-13.1 {Tcl_FileObjCmd: split} testsetplatform { |
---|
763 | testsetplatform unix |
---|
764 | list [catch {file split a b} msg] $msg |
---|
765 | } {1 {wrong # args: should be "file split name"}} |
---|
766 | test cmdAH-13.2 {Tcl_FileObjCmd: split} testsetplatform { |
---|
767 | testsetplatform unix |
---|
768 | file split a |
---|
769 | } a |
---|
770 | test cmdAH-13.3 {Tcl_FileObjCmd: split} testsetplatform { |
---|
771 | testsetplatform unix |
---|
772 | file split a/b |
---|
773 | } {a b} |
---|
774 | |
---|
775 | # join |
---|
776 | |
---|
777 | test cmdAH-14.1 {Tcl_FileObjCmd: join} testsetplatform { |
---|
778 | testsetplatform unix |
---|
779 | file join a |
---|
780 | } a |
---|
781 | test cmdAH-14.2 {Tcl_FileObjCmd: join} testsetplatform { |
---|
782 | testsetplatform unix |
---|
783 | file join a b |
---|
784 | } a/b |
---|
785 | test cmdAH-14.3 {Tcl_FileObjCmd: join} testsetplatform { |
---|
786 | testsetplatform unix |
---|
787 | file join a b c d |
---|
788 | } a/b/c/d |
---|
789 | |
---|
790 | # error handling of Tcl_TranslateFileName |
---|
791 | |
---|
792 | test cmdAH-15.1 {Tcl_FileObjCmd} testsetplatform { |
---|
793 | testsetplatform unix |
---|
794 | list [catch {file atime ~_bad_user} msg] $msg |
---|
795 | } {1 {user "_bad_user" doesn't exist}} |
---|
796 | |
---|
797 | catch {testsetplatform $platform} |
---|
798 | |
---|
799 | # readable |
---|
800 | |
---|
801 | set gorpfile [makeFile abcde gorp.file] |
---|
802 | set dirfile [makeDirectory dir.file] |
---|
803 | |
---|
804 | test cmdAH-16.1 {Tcl_FileObjCmd: readable} { |
---|
805 | -body {list [catch {file readable a b} msg] $msg} |
---|
806 | -result {1 {wrong # args: should be "file readable name"}} |
---|
807 | } |
---|
808 | test cmdAH-16.2 {Tcl_FileObjCmd: readable} { |
---|
809 | -constraints testchmod |
---|
810 | -setup {testchmod 0444 $gorpfile} |
---|
811 | -body {file readable $gorpfile} |
---|
812 | -result 1 |
---|
813 | } |
---|
814 | test cmdAH-16.3 {Tcl_FileObjCmd: readable} { |
---|
815 | -constraints {unix notRoot testchmod} |
---|
816 | -setup {testchmod 0333 $gorpfile} |
---|
817 | -body {file reada $gorpfile} |
---|
818 | -result 0 |
---|
819 | } |
---|
820 | |
---|
821 | # writable |
---|
822 | |
---|
823 | test cmdAH-17.1 {Tcl_FileObjCmd: writable} { |
---|
824 | -body {list [catch {file writable a b} msg] $msg} |
---|
825 | -result {1 {wrong # args: should be "file writable name"}} |
---|
826 | } |
---|
827 | test cmdAH-17.2 {Tcl_FileObjCmd: writable} { |
---|
828 | -constraints {notRoot testchmod} |
---|
829 | -setup {testchmod 0555 $gorpfile} |
---|
830 | -body {file writable $gorpfile} |
---|
831 | -result 0 |
---|
832 | } |
---|
833 | test cmdAH-17.3 {Tcl_FileObjCmd: writable} { |
---|
834 | -constraints testchmod |
---|
835 | -setup {testchmod 0222 $gorpfile} |
---|
836 | -body {file writable $gorpfile} |
---|
837 | -result 1 |
---|
838 | } |
---|
839 | |
---|
840 | |
---|
841 | # executable |
---|
842 | |
---|
843 | removeFile $gorpfile |
---|
844 | removeDirectory $dirfile |
---|
845 | set dirfile [makeDirectory dir.file] |
---|
846 | set gorpfile [makeFile abcde gorp.file] |
---|
847 | |
---|
848 | test cmdAH-18.1 {Tcl_FileObjCmd: executable} {} { |
---|
849 | list [catch {file executable a b} msg] $msg |
---|
850 | } {1 {wrong # args: should be "file executable name"}} |
---|
851 | test cmdAH-18.2 {Tcl_FileObjCmd: executable} {notRoot} { |
---|
852 | file executable $gorpfile |
---|
853 | } 0 |
---|
854 | test cmdAH-18.3 {Tcl_FileObjCmd: executable} {unix testchmod} { |
---|
855 | # Only on unix will setting the execute bit on a regular file |
---|
856 | # cause that file to be executable. |
---|
857 | |
---|
858 | testchmod 0775 $gorpfile |
---|
859 | file exe $gorpfile |
---|
860 | } 1 |
---|
861 | |
---|
862 | test cmdAH-18.5 {Tcl_FileObjCmd: executable} {win} { |
---|
863 | # On pc, must be a .exe, .com, etc. |
---|
864 | |
---|
865 | set x [file exe $gorpfile] |
---|
866 | set gorpexe [makeFile foo gorp.exe] |
---|
867 | lappend x [file exe $gorpexe] |
---|
868 | removeFile $gorpexe |
---|
869 | set x |
---|
870 | } {0 1} |
---|
871 | test cmdAH-18.5.1 {Tcl_FileObjCmd: executable} {win} { |
---|
872 | # On pc, must be a .exe, .com, etc. |
---|
873 | |
---|
874 | set x [file exe $gorpfile] |
---|
875 | set gorpexe [makeFile foo gorp.exe] |
---|
876 | lappend x [file exe [string toupper $gorpexe]] |
---|
877 | removeFile $gorpexe |
---|
878 | set x |
---|
879 | } {0 1} |
---|
880 | test cmdAH-18.6 {Tcl_FileObjCmd: executable} {} { |
---|
881 | # Directories are always executable. |
---|
882 | |
---|
883 | file exe $dirfile |
---|
884 | } 1 |
---|
885 | |
---|
886 | removeDirectory $dirfile |
---|
887 | removeFile $gorpfile |
---|
888 | set linkfile [file join [temporaryDirectory] link.file] |
---|
889 | file delete $linkfile |
---|
890 | |
---|
891 | # exists |
---|
892 | |
---|
893 | test cmdAH-19.1 {Tcl_FileObjCmd: exists} { |
---|
894 | list [catch {file exists a b} msg] $msg |
---|
895 | } {1 {wrong # args: should be "file exists name"}} |
---|
896 | test cmdAH-19.2 {Tcl_FileObjCmd: exists} {file exists $gorpfile} 0 |
---|
897 | test cmdAH-19.3 {Tcl_FileObjCmd: exists} { |
---|
898 | file exists [file join [temporaryDirectory] dir.file gorp.file] |
---|
899 | } 0 |
---|
900 | catch { |
---|
901 | set gorpfile [makeFile abcde gorp.file] |
---|
902 | set dirfile [makeDirectory dir.file] |
---|
903 | set subgorp [makeFile 12345 [file join $dirfile gorp.file]] |
---|
904 | } |
---|
905 | test cmdAH-19.4 {Tcl_FileObjCmd: exists} { |
---|
906 | file exists $gorpfile |
---|
907 | } 1 |
---|
908 | test cmdAH-19.5 {Tcl_FileObjCmd: exists} { |
---|
909 | file exists $subgorp |
---|
910 | } 1 |
---|
911 | |
---|
912 | # nativename |
---|
913 | test cmdAH-19.6 {Tcl_FileObjCmd: nativename} testsetplatform { |
---|
914 | testsetplatform unix |
---|
915 | list [catch {file nativename a/b} msg] $msg [testsetplatform $platform] |
---|
916 | } {0 a/b {}} |
---|
917 | test cmdAH-19.7 {Tcl_FileObjCmd: nativename} testsetplatform { |
---|
918 | testsetplatform windows |
---|
919 | list [catch {file nativename a/b} msg] $msg [testsetplatform $platform] |
---|
920 | } {0 {a\b} {}} |
---|
921 | |
---|
922 | test cmdAH-19.9 {Tcl_FileObjCmd: ~ : exists} { |
---|
923 | file exists ~nOsUcHuSeR |
---|
924 | } 0 |
---|
925 | test cmdAH-19.10 {Tcl_FileObjCmd: ~ : nativename} { |
---|
926 | # should probably be 0 in fact... |
---|
927 | catch {file nativename ~nOsUcHuSeR} |
---|
928 | } 1 |
---|
929 | |
---|
930 | # The test below has to be done in /tmp rather than the current |
---|
931 | # directory in order to guarantee (?) a local file system: some |
---|
932 | # NFS file systems won't do the stuff below correctly. |
---|
933 | |
---|
934 | test cmdAH-19.11 {Tcl_FileObjCmd: exists} {unix notRoot} { |
---|
935 | file delete -force /tmp/tcl.foo.dir/file |
---|
936 | file delete -force /tmp/tcl.foo.dir |
---|
937 | makeDirectory /tmp/tcl.foo.dir |
---|
938 | makeFile 12345 /tmp/tcl.foo.dir/file |
---|
939 | file attributes /tmp/tcl.foo.dir -permissions 0000 |
---|
940 | |
---|
941 | set result [file exists /tmp/tcl.foo.dir/file] |
---|
942 | |
---|
943 | file attributes /tmp/tcl.foo.dir -permissions 0775 |
---|
944 | removeFile /tmp/tcl.foo.dir/file |
---|
945 | removeDirectory /tmp/tcl.foo.dir |
---|
946 | set result |
---|
947 | } 0 |
---|
948 | |
---|
949 | # Stat related commands |
---|
950 | |
---|
951 | catch {testsetplatform $platform} |
---|
952 | removeFile $gorpfile |
---|
953 | set gorpfile [makeFile "Test string" gorp.file] |
---|
954 | catch {file attributes $gorpfile -permissions 0765} |
---|
955 | |
---|
956 | # atime |
---|
957 | |
---|
958 | # avoid problems with non-local filesystems |
---|
959 | if {[testConstraint unix] && [file exists /tmp]} { |
---|
960 | set file [makeFile "data" touch.me /tmp] |
---|
961 | } else { |
---|
962 | set file [makeFile "data" touch.me] |
---|
963 | } |
---|
964 | |
---|
965 | test cmdAH-20.1 {Tcl_FileObjCmd: atime} { |
---|
966 | list [catch {file atime a b c} msg] $msg |
---|
967 | } {1 {wrong # args: should be "file atime name ?time?"}} |
---|
968 | test cmdAH-20.2 {Tcl_FileObjCmd: atime} { |
---|
969 | catch {unset stat} |
---|
970 | file stat $gorpfile stat |
---|
971 | list [expr {[file mtime $gorpfile] == $stat(mtime)}] \ |
---|
972 | [expr {[file atime $gorpfile] == $stat(atime)}] |
---|
973 | } {1 1} |
---|
974 | test cmdAH-20.3 {Tcl_FileObjCmd: atime} { |
---|
975 | string tolower [list [catch {file atime _bogus_} msg] \ |
---|
976 | $msg $errorCode] |
---|
977 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
978 | test cmdAH-20.4 {Tcl_FileObjCmd: atime} { |
---|
979 | list [catch {file atime $file notint} msg] $msg |
---|
980 | } {1 {expected integer but got "notint"}} |
---|
981 | test cmdAH-20.5 {Tcl_FileObjCmd: atime touch} {unix} { |
---|
982 | set atime [file atime $file] |
---|
983 | after 1100; # pause a sec to notice change in atime |
---|
984 | set newatime [clock seconds] |
---|
985 | set modatime [file atime $file $newatime] |
---|
986 | expr {$newatime == $modatime ? 1 : "$newatime != $modatime"} |
---|
987 | } 1 |
---|
988 | test cmdAH-20.6 {Tcl_FileObjCmd: atime touch} {win testvolumetype} { |
---|
989 | set old [pwd] |
---|
990 | cd $::tcltest::temporaryDirectory |
---|
991 | if {"NTFS" ne [testvolumetype]} { |
---|
992 | # Windows FAT doesn't understand atime, but NTFS does |
---|
993 | # May also fail for Windows on NFS mounted disks |
---|
994 | cd $old |
---|
995 | return 1 |
---|
996 | } |
---|
997 | cd $old |
---|
998 | set atime [file atime $file] |
---|
999 | after 1100; # pause a sec to notice change in atime |
---|
1000 | set newatime [clock seconds] |
---|
1001 | set modatime [file atime $file $newatime] |
---|
1002 | expr {$newatime == $modatime ? 1 : "$newatime != $modatime"} |
---|
1003 | } 1 |
---|
1004 | |
---|
1005 | if {[testConstraint unix] && [file exists /tmp]} { |
---|
1006 | removeFile touch.me /tmp |
---|
1007 | } else { |
---|
1008 | removeFile touch.me |
---|
1009 | } |
---|
1010 | |
---|
1011 | # isdirectory |
---|
1012 | |
---|
1013 | test cmdAH-21.1 {Tcl_FileObjCmd: isdirectory} { |
---|
1014 | list [catch {file isdirectory a b} msg] $msg |
---|
1015 | } {1 {wrong # args: should be "file isdirectory name"}} |
---|
1016 | test cmdAH-21.2 {Tcl_FileObjCmd: isdirectory} { |
---|
1017 | file isdirectory $gorpfile |
---|
1018 | } 0 |
---|
1019 | test cmdAH-21.3 {Tcl_FileObjCmd: isdirectory} { |
---|
1020 | file isd $dirfile |
---|
1021 | } 1 |
---|
1022 | |
---|
1023 | # isfile |
---|
1024 | |
---|
1025 | test cmdAH-22.1 {Tcl_FileObjCmd: isfile} { |
---|
1026 | list [catch {file isfile a b} msg] $msg |
---|
1027 | } {1 {wrong # args: should be "file isfile name"}} |
---|
1028 | test cmdAH-22.2 {Tcl_FileObjCmd: isfile} {file isfile $gorpfile} 1 |
---|
1029 | test cmdAH-22.3 {Tcl_FileObjCmd: isfile} {file isfile $dirfile} 0 |
---|
1030 | |
---|
1031 | # lstat and readlink: don't run these tests everywhere, since not all |
---|
1032 | # sites will have symbolic links |
---|
1033 | |
---|
1034 | catch {file link -symbolic $linkfile $gorpfile} |
---|
1035 | test cmdAH-23.1 {Tcl_FileObjCmd: lstat} { |
---|
1036 | list [catch {file lstat a} msg] $msg |
---|
1037 | } {1 {wrong # args: should be "file lstat name varName"}} |
---|
1038 | test cmdAH-23.2 {Tcl_FileObjCmd: lstat} { |
---|
1039 | list [catch {file lstat a b c} msg] $msg |
---|
1040 | } {1 {wrong # args: should be "file lstat name varName"}} |
---|
1041 | test cmdAH-23.3 {Tcl_FileObjCmd: lstat} {unix nonPortable} { |
---|
1042 | catch {unset stat} |
---|
1043 | file lstat $linkfile stat |
---|
1044 | lsort [array names stat] |
---|
1045 | } {atime ctime dev gid ino mode mtime nlink size type uid} |
---|
1046 | test cmdAH-23.4 {Tcl_FileObjCmd: lstat} {unix nonPortable} { |
---|
1047 | catch {unset stat} |
---|
1048 | file lstat $linkfile stat |
---|
1049 | list $stat(nlink) [expr $stat(mode)&0777] $stat(type) |
---|
1050 | } {1 511 link} |
---|
1051 | test cmdAH-23.5 {Tcl_FileObjCmd: lstat errors} {nonPortable} { |
---|
1052 | string tolower [list [catch {file lstat _bogus_ stat} msg] \ |
---|
1053 | $msg $errorCode] |
---|
1054 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1055 | test cmdAH-23.6 {Tcl_FileObjCmd: lstat errors} { |
---|
1056 | catch {unset x} |
---|
1057 | set x 44 |
---|
1058 | list [catch {file lstat $gorpfile x} msg] $msg $errorCode |
---|
1059 | } {1 {can't set "x(dev)": variable isn't array} NONE} |
---|
1060 | catch {unset stat} |
---|
1061 | |
---|
1062 | # mkdir |
---|
1063 | |
---|
1064 | set dirA [file join [temporaryDirectory] a] |
---|
1065 | set dirB [file join [temporaryDirectory] a] |
---|
1066 | test cmdAH-23.7 {Tcl_FileObjCmd: mkdir} { |
---|
1067 | catch {file delete -force $dirA} |
---|
1068 | file mkdir $dirA |
---|
1069 | set res [file isdirectory $dirA] |
---|
1070 | file delete $dirA |
---|
1071 | set res |
---|
1072 | } {1} |
---|
1073 | test cmdAH-23.8 {Tcl_FileObjCmd: mkdir} { |
---|
1074 | catch {file delete -force $dirA} |
---|
1075 | file mkdir $dirA/b |
---|
1076 | set res [file isdirectory $dirA/b] |
---|
1077 | file delete -force $dirA |
---|
1078 | set res |
---|
1079 | } {1} |
---|
1080 | test cmdAH-23.9 {Tcl_FileObjCmd: mkdir} { |
---|
1081 | catch {file delete -force $dirA} |
---|
1082 | file mkdir $dirA/b/c |
---|
1083 | set res [file isdirectory $dirA/b/c] |
---|
1084 | file delete -force $dirA |
---|
1085 | set res |
---|
1086 | } {1} |
---|
1087 | test cmdAH-23.10 {Tcl_FileObjCmd: mkdir} { |
---|
1088 | catch {file delete -force $dirA} |
---|
1089 | catch {file delete -force $dirB} |
---|
1090 | file mkdir $dirA/b $dirB/a/c |
---|
1091 | set res [list [file isdirectory $dirA/b] [file isdirectory $dirB/a/c]] |
---|
1092 | file delete -force $dirA |
---|
1093 | file delete -force $dirB |
---|
1094 | set res |
---|
1095 | } {1 1} |
---|
1096 | |
---|
1097 | # mtime |
---|
1098 | |
---|
1099 | proc waitForEvenSecondForFAT {} { |
---|
1100 | # Windows 9x uses filesystems (the FAT* family of FSes) without |
---|
1101 | # enough data in its timestamps for even per-second-accurate |
---|
1102 | # timings. :^( |
---|
1103 | # This procedure based on work by Helmut Giese |
---|
1104 | |
---|
1105 | if { |
---|
1106 | [testConstraint win] |
---|
1107 | && [lindex [file system [temporaryDirectory]] 1] ne "NTFS" |
---|
1108 | } then { |
---|
1109 | # Assume non-NTFS means FAT{12,16,32} and hence in need of special help |
---|
1110 | set start [clock seconds] |
---|
1111 | while {1} { |
---|
1112 | set now [clock seconds] |
---|
1113 | if {$now!=$start && !($now & 1)} { |
---|
1114 | break |
---|
1115 | } |
---|
1116 | after 50 |
---|
1117 | } |
---|
1118 | } |
---|
1119 | } |
---|
1120 | set file [makeFile "data" touch.me] |
---|
1121 | |
---|
1122 | test cmdAH-24.1 {Tcl_FileObjCmd: mtime} { |
---|
1123 | list [catch {file mtime a b c} msg] $msg |
---|
1124 | } {1 {wrong # args: should be "file mtime name ?time?"}} |
---|
1125 | # Check (allowing for clock-skew and OS interrupts as best we can) |
---|
1126 | # that the change in mtime on a file being written is the time elapsed |
---|
1127 | # between writes. Note that this can still fail on very busy systems |
---|
1128 | # if there are long preemptions between the writes and the reading of |
---|
1129 | # the clock, but there's not much you can do about that other than the |
---|
1130 | # completely horrible "keep on trying to write until you managed to do |
---|
1131 | # it all in less than a second." - DKF |
---|
1132 | test cmdAH-24.2 {Tcl_FileObjCmd: mtime} { |
---|
1133 | waitForEvenSecondForFAT |
---|
1134 | set f [open $gorpfile w] |
---|
1135 | puts $f "More text" |
---|
1136 | close $f |
---|
1137 | set clockOld [clock seconds] |
---|
1138 | set fileOld [file mtime $gorpfile] |
---|
1139 | after 2000 |
---|
1140 | set f [open $gorpfile w] |
---|
1141 | puts $f "More text" |
---|
1142 | close $f |
---|
1143 | set clockNew [clock seconds] |
---|
1144 | set fileNew [file mtime $gorpfile] |
---|
1145 | expr { |
---|
1146 | (($fileNew > $fileOld) && ($clockNew > $clockOld) && |
---|
1147 | (abs(($fileNew-$fileOld) - ($clockNew-$clockOld)) <= 1)) ? "1" : |
---|
1148 | "file:($fileOld=>$fileNew) clock:($clockOld=>$clockNew)" |
---|
1149 | } |
---|
1150 | } {1} |
---|
1151 | test cmdAH-24.3 {Tcl_FileObjCmd: mtime} { |
---|
1152 | catch {unset stat} |
---|
1153 | file stat $gorpfile stat |
---|
1154 | list [expr {[file mtime $gorpfile] == $stat(mtime)}] \ |
---|
1155 | [expr {[file atime $gorpfile] == $stat(atime)}] |
---|
1156 | } {1 1} |
---|
1157 | test cmdAH-24.4 {Tcl_FileObjCmd: mtime} { |
---|
1158 | string tolower [list [catch {file mtime _bogus_} msg] $msg \ |
---|
1159 | $errorCode] |
---|
1160 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1161 | test cmdAH-24.5 {Tcl_FileObjCmd: mtime} { |
---|
1162 | # Under Unix, use a file in /tmp to avoid clock skew due to NFS. |
---|
1163 | # On other platforms, just use a file in the local directory. |
---|
1164 | if {[testConstraint unix]} { |
---|
1165 | set name /tmp/tcl.test.[pid] |
---|
1166 | } else { |
---|
1167 | set name [file join [temporaryDirectory] tf] |
---|
1168 | } |
---|
1169 | # Make sure that a new file's time is correct. 10 seconds variance |
---|
1170 | # is allowed used due to slow networks or clock skew on a network drive. |
---|
1171 | file delete -force $name |
---|
1172 | close [open $name w] |
---|
1173 | set a [expr abs([clock seconds]-[file mtime $name])<10] |
---|
1174 | file delete $name |
---|
1175 | set a |
---|
1176 | } {1} |
---|
1177 | test cmdAH-24.7 {Tcl_FileObjCmd: mtime} { |
---|
1178 | list [catch {file mtime $file notint} msg] $msg |
---|
1179 | } {1 {expected integer but got "notint"}} |
---|
1180 | test cmdAH-24.8 {Tcl_FileObjCmd: mtime touch} unix { |
---|
1181 | set mtime [file mtime $file] |
---|
1182 | after 1100; # pause a sec to notice change in mtime |
---|
1183 | set newmtime [clock seconds] |
---|
1184 | set modmtime [file mtime $file $newmtime] |
---|
1185 | expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} |
---|
1186 | } 1 |
---|
1187 | test cmdAH-24.9 {Tcl_FileObjCmd: mtime touch with non-ascii chars} unix { |
---|
1188 | set oldfile $file |
---|
1189 | # introduce some non-ascii characters. |
---|
1190 | append file \u2022 |
---|
1191 | file delete -force $file |
---|
1192 | file rename $oldfile $file |
---|
1193 | set mtime [file mtime $file] |
---|
1194 | after 1100; # pause a sec to notice change in mtime |
---|
1195 | set newmtime [clock seconds] |
---|
1196 | set err [catch {file mtime $file $newmtime} modmtime] |
---|
1197 | file rename $file $oldfile |
---|
1198 | if {$err} { |
---|
1199 | error $modmtime |
---|
1200 | } |
---|
1201 | expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} |
---|
1202 | } 1 |
---|
1203 | test cmdAH-24.10 {Tcl_FileObjCmd: mtime touch} win { |
---|
1204 | waitForEvenSecondForFAT |
---|
1205 | set mtime [file mtime $file] |
---|
1206 | after 2100; # pause two secs to notice change in mtime on FAT fs'es |
---|
1207 | set newmtime [clock seconds] |
---|
1208 | set modmtime [file mtime $file $newmtime] |
---|
1209 | expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} |
---|
1210 | } 1 |
---|
1211 | test cmdAH-24.11 {Tcl_FileObjCmd: mtime touch with non-ascii chars} win { |
---|
1212 | waitForEvenSecondForFAT |
---|
1213 | set oldfile $file |
---|
1214 | # introduce some non-ascii characters. |
---|
1215 | append file \u2022 |
---|
1216 | file delete -force $file |
---|
1217 | file rename $oldfile $file |
---|
1218 | set mtime [file mtime $file] |
---|
1219 | after 2100; # pause two secs to notice change in mtime on FAT fs'es |
---|
1220 | set newmtime [clock seconds] |
---|
1221 | set err [catch {file mtime $file $newmtime} modmtime] |
---|
1222 | file rename $file $oldfile |
---|
1223 | if {$err} { |
---|
1224 | error $modmtime |
---|
1225 | } |
---|
1226 | expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"} |
---|
1227 | } 1 |
---|
1228 | removeFile touch.me |
---|
1229 | rename waitForEvenSecondForFAT {} |
---|
1230 | test cmdAH-24.12 {Tcl_FileObjCmd: mtime and daylight savings} { |
---|
1231 | set name [file join [temporaryDirectory] clockchange] |
---|
1232 | file delete -force $name |
---|
1233 | close [open $name w] |
---|
1234 | set time [clock scan "21:00:00 October 30 2004 GMT"] |
---|
1235 | file mtime $name $time |
---|
1236 | set newmtime [file mtime $name] |
---|
1237 | file delete $name |
---|
1238 | expr {$newmtime == $time ? 1 : "$newmtime != $time"} |
---|
1239 | } {1} |
---|
1240 | # bug 1420432: setting mtime fails for directories on windows. |
---|
1241 | test cmdAH-24.13 {Tcl_FileObjCmd: directory mtime} -setup { |
---|
1242 | set dirname [file join [temporaryDirectory] tmp[pid]] |
---|
1243 | file delete -force $dirname |
---|
1244 | } -constraints tempNotWin -body { |
---|
1245 | file mkdir $dirname |
---|
1246 | set old [file mtime $dirname] |
---|
1247 | file mtime $dirname 0 |
---|
1248 | set new [file mtime $dirname] |
---|
1249 | list $new [expr {$old != $new}] |
---|
1250 | } -cleanup { |
---|
1251 | file delete -force $dirname |
---|
1252 | } -result {0 1} |
---|
1253 | |
---|
1254 | # owned |
---|
1255 | |
---|
1256 | test cmdAH-25.1 {Tcl_FileObjCmd: owned} { |
---|
1257 | list [catch {file owned a b} msg] $msg |
---|
1258 | } {1 {wrong # args: should be "file owned name"}} |
---|
1259 | test cmdAH-25.2 {Tcl_FileObjCmd: owned} -constraints win -body { |
---|
1260 | file owned $gorpfile |
---|
1261 | } -result 1 |
---|
1262 | test cmdAH-25.2.1 {Tcl_FileObjCmd: owned} -constraints unix -setup { |
---|
1263 | # Avoid problems with AFS |
---|
1264 | set tmpfile [makeFile "data" touch.me /tmp] |
---|
1265 | } -body { |
---|
1266 | file owned $tmpfile |
---|
1267 | } -cleanup { |
---|
1268 | removeFile touch.me /tmp |
---|
1269 | } -result 1 |
---|
1270 | test cmdAH-25.3 {Tcl_FileObjCmd: owned} {unix notRoot} { |
---|
1271 | file owned / |
---|
1272 | } 0 |
---|
1273 | |
---|
1274 | # readlink |
---|
1275 | |
---|
1276 | test cmdAH-26.1 {Tcl_FileObjCmd: readlink} { |
---|
1277 | list [catch {file readlink a b} msg] $msg |
---|
1278 | } {1 {wrong # args: should be "file readlink name"}} |
---|
1279 | test cmdAH-26.2 {Tcl_FileObjCmd: readlink} {unix nonPortable} { |
---|
1280 | file readlink $linkfile |
---|
1281 | } $gorpfile |
---|
1282 | test cmdAH-26.3 {Tcl_FileObjCmd: readlink errors} {unix nonPortable} { |
---|
1283 | list [catch {file readlink _bogus_} msg] [string tolower $msg] \ |
---|
1284 | [string tolower $errorCode] |
---|
1285 | } {1 {could not readlink "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1286 | test cmdAH-26.5 {Tcl_FileObjCmd: readlink errors} {win nonPortable} { |
---|
1287 | list [catch {file readlink _bogus_} msg] [string tolower $msg] \ |
---|
1288 | [string tolower $errorCode] |
---|
1289 | } {1 {could not readlink "_bogus_": invalid argument} {posix einval {invalid argument}}} |
---|
1290 | |
---|
1291 | # size |
---|
1292 | |
---|
1293 | test cmdAH-27.1 {Tcl_FileObjCmd: size} { |
---|
1294 | list [catch {file size a b} msg] $msg |
---|
1295 | } {1 {wrong # args: should be "file size name"}} |
---|
1296 | test cmdAH-27.2 {Tcl_FileObjCmd: size} { |
---|
1297 | set oldsize [file size $gorpfile] |
---|
1298 | set f [open $gorpfile a] |
---|
1299 | fconfigure $f -translation lf -eofchar {} |
---|
1300 | puts $f "More text" |
---|
1301 | close $f |
---|
1302 | expr {[file size $gorpfile] - $oldsize} |
---|
1303 | } {10} |
---|
1304 | test cmdAH-27.3 {Tcl_FileObjCmd: size} { |
---|
1305 | string tolower [list [catch {file size _bogus_} msg] $msg \ |
---|
1306 | $errorCode] |
---|
1307 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1308 | |
---|
1309 | # stat |
---|
1310 | |
---|
1311 | catch {testsetplatform $platform} |
---|
1312 | removeFile $gorpfile |
---|
1313 | set gorpfile [makeFile "Test string" gorp.file] |
---|
1314 | catch {file attributes $gorpfile -permissions 0765} |
---|
1315 | |
---|
1316 | test cmdAH-28.1 {Tcl_FileObjCmd: stat} { |
---|
1317 | list [catch {file stat _bogus_} msg] $msg $errorCode |
---|
1318 | } {1 {wrong # args: should be "file stat name varName"} NONE} |
---|
1319 | test cmdAH-28.2 {Tcl_FileObjCmd: stat} { |
---|
1320 | list [catch {file stat _bogus_ a b} msg] $msg $errorCode |
---|
1321 | } {1 {wrong # args: should be "file stat name varName"} NONE} |
---|
1322 | test cmdAH-28.3 {Tcl_FileObjCmd: stat} { |
---|
1323 | catch {unset stat} |
---|
1324 | file stat $gorpfile stat |
---|
1325 | lsort [array names stat] |
---|
1326 | } {atime ctime dev gid ino mode mtime nlink size type uid} |
---|
1327 | test cmdAH-28.4 {Tcl_FileObjCmd: stat} { |
---|
1328 | catch {unset stat} |
---|
1329 | file stat $gorpfile stat |
---|
1330 | list $stat(nlink) $stat(size) $stat(type) |
---|
1331 | } {1 12 file} |
---|
1332 | test cmdAH-28.5 {Tcl_FileObjCmd: stat} {unix} { |
---|
1333 | catch {unset stat} |
---|
1334 | file stat $gorpfile stat |
---|
1335 | expr $stat(mode)&0o777 |
---|
1336 | } {501} |
---|
1337 | test cmdAH-28.6 {Tcl_FileObjCmd: stat} { |
---|
1338 | string tolower [list [catch {file stat _bogus_ stat} msg] \ |
---|
1339 | $msg $errorCode] |
---|
1340 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1341 | test cmdAH-28.7 {Tcl_FileObjCmd: stat} { |
---|
1342 | catch {unset x} |
---|
1343 | set x 44 |
---|
1344 | list [catch {file stat $gorpfile x} msg] $msg $errorCode |
---|
1345 | } {1 {can't set "x(dev)": variable isn't array} NONE} |
---|
1346 | test cmdAH-28.8 {Tcl_FileObjCmd: stat} { |
---|
1347 | # Sign extension of purported unsigned short to int. |
---|
1348 | |
---|
1349 | set filename [makeFile "" foo.text] |
---|
1350 | file stat $filename stat |
---|
1351 | set x [expr {$stat(mode) > 0}] |
---|
1352 | removeFile $filename |
---|
1353 | set x |
---|
1354 | } 1 |
---|
1355 | test cmdAH-28.9 {Tcl_FileObjCmd: stat} win { |
---|
1356 | # stat of root directory was failing. |
---|
1357 | # don't care about answer, just that test runs. |
---|
1358 | |
---|
1359 | # relative paths that resolve to root |
---|
1360 | set old [pwd] |
---|
1361 | cd c:/ |
---|
1362 | file stat c: stat |
---|
1363 | file stat c:. stat |
---|
1364 | file stat . stat |
---|
1365 | cd $old |
---|
1366 | |
---|
1367 | file stat / stat |
---|
1368 | file stat c:/ stat |
---|
1369 | file stat c:/. stat |
---|
1370 | } {} |
---|
1371 | test cmdAH-28.10 {Tcl_FileObjCmd: stat} {win nonPortable} { |
---|
1372 | # stat of root directory was failing. |
---|
1373 | # don't care about answer, just that test runs. |
---|
1374 | |
---|
1375 | file stat //pop/$env(USERNAME) stat |
---|
1376 | file stat //pop/$env(USERNAME)/ stat |
---|
1377 | file stat //pop/$env(USERNAME)/. stat |
---|
1378 | } {} |
---|
1379 | test cmdAH-28.11 {Tcl_FileObjCmd: stat} {win nonPortable} { |
---|
1380 | # stat of network directory was returning id of current local drive. |
---|
1381 | |
---|
1382 | set old [pwd] |
---|
1383 | cd c:/ |
---|
1384 | |
---|
1385 | file stat //pop/$env(USERNAME) stat |
---|
1386 | cd $old |
---|
1387 | expr {$stat(dev) == 2} |
---|
1388 | } 0 |
---|
1389 | test cmdAH-28.12 {Tcl_FileObjCmd: stat} { |
---|
1390 | # stat(mode) with S_IFREG flag was returned as a negative number |
---|
1391 | # if mode_t was a short instead of an unsigned short. |
---|
1392 | |
---|
1393 | set filename [makeFile "" foo.test] |
---|
1394 | file stat $filename stat |
---|
1395 | removeFile $filename |
---|
1396 | expr {$stat(mode) > 0} |
---|
1397 | } 1 |
---|
1398 | catch {unset stat} |
---|
1399 | |
---|
1400 | # type |
---|
1401 | |
---|
1402 | test cmdAH-29.1 {Tcl_FileObjCmd: type} { |
---|
1403 | list [catch {file size a b} msg] $msg |
---|
1404 | } {1 {wrong # args: should be "file size name"}} |
---|
1405 | test cmdAH-29.2 {Tcl_FileObjCmd: type} { |
---|
1406 | file type $dirfile |
---|
1407 | } directory |
---|
1408 | test cmdAH-29.3.0 {Tcl_FileObjCmd: delete removes link not file} {unix nonPortable} { |
---|
1409 | set exists [list [file exists $linkfile] [file exists $gorpfile]] |
---|
1410 | file delete $linkfile |
---|
1411 | set exists2 [list [file exists $linkfile] [file exists $gorpfile]] |
---|
1412 | list $exists $exists2 |
---|
1413 | } {{1 1} {0 1}} |
---|
1414 | test cmdAH-29.3 {Tcl_FileObjCmd: type} { |
---|
1415 | file type $gorpfile |
---|
1416 | } file |
---|
1417 | test cmdAH-29.4 {Tcl_FileObjCmd: type} {unix} { |
---|
1418 | catch {file delete $linkfile} |
---|
1419 | # Unlike [exec ln -s], [file link] requires an existing target |
---|
1420 | file link -symbolic $linkfile $gorpfile |
---|
1421 | set result [file type $linkfile] |
---|
1422 | file delete $linkfile |
---|
1423 | set result |
---|
1424 | } link |
---|
1425 | test cmdAH-29.4.1 {Tcl_FileObjCmd: type} {linkDirectory} { |
---|
1426 | set tempdir [makeDirectory temp] |
---|
1427 | set linkdir [file join [temporaryDirectory] link.dir] |
---|
1428 | file link -symbolic $linkdir $tempdir |
---|
1429 | set result [file type $linkdir] |
---|
1430 | file delete $linkdir |
---|
1431 | removeDirectory $tempdir |
---|
1432 | set result |
---|
1433 | } link |
---|
1434 | test cmdAH-29.5 {Tcl_FileObjCmd: type} { |
---|
1435 | string tolower [list [catch {file type _bogus_} msg] $msg $errorCode] |
---|
1436 | } {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}} |
---|
1437 | |
---|
1438 | # Error conditions |
---|
1439 | |
---|
1440 | test cmdAH-30.1 {Tcl_FileObjCmd: error conditions} { |
---|
1441 | list [catch {file gorp x} msg] $msg |
---|
1442 | } {1 {bad option "gorp": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1443 | test cmdAH-30.2 {Tcl_FileObjCmd: error conditions} { |
---|
1444 | list [catch {file ex x} msg] $msg |
---|
1445 | } {1 {ambiguous option "ex": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1446 | test cmdAH-30.3 {Tcl_FileObjCmd: error conditions} { |
---|
1447 | list [catch {file is x} msg] $msg |
---|
1448 | } {1 {ambiguous option "is": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1449 | test cmdAH-30.4 {Tcl_FileObjCmd: error conditions} { |
---|
1450 | list [catch {file z x} msg] $msg |
---|
1451 | } {1 {bad option "z": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1452 | test cmdAH-30.5 {Tcl_FileObjCmd: error conditions} { |
---|
1453 | list [catch {file read x} msg] $msg |
---|
1454 | } {1 {ambiguous option "read": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1455 | test cmdAH-30.6 {Tcl_FileObjCmd: error conditions} { |
---|
1456 | list [catch {file s x} msg] $msg |
---|
1457 | } {1 {ambiguous option "s": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1458 | test cmdAH-30.7 {Tcl_FileObjCmd: error conditions} { |
---|
1459 | list [catch {file t x} msg] $msg |
---|
1460 | } {1 {ambiguous option "t": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}} |
---|
1461 | test cmdAH-30.8 {Tcl_FileObjCmd: error conditions} { |
---|
1462 | list [catch {file dirname ~woohgy} msg] $msg |
---|
1463 | } {1 {user "woohgy" doesn't exist}} |
---|
1464 | |
---|
1465 | # channels |
---|
1466 | # In testing 'file channels', we need to make sure that a channel |
---|
1467 | # created in one interp isn't visible in another. |
---|
1468 | |
---|
1469 | interp create simpleInterp |
---|
1470 | interp create -safe safeInterp |
---|
1471 | interp c |
---|
1472 | safeInterp expose file file |
---|
1473 | |
---|
1474 | test cmdAH-31.1 {Tcl_FileObjCmd: channels, too many args} { |
---|
1475 | list [catch {file channels a b} msg] $msg |
---|
1476 | } {1 {wrong # args: should be "file channels ?pattern?"}} |
---|
1477 | test cmdAH-31.2 {Tcl_FileObjCmd: channels, too many args} { |
---|
1478 | # Normal interps start out with only the standard channels |
---|
1479 | lsort [simpleInterp eval [list file chan]] |
---|
1480 | } [lsort {stderr stdout stdin}] |
---|
1481 | test cmdAH-31.3 {Tcl_FileObjCmd: channels, globbing} { |
---|
1482 | string equal [file channels] [file channels *] |
---|
1483 | } {1} |
---|
1484 | test cmdAH-31.4 {Tcl_FileObjCmd: channels, globbing} { |
---|
1485 | lsort [file channels std*] |
---|
1486 | } [lsort {stdout stderr stdin}] |
---|
1487 | |
---|
1488 | set newFileId [open $gorpfile w] |
---|
1489 | |
---|
1490 | test cmdAH-31.5 {Tcl_FileObjCmd: channels} { |
---|
1491 | set res [file channels $newFileId] |
---|
1492 | string equal $newFileId $res |
---|
1493 | } {1} |
---|
1494 | test cmdAH-31.6 {Tcl_FileObjCmd: channels in other interp} { |
---|
1495 | # Safe interps start out with no channels |
---|
1496 | safeInterp eval [list file channels] |
---|
1497 | } {} |
---|
1498 | test cmdAH-31.7 {Tcl_FileObjCmd: channels in other interp} { |
---|
1499 | list [catch {safeInterp eval [list puts $newFileId "hello"]} msg] $msg |
---|
1500 | } [list 1 "can not find channel named \"$newFileId\""] |
---|
1501 | |
---|
1502 | interp share {} $newFileId safeInterp |
---|
1503 | interp share {} stdout safeInterp |
---|
1504 | |
---|
1505 | test cmdAH-31.8 {Tcl_FileObjCmd: channels in other interp} { |
---|
1506 | # $newFileId should now be visible in both interps |
---|
1507 | list [file channels $newFileId] \ |
---|
1508 | [safeInterp eval [list file channels $newFileId]] |
---|
1509 | } [list $newFileId $newFileId] |
---|
1510 | test cmdAH-31.9 {Tcl_FileObjCmd: channels in other interp} { |
---|
1511 | lsort [safeInterp eval [list file channels]] |
---|
1512 | } [lsort [list stdout $newFileId]] |
---|
1513 | test cmdAH-31.10 {Tcl_FileObjCmd: channels in other interp} { |
---|
1514 | # we can now write to $newFileId from slave |
---|
1515 | safeInterp eval [list puts $newFileId "hello"] |
---|
1516 | } {} |
---|
1517 | |
---|
1518 | interp transfer {} $newFileId safeInterp |
---|
1519 | |
---|
1520 | test cmdAH-31.11 {Tcl_FileObjCmd: channels in other interp} { |
---|
1521 | # $newFileId should now be visible only in safeInterp |
---|
1522 | list [file channels $newFileId] \ |
---|
1523 | [safeInterp eval [list file channels $newFileId]] |
---|
1524 | } [list {} $newFileId] |
---|
1525 | test cmdAH-31.12 {Tcl_FileObjCmd: channels in other interp} { |
---|
1526 | lsort [safeInterp eval [list file channels]] |
---|
1527 | } [lsort [list stdout $newFileId]] |
---|
1528 | test cmdAH-31.13 {Tcl_FileObjCmd: channels in other interp} { |
---|
1529 | safeInterp eval [list close $newFileId] |
---|
1530 | safeInterp eval [list file channels] |
---|
1531 | } {stdout} |
---|
1532 | |
---|
1533 | # This shouldn't work, but just in case a test above failed... |
---|
1534 | catch {close $newFileId} |
---|
1535 | |
---|
1536 | interp delete safeInterp |
---|
1537 | interp delete simpleInterp |
---|
1538 | |
---|
1539 | # cleanup |
---|
1540 | catch {testsetplatform $platform} |
---|
1541 | catch {unset platform} |
---|
1542 | |
---|
1543 | # Tcl_ForObjCmd is tested in for.test |
---|
1544 | |
---|
1545 | catch {file attributes $dirfile -permissions 0777} |
---|
1546 | removeDirectory $dirfile |
---|
1547 | removeFile $gorpfile |
---|
1548 | # No idea how well [removeFile] copes with links... |
---|
1549 | file delete $linkfile |
---|
1550 | |
---|
1551 | cd $cmdAHwd |
---|
1552 | |
---|
1553 | ::tcltest::cleanupTests |
---|
1554 | return |
---|
1555 | |
---|
1556 | # Local Variables: |
---|
1557 | # mode: tcl |
---|
1558 | # End: |
---|