Debian Codegraph @

tests/fileSystem.test

raw
1 # This file tests the filesystem and vfs internals.
2 #
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # for errors. No output means no errors were found.
6 #
7 # Copyright (c) 2002 Vincent Darley.
8 #
9 # See the file "license.terms" for information on usage and redistribution of
10 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12 if {"::tcltest" ni [namespace children]} {
13 package require tcltest 2.5
14 namespace import -force ::tcltest::*
15 }
16
17 namespace eval ::tcl::test::fileSystem {
18 namespace import ::tcltest::*
19
20 catch {
21 file delete -force link.file
22 file delete -force dir.link
23 file delete -force [file join dir.dir linkinside.file]
24 }
25
26 testConstraint loaddll 0
27 catch {
28 ::tcltest::loadTestedCommands
29 package require -exact Tcltest [info patchlevel]
30 set ::ddever [package require dde]
31 set ::ddelib [lindex [package ifneeded dde $::ddever] 1]
32 set ::regver [package require registry]
33 set ::reglib [lindex [package ifneeded registry $::regver] 1]
34 if {[file extension $::reglib] eq ".dll"} {
35 testConstraint loaddll 1
36 }
37 }
38
39 # Test for commands defined in Tcltest executable
40 testConstraint testfilesystem [llength [info commands ::testfilesystem]]
41 testConstraint testsetplatform [llength [info commands ::testsetplatform]]
42 testConstraint testsimplefilesystem [llength [info commands ::testsimplefilesystem]]
43 # Some things fail under all Continuous Integration systems for subtle reasons
44 # such as CI often running with elevated privileges in a container.
45 testConstraint notInCIenv [expr {![info exists ::env(CI)]}]
46
47 cd [tcltest::temporaryDirectory]
48 makeFile "test file" gorp.file
49 makeDirectory dir.dir
50 makeDirectory [file join dir.dir dirinside.dir]
51 makeFile "test file in directory" [file join dir.dir inside.file]
52
53 testConstraint unusedDrive 0
54 testConstraint moreThanOneDrive 0
55 apply {{} {
56 # The variables 'drive' and 'drives' will be used below.
57 variable drive {} drives {}
58 if {[testConstraint win]} {
59 set vols [string map [list :/ {}] [file volumes]]
60 for {set i 0} {$i < 26} {incr i} {
61 set drive [format %c [expr {$i + 65}]]
62 if {$drive ni $vols} {
63 testConstraint unusedDrive 1
64 break
65 }
66 }
67
68 set dir [pwd]
69 try {
70 foreach vol [file volumes] {
71 if {![catch {cd $vol}]} {
72 lappend drives $vol
73 }
74 }
75 testConstraint moreThanOneDrive [expr {[llength $drives] > 1}]
76 } finally {
77 cd $dir
78 }
79 }
80 } ::tcl::test::fileSystem}
81
82 proc testPathEqual {one two} {
83 if {$one eq $two} {
84 return "ok"
85 }
86 return "not equal: $one $two"
87 }
88
89 testConstraint hasLinks [expr {![catch {
90 file link link.file gorp.file
91 cd dir.dir
92 file link \
93 [file join linkinside.file] \
94 [file join inside.file]
95 cd ..
96 file link dir.link dir.dir
97 cd dir.dir
98 file link [file join dirinside.link] \
99 [file join dirinside.dir]
100 cd ..
101 }]}]
102
103 if {[testConstraint testsetplatform]} {
104 set platform [testgetplatform]
105 }
106
107 # ----------------------------------------------------------------------
108
109 test filesystem-1.0 {link normalisation} {hasLinks} {
110 string equal [file normalize gorp.file] [file normalize link.file]
111 } {0}
112 test filesystem-1.1 {link normalisation} {hasLinks} {
113 string equal [file normalize dir.dir] [file normalize dir.link]
114 } {0}
115 test filesystem-1.2 {link normalisation} {hasLinks unix} {
116 testPathEqual [file normalize [file join gorp.file foo]] \
117 [file normalize [file join link.file foo]]
118 } ok
119 test filesystem-1.3 {link normalisation} {hasLinks} {
120 testPathEqual [file normalize [file join dir.dir foo]] \
121 [file normalize [file join dir.link foo]]
122 } ok
123 test filesystem-1.4 {link normalisation} {hasLinks} {
124 testPathEqual [file normalize [file join dir.dir inside.file]] \
125 [file normalize [file join dir.link inside.file]]
126 } ok
127 test filesystem-1.5 {link normalisation} {hasLinks} {
128 testPathEqual [file normalize [file join dir.dir linkinside.file]] \
129 [file normalize [file join dir.dir linkinside.file]]
130 } ok
131 test filesystem-1.6 {link normalisation} {hasLinks} {
132 string equal [file normalize [file join dir.dir linkinside.file]] \
133 [file normalize [file join dir.link inside.file]]
134 } {0}
135 test filesystem-1.7 {link normalisation} {hasLinks unix} {
136 testPathEqual [file normalize [file join dir.link linkinside.file foo]] \
137 [file normalize [file join dir.dir inside.file foo]]
138 } ok
139 test filesystem-1.8 {link normalisation} {hasLinks} {
140 string equal [file normalize [file join dir.dir linkinside.filefoo]] \
141 [file normalize [file join dir.link inside.filefoo]]
142 } {0}
143 test filesystem-1.9 {link normalisation} -setup {
144 file delete -force dir.link
145 } -constraints {unix hasLinks} -body {
146 file link dir.link [file nativename dir.dir]
147 testPathEqual [file normalize [file join dir.dir linkinside.file foo]] \
148 [file normalize [file join dir.link inside.file foo]]
149 } -result ok
150 test filesystem-1.10 {link normalisation: double link} -constraints {
151 unix hasLinks
152 } -body {
153 file link dir2.link dir.link
154 testPathEqual [file normalize [file join dir.dir linkinside.file foo]] \
155 [file normalize [file join dir2.link inside.file foo]]
156 } -cleanup {
157 file delete dir2.link
158 } -result ok
159 makeDirectory dir2.file
160 test filesystem-1.11 {link normalisation: double link, back in tree} {unix hasLinks} {
161 file link dir2.link dir.link
162 file link [file join dir2.file dir2.link] [file join .. dir2.link]
163 testPathEqual [file normalize [file join dir.dir linkinside.file foo]] \
164 [file normalize [file join dir2.file dir2.link inside.file foo]]
165 } ok
166 test filesystem-1.12 {file new native path} {} {
167 for {set i 0} {$i < 10} {incr i} {
168 foreach f [lsort [glob -nocomplain -type l *]] {
169 catch {file readlink $f}
170 }
171 }
172 # If we reach here we've succeeded. We used to crash above.
173 expr {1}
174 } {1}
175 test filesystem-1.13 {file normalisation} {win} {
176 # This used to be broken
177 file normalize C:/thislongnamedoesntexist
178 } {C:/thislongnamedoesntexist}
179 test filesystem-1.14 {file normalisation} {win} {
180 # This used to be broken
181 file normalize c:/
182 } {C:/}
183 test filesystem-1.15 {file normalisation} {win} {
184 file normalize c:/../
185 } {C:/}
186 test filesystem-1.16 {file normalisation} {win} {
187 file normalize c:/.
188 } {C:/}
189 test filesystem-1.17 {file normalisation} {win} {
190 file normalize c:/..
191 } {C:/}
192 test filesystem-1.17.1 {file normalisation} {win} {
193 file normalize c:\\..
194 } {C:/}
195 test filesystem-1.18 {file normalisation} {win} {
196 file normalize c:/./
197 } {C:/}
198 test filesystem-1.19 {file normalisation} {win unusedDrive} {
199 file normalize ${drive}:/./../../..
200 } "${drive}:/"
201 test filesystem-1.20 {file normalisation} {win} {
202 file normalize //name/foo/../
203 } {//name/foo}
204 test filesystem-1.21 {file normalisation} {win} {
205 file normalize C:///foo/./
206 } {C:/foo}
207 test filesystem-1.22 {file normalisation} {win} {
208 file normalize //name/foo/.
209 } {//name/foo}
210 test filesystem-1.23 {file normalisation} {win} {
211 file normalize c:/./foo
212 } {C:/foo}
213 test filesystem-1.24 {file normalisation} {win unusedDrive} {
214 file normalize ${drive}:/./../../../a
215 } "${drive}:/a"
216 test filesystem-1.25 {file normalisation} {win unusedDrive} {
217 file normalize ${drive}:/./.././../../a
218 } "${drive}:/a"
219 test filesystem-1.25.1 {file normalisation} {win unusedDrive} {
220 file normalize ${drive}:/./.././..\\..\\a\\bb
221 } "${drive}:/a/bb"
222 test filesystem-1.26 {link normalisation: link and ..} -setup {
223 file delete -force dir2.link
224 } -constraints {hasLinks} -body {
225 set dir [file join dir2 foo bar]
226 file mkdir $dir
227 file link dir2.link [file join dir2 foo bar]
228 testPathEqual [file normalize [file join dir2 foo x]] \
229 [file normalize [file join dir2.link .. x]]
230 } -result ok
231 test filesystem-1.27 {file normalisation: up and down with ..} {
232 set dir [file join dir2 foo bar]
233 file mkdir $dir
234 set dir2 [file join dir2 .. dir2 foo .. foo bar]
235 list [testPathEqual [file normalize $dir] [file normalize $dir2]] \
236 [file exists $dir] [file exists $dir2]
237 } {ok 1 1}
238 test filesystem-1.28 {link normalisation: link with .. and ..} -setup {
239 file delete -force dir2.link
240 } -constraints {hasLinks} -body {
241 set dir [file join dir2 foo bar]
242 file mkdir $dir
243 set to [file join dir2 .. dir2 foo .. foo bar]
244 file link dir2.link $to
245 testPathEqual [file normalize [file join dir2 foo x]] \
246 [file normalize [file join dir2.link .. x]]
247 } -result ok
248 test filesystem-1.29 {link normalisation: link with ..} -setup {
249 file delete -force dir2.link
250 } -constraints {hasLinks} -body {
251 set dir [file join dir2 foo bar]
252 file mkdir $dir
253 set to [file join dir2 .. dir2 foo .. foo bar]
254 file link dir2.link $to
255 set res [file normalize [file join dir2.link x yyy z]]
256 if {[string match *..* $res]} {
257 return "$res must not contain '..'"
258 }
259 return "ok"
260 } -result {ok}
261 test filesystem-1.29.1 {link normalisation with two consecutive links} {hasLinks} {
262 testPathEqual [file normalize [file join dir.link dirinside.link abc]] \
263 [file normalize [file join dir.dir dirinside.dir abc]]
264 } ok
265 file delete -force dir2.file
266 file delete -force dir2.link
267 file delete -force link.file dir.link
268 file delete -force dir2
269 file delete -force [file join dir.dir dirinside.link]
270 removeFile [file join dir.dir inside.file]
271 removeDirectory [file join dir.dir dirinside.dir]
272 removeDirectory dir.dir
273 test filesystem-1.30 {normalisation of nonexistent user} -body {
274 file normalize ~noonewiththisname
275 } -returnCodes error -result {user "noonewiththisname" doesn't exist}
276 test filesystem-1.30.1 {normalisation of existing user} -body {
277 catch {file normalize ~$::tcl_platform(user)}
278 } -result {0}
279 test filesystem-1.30.2 {normalisation of nonexistent user specified as user@domain} -body {
280 file normalize ~nonexistentuser@nonexistentdomain
281 } -returnCodes error -result {user "nonexistentuser@nonexistentdomain" doesn't exist}
282 test filesystem-1.30.3 {file normalization should distinguish between ~ and ~user} -setup {
283 set oldhome $::env(HOME)
284 set olduserhome [file normalize ~$::tcl_platform(user)]
285 set ::env(HOME) [file join $oldhome temp]
286 } -cleanup {
287 set ::env(HOME) $oldhome
288 } -body {
289 list [string equal [file normalize ~] [file normalize $::env(HOME)]] \
290 [string equal $olduserhome [file normalize ~$::tcl_platform(user)]]
291 } -result {1 1}
292 test filesystem-1.31 {link normalisation: link near filesystem root} {testsetplatform} {
293 testsetplatform unix
294 file normalize /foo/../bar
295 } {/bar}
296 test filesystem-1.32 {link normalisation: link near filesystem root} {testsetplatform} {
297 testsetplatform unix
298 file normalize /../bar
299 } {/bar}
300 test filesystem-1.33 {link normalisation: link near filesystem root} {testsetplatform} {
301 testsetplatform windows
302 set res [file normalize C:/../bar]
303 if {[testConstraint unix]} {
304 # Some Unices go further in normalizing this -- not really a problem
305 # since this is a Windows test.
306 regexp {C:/bar$} $res res
307 }
308 set res
309 } {C:/bar}
310 if {[testConstraint testsetplatform]} {
311 testsetplatform $platform
312 }
313 test filesystem-1.34 {file normalisation with '/./'} -body {
314 file normalize /foo/bar/anc/./.tml
315 } -match regexp -result {^(?:(?!/\./).)*$}
316 test filesystem-1.35a {file normalisation with '/./'} -body {
317 file normalize /ffo/bar/anc/./foo/.tml
318 } -match regexp -result {^(?:(?!/\./).)*$}
319 test filesystem-1.35b {file normalisation with '/./'} {
320 llength [regexp -all foo [file normalize /ffo/bar/anc/./foo/.tml]]
321 } 1
322 test filesystem-1.36a {file normalisation with '/./'} -body {
323 file normalize /foo/bar/anc/././asdasd/.tml
324 } -match regexp -result {^(?:(?!/\./).)*$}
325 test filesystem-1.36b {file normalisation with '/./'} {
326 llength [regexp -all asdasd [file normalize /foo/bar/anc/././asdasd/.tml]]
327 } 1
328 test filesystem-1.37 {file normalisation with '/./'} -body {
329 set fname "/abc/./def/./ghi/./asda/.././.././asd/x/../../../../....."
330 file norm $fname
331 } -match regexp -result {^(?:[^/]|/(?:[^/]|$))+$}
332 test filesystem-1.38 {file normalisation with volume relative} -setup {
333 set dir [pwd]
334 } -constraints {win moreThanOneDrive notInCIenv} -body {
335 set path "[string range [lindex $drives 0] 0 1]foo"
336 cd [lindex $drives 1]
337 file norm $path
338 } -cleanup {
339 cd $dir
340 } -result "[lindex $drives 0]foo"
341 test filesystem-1.39 {file normalisation with volume relative} -setup {
342 set old [pwd]
343 } -constraints {win} -body {
344 set drv C:/
345 cd [lindex [glob -type d -dir $drv *] 0]
346 file norm [string range $drv 0 1]
347 } -cleanup {
348 cd $old
349 } -match regexp -result {.*[^/]}
350 test filesystem-1.40 {file normalisation with repeated separators} {
351 testPathEqual [file norm foo////bar] [file norm foo/bar]
352 } ok
353 test filesystem-1.41 {file normalisation with repeated separators} {win} {
354 testPathEqual [file norm foo\\\\\\bar] [file norm foo/bar]
355 } ok
356 test filesystem-1.42 {file normalisation .. beyond root (Bug 1379287)} {
357 testPathEqual [file norm /xxx/..] [file norm /]
358 } ok
359 test filesystem-1.42.1 {file normalisation .. beyond root (Bug 1379287)} {
360 testPathEqual [file norm /xxx/../] [file norm /]
361 } ok
362 test filesystem-1.43 {file normalisation .. beyond root (Bug 1379287)} {
363 testPathEqual [file norm /xxx/foo/../..] [file norm /]
364 } ok
365 test filesystem-1.43.1 {file normalisation .. beyond root (Bug 1379287)} {
366 testPathEqual [file norm /xxx/foo/../../] [file norm /]
367 } ok
368 test filesystem-1.44 {file normalisation .. beyond root (Bug 1379287)} {
369 testPathEqual [file norm /xxx/foo/../../bar] [file norm /bar]
370 } ok
371 test filesystem-1.45 {file normalisation .. beyond root (Bug 1379287)} {
372 testPathEqual [file norm /xxx/../../bar] [file norm /bar]
373 } ok
374 test filesystem-1.46 {file normalisation .. beyond root (Bug 1379287)} {
375 testPathEqual [file norm /xxx/../bar] [file norm /bar]
376 } ok
377 test filesystem-1.47 {file normalisation .. beyond root (Bug 1379287)} {
378 testPathEqual [file norm /..] [file norm /]
379 } ok
380 test filesystem-1.48 {file normalisation .. beyond root (Bug 1379287)} {
381 testPathEqual [file norm /../] [file norm /]
382 } ok
383 test filesystem-1.49 {file normalisation .. beyond root (Bug 1379287)} {
384 testPathEqual [file norm /.] [file norm /]
385 } ok
386 test filesystem-1.50 {file normalisation .. beyond root (Bug 1379287)} {
387 testPathEqual [file norm /./] [file norm /]
388 } ok
389 test filesystem-1.51 {file normalisation .. beyond root (Bug 1379287)} {
390 testPathEqual [file norm /../..] [file norm /]
391 } ok
392 test filesystem-1.51.1 {file normalisation .. beyond root (Bug 1379287)} {
393 testPathEqual [file norm /../../] [file norm /]
394 } ok
395 test filesystem-1.52 {bug f9f390d0fa: file join where strep is not canonical} -constraints unix -body {
396 set x //foo
397 file normalize $x
398 file join $x bar
399 } -result /foo/bar
400 test filesystem-1.52.1 {bug f9f390d0fa: file join where strep is not canonical} -body {
401 set x //foo
402 file normalize $x
403 file join $x
404 } -result /foo
405 test filesystem-1.53 {[Bug 3559678] - normalize when tail is empty} {
406 string match */ [file normalize [lindex [glob -dir [pwd] {{}}] 0]]
407 } 0
408 test filesystem-1.54 {[Bug ce3a211dcb] - normalize when tail is empty} -setup {
409 set save [pwd]
410 cd [set home [makeDirectory ce3a211dcb]]
411 makeDirectory A $home
412 cd [lindex [glob */] 0]
413 } -body {
414 string match */A [pwd]
415 } -cleanup {
416 cd $home
417 removeDirectory A $home
418 cd $save
419 removeDirectory ce3a211dcb
420 } -result 1
421
422 test filesystem-2.0 {new native path} {unix} {
423 foreach f [lsort [glob -nocomplain /usr/bin/c*]] {
424 catch {file readlink $f}
425 }
426 # If we reach here we've succeeded. We used to crash above.
427 return ok
428 } ok
429
430 # Make sure the testfilesystem hasn't been registered.
431 if {[testConstraint testfilesystem]} {
432 proc resetfs {} {
433 while {![catch {testfilesystem 0}]} {}
434 }
435 }
436
437 test filesystem-3.1 {Tcl_FSRegister & Tcl_FSUnregister} testfilesystem {
438 set result {}
439 lappend result [testfilesystem 1]
440 lappend result [testfilesystem 0]
441 lappend result [catch {testfilesystem 0} msg] $msg
442 } {registered unregistered 1 failed}
443 test filesystem-3.3 {Tcl_FSRegister} testfilesystem {
444 testfilesystem 1
445 testfilesystem 1
446 testfilesystem 0
447 testfilesystem 0
448 } {unregistered}
449 test filesystem-3.4 {Tcl_FSRegister} -constraints testfilesystem -body {
450 testfilesystem 1
451 file system bar
452 } -cleanup {
453 testfilesystem 0
454 } -result {reporting}
455 test filesystem-3.5 {Tcl_FSUnregister} testfilesystem {
456 resetfs
457 lindex [file system bar] 0
458 } {native}
459
460 test filesystem-4.0 {testfilesystem} -constraints testfilesystem -body {
461 testfilesystem 1
462 set filesystemReport {}
463 file exists foo
464 testfilesystem 0
465 return $filesystemReport
466 } -match glob -result {*{access foo}}
467 test filesystem-4.1 {testfilesystem} -constraints testfilesystem -body {
468 testfilesystem 1
469 set filesystemReport {}
470 catch {file stat foo bar}
471 testfilesystem 0
472 return $filesystemReport
473 } -match glob -result {*{stat foo}}
474 test filesystem-4.2 {testfilesystem} -constraints testfilesystem -body {
475 testfilesystem 1
476 set filesystemReport {}
477 catch {file lstat foo bar}
478 testfilesystem 0
479 return $filesystemReport
480 } -match glob -result {*{lstat foo}}
481 test filesystem-4.3 {testfilesystem} -constraints testfilesystem -body {
482 testfilesystem 1
483 set filesystemReport {}
484 catch {glob *}
485 testfilesystem 0
486 return $filesystemReport
487 } -match glob -result {*{matchindirectory *}*}
488
489 test filesystem-5.1 {cache and ~} -constraints testfilesystem -setup {
490 set orig $::env(HOME)
491 } -body {
492 set ::env(HOME) /foo/bar/blah
493 set testdir ~
494 set res1 "Parent of ~ (/foo/bar/blah) is [file dirname $testdir]"
495 set ::env(HOME) /a/b/c
496 set res2 "Parent of ~ (/a/b/c) is [file dirname $testdir]"
497 list $res1 $res2
498 } -cleanup {
499 set ::env(HOME) $orig
500 } -match regexp -result {{Parent of ~ \(/foo/bar/blah\) is ([a-zA-Z]:)?(/cygwin)?(/foo/bar|foo:bar)} {Parent of ~ \(/a/b/c\) is ([a-zA-Z]:)?(/cygwin)?(/a/b|a:b)}}
501
502 test filesystem-6.1 {empty file name} -returnCodes error -body {
503 open ""
504 } -result {couldn't open "": no such file or directory}
505 test filesystem-6.2 {empty file name} -returnCodes error -body {
506 file stat "" arr
507 } -result {could not read "": no such file or directory}
508 test filesystem-6.3 {empty file name} -returnCodes error -body {
509 file atime ""
510 } -result {could not read "": no such file or directory}
511 test filesystem-6.4 {empty file name} -returnCodes error -body {
512 file attributes ""
513 } -result {could not read "": no such file or directory}
514 test filesystem-6.5 {empty file name} -returnCodes error -body {
515 file copy "" ""
516 } -result {error copying "": no such file or directory}
517 test filesystem-6.6 {empty file name} {file delete ""} {}
518 test filesystem-6.7 {empty file name} {file dirname ""} .
519 test filesystem-6.8 {empty file name} {file executable ""} 0
520 test filesystem-6.9 {empty file name} {file exists ""} 0
521 test filesystem-6.10 {empty file name} {file extension ""} {}
522 test filesystem-6.11 {empty file name} {file isdirectory ""} 0
523 test filesystem-6.12 {empty file name} {file isfile ""} 0
524 test filesystem-6.13 {empty file name} {file join ""} {}
525 test filesystem-6.14 {empty file name} -returnCodes error -body {
526 file link ""
527 } -result {could not read link "": no such file or directory}
528 test filesystem-6.15 {empty file name} -returnCodes error -body {
529 file lstat "" arr
530 } -result {could not read "": no such file or directory}
531 test filesystem-6.16 {empty file name} -returnCodes error -body {
532 file mtime ""
533 } -result {could not read "": no such file or directory}
534 test filesystem-6.17 {empty file name} -returnCodes error -body {
535 file mtime "" 0
536 } -result {could not read "": no such file or directory}
537 test filesystem-6.18 {empty file name} -returnCodes error -body {
538 file mkdir ""
539 } -result {can't create directory "": no such file or directory}
540 test filesystem-6.19 {empty file name} {file nativename ""} {}
541 test filesystem-6.20 {empty file name} {file normalize ""} {}
542 test filesystem-6.21 {empty file name} {file owned ""} 0
543 test filesystem-6.22 {empty file name} {file pathtype ""} relative
544 test filesystem-6.23 {empty file name} {file readable ""} 0
545 test filesystem-6.24 {empty file name} -returnCodes error -body {
546 file readlink ""
547 } -result {could not read link "": no such file or directory}
548 test filesystem-6.25 {empty file name} -returnCodes error -body {
549 file rename "" ""
550 } -result {error renaming "": no such file or directory}
551 test filesystem-6.26 {empty file name} {file rootname ""} {}
552 test filesystem-6.27 {empty file name} -returnCodes error -body {
553 file separator ""
554 } -result {unrecognised path}
555 test filesystem-6.28 {empty file name} -returnCodes error -body {
556 file size ""
557 } -result {could not read "": no such file or directory}
558 test filesystem-6.29 {empty file name} {file split ""} {}
559 test filesystem-6.30 {empty file name} -returnCodes error -body {
560 file system ""
561 } -result {unrecognised path}
562 test filesystem-6.31 {empty file name} {file tail ""} {}
563 test filesystem-6.32 {empty file name} -returnCodes error -body {
564 file type ""
565 } -result {could not read "": no such file or directory}
566 test filesystem-6.33 {empty file name} {file writable ""} 0
567 test filesystem-6.34 {file name with (invalid) nul character} {
568 list [catch "open foo\x00" msg] $msg
569 } [list 1 "couldn't open \"foo\x00\": filename is invalid on this platform"]
570
571 # Make sure the testfilesystem hasn't been registered.
572 if {[testConstraint testfilesystem]} {
573 while {![catch {testfilesystem 0}]} {}
574 }
575
576 test filesystem-7.1.1 {load from vfs} -setup {
577 set dir [pwd]
578 } -constraints {win testsimplefilesystem loaddll} -body {
579 # This may cause a crash on exit
580 if {[file dirname $::ddelib] ne "."} {
581 cd [file dirname $::ddelib]
582 } else {
583 cd [file dirname [info nameofexecutable]]
584 }
585 if {![file exists [file tail $::ddelib]]} {
586 ::tcltest::Skip "no-ddelib"
587 }
588 testsimplefilesystem 1
589 # This loads dde via a complex copy-to-temp operation
590 load simplefs:/[file tail $::ddelib] Dde
591 testsimplefilesystem 0
592 return ok
593 # The real result of this test is what happens when Tcl exits.
594 } -cleanup {
595 cd $dir
596 } -result ok
597 test filesystem-7.1.2 {load from vfs, and then unload again} -setup {
598 set dir [pwd]
599 } -constraints {win testsimplefilesystem loaddll} -body {
600 # This may cause a crash on exit
601 if {[file dirname $::reglib] ne "."} {
602 cd [file dirname $::reglib]
603 } else {
604 cd [file dirname [info nameofexecutable]]
605 }
606 if {![file exists [file tail $::reglib]]} {
607 ::tcltest::Skip "no-reglib"
608 }
609 testsimplefilesystem 1
610 # This loads reg via a complex copy-to-temp operation
611 load simplefs:/[file tail $::reglib] Registry
612 unload simplefs:/[file tail $::reglib]
613 testsimplefilesystem 0
614 return ok
615 # The real result of this test is what happens when Tcl exits.
616 } -cleanup {
617 cd $dir
618 } -result ok
619 test filesystem-7.2 {cross-filesystem copy from vfs maintains mtime} -setup {
620 set dir [pwd]
621 cd [tcltest::temporaryDirectory]
622 } -constraints testsimplefilesystem -body {
623 # We created this file several tests ago.
624 set origtime [file mtime gorp.file]
625 set res [file exists gorp.file]
626 testsimplefilesystem 1
627 file delete -force theCopy
628 file copy simplefs:/gorp.file theCopy
629 testsimplefilesystem 0
630 set newtime [file mtime theCopy]
631 lappend res [expr {$origtime == $newtime ? 1 : "$origtime != $newtime"}]
632 } -cleanup {
633 catch {file delete theCopy}
634 cd $dir
635 } -result {1 1}
636 test filesystem-7.3 {glob in simplefs} -setup {
637 set dir [pwd]
638 cd [tcltest::temporaryDirectory]
639 } -constraints testsimplefilesystem -body {
640 file mkdir simpledir
641 close [open [file join simpledir simplefile] w]
642 testsimplefilesystem 1
643 glob -nocomplain -dir simplefs:/simpledir *
644 } -cleanup {
645 catch {testsimplefilesystem 0}
646 file delete -force simpledir
647 cd $dir
648 } -result {simplefs:/simpledir/simplefile}
649 test filesystem-7.3.1 {glob in simplefs: no path/dir} -setup {
650 set dir [pwd]
651 cd [tcltest::temporaryDirectory]
652 } -constraints testsimplefilesystem -body {
653 file mkdir simpledir
654 close [open [file join simpledir simplefile] w]
655 testsimplefilesystem 1
656 set res [glob -nocomplain simplefs:/simpledir/*]
657 lappend res {*}[glob -nocomplain simplefs:/simpledir]
658 } -cleanup {
659 catch {testsimplefilesystem 0}
660 file delete -force simpledir
661 cd $dir
662 } -result {simplefs:/simpledir/simplefile simplefs:/simpledir}
663 test filesystem-7.3.2 {glob in simplefs: no path/dir, no subdirectory} -setup {
664 set dir [pwd]
665 cd [tcltest::temporaryDirectory]
666 } -constraints testsimplefilesystem -body {
667 file mkdir simpledir
668 close [open [file join simpledir simplefile] w]
669 testsimplefilesystem 1
670 glob -nocomplain simplefs:/s*
671 } -cleanup {
672 catch {testsimplefilesystem 0}
673 file delete -force simpledir
674 cd $dir
675 } -match glob -result ?*
676 test filesystem-7.3.3 {glob in simplefs: pattern is a volume} -setup {
677 set dir [pwd]
678 cd [tcltest::temporaryDirectory]
679 } -constraints testsimplefilesystem -body {
680 file mkdir simpledir
681 close [open [file join simpledir simplefile] w]
682 testsimplefilesystem 1
683 glob -nocomplain simplefs:/*
684 } -cleanup {
685 testsimplefilesystem 0
686 file delete -force simpledir
687 cd $dir
688 } -match glob -result ?*
689 test filesystem-7.4 {cross-filesystem file copy with -force} -setup {
690 set dir [pwd]
691 cd [tcltest::temporaryDirectory]
692 set fout [open [file join simplefile] w]
693 puts -nonewline $fout "1234567890"
694 close $fout
695 testsimplefilesystem 1
696 } -constraints testsimplefilesystem -body {
697 # First copy should succeed
698 set res [catch {file copy simplefs:/simplefile file2} err]
699 lappend res $err
700 # Second copy should fail (no -force)
701 lappend res [catch {file copy simplefs:/simplefile file2} err]
702 lappend res $err
703 # Third copy should succeed (-force)
704 lappend res [catch {file copy -force simplefs:/simplefile file2} err]
705 lappend res $err
706 lappend res [file exists file2]
707 } -cleanup {
708 catch {testsimplefilesystem 0}
709 file delete -force simplefile
710 file delete -force file2
711 cd $dir
712 } -result {0 {} 1 {error copying "simplefs:/simplefile" to "file2": file already exists} 0 {} 1}
713 test filesystem-7.5 {cross-filesystem file copy with -force} -setup {
714 set dir [pwd]
715 cd [tcltest::temporaryDirectory]
716 set fout [open [file join simplefile] w]
717 puts -nonewline $fout "1234567890"
718 close $fout
719 testsimplefilesystem 1
720 } -constraints {testsimplefilesystem unix} -body {
721 # First copy should succeed
722 set res [catch {file copy simplefs:/simplefile file2} err]
723 lappend res $err
724 file attributes file2 -permissions 0o000
725 # Second copy should fail (no -force)
726 lappend res [catch {file copy simplefs:/simplefile file2} err]
727 lappend res $err
728 # Third copy should succeed (-force)
729 lappend res [catch {file copy -force simplefs:/simplefile file2} err]
730 lappend res $err
731 lappend res [file exists file2]
732 } -cleanup {
733 testsimplefilesystem 0
734 file delete -force simplefile
735 file delete -force file2
736 cd $dir
737 } -result {0 {} 1 {error copying "simplefs:/simplefile" to "file2": file already exists} 0 {} 1}
738 test filesystem-7.6 {cross-filesystem dir copy with -force} -setup {
739 set dir [pwd]
740 cd [tcltest::temporaryDirectory]
741 file delete -force simpledir
742 file mkdir simpledir
743 file mkdir dir2
744 set fout [open [file join simpledir simplefile] w]
745 puts -nonewline $fout "1234567890"
746 close $fout
747 testsimplefilesystem 1
748 } -constraints testsimplefilesystem -body {
749 # First copy should succeed
750 set res [catch {file copy simplefs:/simpledir dir2} err]
751 lappend res $err
752 # Second copy should fail (no -force)
753 lappend res [catch {file copy simplefs:/simpledir dir2} err]
754 lappend res $err
755 # Third copy should succeed (-force)
756 lappend res [catch {file copy -force simplefs:/simpledir dir2} err]
757 lappend res $err
758 lappend res [file exists [file join dir2 simpledir]] \
759 [file exists [file join dir2 simpledir simplefile]]
760 } -cleanup {
761 testsimplefilesystem 0
762 file delete -force simpledir
763 file delete -force dir2
764 cd $dir
765 } -result {0 {} 1 {error copying "simplefs:/simpledir" to "dir2/simpledir": file already exists} 0 {} 1 1}
766 test filesystem-7.7 {cross-filesystem dir copy with -force} -setup {
767 set dir [pwd]
768 cd [tcltest::temporaryDirectory]
769 file delete -force simpledir
770 file mkdir simpledir
771 file mkdir dir2
772 set fout [open [file join simpledir simplefile] w]
773 puts -nonewline $fout "1234567890"
774 close $fout
775 testsimplefilesystem 1
776 } -constraints {testsimplefilesystem unix} -body {
777 # First copy should succeed
778 set res [catch {file copy simplefs:/simpledir dir2} err]
779 lappend res $err
780 # Second copy should fail (no -force)
781 lappend res [catch {file copy simplefs:/simpledir dir2} err]
782 lappend res $err
783 # Third copy should succeed (-force)
784 # I've noticed on some Unices that this only succeeds intermittently (some
785 # runs work, some fail). This needs examining further.
786 lappend res [catch {file copy -force simplefs:/simpledir dir2} err]
787 lappend res $err
788 lappend res [file exists [file join dir2 simpledir]] \
789 [file exists [file join dir2 simpledir simplefile]]
790 } -cleanup {
791 testsimplefilesystem 0
792 file delete -force simpledir
793 file delete -force dir2
794 cd $dir
795 } -result {0 {} 1 {error copying "simplefs:/simpledir" to "dir2/simpledir": file already exists} 0 {} 1 1}
796 removeFile gorp.file
797 test filesystem-7.8 {vfs cd} -setup {
798 set dir [pwd]
799 cd [tcltest::temporaryDirectory]
800 file delete -force simpledir
801 file mkdir simpledir
802 testsimplefilesystem 1
803 } -constraints testsimplefilesystem -body {
804 # This can variously cause an infinite loop or simply have no effect at
805 # all (before certain bugs were fixed, of course).
806 cd simplefs:/simpledir
807 pwd
808 } -cleanup {
809 cd [tcltest::temporaryDirectory]
810 testsimplefilesystem 0
811 file delete -force simpledir
812 cd $dir
813 } -result {simplefs:/simpledir}
814
815 test filesystem-8.1 {relative path objects and caching of pwd} -setup {
816 set dir [pwd]
817 cd [tcltest::temporaryDirectory]
818 } -body {
819 makeDirectory abc
820 makeDirectory def
821 makeFile "contents" [file join abc foo]
822 cd abc
823 set f "foo"
824 set res {}
825 lappend res [file exists $f]
826 lappend res [file exists $f]
827 cd ..
828 cd def
829 # If we haven't cleared the object's cwd cache, Tcl will think it still
830 # exists.
831 lappend res [file exists $f]
832 lappend res [file exists $f]
833 } -cleanup {
834 removeFile [file join abc foo]
835 removeDirectory abc
836 removeDirectory def
837 cd $dir
838 } -result {1 1 0 0}
839 test filesystem-8.2 {relative path objects and use of pwd} -setup {
840 set origdir [pwd]
841 cd [tcltest::temporaryDirectory]
842 } -body {
843 set dir "abc"
844 makeDirectory $dir
845 makeFile "contents" [file join abc foo]
846 cd $dir
847 file exists [lindex [glob *] 0]
848 } -cleanup {
849 cd [tcltest::temporaryDirectory]
850 removeFile [file join abc foo]
851 removeDirectory abc
852 cd $origdir
853 } -result 1
854 test filesystem-8.3 {path objects and empty string} {
855 set anchor ""
856 set dst foo
857 set res $dst
858 set yyy [file split $anchor]
859 set dst [file join $anchor $dst]
860 lappend res $dst $yyy
861 } {foo foo {}}
862
863 proc TestFind1 {d f} {
864 set r1 [file exists [file join $d $f]]
865 lappend res "[file join $d $f] found: $r1"
866 lappend res "is dir a dir? [file isdirectory $d]"
867 set r2 [file exists [file join $d $f]]
868 lappend res "[file join $d $f] found: $r2"
869 return $res
870 }
871 proc TestFind2 {d f} {
872 set r1 [file exists [file join $d $f]]
873 lappend res "[file join $d $f] found: $r1"
874 lappend res "is dir a dir? [file isdirectory [file join $d]]"
875 set r2 [file exists [file join $d $f]]
876 lappend res "[file join $d $f] found: $r2"
877 return $res
878 }
879
880 test filesystem-9.1 {path objects and join and object rep} -setup {
881 set origdir [pwd]
882 cd [tcltest::temporaryDirectory]
883 } -body {
884 file mkdir [file join a b c]
885 TestFind1 a [file join b . c]
886 } -cleanup {
887 file delete -force a
888 cd $origdir
889 } -result {{a/b/./c found: 1} {is dir a dir? 1} {a/b/./c found: 1}}
890 test filesystem-9.2 {path objects and join and object rep} -setup {
891 set origdir [pwd]
892 cd [tcltest::temporaryDirectory]
893 } -body {
894 file mkdir [file join a b c]
895 TestFind2 a [file join b . c]
896 } -cleanup {
897 file delete -force a
898 cd $origdir
899 } -result {{a/b/./c found: 1} {is dir a dir? 1} {a/b/./c found: 1}}
900 test filesystem-9.2.1 {path objects and join and object rep} -setup {
901 set origdir [pwd]
902 cd [tcltest::temporaryDirectory]
903 } -body {
904 file mkdir [file join a b c]
905 TestFind2 a [file join b .]
906 } -cleanup {
907 file delete -force a
908 cd $origdir
909 } -result {{a/b/. found: 1} {is dir a dir? 1} {a/b/. found: 1}}
910 test filesystem-9.3 {path objects and join and object rep} -setup {
911 set origdir [pwd]
912 cd [tcltest::temporaryDirectory]
913 } -body {
914 file mkdir [file join a b c]
915 TestFind1 a [file join b .. b c]
916 } -cleanup {
917 file delete -force a
918 cd $origdir
919 } -result {{a/b/../b/c found: 1} {is dir a dir? 1} {a/b/../b/c found: 1}}
920 test filesystem-9.4 {path objects and join and object rep} -setup {
921 set origdir [pwd]
922 cd [tcltest::temporaryDirectory]
923 } -body {
924 file mkdir [file join a b c]
925 TestFind2 a [file join b .. b c]
926 } -cleanup {
927 file delete -force a
928 cd $origdir
929 } -result {{a/b/../b/c found: 1} {is dir a dir? 1} {a/b/../b/c found: 1}}
930 test filesystem-9.5 {path objects and file tail and object rep} -setup {
931 set origdir [pwd]
932 cd [tcltest::temporaryDirectory]
933 } -body {
934 file mkdir dgp
935 close [open dgp/test w]
936 foreach relative [glob -nocomplain [file join * test]] {
937 set absolute [file join [pwd] $relative]
938 set res [list [file tail $absolute] "test"]
939 }
940 return $res
941 } -cleanup {
942 file delete -force dgp
943 cd $origdir
944 } -result {test test}
945 test filesystem-9.6 {path objects and file tail and object rep} win {
946 set res {}
947 set p "C:\\toto"
948 lappend res [file join $p toto]
949 file isdirectory $p
950 lappend res [file join $p toto]
951 } {C:/toto/toto C:/toto/toto}
952 test filesystem-9.7 {path objects and glob and file tail and tilde} -setup {
953 set res {}
954 set origdir [pwd]
955 cd [tcltest::temporaryDirectory]
956 } -body {
957 file mkdir tilde
958 close [open tilde/~testNotExist w]
959 cd tilde
960 set file [lindex [glob *test*] 0]
961 lappend res [file exists $file] [catch {file tail $file} r] $r
962 lappend res $file
963 lappend res [file exists $file] [catch {file tail $file} r] $r
964 lappend res [catch {file tail $file} r] $r
965 } -cleanup {
966 cd [tcltest::temporaryDirectory]
967 file delete -force tilde
968 cd $origdir
969 } -result {0 1 {user "testNotExist" doesn't exist} ~testNotExist 0 1 {user "testNotExist" doesn't exist} 1 {user "testNotExist" doesn't exist}}
970 test filesystem-9.8 {path objects and glob and file tail and tilde} -setup {
971 set res {}
972 set origdir [pwd]
973 cd [tcltest::temporaryDirectory]
974 } -body {
975 file mkdir tilde
976 close [open tilde/~testNotExist w]
977 cd tilde
978 set file1 [lindex [glob *test*] 0]
979 set file2 "~testNotExist"
980 lappend res $file1 $file2
981 lappend res [catch {file tail $file1} r] $r
982 lappend res [catch {file tail $file2} r] $r
983 } -cleanup {
984 cd [tcltest::temporaryDirectory]
985 file delete -force tilde
986 cd $origdir
987 } -result {~testNotExist ~testNotExist 1 {user "testNotExist" doesn't exist} 1 {user "testNotExist" doesn't exist}}
988 test filesystem-9.9 {path objects and glob and file tail and tilde} -setup {
989 set res {}
990 set origdir [pwd]
991 cd [tcltest::temporaryDirectory]
992 } -body {
993 file mkdir tilde
994 close [open tilde/~testNotExist w]
995 cd tilde
996 set file1 [lindex [glob *test*] 0]
997 set file2 "~testNotExist"
998 lappend res [catch {file exists $file1} r] $r
999 lappend res [catch {file exists $file2} r] $r
1000 lappend res [string equal $file1 $file2]
1001 } -cleanup {
1002 cd [tcltest::temporaryDirectory]
1003 file delete -force tilde
1004 cd $origdir
1005 } -result {0 0 0 0 1}
1006
1007 # ----------------------------------------------------------------------
1008
1009 test filesystem-10.1 {Bug 3414754} {
1010 string match */ [file join [pwd] foo/]
1011 } 0
1012
1013 cleanupTests
1014 unset -nocomplain drive drives
1015 }
1016 namespace delete ::tcl::test::fileSystem
1017 return
1018
1019 # Local Variables:
1020 # mode: tcl
1021 # End: