1 source [file dirname [info script]]/testing.tcl
5 testConstraint filelink [string match "wrong # args:*" $msg]
7 testConstraint filelstat [string match "wrong # args:*" $msg]
8 testConstraint unix [expr {$tcl_platform(platform) eq "unix"}]
10 test join-1.1 "One name" {
14 test join-1.2 "One name with trailing slash" {
18 test join-1.3 "One name with leading slash" {
22 test join-1.4 "One name with leading and trailing slash" {
26 test join-1.5 "Two names" {
30 test join-1.6 "Two names with dir trailing slash" {
34 test join-1.7 "Two names with dir leading slash" {
38 test join-1.8 "Two names with dir leading and trailing slash" {
42 test join-1.9 "Two names with file trailing slash" {
46 test join-1.10 "Two names with file leading slash" {
50 test join-1.11 "Two names with file leading and trailing slash" {
54 test join-1.12 "Two names with double slashes" {
58 test join-1.13 "Join to root" {
62 test join-1.14 "Join to root" {
63 set dir [file join / .]
64 # Either / or /. is OK here
68 test join-1.15 "Join to root" {
72 test join-1.16 "Join to root" {
76 test join-1.17 "With trailing slash" {
77 file join /abc/def/ ghi/jkl
80 test join-2.1 "Dir is empty string" {
84 test join-2.2 "File is empty string" {
88 test join-2.3 "Path too long" jim {
89 set components [string repeat {abcdefghi } 500]
90 list [catch [concat file join $components] msg] $msg
93 test tail-1.1 "One component" {
97 test tail-1.2 "Two components" {
101 test tail-1.3 "Absolute one component" {
105 test tail-1.4 "Trailing slash" {
109 test dirname-1.1 "One component" {
113 test dirname-1.2 "Two components" {
117 test dirname-1.3 "Absolute one component" {
121 test dirname-1.4 "Trailing slash" {
125 test dirname-1.5 ".." {
129 test dirname-1.6 "abc/.." {
133 test dirname-1.7 "../abc" {
137 test stat-1.1 {file stat usage} -body {
139 } -returnCodes error -match glob -result {wrong # args: should be "file stat name*"}
141 test stat-1.2 {file stat usage} -body {
142 file stat nonexistent a
143 } -returnCodes error -match glob -result {could not read "nonexistent": *}
145 test stat-1.3 {file stat} {
147 file stat [info script] a
151 test stat-1.4 {file stat update array} {
153 file stat [info nameofexecutable] a
157 test stat-1.5 {file stat update bad array} -body {
161 file stat [info nameofexecutable] a
162 } -returnCodes error -result {can't set "a(dev)": variable isn't array}
164 test stat-1.7 {file stat no variable} jim {
165 set a [file stat [info script]]
169 test ext-1.1 {file ext} -body {
171 } -returnCodes error -result {wrong # args: should be "file extension name"}
173 test ext-1.2 {file ext basic} {
177 test ext-1.3 {file ext path} {
181 test ext-1.4 {file ext noext} {
185 test ext-1.5 {file ext noext} {
189 test rootname-1.1 {file rootname} -body {
191 } -returnCodes error -result {wrong # args: should be "file rootname name"}
193 test rootname-1.2 {file rootname basic} -body {
197 test rootname-1.3 {file rootname basic} -body {
198 file rootname abc/def
201 test rootname-1.4 {file rootname basic} -body {
205 test rootname-1.5 {file rootname basic} -body {
206 file rootname abc/def.c
209 test rootname-1.6 {file rootname odd cases} -body {
210 file rootname abc/def.c/ghi
211 } -result {abc/def.c/ghi}
213 test rootname-1.7 {file rootname odd cases} -body {
214 file rootname abc/def.c/
215 } -result {abc/def.c/}
217 test rootname-1.8 {file rootname odd cases} -body {
218 file rootname abc/def.c//
219 } -result {abc/def.c//}
221 test readable-1.1 {file readable} {
222 file readable [info script]
225 test writable-1.1 {file writable} -body {
227 makeFile testing $name
229 } -result 1 -cleanup {
233 test rename-1.1 {file rename usage} -body {
235 } -returnCodes error -match glob -result {wrong # args: should be *}
237 test rename-1.2 {file rename usage} -body {
238 file rename -badarg name1 name2
239 } -returnCodes error -match glob -result {*}
241 test rename-1.1 {file rename, target exists} -body {
244 makeFile testing $name1
245 makeFile testing2 $name2
246 file rename $name1 $name2
247 } -returnCodes error -match glob -result {error renaming *}
249 test rename-1.2 {file rename -force, target exists} -body {
250 file rename -force $name1 $name2
251 list [file exists $name1] [file exists $name2]
252 } -result {0 1} -cleanup {
256 test link-1.1 {file link usage} -constraints filelink -body {
258 } -returnCodes error -match glob -result {wrong # args: should be "file link*}
260 test link-1.2 {file hard link} -constraints filelink -body {
262 file link $name [info script]
264 } -result {1} -cleanup {
268 test link-1.3 {file hard link} -constraints filelink -body {
270 file link -hard $name [info script]
272 } -result {1} -cleanup {
276 test link-1.4 {file sym link} -constraints filelink -body {
278 file link -sym $name [info script]
279 list [file exists $name] [file tail [file readlink $name]]
280 } -result {1 file.test} -cleanup {
284 test link-1.5 {file readlink, bad link} -constraints filelink -body {
285 file readlink [info script]
286 } -returnCodes error -match glob -result {could not read*link "*file.test": *}
288 test link-1.6 {file link badopt} -constraints filelink -body {
289 file link -bad name1 name2
290 } -returnCodes error -match glob -result {bad * "-bad": must be *}
292 test lstat-1.1 {file lstat} -constraints filelstat -body {
294 } -returnCodes error -match glob -result {wrong # args: should be "file lstat name *}
296 test lstat-1.2 {file lstat} -constraints filelstat -body {
297 file lstat nonexistent ls
298 } -returnCodes error -match glob -result {could not read "nonexistent": *}
300 test lstat-1.3 {file lstat} -constraints {filelink filelstat} -body {
302 file link -sym $name [info script]
303 unset -nocomplain s ls
305 file stat [info script] s
306 list $ls(type) $s(type)
307 } -match glob -result {link file} -cleanup {
311 test type-1.1 {file type} {
312 file type [info script]
315 test type-1.2 {file type} {
316 file type [file dirname [info script]]
319 test type-1.2 {file type} -body {
320 file type nonexistent
321 } -returnCodes error -match glob -result {could not read "nonexistent": *}
323 test isfile-1.1 {file isfile} -body {
325 } -returnCodes error -result {wrong # args: should be "file isfile name"}
327 test isfile-1.2 {file isfile} {
328 file isfile [info script]
331 test isfile-1.3 {file isfile} {
332 file isfile [file dirname [info script]]
335 test size-1.1 {file size} -body {
337 } -returnCodes error -result {wrong # args: should be "file size name"}
339 test size-1.2 {file size} -body {
340 file size nonexistent
341 } -returnCodes error -match glob -result {could not read "nonexistent":*}
343 test size-1.3 {file size} {
344 set size [file size [info script]]
345 file stat [info script] s
346 expr {$size - $s(size)}
349 test mtime-1.1 {file mtime} -body {
351 } -returnCodes error -result {wrong # args: should be "file mtime name ?time?"}
353 test mtime-1.2 {file mtime} -body {
354 file mtime nonexistent
355 } -returnCodes error -match glob -result {could not read "nonexistent":*}
357 test mtime-1.3 {file mtime} -body {
358 file mtime [info script] bad
359 } -returnCodes error -result {expected integer but got "bad"}
361 test mtime-1.4 {file mtime} {
362 set mtime [file mtime [info script]]
363 file stat [info script] s
364 if {$mtime != $s(mtime)} {
365 error "mtime was $mtime but s(mtime) was $s(mtime)"
369 test mtime-1.5 {file mtime} -constraints unix -body {
371 makeFile testing $name
372 set t [file mtime [info script]]
374 expr {$t - [file mtime $name]}
375 } -result {0} -cleanup {
379 test atime-1.1 {file atime} -body {
381 } -returnCodes error -match glob -result {wrong # args: should be "file atime name*}
383 test atime-1.2 {file atime} -body {
384 file atime nonexistent
385 } -returnCodes error -match glob -result {could not read "nonexistent":*}
387 test atime-1.3 {file atime} {
388 set atime [file atime [info script]]
389 file stat [info script] s
390 expr {$atime - $s(atime)}
393 # These tests are courtesy of picol
395 test file.12.1 "picol test" {file dirname /foo/bar/grill.txt} /foo/bar
396 test file.12.2 "picol test" {file dirname /foo/bar/baz/} /foo/bar
397 test file.12.3 "picol test" {file dirname /foo/bar/baz///} /foo/bar
398 test file.12.4 "picol test" {file dirname /foo/bar/baz///qux} /foo/bar/baz
399 test file.12.5 "picol test" {file dirname foo/bar/grill.txt} foo/bar
400 test file.12.6 "picol test" {file dirname foo/bar/baz/} foo/bar
401 test file.12.7 "picol test" {file dirname {}} .
402 test file.12.8 "picol test" {file dirname /} /
403 test file.12.9 "picol test" {file dirname ///} /
405 test file.13.1 "picol test" {file tail /foo/bar/grill.txt} grill.txt
406 test file.13.2 "picol test" {file tail /foo/bar/baz/} baz
407 test file.13.3 "picol test" {file tail /foo/bar/baz///} baz
408 test file.13.4 "picol test" {file dirname /foo/bar/baz///qux} /foo/bar/baz
409 test file.13.5 "picol test" {file tail foo/bar/grill.txt} grill.txt
410 test file.13.6 "picol test" {file tail foo/bar/baz/} baz
411 test file.13.7 "picol test" {file tail {}} {}
412 test file.13.8 "picol test" {file tail /} {}
413 test file.13.9 "picol test" {file tail ///} {}
415 test file.14 "picol test" {file join foo} foo
416 test file.15 "picol test" {file join foo bar} foo/bar
417 test file.16 "picol test" {file join foo /bar} /bar
419 if {$tcl_platform(platform) eq {windows}} {
420 test file.17 "picol test" {file join foo C:/bar grill} C:/bar/grill
423 test file.18 "picol test" {file split {/foo/space station/bar}} {/ foo {space station} bar}
424 test file.19 "picol test" {file split {/foo/space station/bar/}} {/ foo {space station} bar}
425 test file.20 "picol test" {file split {foo/space station/bar}} {foo {space station} bar}
426 test file.21 "picol test" {file split foo///bar} {foo bar}
427 test file.22 "picol test" {file split foo} foo