Debian Codegraph @

tests/fCmd.test

raw
1 # This file tests the tclFCmd.c file.
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) 1996-1997 Sun Microsystems, Inc.
8 # Copyright (c) 1999 Scriptics Corporation.
9 #
10 # See the file "license.terms" for information on usage and redistribution of
11 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
13 if {"::tcltest" ni [namespace children]} {
14 package require tcltest 2.5
15 namespace import -force ::tcltest::*
16 }
17
18 ::tcltest::loadTestedCommands
19 catch [list package require -exact Tcltest [info patchlevel]]
20
21 cd [temporaryDirectory]
22
23 testConstraint testsetplatform [llength [info commands testsetplatform]]
24 testConstraint testchmod [llength [info commands testchmod]]
25 testConstraint winVista 0
26 testConstraint win2000orXP 0
27 testConstraint winLessThan10 0
28 # Don't know how to determine this constraint correctly
29 testConstraint notNetworkFilesystem 0
30 testConstraint reg 0
31 if {[testConstraint win]} {
32 if {[catch {
33 # Is the registry extension already static to this shell?
34 try {
35 load {} Registry
36 set ::reglib {}
37 } on error {} {
38 # try the location given to use on the commandline to tcltest
39 ::tcltest::loadTestedCommands
40 load $::reglib Registry
41 }
42 testConstraint reg 1
43 } regError]} {
44 catch {package require registry; testConstraint reg 1}
45 }
46 }
47
48 # File permissions broken on wsl without some "exotic" wsl configuration
49 testConstraint notWsl [expr {[llength [array names ::env *WSL*]] == 0}]
50
51 set tmpspace /tmp;# default value
52 # Find a group that exists on this Unix system, or else skip tests that
53 # require Unix groups.
54 testConstraint foundGroup [expr {![testConstraint unix]}]
55 if {[testConstraint unix]} {
56 catch {
57 set groupList [exec groups]
58 set group [lindex $groupList 0]
59 testConstraint foundGroup 1
60 }
61
62 proc dev dir {
63 file stat $dir stat
64 return $stat(dev)
65 }
66
67 if {[catch {makeDirectory tcl[pid] /tmp} tmpspace] == 0} {
68 testConstraint xdev [expr {([dev .] != [dev $tmpspace])}]
69 }
70 }
71
72 # Also used in winFCmd...
73 if {[testConstraint win] && [testConstraint nt]} {
74 if {$::tcl_platform(osVersion) >= 5.0} {
75 if {$::tcl_platform(osVersion) < 10.0} {
76 testConstraint winLessThan10 1
77 }
78 if {$::tcl_platform(osVersion) >= 6.0} {
79 testConstraint winVista 1
80 } else {
81 testConstraint win2000orXP 1
82 }
83 }
84 }
85
86 testConstraint darwin9 [expr {
87 [testConstraint unix]
88 && $tcl_platform(os) eq "Darwin"
89 && [package vsatisfies 1.$::tcl_platform(osVersion) 1.9]
90 }]
91 testConstraint notDarwin9 [expr {![testConstraint darwin9]}]
92 testConstraint notContinuousIntegration [expr {![info exists ::env(CI)]}]
93
94 testConstraint fileSharing 0
95 testConstraint notFileSharing 1
96 testConstraint linkFile 1
97 testConstraint linkDirectory 1
98
99 # Several tests require need to match results against the Unix username
100 set user {}
101 if {[testConstraint unix]} {
102 catch {
103 set user [exec whoami]
104 }
105 if {$user eq ""} {
106 catch {
107 regexp {^[^(]*\(([^)]*)\)} [exec id] -> user
108 }
109 }
110 if {$user eq ""} {
111 set user "root"
112 }
113 }
114
115 proc createfile {file {string a}} {
116 set f [open $file w]
117 puts -nonewline $f $string
118 close $f
119 return $string
120 }
121
122 #
123 # checkcontent --
124 #
125 # Ensures that file "file" contains only the string "matchString" returns 0
126 # if the file does not exist, or has a different content
127 #
128 proc checkcontent {file matchString} {
129 try {
130 set f [open $file]
131 set fileString [read $f]
132 close $f
133 } on error {} {
134 return 0
135 }
136 return [string match $matchString $fileString]
137 }
138
139 proc openup {path} {
140 testchmod 0o777 $path
141 if {[file isdirectory $path]} {
142 catch {
143 foreach p [glob -directory $path *] {
144 openup $p
145 }
146 }
147 }
148 }
149
150 proc cleanup {args} {
151 set wd [list .]
152 foreach p [concat $wd $args] {
153 set x ""
154 catch {
155 set x [glob -directory $p tf* td*]
156 }
157 foreach file $x {
158 if {
159 [catch {file delete -force -- $file}]
160 && [testConstraint testchmod]
161 } then {
162 catch {openup $file}
163 catch {file delete -force -- $file}
164 }
165 }
166 }
167 }
168
169 proc contents {file} {
170 set f [open $file]
171 set r [read $f]
172 close $f
173 return $r
174 }
175
176
177 set root [lindex [file split [pwd]] 0]
178
179 # A really long file name.
180 # Length of long is 1216 chars, which should be greater than any static buffer
181 # or allowable filename.
182
183 set long "abcdefghihjllmnopqrstuvwxyz01234567890"
184 append long $long
185 append long $long
186 append long $long
187 append long $long
188 append long $long
189
190 test fCmd-1.1 {TclFileRenameCmd} -constraints {notRoot} -setup {
191 cleanup
192 } -body {
193 createfile tf1
194 file rename tf1 tf2
195 glob tf*
196 } -result {tf2}
197
198 test fCmd-2.1 {TclFileCopyCmd} -constraints {notRoot} -setup {
199 cleanup
200 } -body {
201 createfile tf1
202 file copy tf1 tf2
203 lsort [glob tf*]
204 } -result {tf1 tf2}
205
206 test fCmd-3.1 {FileCopyRename: FileForceOption fails} -constraints {notRoot} -body {
207 file rename -xyz
208 } -returnCodes error -result {bad option "-xyz": must be -force or --}
209 test fCmd-3.2 {FileCopyRename: not enough args} -constraints {notRoot} -body {
210 file rename xyz
211 } -returnCodes error -result {wrong # args: should be "file rename ?-option value ...? source ?source ...? target"}
212 test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
213 file rename xyz ~_totally_bogus_user
214 } -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
215 test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} -setup {
216 cleanup
217 } -constraints {notRoot} -returnCodes error -body {
218 file copy tf1 ~
219 } -result {error copying "tf1": no such file or directory}
220 test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} -setup {
221 cleanup
222 } -constraints {notRoot} -returnCodes error -body {
223 file rename tf1 tf2 tf3
224 } -result {error renaming: target "tf3" is not a directory}
225 test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} -setup {
226 cleanup
227 } -constraints {notRoot} -returnCodes error -body {
228 createfile tf3
229 file rename tf1 tf2 tf3
230 } -result {error renaming: target "tf3" is not a directory}
231 test fCmd-3.7 {FileCopyRename: target exists & is directory} -setup {
232 cleanup
233 } -constraints {notRoot} -body {
234 file mkdir td1
235 createfile tf1 tf1
236 file rename tf1 td1
237 contents [file join td1 tf1]
238 } -result {tf1}
239 test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} -setup {
240 cleanup
241 } -constraints {notRoot} -returnCodes error -body {
242 file rename tf1 tf2 tf3
243 } -result {error renaming: target "tf3" is not a directory}
244 test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} -setup {
245 cleanup
246 } -constraints {notRoot} -returnCodes error -body {
247 file copy -force -- tf1 tf2 tf3
248 } -result {error copying: target "tf3" is not a directory}
249 test fCmd-3.10 {FileCopyRename: just 2 arguments} -constraints notRoot -setup {
250 cleanup
251 } -body {
252 createfile tf1 tf1
253 file rename tf1 tf2
254 contents tf2
255 } -result {tf1}
256 test fCmd-3.11 {FileCopyRename: just 2 arguments} -constraints notRoot -setup {
257 cleanup
258 } -body {
259 createfile tf1 tf1
260 file rename -force -force -- tf1 tf2
261 contents tf2
262 } -result {tf1}
263 test fCmd-3.12 {FileCopyRename: move each source: 1 source} -setup {
264 cleanup
265 } -constraints {notRoot} -body {
266 createfile tf1 tf1
267 file mkdir td1
268 file rename tf1 td1
269 contents [file join td1 tf1]
270 } -result {tf1}
271 test fCmd-3.13 {FileCopyRename: move each source: multiple sources} -setup {
272 cleanup
273 } -constraints {notRoot} -body {
274 createfile tf1 tf1
275 createfile tf2 tf2
276 createfile tf3 tf3
277 createfile tf4 tf4
278 file mkdir td1
279 file rename tf1 tf2 tf3 tf4 td1
280 list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
281 [contents [file join td1 tf3]] [contents [file join td1 tf4]]
282 } -result {tf1 tf2 tf3 tf4}
283 test fCmd-3.14 {FileCopyRename: FileBasename fails} -setup {
284 cleanup
285 } -constraints {notRoot} -returnCodes error -body {
286 file mkdir td1
287 file rename ~_totally_bogus_user td1
288 } -result {user "_totally_bogus_user" doesn't exist}
289 test fCmd-3.15 {FileCopyRename: source[0] == '\x00'} -setup {
290 cleanup
291 } -constraints {notRoot unixOrWin} -returnCodes error -body {
292 file mkdir td1
293 file rename / td1
294 } -result {error renaming "/" to "td1": file already exists}
295 test fCmd-3.16 {FileCopyRename: break on first error} -setup {
296 cleanup
297 } -constraints {notRoot} -returnCodes error -body {
298 createfile tf1
299 createfile tf2
300 createfile tf3
301 createfile tf4
302 file mkdir td1
303 createfile [file join td1 tf3]
304 file rename tf1 tf2 tf3 tf4 td1
305 } -result [subst {error renaming "tf3" to "[file join td1 tf3]": file already exists}]
306
307 test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} -setup {
308 cleanup
309 } -constraints {notRoot} -body {
310 file mkdir td1
311 glob td*
312 } -result {td1}
313 test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} -setup {
314 cleanup
315 } -constraints {notRoot} -body {
316 file mkdir td1 td2 td3
317 lsort [glob td*]
318 } -result {td1 td2 td3}
319 test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} -setup {
320 cleanup
321 } -constraints {notRoot} -body {
322 createfile tf1
323 catch {file mkdir td1 td2 tf1 td3 td4}
324 glob td1 td2 tf1 td3 td4
325 } -result {td1 td2 tf1}
326 test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} -setup {
327 cleanup
328 } -constraints {notRoot} -returnCodes error -body {
329 file mkdir ~_totally_bogus_user
330 } -result {user "_totally_bogus_user" doesn't exist}
331 test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\x00'} -setup {
332 cleanup
333 } -constraints {notRoot} -returnCodes error -body {
334 file mkdir ""
335 } -result {can't create directory "": no such file or directory}
336 test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} -setup {
337 cleanup
338 } -constraints {notRoot} -body {
339 file mkdir td1
340 glob td1
341 } -result {td1}
342 test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} -setup {
343 cleanup
344 } -constraints {notRoot} -body {
345 file mkdir [file join td1 td2 td3 td4]
346 glob td1 [file join td1 td2]
347 } -result "td1 [file join td1 td2]"
348 test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} -setup {
349 cleanup
350 } -constraints {notRoot} -body {
351 file mkdir td1
352 set x [file exists td1]
353 file mkdir td1
354 list $x [file exists td1]
355 } -result {1 1}
356 test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} -setup {
357 cleanup
358 } -constraints {notRoot} -returnCodes error -body {
359 createfile tf1
360 file mkdir tf1
361 } -result [subst {can't create directory "[file join tf1]": file already exists}]
362 test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} -setup {
363 cleanup
364 } -constraints {notRoot} -body {
365 file mkdir td1
366 set x [file exists td1]
367 file mkdir td1
368 list $x [file exists td1]
369 } -result {1 1}
370 test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} -setup {
371 cleanup
372 } -constraints {unix notRoot testchmod notWsl} -returnCodes error -body {
373 file mkdir td1/td2/td3
374 testchmod 0 td1/td2
375 file mkdir td1/td2/td3/td4
376 } -cleanup {
377 testchmod 0o755 td1/td2
378 cleanup
379 } -result {can't create directory "td1/td2/td3": permission denied}
380 test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} -setup {
381 cleanup
382 } -constraints {notRoot} -body {
383 set x [file exists td1]
384 file mkdir td1
385 list $x [file exists td1]
386 } -result {0 1}
387 test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} -setup {
388 cleanup
389 file delete -force foo
390 } -constraints {unix notRoot notWsl} -body {
391 file mkdir foo
392 file attr foo -perm 0o40000
393 file mkdir foo/tf1
394 } -returnCodes error -cleanup {
395 file delete -force foo
396 } -result {can't create directory "foo/tf1": permission denied}
397 test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} -setup {
398 cleanup
399 } -constraints {notRoot} -body {
400 file mkdir tf1
401 file exists tf1
402 } -result 1
403
404 test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} -constraints {notRoot} -body {
405 file delete -xyz
406 } -returnCodes error -result {bad option "-xyz": must be -force or --}
407 test fCmd-5.2 {TclFileDeleteCmd: accept 0 files (TIP 323)} -body {
408 file delete -force -force
409 } -result {}
410 test fCmd-5.3 {TclFileDeleteCmd: 1 file} -constraints {notRoot} -setup {
411 cleanup
412 } -body {
413 createfile tf1
414 createfile tf2
415 file mkdir td1
416 file delete tf2
417 glob tf* td*
418 } -result {tf1 td1}
419 test fCmd-5.4 {TclFileDeleteCmd: multiple files} -constraints notRoot -setup {
420 cleanup
421 } -body {
422 createfile tf1
423 createfile tf2
424 file mkdir td1
425 set x [list [file exists tf1] [file exists tf2] [file exists td1]]
426 file delete tf1 td1 tf2
427 lappend x [file exists tf1] [file exists tf2] [file exists tf3]
428 } -cleanup {cleanup} -result {1 1 1 0 0 0}
429 test fCmd-5.5 {TclFileDeleteCmd: stop at first error} -setup {
430 cleanup
431 } -constraints {notRoot unixOrWin} -body {
432 createfile tf1
433 createfile tf2
434 file mkdir td1
435 catch {file delete tf1 td1 $root tf2}
436 list [file exists tf1] [file exists tf2] [file exists td1]
437 } -cleanup {cleanup} -result {0 1 0}
438 test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
439 file delete ~_totally_bogus_user
440 } -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
441 test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} -setup {
442 catch {file delete ~/tf1}
443 } -constraints {notRoot} -body {
444 createfile ~/tf1
445 file delete ~/tf1
446 } -result {}
447 test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} -setup {
448 cleanup
449 } -constraints {notRoot} -body {
450 set x [file exists tf1]
451 file delete tf1
452 list $x [file exists tf1]
453 } -result {0 0}
454 test fCmd-5.9 {TclFileDeleteCmd: is directory} -constraints {notRoot} -setup {
455 cleanup
456 } -body {
457 file mkdir td1
458 file delete td1
459 file exists td1
460 } -result {0}
461 test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} -setup {
462 cleanup
463 } -constraints {notRoot} -returnCodes error -body {
464 file mkdir [file join td1 td2]
465 file delete td1
466 } -result {error deleting "td1": directory not empty}
467 test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} -setup {
468 cleanup
469 set dir [pwd]
470 } -constraints {notRoot} -body {
471 file mkdir [file join td1 td2]
472 cd [file join td1 td2]
473 set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
474 cd $dir
475 lappend res [file exists td1] $msg
476 } -cleanup {
477 cd $dir
478 } -result {0 0 {}}
479 test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} -setup {
480 cleanup
481 } -constraints {unix} -body {
482 file mkdir [file join td1 td2]
483 file attributes [file join td1 td2] -permissions u+rwx
484 set res [list [catch {file delete -force td1} msg]]
485 lappend res [file exists td1] $msg
486 } -result {0 0 {}}
487
488 test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot emptyTest} {
489 # can't test this, because it's caught by FileCopyRename
490 } {}
491 test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot emptyTest} {
492 # can't test this, because it's caught by FileCopyRename
493 } {}
494 test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} -setup {
495 cleanup
496 } -constraints {notRoot} -returnCodes error -body {
497 file rename tf1 tf2
498 } -result {error renaming "tf1": no such file or directory}
499 test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} -setup {
500 cleanup
501 } -constraints {notRoot} -body {
502 createfile tf1
503 file rename tf1 tf2
504 glob tf*
505 } -result {tf2}
506 test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} -setup {
507 cleanup
508 } -constraints {notRoot} -body {
509 createfile tf1
510 file rename tf1 tf2
511 glob tf*
512 } -result {tf2}
513 test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} -setup {
514 cleanup
515 } -constraints {unix notRoot testchmod notWsl} -body {
516 file mkdir td1
517 testchmod 0 td1
518 createfile tf1
519 file rename tf1 td1
520 } -returnCodes error -cleanup {
521 testchmod 0o755 td1
522 } -result {error renaming "tf1" to "td1/tf1": permission denied}
523 test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} -setup {
524 cleanup
525 } -constraints {unix notRoot} -body {
526 createfile tf1
527 file rename tf1 tf2
528 glob tf*
529 } -result {tf2}
530 test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 0} -setup {
531 cleanup
532 } -constraints {notRoot} -returnCodes error -body {
533 createfile tf1
534 createfile tf2
535 file rename tf1 tf2
536 } -result {error renaming "tf1" to "tf2": file already exists}
537 test fCmd-6.11 {CopyRenameOneFile: force == 0} -setup {
538 cleanup
539 } -constraints {notRoot} -returnCodes error -body {
540 createfile tf1
541 createfile tf2
542 file rename tf1 tf2
543 } -result {error renaming "tf1" to "tf2": file already exists}
544 test fCmd-6.12 {CopyRenameOneFile: force != 0} -setup {
545 cleanup
546 } -constraints {notRoot} -body {
547 createfile tf1
548 createfile tf2
549 file rename -force tf1 tf2
550 glob tf*
551 } -result {tf2}
552 test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} -setup {
553 cleanup
554 } -constraints {notRoot} -returnCodes error -body {
555 file mkdir td1
556 file mkdir td2
557 createfile [file join td2 td1]
558 file rename -force td1 td2
559 } -result [subst {can't overwrite file "[file join td2 td1]" with directory "td1"}]
560 test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} -setup {
561 cleanup
562 } -constraints {notRoot} -returnCodes error -body {
563 createfile tf1
564 file mkdir [file join td1 tf1]
565 file rename -force tf1 td1
566 } -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
567 test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} -setup {
568 cleanup
569 } -constraints {notRoot notNetworkFilesystem} -body {
570 file mkdir [file join td1 td2]
571 file mkdir td2
572 createfile [file join td2 tf1]
573 file rename -force td2 td1
574 file exists [file join td1 td2 tf1]
575 } -result 1
576 test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} -setup {
577 cleanup
578 } -constraints {notRoot} -body {
579 file mkdir [file join td1 td2]
580 createfile [file join td1 td2 tf1]
581 file mkdir td2
582 file rename -force td2 td1
583 } -returnCodes error -match glob -result \
584 [subst {error renaming "td2" to "[file join td1 td2]": file *}]
585 test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} -setup {
586 cleanup
587 } -constraints {notRoot} -returnCodes error -body {
588 file rename -force $root tf1
589 } -result [subst {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}]
590 test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} -setup {
591 cleanup
592 } -constraints {notRoot} -body {
593 file mkdir [file join td1 td2]
594 createfile [file join td1 td2 tf1]
595 file mkdir td2
596 file rename -force td2 td1
597 } -returnCodes error -match glob -result \
598 [subst {error renaming "td2" to "[file join td1 td2]": file *}]
599 test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} -setup {
600 cleanup $tmpspace
601 } -constraints {unix notRoot} -body {
602 createfile tf1
603 file rename tf1 $tmpspace
604 glob -nocomplain tf* [file join $tmpspace tf1]
605 } -result [file join $tmpspace tf1]
606 test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} -constraints {win} -setup {
607 catch {file delete -force c:/tcl8975@ d:/tcl8975@}
608 } -body {
609 file mkdir c:/tcl8975@
610 if {[catch {file rename c:/tcl8975@ d:/}]} {
611 return d:/tcl8975@
612 }
613 glob c:/tcl8975@ d:/tcl8975@
614 } -cleanup {
615 file delete -force c:/tcl8975@
616 catch {file delete -force d:/tcl8975@}
617 } -result {d:/tcl8975@}
618 test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} -setup {
619 cleanup $tmpspace
620 } -constraints {unix notRoot} -body {
621 file mkdir td1
622 file rename td1 $tmpspace
623 glob -nocomplain td* [file join $tmpspace td*]
624 } -result [file join $tmpspace td1]
625 test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} -setup {
626 cleanup $tmpspace
627 } -constraints {unix notRoot} -body {
628 createfile tf1
629 file rename tf1 $tmpspace
630 glob -nocomplain tf* [file join $tmpspace tf*]
631 } -result [file join $tmpspace tf1]
632 test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
633 cleanup $tmpspace
634 } -constraints {xdev notRoot notWsl} -body {
635 file mkdir td1/td2/td3
636 file attributes td1 -permissions 0o000
637 file rename td1 $tmpspace
638 } -returnCodes error -cleanup {
639 file attributes td1 -permissions 0o755
640 cleanup
641 } -match regexp -result {^error renaming "td1"( to "/tmp/tcl\d+/td1")?: permission denied$}
642 test fCmd-6.24 {CopyRenameOneFile: error uses original name} -setup {
643 cleanup
644 } -constraints {unix notRoot} -body {
645 file mkdir ~/td1/td2
646 set td1name [file join [file dirname ~] [file tail ~] td1]
647 file attributes $td1name -permissions 0o000
648 file copy ~/td1 td1
649 } -returnCodes error -cleanup {
650 file attributes $td1name -permissions 0o755
651 file delete -force ~/td1
652 } -result {error copying "~/td1": permission denied}
653 test fCmd-6.25 {CopyRenameOneFile: error uses original name} -setup {
654 cleanup
655 } -constraints {unix notRoot} -body {
656 file mkdir td2
657 file mkdir ~/td1
658 set td1name [file join [file dirname ~] [file tail ~] td1]
659 file attributes $td1name -permissions 0o000
660 file copy td2 ~/td1
661 } -returnCodes error -cleanup {
662 file attributes $td1name -permissions 0o755
663 file delete -force ~/td1
664 } -result {error copying "td2" to "~/td1/td2": permission denied}
665 test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} -setup {
666 cleanup
667 } -constraints {unix notRoot} -body {
668 file mkdir ~/td1/td2
669 set td2name [file join [file dirname ~] [file tail ~] td1 td2]
670 file attributes $td2name -permissions 0o000
671 file copy ~/td1 td1
672 } -returnCodes error -cleanup {
673 file attributes $td2name -permissions 0o755
674 file delete -force ~/td1
675 } -result "error copying \"~/td1\" to \"td1\": \"[file join $::env(HOME) td1 td2]\": permission denied"
676 test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
677 cleanup $tmpspace
678 } -constraints {notRoot xdev} -returnCodes error -body {
679 file mkdir td1/td2/td3
680 file mkdir [file join $tmpspace td1]
681 createfile [file join $tmpspace td1 tf1]
682 file rename -force td1 $tmpspace
683 } -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": file already exists}
684 test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
685 cleanup $tmpspace
686 } -constraints {notRoot xdev notWsl} -body {
687 file mkdir td1/td2/td3
688 file attributes td1/td2/td3 -permissions 0o000
689 file rename td1 $tmpspace
690 } -returnCodes error -cleanup {
691 file attributes td1/td2/td3 -permissions 0o755
692 cleanup $tmpspace
693 } -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": "td1/td2/td3": permission denied}
694 test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} -setup {
695 cleanup $tmpspace
696 } -constraints {notRoot xdev} -body {
697 file mkdir td1/td2/td3
698 file rename td1 $tmpspace
699 glob td* [file join $tmpspace td1 t*]
700 } -result [file join $tmpspace td1 td2]
701 test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} -setup {
702 cleanup $tmpspace
703 } -constraints {unix notRoot notWsl} -body {
704 file mkdir foo/bar
705 file attr foo -perm 0o40555
706 file rename foo/bar $tmpspace
707 } -returnCodes error -cleanup {
708 catch {file delete [file join $tmpspace bar]}
709 catch {file attr foo -perm 0o40777}
710 catch {file delete -force foo}
711 } -match glob -result {*: permission denied}
712 test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} -setup {
713 cleanup $tmpspace
714 } -constraints {notRoot xdev} -body {
715 file mkdir [file join $tmpspace td1]
716 createfile [file join $tmpspace td1 tf1]
717 file rename [file join $tmpspace td1 tf1] tf1
718 list [file exists [file join $tmpspace td1 tf1]] [file exists tf1]
719 } -result {0 1}
720 test fCmd-6.32 {CopyRenameOneFile: copy} -constraints {notRoot} -setup {
721 cleanup
722 } -returnCodes error -body {
723 file copy tf1 tf2
724 } -result {error copying "tf1": no such file or directory}
725
726 test fCmd-7.1 {FileForceOption: none} -constraints {notRoot} -setup {
727 cleanup
728 } -returnCodes error -body {
729 file mkdir [file join tf1 tf2]
730 file delete tf1
731 } -result {error deleting "tf1": directory not empty}
732 test fCmd-7.2 {FileForceOption: -force} -constraints {notRoot} -setup {
733 cleanup
734 } -body {
735 file mkdir [file join tf1 tf2]
736 file delete -force tf1
737 } -result {}
738 test fCmd-7.3 {FileForceOption: --} -constraints {notRoot} -body {
739 createfile -tf1
740 file delete -- -tf1
741 } -result {}
742 test fCmd-7.4 {FileForceOption: bad option} -constraints {notRoot} -setup {
743 createfile -tf1
744 } -body {
745 file delete -tf1
746 } -returnCodes error -cleanup {
747 file delete -- -tf1
748 } -result {bad option "-tf1": must be -force or --}
749 test fCmd-7.5 {FileForceOption: multiple times through loop} -setup {
750 cleanup
751 } -constraints {notRoot} -returnCodes error -body {
752 createfile --
753 createfile -force
754 file delete -force -force -- -- -force
755 glob -- -- -force
756 } -result {no files matched glob patterns "-- -force"}
757
758 test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
759 -constraints {unix notRoot knownBug} -body {
760 # Labeled knownBug because it is dangerous [Bug: 3881]
761 file mkdir td1
762 file attr td1 -perm 0o40000
763 file rename ~$user td1
764 } -returnCodes error -cleanup {
765 file delete -force td1
766 } -result "error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied"
767 test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
768 -constraints {unix notRoot} -body {
769 string equal [file tail ~$user] ~$user
770 } -result 0
771 test fCmd-8.3 {file copy and path translation: ensure correct error} -body {
772 file copy ~ [file join this file doesnt exist]
773 } -returnCodes error -result [subst \
774 {error copying "~" to "[file join this file doesnt exist]": no such file or directory}]
775
776 test fCmd-9.1 {file rename: comprehensive: EACCES} -setup {
777 cleanup
778 } -constraints {unix notRoot notWsl} -body {
779 file mkdir td1
780 file mkdir td2
781 file attr td2 -perm 0o40000
782 file rename td1 td2/
783 } -returnCodes error -cleanup {
784 file delete -force td2
785 file delete -force td1
786 } -result {error renaming "td1" to "td2/td1": permission denied}
787 test fCmd-9.2 {file rename: comprehensive: source doesn't exist} -setup {
788 cleanup
789 } -constraints {notRoot} -returnCodes error -body {
790 file rename tf1 tf2
791 } -result {error renaming "tf1": no such file or directory}
792 test fCmd-9.3 {file rename: comprehensive: file to new name} -setup {
793 cleanup
794 } -constraints {notRoot testchmod} -body {
795 createfile tf1
796 createfile tf2
797 testchmod 0o444 tf2
798 file rename tf1 tf3
799 file rename tf2 tf4
800 list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
801 } -result {{tf3 tf4} 1 0}
802 test fCmd-9.4.a {file rename: comprehensive: dir to new name} -setup {
803 cleanup
804 } -constraints {win win2000orXP testchmod} -body {
805 file mkdir td1 td2
806 testchmod 0o555 td2
807 file rename td1 td3
808 file rename td2 td4
809 list [lsort [glob td*]] [file writable td3] [file writable td4]
810 } -cleanup {
811 cleanup
812 } -result {{td3 td4} 1 0}
813 test fCmd-9.4.b {file rename: comprehensive: dir to new name} -setup {
814 cleanup
815 } -constraints {unix notRoot testchmod notDarwin9 notWsl} -body {
816 file mkdir td1 td2
817 testchmod 0o555 td2
818 file rename td1 td3
819 file rename td2 td4
820 list [lsort [glob td*]] [file writable td3] [file writable td4]
821 } -cleanup {
822 cleanup
823 } -result {{td3 td4} 1 0}
824 test fCmd-9.5 {file rename: comprehensive: file to self} -setup {
825 cleanup
826 } -constraints {notRoot testchmod} -body {
827 createfile tf1 tf1
828 createfile tf2 tf2
829 testchmod 0o444 tf2
830 file rename -force tf1 tf1
831 file rename -force tf2 tf2
832 list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
833 } -result {tf1 tf2 1 0}
834 test fCmd-9.6.a {file rename: comprehensive: dir to self} -setup {
835 cleanup
836 } -constraints {win win2000orXP testchmod} -body {
837 file mkdir td1
838 file mkdir td2
839 testchmod 0o555 td2
840 file rename -force td1 .
841 file rename -force td2 .
842 list [lsort [glob td*]] [file writable td1] [file writable td2]
843 } -result {{td1 td2} 1 0}
844 test fCmd-9.6.b {file rename: comprehensive: dir to self} -setup {
845 cleanup
846 } -constraints {unix notRoot testchmod notWsl} -body {
847 file mkdir td1
848 file mkdir td2
849 testchmod 0o555 td2
850 file rename -force td1 .
851 file rename -force td2 .
852 list [lsort [glob td*]] [file writable td1] [file writable td2]
853 } -result {{td1 td2} 1 0}
854 test fCmd-9.7 {file rename: comprehensive: file to existing file} -setup {
855 cleanup
856 } -constraints {notRoot testchmod} -body {
857 createfile tf1
858 createfile tf2
859 createfile tfs1
860 createfile tfs2
861 createfile tfs3
862 createfile tfs4
863 createfile tfd1
864 createfile tfd2
865 createfile tfd3
866 createfile tfd4
867 testchmod 0o444 tfs3
868 testchmod 0o444 tfs4
869 testchmod 0o444 tfd2
870 testchmod 0o444 tfd4
871 set msg [list [catch {file rename tf1 tf2} msg] $msg]
872 file rename -force tfs1 tfd1
873 file rename -force tfs2 tfd2
874 file rename -force tfs3 tfd3
875 file rename -force tfs4 tfd4
876 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
877 } -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
878 test fCmd-9.8 {file rename: comprehensive: dir to empty dir} -setup {
879 cleanup
880 } -constraints {notRoot testchmod notNetworkFilesystem} -body {
881 # Under Unix you can rename a read-only directory, but you can't move it
882 # into another directory.
883 file mkdir td1
884 file mkdir [file join td2 td1]
885 file mkdir tds1
886 file mkdir tds2
887 file mkdir tds3
888 file mkdir tds4
889 file mkdir [file join tdd1 tds1]
890 file mkdir [file join tdd2 tds2]
891 file mkdir [file join tdd3 tds3]
892 file mkdir [file join tdd4 tds4]
893 if {![testConstraint unix]} {
894 testchmod 0o555 tds3
895 testchmod 0o555 tds4
896 }
897 testchmod 0o555 [file join tdd2 tds2]
898 testchmod 0o555 [file join tdd4 tds4]
899 set msg [list [catch {file rename td1 td2} msg] $msg]
900 file rename -force tds1 tdd1
901 file rename -force tds2 tdd2
902 file rename -force tds3 tdd3
903 file rename -force tds4 tdd4
904 if {[testConstraint unix]} {
905 set w3 0
906 set w4 0
907 } else {
908 set w3 [file writable [file join tdd3 tds3]]
909 set w4 [file writable [file join tdd4 tds4]]
910 }
911 list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
912 [file writable [file join tdd2 tds2]] $w3 $w4
913 } -result [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
914 # Test can hit EEXIST or EBUSY, depending on underlying filesystem
915 test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} -setup {
916 cleanup
917 } -constraints {notRoot testchmod} -body {
918 file mkdir tds1
919 file mkdir tds2
920 file mkdir [file join tdd1 tds1 xxx]
921 file mkdir [file join tdd2 tds2 xxx]
922 if {!([testConstraint unix] || [testConstraint winVista])} {
923 testchmod 0o555 tds2
924 }
925 set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
926 set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
927 if {[testConstraint unix] || [testConstraint winVista]} {
928 set w2 0
929 } else {
930 set w2 [file writable tds2]
931 }
932 list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
933 } -match glob -result \
934 [subst {{tdd1 tdd2 tds1 tds2} {1 {error renaming "tds1" to "[file join tdd1 tds1]": file *}} {1 {error renaming "tds2" to "[file join tdd2 tds2]": file *}} 1 0}]
935 test fCmd-9.10 {file rename: comprehensive: file to new name and dir} -setup {
936 cleanup
937 } -constraints {notRoot testchmod} -body {
938 createfile tf1
939 createfile tf2
940 file mkdir td1
941 testchmod 0o444 tf2
942 file rename tf1 [file join td1 tf3]
943 file rename tf2 [file join td1 tf4]
944 list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \
945 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
946 } -result [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}]
947 test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} -setup {
948 cleanup
949 } -constraints {notRoot testchmod} -body {
950 file mkdir td1
951 file mkdir td2
952 file mkdir td3
953 if {!([testConstraint unix] || [testConstraint winVista])} {
954 testchmod 0o555 td2
955 }
956 file rename td1 [file join td3 td3]
957 file rename td2 [file join td3 td4]
958 if {[testConstraint unix] || [testConstraint winVista]} {
959 set w4 0
960 } else {
961 set w4 [file writable [file join td3 td4]]
962 }
963 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
964 [file writable [file join td3 td3]] $w4
965 } -result [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
966 test fCmd-9.12 {file rename: comprehensive: target exists} -setup {
967 cleanup
968 } -constraints {notRoot testchmod notNetworkFilesystem} -body {
969 file mkdir [file join td1 td2] [file join td2 td1]
970 testchmod 0o555 [file join td2 td1]
971 file mkdir [file join td3 td4] [file join td4 td3]
972 file rename -force td3 td4
973 list [file exists td3] [file exists [file join td4 td3 td4]] \
974 [catch {file rename td1 td2} msg] $msg
975 } -cleanup {
976 testchmod 0o755 [file join td2 td1]
977 } -result [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
978 # Test can hit EEXIST or EBUSY, depending on underlying filesystem
979 test fCmd-9.13 {file rename: comprehensive: can't overwrite target} -setup {
980 cleanup
981 } -constraints {notRoot} -body {
982 file mkdir [file join td1 td2] [file join td2 td1 td4]
983 file rename -force td1 td2
984 } -returnCodes error -match glob -result \
985 [subst {error renaming "td1" to "[file join td2 td1]": file *}]
986 test fCmd-9.14 {file rename: comprehensive: dir into self} -setup {
987 cleanup
988 } -constraints {notRoot} -body {
989 file mkdir td1
990 list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
991 } -result [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
992 test fCmd-9.14.1 {file rename: comprehensive: dir into self} -setup {
993 cleanup
994 } -constraints {notRoot} -body {
995 file mkdir td1
996 file rename td1 td1x
997 file rename td1x td1
998 set msg "ok"
999 } -result {ok}
1000 test fCmd-9.14.2 {file rename: comprehensive: dir into self} -setup {
1001 cleanup
1002 set dir [pwd]
1003 } -constraints {nonPortable notRoot} -body {
1004 file mkdir td1
1005 cd td1
1006 file rename [file join .. td1] [file join .. td1x]
1007 } -returnCodes error -cleanup {
1008 cd $dir
1009 } -result [subst {error renaming "[file join .. td1]" to "[file join .. td1x]": permission denied}]
1010 test fCmd-9.14.3 {file rename: comprehensive: dir into self} -setup {
1011 cleanup
1012 set dir [pwd]
1013 } -constraints {notRoot} -body {
1014 file mkdir td1
1015 cd td1
1016 file rename [file join .. td1] [file join .. td1 foo]
1017 } -returnCodes error -cleanup {
1018 cd $dir
1019 } -result [subst {error renaming "[file join .. td1]" to "[file join .. td1 foo]": trying to rename a volume or move a directory into itself}]
1020 test fCmd-9.15 {file rename: comprehensive: source and target incompatible} -setup {
1021 cleanup
1022 } -constraints {notRoot} -returnCodes error -body {
1023 file mkdir td1
1024 createfile tf1
1025 file rename -force td1 tf1
1026 } -cleanup {
1027 cleanup
1028 } -result {can't overwrite file "tf1" with directory "td1"}
1029 test fCmd-9.16 {file rename: comprehensive: source and target incompatible} -setup {
1030 cleanup
1031 } -constraints {notRoot} -returnCodes error -body {
1032 file mkdir td1/tf1
1033 createfile tf1
1034 file rename -force tf1 td1
1035 } -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
1036
1037 test fCmd-10.1 {file copy: comprehensive: source doesn't exist} -setup {
1038 cleanup
1039 } -constraints {notRoot} -returnCodes error -body {
1040 file copy tf1 tf2
1041 } -result {error copying "tf1": no such file or directory}
1042 test fCmd-10.2 {file copy: comprehensive: file to new name} -setup {
1043 cleanup
1044 } -constraints {notRoot testchmod} -body {
1045 createfile tf1 tf1
1046 createfile tf2 tf2
1047 testchmod 0o444 tf2
1048 file copy tf1 tf3
1049 file copy tf2 tf4
1050 list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
1051 } -result {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
1052 test fCmd-10.3 {file copy: comprehensive: dir to new name} -setup {
1053 cleanup
1054 } -constraints {unix notRoot testchmod notWsl} -body {
1055 file mkdir [file join td1 tdx]
1056 file mkdir [file join td2 tdy]
1057 testchmod 0o555 td2
1058 file copy td1 td3
1059 file copy td2 td4
1060 list [lsort [glob td*]] [glob -directory td3 t*] \
1061 [glob -directory td4 t*] [file writable td3] [file writable td4]
1062 } -cleanup {
1063 testchmod 0o755 td2
1064 testchmod 0o755 td4
1065 } -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0]
1066 test fCmd-10.3.1 {file copy: comprehensive: dir to new name} -setup {
1067 cleanup
1068 } -constraints {win notRoot testchmod} -body {
1069 # On Windows with ACLs, copying a directory is defined like this
1070 file mkdir [file join td1 tdx]
1071 file mkdir [file join td2 tdy]
1072 testchmod 0o555 td2
1073 testchmod 0o555 td2/tdy; # Above line removes inherited perms. So restore.
1074 file copy td1 td3
1075 file copy td2 td4
1076 list [lsort [glob td*]] [glob -directory td3 t*] \
1077 [glob -directory td4 t*] [file writable td3] [file writable td4]
1078 } -cleanup {
1079 testchmod 0o755 td2
1080 testchmod 0o755 td4
1081 } -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 1]
1082 test fCmd-10.4 {file copy: comprehensive: file to existing file} -setup {
1083 cleanup
1084 } -constraints {notRoot testchmod} -body {
1085 createfile tf1
1086 createfile tf2
1087 createfile tfs1
1088 createfile tfs2
1089 createfile tfs3
1090 createfile tfs4
1091 createfile tfd1
1092 createfile tfd2
1093 createfile tfd3
1094 createfile tfd4
1095 if {$::tcl_platform(platform) eq "windows"} {
1096 # On Windows testchmode will attach an ACL which file copy cannot handle
1097 # so use good old attributes which file copy does understand
1098 file attribute tfs3 -readonly 1
1099 file attribute tfs4 -readonly 1
1100 file attribute tfd2 -readonly 1
1101 file attribute tfd4 -readonly 1
1102 } else {
1103 testchmod 0o444 tfs3
1104 testchmod 0o444 tfs4
1105 testchmod 0o444 tfd2
1106 testchmod 0o444 tfd4
1107 }
1108 set msg [list [catch {file copy tf1 tf2} msg] $msg]
1109 file copy -force tfs1 tfd1
1110 file copy -force tfs2 tfd2
1111 file copy -force tfs3 tfd3
1112 file copy -force tfs4 tfd4
1113 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
1114 } -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
1115 test fCmd-10.5 {file copy: comprehensive: dir to empty dir} -setup {
1116 cleanup
1117 } -constraints {notRoot testchmod} -body {
1118 file mkdir td1
1119 file mkdir [file join td2 td1]
1120 file mkdir tds1
1121 file mkdir tds2
1122 file mkdir tds3
1123 file mkdir tds4
1124 file mkdir [file join tdd1 tds1]
1125 file mkdir [file join tdd2 tds2]
1126 file mkdir [file join tdd3 tds3]
1127 file mkdir [file join tdd4 tds4]
1128 testchmod 0o555 tds3
1129 testchmod 0o555 tds4
1130 testchmod 0o555 [file join tdd2 tds2]
1131 testchmod 0o555 [file join tdd4 tds4]
1132 set a1 [list [catch {file copy td1 td2} msg] $msg]
1133 set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
1134 set a3 [catch {file copy -force tds2 tdd2}]
1135 set a4 [catch {file copy -force tds3 tdd3}]
1136 set a5 [catch {file copy -force tds4 tdd4}]
1137 list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5
1138 } -result [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4 tds1 tds2 tds3 tds4} {1 {error copying "td1" to "[file join td2 td1]": file already exists}} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} 1 1 1}]
1139 test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} -setup {
1140 cleanup
1141 } -constraints {notRoot unixOrWin testchmod notWsl} -body {
1142 file mkdir tds1
1143 file mkdir tds2
1144 file mkdir [file join tdd1 tds1 xxx]
1145 file mkdir [file join tdd2 tds2 xxx]
1146 testchmod 0o555 tds2
1147 set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
1148 set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
1149 list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
1150 } -result [subst {{tdd1 tdd2 tds1 tds2} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} {1 {error copying "tds2" to "[file join tdd2 tds2]": file already exists}} 1 0}]
1151 test fCmd-10.7 {file rename: comprehensive: file to new name and dir} -setup {
1152 cleanup
1153 } -constraints {notRoot testchmod} -body {
1154 createfile tf1
1155 createfile tf2
1156 file mkdir td1
1157 testchmod 0o444 tf2
1158 file copy tf1 [file join td1 tf3]
1159 file copy tf2 [file join td1 tf4]
1160 list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
1161 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
1162 } -result [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
1163 test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} -setup {
1164 cleanup
1165 } -constraints {unix notRoot testchmod notWsl} -body {
1166 file mkdir td1
1167 file mkdir td2
1168 file mkdir td3
1169 testchmod 0o555 td2
1170 file copy td1 [file join td3 td3]
1171 file copy td2 [file join td3 td4]
1172 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1173 [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1174 } -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
1175 test fCmd-10.8.1 {file rename: comprehensive: dir to new name and dir} -setup {
1176 cleanup
1177 } -constraints {win notRoot testchmod} -body {
1178 # On Windows with ACLs, copying a directory is defined like this
1179 file mkdir td1
1180 file mkdir td2
1181 file mkdir td3
1182 testchmod 0o555 td2
1183 file copy td1 [file join td3 td3]
1184 file copy td2 [file join td3 td4]
1185 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1186 [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1187 } -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 1}]
1188 test fCmd-10.9 {file copy: comprehensive: source and target incompatible} -setup {
1189 cleanup
1190 } -constraints {notRoot} -returnCodes error -body {
1191 file mkdir td1
1192 createfile tf1
1193 file copy -force td1 tf1
1194 } -result {can't overwrite file "tf1" with directory "td1"}
1195 test fCmd-10.10 {file copy: comprehensive: source and target incompatible} -setup {
1196 cleanup
1197 } -constraints {notRoot} -returnCodes error -body {
1198 file mkdir [file join td1 tf1]
1199 createfile tf1
1200 file copy -force tf1 td1
1201 } -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
1202 test fCmd-10.11 {file copy: copy to empty file name} -setup {
1203 cleanup
1204 } -returnCodes error -body {
1205 createfile tf1
1206 file copy tf1 ""
1207 } -result {error copying "tf1" to "": no such file or directory}
1208 test fCmd-10.12 {file rename: rename to empty file name} -setup {
1209 cleanup
1210 } -returnCodes error -body {
1211 createfile tf1
1212 file rename tf1 ""
1213 } -result {error renaming "tf1" to "": no such file or directory}
1214 cleanup
1215
1216 # old tests
1217
1218 test fCmd-11.1 {TclFileRenameCmd: -- option} -constraints notRoot -setup {
1219 catch {file delete -force -- -tfa1}
1220 } -body {
1221 set s [createfile -tfa1]
1222 file rename -- -tfa1 tfa2
1223 list [checkcontent tfa2 $s] [file exists -tfa1]
1224 } -cleanup {
1225 file delete tfa2
1226 } -result {1 0}
1227 test fCmd-11.2 {TclFileRenameCmd: bad option} -constraints notRoot -setup {
1228 catch {file delete -force -- tfa1}
1229 } -body {
1230 set s [createfile tfa1]
1231 list [catch {file rename -x tfa1 tfa2}] \
1232 [checkcontent tfa1 $s] [file exists tfa2]
1233 } -cleanup {
1234 file delete tfa1
1235 } -result {1 1 0}
1236 test fCmd-11.3 {TclFileRenameCmd: bad \# args} -returnCodes error -body {
1237 file rename --
1238 } -match glob -result *
1239 test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} -setup {
1240 set temp $::env(HOME)
1241 } -constraints notRoot -body {
1242 global env
1243 unset env(HOME)
1244 catch { file rename tfa ~/foobar }
1245 } -cleanup {
1246 set ::env(HOME) $temp
1247 } -result 1
1248 test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} -setup {
1249 catch {file delete -force -- tfa1 tfa2 tfa3}
1250 } -constraints {notRoot} -body {
1251 createfile tfa1
1252 createfile tfa2
1253 createfile tfa3
1254 catch {file rename tfa1 tfa2 tfa3}
1255 } -cleanup {
1256 file delete tfa1 tfa2 tfa3
1257 } -result 1
1258 test fCmd-11.6 {TclFileRenameCmd: : single file into directory} -setup {
1259 catch {file delete -force -- tfa1 tfad}
1260 } -constraints {notRoot} -body {
1261 set s [createfile tfa1]
1262 file mkdir tfad
1263 file rename tfa1 tfad
1264 list [checkcontent tfad/tfa1 $s] [file exists tfa1]
1265 } -cleanup {
1266 file delete -force tfad
1267 } -result {1 0}
1268 test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} -setup {
1269 catch {file delete -force -- tfa1 tfa2 tfad}
1270 } -constraints {notRoot} -body {
1271 set s1 [createfile tfa1]
1272 set s2 [createfile tfa2]
1273 file mkdir tfad
1274 file rename tfa1 tfa2 tfad
1275 list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
1276 [file exists tfa1] [file exists tfa2]
1277 } -cleanup {
1278 file delete -force tfad
1279 } -result {1 1 0 0}
1280 test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} -setup {
1281 catch {file delete -force -- tfa tfad}
1282 } -constraints {notRoot} -body {
1283 set s [createfile tfa]
1284 file mkdir tfad
1285 file mkdir tfad/tfa
1286 list [catch {file rename tfa tfad}] [checkcontent tfa $s] [file isdir tfad]
1287 } -cleanup {
1288 file delete -force tfa tfad
1289 } -result {1 1 1}
1290
1291 #
1292 # Coverage tests for renamefile() ;
1293 #
1294 test fCmd-12.1 {renamefile: source filename translation failing} -setup {
1295 set temp $::env(HOME)
1296 } -constraints {notRoot} -body {
1297 global env
1298 unset env(HOME)
1299 catch {file rename ~/tfa1 tfa2}
1300 } -cleanup {
1301 set ::env(HOME) $temp
1302 } -result 1
1303 test fCmd-12.2 {renamefile: src filename translation failing} -setup {
1304 set temp $::env(HOME)
1305 } -constraints {notRoot} -body {
1306 global env
1307 unset env(HOME)
1308 set s [createfile tfa1]
1309 file mkdir tfad
1310 catch {file rename tfa1 ~/tfa2 tfad}
1311 } -cleanup {
1312 set ::env(HOME) $temp
1313 file delete -force tfad
1314 } -result 1
1315 test fCmd-12.3 {renamefile: stat failing on source} -setup {
1316 catch {file delete -force -- tfa1 tfa2}
1317 } -constraints {notRoot} -body {
1318 list [catch {file rename tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
1319 } -result {1 0 0}
1320 test fCmd-12.4 {renamefile: error renaming file to directory} -setup {
1321 catch {file delete -force -- tfa tfad}
1322 } -constraints {notRoot} -body {
1323 set s1 [createfile tfa]
1324 file mkdir tfad
1325 file mkdir tfad/tfa
1326 list [catch {file rename tfa tfad}] [checkcontent tfa $s1] \
1327 [file isdir tfad/tfa]
1328 } -cleanup {
1329 file delete -force tfa tfad
1330 } -result {1 1 1}
1331 test fCmd-12.5 {renamefile: error renaming directory to file} -setup {
1332 catch {file delete -force -- tfa tfad}
1333 } -constraints {notRoot} -body {
1334 file mkdir tfa
1335 file mkdir tfad
1336 set s [createfile tfad/tfa]
1337 list [catch {file rename tfa tfad}] [checkcontent tfad/tfa $s] \
1338 [file isdir tfad] [file isdir tfa]
1339 } -cleanup {
1340 file delete -force tfa tfad
1341 } -result {1 1 1 1}
1342 test fCmd-12.6 {renamefile: TclRenameFile succeeding} -setup {
1343 catch {file delete -force -- tfa1 tfa2}
1344 } -constraints {notRoot} -body {
1345 set s [createfile tfa1]
1346 file rename tfa1 tfa2
1347 list [checkcontent tfa2 $s] [file exists tfa1]
1348 } -cleanup {
1349 file delete tfa2
1350 } -result {1 0}
1351 test fCmd-12.7 {renamefile: renaming directory into offspring} -setup {
1352 catch {file delete -force -- tfad}
1353 } -constraints {notRoot} -body {
1354 file mkdir tfad
1355 file mkdir tfad/dir
1356 catch {file rename tfad tfad/dir}
1357 } -cleanup {
1358 file delete -force tfad
1359 } -result 1
1360 test fCmd-12.8 {renamefile: generic error} -setup {
1361 catch {file delete -force -- tfa}
1362 } -constraints {unix notRoot notWsl} -body {
1363 file mkdir tfa
1364 file mkdir tfa/dir
1365 file attributes tfa -permissions 0o555
1366 catch {file rename tfa/dir tfa2}
1367 } -cleanup {
1368 catch {file attributes tfa -permissions 0o777}
1369 file delete -force tfa
1370 } -result 1
1371 test fCmd-12.9 {renamefile: moving a file across volumes} -setup {
1372 cleanup $tmpspace
1373 } -constraints {unix notRoot} -body {
1374 set s [createfile tfa]
1375 file rename tfa $tmpspace
1376 list [checkcontent [file join $tmpspace tfa] $s] [file exists tfa]
1377 } -cleanup {
1378 cleanup $tmpspace
1379 } -result {1 0}
1380 test fCmd-12.10 {renamefile: moving a directory across volumes} -setup {
1381 cleanup $tmpspace
1382 } -constraints {xdev notRoot} -body {
1383 file mkdir tfad
1384 set s [createfile tfad/a]
1385 file rename tfad $tmpspace
1386 list [checkcontent [file join $tmpspace tfad a] $s] [file exists tfad]
1387 } -cleanup {
1388 cleanup $tmpspace
1389 } -result {1 0}
1390
1391 #
1392 # Coverage tests for TclCopyFilesCmd()
1393 #
1394 test fCmd-13.1 {TclCopyFilesCmd: -force option} -constraints notRoot -setup {
1395 catch {file delete -force -- tfa1}
1396 } -body {
1397 set s [createfile tfa1]
1398 file copy -force tfa1 tfa2
1399 list [checkcontent tfa2 $s] [checkcontent tfa1 $s]
1400 } -cleanup {
1401 file delete tfa1 tfa2
1402 } -result {1 1}
1403 test fCmd-13.2 {TclCopyFilesCmd: -- option} -constraints {notRoot} -setup {
1404 catch {file delete -force -- tfa1}
1405 } -body {
1406 set s [createfile -tfa1]
1407 file copy -- -tfa1 tfa2
1408 list [checkcontent tfa2 $s] [checkcontent -tfa1 $s]
1409 } -cleanup {
1410 file delete -- -tfa1 tfa2
1411 } -result {1 1}
1412 test fCmd-13.3 {TclCopyFilesCmd: bad option} -constraints {notRoot} -setup {
1413 catch {file delete -force -- tfa1}
1414 } -body {
1415 set s [createfile tfa1]
1416 list [catch {file copy -x tfa1 tfa2}] \
1417 [checkcontent tfa1 $s] [file exists tfa2]
1418 } -cleanup {
1419 file delete tfa1
1420 } -result {1 1 0}
1421 test fCmd-13.4 {TclCopyFilesCmd: bad \# args} -constraints {notRoot} -body {
1422 file copy --
1423 } -returnCodes error -match glob -result *
1424 test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} -setup {
1425 set temp $::env(HOME)
1426 } -body {
1427 global env
1428 unset env(HOME)
1429 catch { file copy tfa ~/foobar }
1430 } -cleanup {
1431 set ::env(HOME) $temp
1432 } -result 1
1433 test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} -setup {
1434 catch {file delete -force -- tfa1 tfa2 tfa3}
1435 } -constraints {notRoot} -body {
1436 createfile tfa1
1437 createfile tfa2
1438 createfile tfa3
1439 catch {file copy tfa1 tfa2 tfa3}
1440 } -cleanup {
1441 file delete tfa1 tfa2 tfa3
1442 } -result 1
1443 test fCmd-13.7 {TclCopyFilesCmd: single file into directory} -setup {
1444 catch {file delete -force -- tfa1 tfad}
1445 } -constraints {notRoot} -body {
1446 set s [createfile tfa1]
1447 file mkdir tfad
1448 file copy tfa1 tfad
1449 list [checkcontent tfad/tfa1 $s] [checkcontent tfa1 $s]
1450 } -cleanup {
1451 file delete -force tfad tfa1
1452 } -result {1 1}
1453 test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} -setup {
1454 catch {file delete -force -- tfa1 tfa2 tfad}
1455 } -constraints {notRoot} -body {
1456 set s1 [createfile tfa1]
1457 set s2 [createfile tfa2]
1458 file mkdir tfad
1459 file copy tfa1 tfa2 tfad
1460 list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
1461 [checkcontent tfa1 $s1] [checkcontent tfa2 $s2]
1462 } -cleanup {
1463 file delete -force tfad tfa1 tfa2
1464 } -result {1 1 1 1}
1465 test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} -setup {
1466 catch {file delete -force -- tfa tfad}
1467 } -constraints {notRoot} -body {
1468 set s [createfile tfa]
1469 file mkdir tfad
1470 file mkdir tfad/tfa
1471 list [catch {file copy tfa tfad}] [checkcontent tfa $s] \
1472 [file isdir tfad/tfa] [file isdir tfad]
1473 } -cleanup {
1474 file delete -force tfa tfad
1475 } -result {1 1 1 1}
1476
1477 #
1478 # Coverage tests for copyfile()
1479 #
1480 test fCmd-14.1 {copyfile: source filename translation failing} -setup {
1481 set temp $::env(HOME)
1482 } -constraints {notRoot} -body {
1483 global env
1484 unset env(HOME)
1485 catch {file copy ~/tfa1 tfa2}
1486 } -cleanup {
1487 set ::env(HOME) $temp
1488 } -result 1
1489 test fCmd-14.2 {copyfile: dst filename translation failing} -setup {
1490 set temp $::env(HOME)
1491 } -constraints {notRoot} -body {
1492 global env
1493 unset env(HOME)
1494 set s [createfile tfa1]
1495 file mkdir tfad
1496 list [catch {file copy tfa1 ~/tfa2 tfad}] [checkcontent tfad/tfa1 $s]
1497 } -cleanup {
1498 set ::env(HOME) $temp
1499 file delete -force tfa1 tfad
1500 } -result {1 1}
1501 test fCmd-14.3 {copyfile: stat failing on source} -setup {
1502 catch {file delete -force -- tfa1 tfa2}
1503 } -constraints notRoot -body {
1504 list [catch {file copy tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
1505 } -result {1 0 0}
1506 test fCmd-14.4 {copyfile: error copying file to directory} -setup {
1507 catch {file delete -force -- tfa tfad}
1508 } -constraints {notRoot} -body {
1509 set s1 [createfile tfa]
1510 file mkdir tfad
1511 file mkdir tfad/tfa
1512 list [catch {file copy tfa tfad}] [checkcontent tfa $s1] \
1513 [file isdir tfad] [file isdir tfad/tfa]
1514 } -cleanup {
1515 file delete -force tfa tfad
1516 } -result {1 1 1 1}
1517 test fCmd-14.5 {copyfile: error copying directory to file} -setup {
1518 catch {file delete -force -- tfa tfad}
1519 } -constraints {notRoot} -body {
1520 file mkdir tfa
1521 file mkdir tfad
1522 set s [createfile tfad/tfa]
1523 list [catch {file copy tfa tfad}] [checkcontent tfad/tfa $s] \
1524 [file isdir tfad] [file isdir tfa]
1525 } -cleanup {
1526 file delete -force tfa tfad
1527 } -result {1 1 1 1}
1528 test fCmd-14.6 {copyfile: copy file succeeding} -constraints notRoot -setup {
1529 catch {file delete -force -- tfa tfa2}
1530 } -body {
1531 set s [createfile tfa]
1532 file copy tfa tfa2
1533 list [checkcontent tfa $s] [checkcontent tfa2 $s]
1534 } -cleanup {
1535 file delete tfa tfa2
1536 } -result {1 1}
1537 test fCmd-14.7 {copyfile: copy directory succeeding} -setup {
1538 catch {file delete -force -- tfa tfa2}
1539 } -constraints {notRoot} -body {
1540 file mkdir tfa
1541 set s [createfile tfa/file]
1542 file copy tfa tfa2
1543 list [checkcontent tfa/file $s] [checkcontent tfa2/file $s]
1544 } -cleanup {
1545 file delete -force tfa tfa2
1546 } -result {1 1}
1547 test fCmd-14.8 {copyfile: copy directory failing} -setup {
1548 catch {file delete -force -- tfa}
1549 } -constraints {unix notRoot notWsl} -body {
1550 file mkdir tfa/dir/a/b/c
1551 file attributes tfa/dir -permissions 0o000
1552 catch {file copy tfa tfa2}
1553 } -cleanup {
1554 file attributes tfa/dir -permissions 0o777
1555 file delete -force tfa tfa2
1556 } -result 1
1557
1558 #
1559 # Coverage tests for TclMkdirCmd()
1560 #
1561 test fCmd-15.1 {TclMakeDirsCmd: target filename translation failing} -setup {
1562 set temp $::env(HOME)
1563 } -constraints {notRoot} -body {
1564 global env
1565 unset env(HOME)
1566 catch {file mkdir ~/tfa}
1567 } -cleanup {
1568 set ::env(HOME) $temp
1569 } -result 1
1570 #
1571 # Can Tcl_SplitPath return argc == 0? If so them we need a test for that code.
1572 #
1573 test fCmd-15.2 {TclMakeDirsCmd - one directory} -setup {
1574 catch {file delete -force -- tfa}
1575 } -constraints {notRoot} -body {
1576 file mkdir tfa
1577 file isdirectory tfa
1578 } -cleanup {
1579 file delete tfa
1580 } -result 1
1581 test fCmd-15.3 {TclMakeDirsCmd: - two directories} -setup {
1582 catch {file delete -force -- tfa1 tfa2}
1583 } -constraints {notRoot} -body {
1584 file mkdir tfa1 tfa2
1585 list [file isdirectory tfa1] [file isdirectory tfa2]
1586 } -cleanup {
1587 file delete tfa1 tfa2
1588 } -result {1 1}
1589 test fCmd-15.4 {TclMakeDirsCmd - stat failing} -setup {
1590 catch {file delete -force -- tfa}
1591 } -constraints {unix notRoot} -body {
1592 file mkdir tfa
1593 createfile tfa/file
1594 file attributes tfa -permissions 0o000
1595 catch {file mkdir tfa/file}
1596 } -cleanup {
1597 file attributes tfa -permissions 0o777
1598 file delete -force tfa
1599 } -result 1
1600 test fCmd-15.5 {TclMakeDirsCmd: - making a directory several levels deep} -setup {
1601 catch {file delete -force -- tfa}
1602 } -constraints {notRoot} -body {
1603 file mkdir tfa/a/b/c
1604 file isdir tfa/a/b/c
1605 } -cleanup {
1606 file delete -force tfa
1607 } -result 1
1608 test fCmd-15.6 {TclMakeDirsCmd: - trying to overwrite a file} -setup {
1609 catch {file delete -force -- tfa}
1610 } -constraints {notRoot} -body {
1611 set s [createfile tfa]
1612 list [catch {file mkdir tfa}] [file isdir tfa] [file exists tfa] \
1613 [checkcontent tfa $s]
1614 } -cleanup {
1615 file delete tfa
1616 } -result {1 0 1 1}
1617 test fCmd-15.7 {TclMakeDirsCmd - making several directories} -setup {
1618 catch {file delete -force -- tfa1 tfa2}
1619 } -constraints {notRoot} -body {
1620 file mkdir tfa1 tfa2/a/b/c
1621 list [file isdir tfa1] [file isdir tfa2/a/b/c]
1622 } -cleanup {
1623 file delete -force tfa1 tfa2
1624 } -result {1 1}
1625 test fCmd-15.8 {TclFileMakeDirsCmd: trying to create an existing dir} -body {
1626 file mkdir tfa
1627 file mkdir tfa
1628 file isdir tfa
1629 } -constraints {notRoot} -cleanup {
1630 file delete tfa
1631 } -result 1
1632
1633 # Coverage tests for TclDeleteFilesCommand()
1634 test fCmd-16.1 {test the -- argument} -constraints {notRoot} -setup {
1635 catch {file delete -force -- tfa}
1636 } -body {
1637 createfile tfa
1638 file delete -- tfa
1639 file exists tfa
1640 } -result 0
1641 test fCmd-16.2 {test the -force and -- arguments} -constraints notRoot -setup {
1642 catch {file delete -force -- tfa}
1643 } -body {
1644 createfile tfa
1645 file delete -force -- tfa
1646 file exists tfa
1647 } -result 0
1648 test fCmd-16.3 {test bad option} -constraints {notRoot} -setup {
1649 catch {file delete -force -- tfa}
1650 } -body {
1651 createfile tfa
1652 catch {file delete -dog tfa}
1653 } -cleanup {
1654 file delete tfa
1655 } -result 1
1656 test fCmd-16.4 {accept zero files (TIP 323)} -body {
1657 file delete
1658 } -result {}
1659 test fCmd-16.5 {accept zero files (TIP 323)} -body {
1660 file delete --
1661 } -result {}
1662 test fCmd-16.6 {delete: source filename translation failing} -setup {
1663 set temp $::env(HOME)
1664 } -constraints {notRoot} -body {
1665 global env
1666 unset env(HOME)
1667 catch {file delete ~/tfa}
1668 } -cleanup {
1669 set ::env(HOME) $temp
1670 } -result 1
1671 test fCmd-16.7 {remove a non-empty directory without -force} -setup {
1672 catch {file delete -force -- tfa}
1673 } -constraints {notRoot} -body {
1674 file mkdir tfa
1675 createfile tfa/a
1676 catch {file delete tfa}
1677 } -cleanup {
1678 file delete -force tfa
1679 } -result 1
1680 test fCmd-16.8 {remove a normal file} -constraints {notRoot} -setup {
1681 catch {file delete -force -- tfa}
1682 } -body {
1683 file mkdir tfa
1684 createfile tfa/a
1685 catch {file delete tfa}
1686 } -cleanup {
1687 file delete -force tfa
1688 } -result 1
1689 test fCmd-16.9 {error while deleting file} -setup {
1690 catch {file delete -force -- tfa}
1691 } -constraints {unix notRoot notWsl} -body {
1692 file mkdir tfa
1693 createfile tfa/a
1694 file attributes tfa -permissions 0o555
1695 catch {file delete tfa/a}
1696 #######
1697 ####### If any directory in a tree that is being removed does not have
1698 ####### write permission, the process will fail! This is also the case
1699 ####### with "rm -rf"
1700 #######
1701 } -cleanup {
1702 file attributes tfa -permissions 0o777
1703 file delete -force tfa
1704 } -result 1
1705 test fCmd-16.10 {deleting multiple files} -constraints {notRoot} -setup {
1706 catch {file delete -force -- tfa1 tfa2}
1707 } -body {
1708 createfile tfa1
1709 createfile tfa2
1710 file delete tfa1 tfa2
1711 list [file exists tfa1] [file exists tfa2]
1712 } -result {0 0}
1713 test fCmd-16.11 {TclFileDeleteCmd: removing a nonexistant file} -setup {
1714 catch {file delete -force -- tfa}
1715 } -constraints {notRoot} -body {
1716 file delete tfa
1717 } -result {}
1718
1719 # More coverage tests for mkpath()
1720 test fCmd-17.1 {mkdir stat failing on target but not ENOENT} -setup {
1721 catch {file delete -force -- tfa1}
1722 } -constraints {unix notRoot notWsl} -body {
1723 file mkdir tfa1
1724 file attributes tfa1 -permissions 0o555
1725 catch {file mkdir tfa1/tfa2}
1726 } -cleanup {
1727 file attributes tfa1 -permissions 0o777
1728 file delete -force tfa1
1729 } -result 1
1730 test fCmd-17.2 {mkdir several levels deep - relative} -setup {
1731 catch {file delete -force -- tfa}
1732 } -constraints {notRoot} -body {
1733 file mkdir tfa/a/b
1734 file isdir tfa/a/b
1735 } -cleanup {
1736 file delete tfa/a/b tfa/a tfa
1737 } -result 1
1738 test fCmd-17.3 {mkdir several levels deep - absolute} -setup {
1739 catch {file delete -force -- tfa}
1740 } -constraints {notRoot} -body {
1741 set f [file join [pwd] tfa a]
1742 file mkdir $f
1743 file isdir $f
1744 } -cleanup {
1745 file delete $f [file join [pwd] tfa]
1746 } -result 1
1747
1748 #
1749 # Functionality tests for TclFileRenameCmd()
1750 #
1751 test fCmd-18.1 {TclFileRenameCmd: rename (first form) in the same directory} \
1752 -setup {
1753 catch {file delete -force -- tfad}
1754 set savedDir [pwd]
1755 } -constraints {notRoot} -body {
1756 file mkdir tfad/dir
1757 cd tfad/dir
1758 set s [createfile foo]
1759 file rename foo bar
1760 file rename bar ./foo
1761 file rename ./foo bar
1762 file rename ./bar ./foo
1763 file rename foo ../dir/bar
1764 file rename ../dir/bar ./foo
1765 file rename ../../tfad/dir/foo ../../tfad/dir/bar
1766 file rename [file join [pwd] bar] foo
1767 file rename foo [file join [pwd] bar]
1768 list [checkcontent bar $s] [file exists foo]
1769 } -cleanup {
1770 cd $savedDir
1771 file delete -force tfad
1772 } -result {1 0}
1773 test fCmd-18.2 {TclFileRenameCmd: single dir to nonexistant} -setup {
1774 catch {file delete -force -- tfa1 tfa2}
1775 } -constraints {notRoot} -body {
1776 file mkdir tfa1
1777 file rename tfa1 tfa2
1778 list [file exists tfa2] [file exists tfa1]
1779 } -cleanup {
1780 file delete tfa2
1781 } -result {1 0}
1782 test fCmd-18.3 {TclFileRenameCmd: mixed dirs and files into directory} -setup {
1783 catch {file delete -force -- tfa1 tfad1 tfad2}
1784 } -constraints {notRoot} -body {
1785 set s [createfile tfa1]
1786 file mkdir tfad1 tfad2
1787 file rename tfa1 tfad1 tfad2
1788 list [checkcontent tfad2/tfa1 $s] [file isdir tfad2/tfad1] \
1789 [file exists tfa1] [file exists tfad1]
1790 } -cleanup {
1791 file delete tfad2/tfa1
1792 file delete -force tfad2
1793 } -result {1 1 0 0}
1794 test fCmd-18.4 {TclFileRenameCmd: attempt to replace non-dir with dir} -setup {
1795 catch {file delete -force -- tfa tfad}
1796 } -constraints {notRoot} -body {
1797 set s [createfile tfa]
1798 file mkdir tfad
1799 list [catch {file rename tfad tfa}] [checkcontent tfa $s] [file isdir tfad]
1800 } -cleanup {
1801 file delete tfa tfad
1802 } -result {1 1 1}
1803 test fCmd-18.5 {TclFileRenameCmd: attempt to replace dir with non-dir} -setup {
1804 catch {file delete -force -- tfa tfad}
1805 } -constraints {notRoot} -body {
1806 set s [createfile tfa]
1807 file mkdir tfad/tfa
1808 list [catch {file rename tfa tfad}] [checkcontent tfa $s] \
1809 [file isdir tfad/tfa]
1810 } -cleanup {
1811 file delete -force tfa tfad
1812 } -result {1 1 1}
1813 #
1814 # On Windows there is no easy way to determine if two files are the same
1815 #
1816 test fCmd-18.6 {TclFileRenameCmd: rename a file to itself} -setup {
1817 catch {file delete -force -- tfa}
1818 } -constraints {unix notRoot} -body {
1819 set s [createfile tfa]
1820 list [catch {file rename tfa tfa}] [checkcontent tfa $s]
1821 } -cleanup {
1822 file delete tfa
1823 } -result {1 1}
1824 test fCmd-18.7 {TclFileRenameCmd: rename dir on top of another empty dir w/o -force} -setup {
1825 catch {file delete -force -- tfa tfad}
1826 } -constraints {notRoot} -body {
1827 file mkdir tfa tfad/tfa
1828 list [catch {file rename tfa tfad}] [file isdir tfa]
1829 } -cleanup {
1830 file delete -force tfa tfad
1831 } -result {1 1}
1832 test fCmd-18.8 {TclFileRenameCmd: rename dir on top of another empty dir w/ -force} -setup {
1833 catch {file delete -force -- tfa tfad}
1834 } -constraints {notRoot notNetworkFilesystem} -body {
1835 file mkdir tfa tfad/tfa
1836 file rename -force tfa tfad
1837 file isdir tfa
1838 } -cleanup {
1839 file delete -force tfad
1840 } -result 0
1841 test fCmd-18.9 {TclFileRenameCmd: rename dir on top of a non-empty dir w/o -force} -setup {
1842 catch {file delete -force -- tfa tfad}
1843 } -constraints {notRoot} -body {
1844 file mkdir tfa tfad/tfa/file
1845 list [catch {file rename tfa tfad}] [file isdir tfa] \
1846 [file isdir tfad/tfa/file]
1847 } -cleanup {
1848 file delete -force tfa tfad
1849 } -result {1 1 1}
1850 test fCmd-18.10 {TclFileRenameCmd: rename dir on top of a non-empty dir w/ -force} -setup {
1851 catch {file delete -force -- tfa tfad}
1852 } -constraints {notRoot notNetworkFilesystem} -body {
1853 file mkdir tfa tfad/tfa/file
1854 list [catch {file rename -force tfa tfad}] [file isdir tfa] \
1855 [file isdir tfad/tfa/file]
1856 } -cleanup {
1857 file delete -force tfa tfad
1858 } -result {1 1 1}
1859 test fCmd-18.11 {TclFileRenameCmd: rename a non-existant file} -setup {
1860 catch {file delete -force -- tfa1}
1861 } -constraints {notRoot} -body {
1862 list [catch {file rename tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
1863 } -result {1 0 0}
1864 test fCmd-18.12 {TclFileRenameCmd : rename a symbolic link to file} -setup {
1865 catch {file delete -force -- tfa1 tfa2 tfa3}
1866 } -constraints {unix notRoot} -body {
1867 set s [createfile tfa1]
1868 file link -symbolic tfa2 tfa1
1869 file rename tfa2 tfa3
1870 file type tfa3
1871 } -cleanup {
1872 file delete tfa1 tfa3
1873 } -result link
1874 test fCmd-18.13 {TclFileRenameCmd : rename a symbolic link to dir} -setup {
1875 catch {file delete -force -- tfa1 tfa2 tfa3}
1876 } -constraints {unix notRoot} -body {
1877 file mkdir tfa1
1878 file link -symbolic tfa2 tfa1
1879 file rename tfa2 tfa3
1880 file type tfa3
1881 } -cleanup {
1882 file delete tfa1 tfa3
1883 } -result link
1884 test fCmd-18.14 {TclFileRenameCmd : rename a path with sym link} -setup {
1885 catch {file delete -force -- tfa1 tfa2 tfa3}
1886 } -constraints {unix notRoot} -body {
1887 file mkdir tfa1/a/b/c/d
1888 file mkdir tfa2
1889 set f [file join [pwd] tfa1/a/b]
1890 set f2 [file join [pwd] {tfa2/b alias}]
1891 file link -symbolic $f2 $f
1892 file rename {tfa2/b alias/c} tfa3
1893 list [file isdir tfa3] [file exists tfa1/a/b/c]
1894 } -cleanup {
1895 file delete -force tfa1 tfa2 tfa3
1896 } -result {1 0}
1897 test fCmd-18.15 {TclFileRenameCmd : rename a file to a symlink dir} -setup {
1898 catch {file delete -force -- tfa1 tfa2 tfalink}
1899 } -constraints {unix notRoot} -body {
1900 file mkdir tfa1
1901 set s [createfile tfa2]
1902 file link -symbolic tfalink tfa1
1903 file rename tfa2 tfalink
1904 checkcontent tfa1/tfa2 $s
1905 } -cleanup {
1906 file delete -force tfa1 tfalink
1907 } -result 1
1908 test fCmd-18.16 {TclFileRenameCmd: rename a dangling symlink} -setup {
1909 catch {file delete -force -- tfa1 tfalink}
1910 } -constraints {unix notRoot} -body {
1911 file mkdir tfa1
1912 file link -symbolic tfalink tfa1
1913 file delete tfa1
1914 file rename tfalink tfa2
1915 file type tfa2
1916 } -cleanup {
1917 file delete tfa2
1918 } -result link
1919
1920 #
1921 # Coverage tests for TclUnixRmdir
1922 #
1923 test fCmd-19.1 {remove empty directory} -constraints {notRoot} -setup {
1924 catch {file delete -force -- tfa}
1925 } -body {
1926 file mkdir tfa
1927 file delete tfa
1928 file exists tfa
1929 } -result {0}
1930 test fCmd-19.2 {rmdir error besides EEXIST} -setup {
1931 catch {file delete -force -- tfa}
1932 } -constraints {unix notRoot notWsl} -body {
1933 file mkdir tfa
1934 file mkdir tfa/a
1935 file attributes tfa -permissions 0o555
1936 catch {file delete tfa/a}
1937 } -cleanup {
1938 file attributes tfa -permissions 0o777
1939 file delete -force tfa
1940 } -result 1
1941 test fCmd-19.3 {recursive remove} -constraints {notRoot} -setup {
1942 catch {file delete -force -- tfa}
1943 } -body {
1944 file mkdir tfa
1945 file mkdir tfa/a
1946 file delete -force tfa
1947 file exists tfa
1948 } -result {0}
1949
1950 #
1951 # TclUnixDeleteFile and TraversalDelete are covered by tests from the
1952 # TclDeleteFilesCmd suite
1953 #
1954
1955 #
1956 # Coverage tests for TraverseUnixTree(), called from TclDeleteFilesCmd
1957 #
1958 test fCmd-20.1 {TraverseUnixTree : failure opening a subdirectory directory} -setup {
1959 catch {file delete -force -- tfa}
1960 } -constraints {unix notRoot notWsl} -body {
1961 file mkdir tfa
1962 file mkdir tfa/a
1963 file attributes tfa/a -permissions 0o000
1964 catch {file delete -force tfa}
1965 } -cleanup {
1966 file attributes tfa/a -permissions 0o777
1967 file delete -force tfa
1968 } -result 1
1969 test fCmd-20.2 {TraverseUnixTree : recursive delete of large directory: Bug 1034337} -setup {
1970 catch {file delete -force -- tfa}
1971 } -constraints {unix notRoot} -body {
1972 file mkdir tfa
1973 for {set i 1} {$i <= 300} {incr i} {
1974 createfile tfa/testfile_$i
1975 }
1976 file delete -force tfa
1977 } -cleanup {
1978 while {[catch {file delete -force tfa}]} {}
1979 } -result {}
1980
1981 #
1982 # Feature testing for TclCopyFilesCmd
1983 #
1984 test fCmd-21.1 {copy : single file to nonexistant} -setup {
1985 catch {file delete -force -- tfa1 tfa2}
1986 } -constraints {notRoot} -body {
1987 set s [createfile tfa1]
1988 file copy tfa1 tfa2
1989 list [checkcontent tfa2 $s] [checkcontent tfa1 $s]
1990 } -cleanup {
1991 file delete tfa1 tfa2
1992 } -result {1 1}
1993 test fCmd-21.2 {copy : single dir to nonexistant} -setup {
1994 catch {file delete -force -- tfa1 tfa2}
1995 } -constraints {notRoot} -body {
1996 file mkdir tfa1
1997 file copy tfa1 tfa2
1998 list [file isdir tfa2] [file isdir tfa1]
1999 } -cleanup {
2000 file delete tfa1 tfa2
2001 } -result {1 1}
2002 test fCmd-21.3 {copy : single file into directory} -setup {
2003 catch {file delete -force -- tfa1 tfad}
2004 } -constraints {notRoot} -body {
2005 set s [createfile tfa1]
2006 file mkdir tfad
2007 file copy tfa1 tfad
2008 list [checkcontent tfad/tfa1 $s] [checkcontent tfa1 $s]
2009 } -cleanup {
2010 file delete -force tfa1 tfad
2011 } -result {1 1}
2012 test fCmd-21.4 {copy : more than one source and target is not a directory} -setup {
2013 catch {file delete -force -- tfa1 tfa2 tfa3}
2014 } -constraints {notRoot} -body {
2015 createfile tfa1
2016 createfile tfa2
2017 createfile tfa3
2018 catch {file copy tfa1 tfa2 tfa3}
2019 } -cleanup {
2020 file delete tfa1 tfa2 tfa3
2021 } -result 1
2022 test fCmd-21.5 {copy : multiple files into directory} -constraints {notRoot} -setup {
2023 catch {file delete -force -- tfa1 tfa2 tfad}
2024 } -body {
2025 set s1 [createfile tfa1]
2026 set s2 [createfile tfa2]
2027 file mkdir tfad
2028 file copy tfa1 tfa2 tfad
2029 list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
2030 [checkcontent tfa1 $s1] [checkcontent tfa2 $s2]
2031 } -cleanup {
2032 file delete -force tfa1 tfa2 tfad
2033 } -result {1 1 1 1}
2034 test fCmd-21.6 {copy: mixed dirs and files into directory} -setup {
2035 catch {file delete -force -- tfa1 tfad1 tfad2}
2036 } -constraints {notRoot notFileSharing} -body {
2037 set s [createfile tfa1]
2038 file mkdir tfad1 tfad2
2039 file copy tfa1 tfad1 tfad2
2040 list [checkcontent [file join tfad2 tfa1] $s] \
2041 [file isdir [file join tfad2 tfad1]] \
2042 [checkcontent tfa1 $s] [file isdir tfad1]
2043 } -cleanup {
2044 file delete -force tfa1 tfad1 tfad2
2045 } -result {1 1 1 1}
2046 test fCmd-21.7.1 {TclCopyFilesCmd: copy a dangling link} -setup {
2047 catch {file delete -force tfad1 tfalink tfalink2}
2048 } -constraints {unix notRoot dontCopyLinks} -body {
2049 file mkdir tfad1
2050 file link -symbolic tfalink tfad1
2051 file delete tfad1
2052 file copy tfalink tfalink2
2053 } -returnCodes error -cleanup {
2054 file delete -force tfalink tfalink2
2055 } -result {error copying "tfalink": the target of this link doesn't exist}
2056 test fCmd-21.7.2 {TclCopyFilesCmd: copy a dangling link} -setup {
2057 catch {file delete -force tfad1 tfalink tfalink2}
2058 } -constraints {unix notRoot} -body {
2059 file mkdir tfad1
2060 file link -symbolic tfalink tfad1
2061 file delete tfad1
2062 file copy tfalink tfalink2
2063 file type tfalink2
2064 } -cleanup {
2065 file delete tfalink tfalink2
2066 } -result link
2067 test fCmd-21.8.1 {TclCopyFilesCmd: copy a link} -setup {
2068 catch {file delete -force tfad1 tfalink tfalink2}
2069 } -constraints {unix notRoot dontCopyLinks} -body {
2070 file mkdir tfad1
2071 file link -symbolic tfalink tfad1
2072 file copy tfalink tfalink2
2073 list [file type tfalink] [file type tfalink2] [file isdir tfad1]
2074 } -cleanup {
2075 file delete -force tfad1 tfalink tfalink2
2076 } -result {link directory 1}
2077 test fCmd-21.8.2 {TclCopyFilesCmd: copy a link} -setup {
2078 catch {file delete -force tfad1 tfalink tfalink2}
2079 } -constraints {unix notRoot} -body {
2080 file mkdir tfad1
2081 file link -symbolic tfalink tfad1
2082 file copy tfalink tfalink2
2083 list [file type tfalink] [file type tfalink2] [file isdir tfad1]
2084 } -cleanup {
2085 file delete -force tfad1 tfalink tfalink2
2086 } -result {link link 1}
2087 test fCmd-21.9 {TclCopyFilesCmd: copy dir with a link in it} -setup {
2088 catch {file delete -force tfad1 tfad2}
2089 } -constraints {unix notRoot} -body {
2090 file mkdir tfad1
2091 file link -symbolic tfad1/tfalink "[pwd]/tfad1"
2092 file copy tfad1 tfad2
2093 file type tfad2/tfalink
2094 } -cleanup {
2095 file delete -force tfad1 tfad2
2096 } -result link
2097 test fCmd-21.10 {TclFileCopyCmd: copy dir on top of another empty dir w/o -force} -setup {
2098 catch {file delete -force -- tfa tfad}
2099 } -constraints {notRoot} -body {
2100 file mkdir tfa [file join tfad tfa]
2101 list [catch {file copy tfa tfad}] [file isdir tfa]
2102 } -cleanup {
2103 file delete -force tfa tfad
2104 } -result {1 1}
2105 test fCmd-21.11 {TclFileCopyCmd: copy dir on top of a dir w/o -force} -setup {
2106 catch {file delete -force -- tfa tfad}
2107 } -constraints {notRoot} -body {
2108 file mkdir tfa [file join tfad tfa file]
2109 list [catch {file copy tfa tfad}] [file isdir tfa] \
2110 [file isdir [file join tfad tfa file]]
2111 } -cleanup {
2112 file delete -force tfa tfad
2113 } -result {1 1 1}
2114 test fCmd-21.12 {TclFileCopyCmd: copy dir on top of a non-empty dir w/ -force} -setup {
2115 catch {file delete -force -- tfa tfad}
2116 } -constraints {notRoot} -body {
2117 file mkdir tfa [file join tfad tfa file]
2118 list [catch {file copy -force tfa tfad}] [file isdir tfa] \
2119 [file isdir [file join tfad tfa file]]
2120 } -cleanup {
2121 file delete -force tfa tfad
2122 } -result {1 1 1}
2123
2124 #
2125 # Coverage testing for TclpRenameFile
2126 #
2127 test fCmd-22.1 {TclpRenameFile: rename and overwrite in a single dir} -setup {
2128 catch {file delete -force -- tfa1 tfa2}
2129 } -constraints {notRoot} -body {
2130 set s [createfile tfa1]
2131 set s2 [createfile tfa2 q]
2132 set result [catch {file rename tfa1 tfa2}]
2133 file rename -force tfa1 tfa2
2134 lappend result [checkcontent tfa2 $s]
2135 } -cleanup {
2136 file delete [glob tfa1 tfa2]
2137 } -result {1 1}
2138 test fCmd-22.2 {TclpRenameFile: attempt to overwrite itself} -setup {
2139 catch {file delete -force -- tfa1}
2140 } -constraints {unix notRoot} -body {
2141 set s [createfile tfa1]
2142 file rename -force tfa1 tfa1
2143 checkcontent tfa1 $s
2144 } -cleanup {
2145 file delete tfa1
2146 } -result 1
2147 test fCmd-22.3 {TclpRenameFile: rename dir to existing dir} -setup {
2148 catch {file delete -force -- d1 tfad}
2149 } -constraints {notRoot} -body {
2150 file mkdir d1 [file join tfad d1]
2151 list [catch {file rename d1 tfad}] [file isdir d1] \
2152 [file isdir [file join tfad d1]]
2153 } -cleanup {
2154 file delete -force d1 tfad
2155 } -result {1 1 1}
2156 test fCmd-22.4 {TclpRenameFile: rename dir to dir several levels deep} -setup {
2157 catch {file delete -force -- d1 tfad}
2158 } -constraints {notRoot} -body {
2159 file mkdir d1 [file join tfad a b c]
2160 file rename d1 [file join tfad a b c d1]
2161 list [file isdir d1] [file isdir [file join tfad a b c d1]]
2162 } -cleanup {
2163 file delete -force [glob d1 tfad]
2164 } -result {0 1}
2165 #
2166 # TclMacCopyFile needs to be redone.
2167 #
2168 test fCmd-22.5 {TclMacCopyFile: copy and overwrite in a single dir} -setup {
2169 catch {file delete -force -- tfa1 tfa2}
2170 } -constraints {notRoot} -body {
2171 set s [createfile tfa1]
2172 set s2 [createfile tfa2 q]
2173 set result [catch {file copy tfa1 tfa2}]
2174 file copy -force tfa1 tfa2
2175 lappend result [checkcontent tfa2 $s] [checkcontent tfa1 $s]
2176 } -cleanup {
2177 file delete tfa1 tfa2
2178 } -result {1 1 1}
2179
2180 #
2181 # TclMacMkdir - basic cases are covered elsewhere.
2182 # Error cases are not covered.
2183 #
2184
2185 #
2186 # TclMacRmdir
2187 # Error cases are not covered.
2188 #
2189 test fCmd-23.1 {TclMacRmdir: trying to remove a nonempty directory} -setup {
2190 catch {file delete -force -- tfad}
2191 } -constraints {notRoot} -body {
2192 file mkdir [file join tfad dir]
2193 list [catch {file delete tfad}] [file delete -force tfad]
2194 } -cleanup {
2195 catch {file delete -force tfad}
2196 } -result {1 {}}
2197
2198 #
2199 # TclMacDeleteFile
2200 # Error cases are not covered.
2201 #
2202 test fCmd-24.1 {TclMacDeleteFile: deleting a normal file} -setup {
2203 catch {file delete -force -- tfa1}
2204 } -constraints {notRoot} -body {
2205 createfile tfa1
2206 file delete tfa1
2207 file exists tfa1
2208 } -cleanup {
2209 catch {file delete -force tfa1}
2210 } -result {0}
2211
2212 #
2213 # TclMacCopyDirectory
2214 # Error cases are not covered.
2215 #
2216 test fCmd-25.1 {TclMacCopyDirectory: copying a normal directory} -setup {
2217 catch {file delete -force -- tfad1 tfad2}
2218 } -constraints {notRoot notFileSharing} -body {
2219 file mkdir [file join tfad1 a b c]
2220 file copy tfad1 tfad2
2221 list [file isdir [file join tfad1 a b c]] \
2222 [file isdir [file join tfad2 a b c]]
2223 } -cleanup {
2224 file delete -force tfad1 tfad2
2225 } -result {1 1}
2226 test fCmd-25.2 {TclMacCopyDirectory: copying a short path normal directory} -setup {
2227 catch {file delete -force -- tfad1 tfad2}
2228 } -constraints {notRoot notFileSharing} -body {
2229 file mkdir tfad1
2230 file copy tfad1 tfad2
2231 list [file isdir tfad1] [file isdir tfad2]
2232 } -cleanup {
2233 file delete tfad1 tfad2
2234 } -result {1 1}
2235 test fCmd-25.3 {TclMacCopyDirectory: copying dirs between different dirs} -setup {
2236 catch {file delete -force -- tfad1 tfad2}
2237 } -constraints {notRoot notFileSharing} -body {
2238 file mkdir [file join tfad1 x y z]
2239 file mkdir [file join tfad2 dir]
2240 file copy tfad1 [file join tfad2 dir]
2241 list [file isdir [file join tfad1 x y z]] \
2242 [file isdir [file join tfad2 dir tfad1 x y z]]
2243 } -cleanup {
2244 file delete -force tfad1 tfad2
2245 } -result {1 1}
2246
2247 #
2248 # Functionality tests for TclDeleteFilesCmd
2249 #
2250 test fCmd-26.1 {TclDeleteFilesCmd: delete symlink} -setup {
2251 catch {file delete -force -- tfad1 tfad2}
2252 } -constraints {unix notRoot} -body {
2253 file mkdir tfad1
2254 file link -symbolic tfalink tfad1
2255 file delete tfalink
2256 list [file isdir tfad1] [file exists tfalink]
2257 } -cleanup {
2258 file delete tfad1
2259 catch {file delete tfalink}
2260 } -result {1 0}
2261 test fCmd-26.2 {TclDeleteFilesCmd: delete dir with symlink} -setup {
2262 catch {file delete -force -- tfad1 tfad2}
2263 } -constraints {unix notRoot} -body {
2264 file mkdir tfad1
2265 file mkdir tfad2
2266 file link -symbolic [file join tfad2 link] [file join .. tfad1]
2267 file delete -force tfad2
2268 list [file isdir tfad1] [file exists tfad2]
2269 } -cleanup {
2270 file delete tfad1
2271 } -result {1 0}
2272 test fCmd-26.3 {TclDeleteFilesCmd: delete dangling symlink} -setup {
2273 catch {file delete -force -- tfad1 tfad2}
2274 } -constraints {unix notRoot} -body {
2275 file mkdir tfad1
2276 file link -symbolic tfad2 tfad1
2277 file delete tfad1
2278 file delete tfad2
2279 list [file exists tfad1] [file exists tfad2]
2280 } -result {0 0}
2281
2282 # There is no fCmd-27.1
2283 test fCmd-27.2 {TclFileAttrsCmd - Tcl_TranslateFileName fails} -setup {
2284 set platform [testgetplatform]
2285 } -constraints {testsetplatform} -body {
2286 testsetplatform unix
2287 file attributes ~_totally_bogus_user
2288 } -returnCodes error -cleanup {
2289 testsetplatform $platform
2290 } -result {user "_totally_bogus_user" doesn't exist}
2291 test fCmd-27.3 {TclFileAttrsCmd - all attributes} -setup {
2292 catch {file delete -force -- foo.tmp}
2293 } -body {
2294 createfile foo.tmp
2295 file attributes foo.tmp
2296 # Must be non-empty result
2297 } -cleanup {
2298 file delete -force -- foo.tmp
2299 } -match glob -result {?*}
2300 test fCmd-27.4 {TclFileAttrsCmd - getting one option} -setup {
2301 catch {file delete -force -- foo.tmp}
2302 } -body {
2303 createfile foo.tmp
2304 set attrs [file attributes foo.tmp]
2305 file attributes foo.tmp {*}[lindex $attrs 0]
2306 # Any successful result will do
2307 } -cleanup {
2308 file delete -force -- foo.tmp
2309 } -match glob -result *
2310 test fCmd-27.5 {TclFileAttrsCmd - setting one option} -setup {
2311 catch {file delete -force -- foo.tmp}
2312 } -constraints {foundGroup} -body {
2313 createfile foo.tmp
2314 set attrs [file attributes foo.tmp]
2315 file attributes foo.tmp {*}[lrange $attrs 0 1]
2316 } -cleanup {
2317 file delete -force -- foo.tmp
2318 } -result {}
2319 test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} -setup {
2320 catch {file delete -force -- foo.tmp}
2321 } -constraints {foundGroup} -body {
2322 createfile foo.tmp
2323 set attrs [file attributes foo.tmp]
2324 file attributes foo.tmp {*}[lrange $attrs 0 3]
2325 } -cleanup {
2326 file delete -force -- foo.tmp
2327 } -result {}
2328
2329 if {
2330 [testConstraint win] &&
2331 ($::tcl_platform(osVersion) < 5.0
2332 || [lindex [file system [temporaryDirectory]] 1] ne "NTFS")
2333 } then {
2334 testConstraint linkDirectory 0
2335 testConstraint linkFile 0
2336 }
2337
2338 test fCmd-28.1 {file link} -returnCodes error -body {
2339 file link
2340 } -result {wrong # args: should be "file link ?-linktype? linkname ?target?"}
2341 test fCmd-28.2 {file link} -returnCodes error -body {
2342 file link a b c d
2343 } -result {wrong # args: should be "file link ?-linktype? linkname ?target?"}
2344 test fCmd-28.3 {file link} -returnCodes error -body {
2345 file link abc b c
2346 } -result {bad option "abc": must be -symbolic or -hard}
2347 test fCmd-28.4 {file link} -returnCodes error -body {
2348 file link -abc b c
2349 } -result {bad option "-abc": must be -symbolic or -hard}
2350 cd [workingDirectory]
2351 makeDirectory abc.dir
2352 makeDirectory abc2.dir
2353 makeFile contents abc.file
2354 makeFile contents abc2.file
2355 cd [temporaryDirectory]
2356 test fCmd-28.5 {file link: source already exists} -setup {
2357 cd [temporaryDirectory]
2358 } -constraints {linkDirectory} -body {
2359 file link abc.dir abc2.dir
2360 } -returnCodes error -cleanup {
2361 cd [workingDirectory]
2362 } -result {could not create new link "abc.dir": that path already exists}
2363 test fCmd-28.6 {file link: unsupported operation} -setup {
2364 cd [temporaryDirectory]
2365 } -constraints {linkDirectory win} -body {
2366 file link -hard abc.link abc.dir
2367 } -returnCodes error -cleanup {
2368 cd [workingDirectory]
2369 } -result {could not create new link "abc.link" pointing to "abc.dir": illegal operation on a directory}
2370 test fCmd-28.7 {file link: source already exists} -setup {
2371 cd [temporaryDirectory]
2372 } -constraints {linkFile} -body {
2373 file link abc.file abc2.file
2374 } -returnCodes error -cleanup {
2375 cd [workingDirectory]
2376 } -result {could not create new link "abc.file": that path already exists}
2377 # In Windows 10 developer mode, we _can_ create symbolic links to files!
2378 test fCmd-28.8 {file link} -constraints {linkFile winLessThan10} -setup {
2379 cd [temporaryDirectory]
2380 } -body {
2381 file link -symbolic abc.link abc.file
2382 } -cleanup {
2383 file delete -force abc.link
2384 cd [workingDirectory]
2385 } -returnCodes error -result {could not create new link "abc.link" pointing to "abc.file": invalid argument}
2386 test fCmd-28.9 {file link: success with file} -constraints {linkFile} -setup {
2387 cd [temporaryDirectory]
2388 file delete -force abc.link
2389 } -body {
2390 file link abc.link abc.file
2391 } -cleanup {
2392 cd [workingDirectory]
2393 } -result abc.file
2394 test fCmd-28.9.1 {file link: success with file} -setup {
2395 cd [temporaryDirectory]
2396 file delete -force abc.link
2397 } -constraints {linkFile win} -body {
2398 file stat abc.file arr
2399 set res $arr(nlink)
2400 lappend res [catch {file link abc.link abc.file} msg] $msg
2401 file stat abc.file arr
2402 lappend res $arr(nlink)
2403 } -cleanup {
2404 cd [workingDirectory]
2405 } -result {1 0 abc.file 2}
2406 cd [temporaryDirectory]
2407 catch {file delete -force abc.link}
2408 cd [workingDirectory]
2409 test fCmd-28.10 {file link: linking to nonexistent path} -setup {
2410 cd [temporaryDirectory]
2411 file delete -force abc.link
2412 } -constraints {linkDirectory} -body {
2413 file link abc.link abc2.doesnt
2414 } -returnCodes error -cleanup {
2415 cd [workingDirectory]
2416 } -result {could not create new link "abc.link": target "abc2.doesnt" doesn't exist}
2417 test fCmd-28.10.1 {file link: linking to nonexistent path} -setup {
2418 cd [temporaryDirectory]
2419 file delete -force abc.link
2420 } -constraints {linkDirectory} -body {
2421 file link doesnt/abc.link abc.dir
2422 } -returnCodes error -cleanup {
2423 cd [workingDirectory]
2424 } -result {could not create new link "doesnt/abc.link": no such file or directory}
2425 test fCmd-28.11 {file link: success with directory} -setup {
2426 cd [temporaryDirectory]
2427 file delete -force abc.link
2428 } -constraints {linkDirectory} -body {
2429 file link abc.link abc.dir
2430 } -cleanup {
2431 cd [workingDirectory]
2432 } -result abc.dir
2433 test fCmd-28.12 {file link: cd into a link} -setup {
2434 cd [temporaryDirectory]
2435 file delete -force abc.link
2436 } -constraints {linkDirectory} -body {
2437 file link abc.link abc.dir
2438 set orig [pwd]
2439 cd abc.link
2440 set dir [pwd]
2441 cd ..
2442 set up [pwd]
2443 cd $orig
2444 # Now '$up' should be either $orig or [file dirname abc.dir], depending on
2445 # whether 'cd' actually moves to the destination of a link, or simply
2446 # treats the link as a directory. (On windows the former, on Unix the
2447 # latter, I believe)
2448 if {
2449 ([file normalize $up] ne [file normalize $orig]) &&
2450 ([file normalize $up] ne [file normalize [file dirname abc.dir]])
2451 } then {
2452 return "wrong directory with 'cd abc.link ; cd ..': \
2453 \"[file normalize $up]\" should be \"[file normalize $orig]\"\
2454 or \"[file normalize [file dirname abc.dir]]\""
2455 } else {
2456 return "ok"
2457 }
2458 } -cleanup {
2459 file delete -force abc.link
2460 cd [workingDirectory]
2461 } -result ok
2462 test fCmd-28.13 {file link} -constraints {linkDirectory} -setup {
2463 cd [temporaryDirectory]
2464 file link abc.link abc.dir
2465 } -body {
2466 # duplicate link throws error
2467 file link abc.link abc.dir
2468 } -returnCodes error -cleanup {
2469 file delete -force abc.link
2470 cd [workingDirectory]
2471 } -result {could not create new link "abc.link": that path already exists}
2472 test fCmd-28.14 {file link: deletes link not dir} -setup {
2473 cd [temporaryDirectory]
2474 } -constraints {linkDirectory} -body {
2475 file delete -force abc.link
2476 list [file exists abc.link] [file exists abc.dir]
2477 } -cleanup {
2478 cd [workingDirectory]
2479 } -result {0 1}
2480 test fCmd-28.15.1 {file link: copies link not dir} -setup {
2481 cd [temporaryDirectory]
2482 file delete -force abc.link
2483 } -constraints {linkDirectory dontCopyLinks} -body {
2484 file link abc.link abc.dir
2485 file copy abc.link abc2.link
2486 # abc2.linkdir was a copy of a link to a dir, so it should end up as a
2487 # directory, not a link (links trace to endpoint).
2488 list [file type abc2.link] [file tail [file link abc.link]]
2489 } -cleanup {
2490 file delete -force abc.link
2491 cd [workingDirectory]
2492 } -result {directory abc.dir}
2493 test fCmd-28.15.2 {file link: copies link not dir} -setup {
2494 cd [temporaryDirectory]
2495 file delete -force abc.link
2496 } -constraints {linkDirectory} -body {
2497 file link abc.link abc.dir
2498 file copy abc.link abc2.link
2499 list [file type abc2.link] [file tail [file link abc2.link]]
2500 } -cleanup {
2501 file delete -force abc.link
2502 cd [workingDirectory]
2503 } -result {link abc.dir}
2504 cd [temporaryDirectory]
2505 file delete -force abc.link
2506 file delete -force abc2.link
2507 cd abc.dir
2508 file delete -force abc.file
2509 file delete -force abc2.file
2510 cd ..
2511 file copy abc.file abc.dir
2512 file copy abc2.file abc.dir
2513 cd [workingDirectory]
2514 test fCmd-28.16 {file link: glob inside link} -setup {
2515 cd [temporaryDirectory]
2516 file delete -force abc.link
2517 } -constraints {linkDirectory} -body {
2518 file link abc.link abc.dir
2519 lsort [glob -dir abc.link -tails *]
2520 } -cleanup {
2521 file delete -force abc.link
2522 cd [workingDirectory]
2523 } -result {abc.file abc2.file}
2524 test fCmd-28.17 {file link: glob -type l} -setup {
2525 cd [temporaryDirectory]
2526 file link abc.link abc.dir
2527 } -constraints {linkDirectory} -body {
2528 glob -dir [pwd] -type l -tails abc*
2529 } -cleanup {
2530 file delete -force abc.link
2531 cd [workingDirectory]
2532 } -result {abc.link}
2533 test fCmd-28.18 {file link: glob -type d} -constraints linkDirectory -setup {
2534 cd [temporaryDirectory]
2535 file link abc.link abc.dir
2536 } -body {
2537 lsort [glob -dir [pwd] -type d -tails abc*]
2538 } -cleanup {
2539 file delete -force abc.link
2540 cd [workingDirectory]
2541 } -result [lsort [list abc.link abc.dir abc2.dir]]
2542 test fCmd-28.19 {file link: relative paths} -setup {
2543 cd [temporaryDirectory]
2544 } -constraints {win linkDirectory} -body {
2545 file mkdir d1/d2/d3
2546 file link d1/l2 d1/d2
2547 } -cleanup {
2548 catch {file delete -force d1}
2549 cd [workingDirectory]
2550 } -result d1/d2
2551 test fCmd-28.20 {file link: relative paths} -setup {
2552 cd [temporaryDirectory]
2553 } -constraints {unix linkDirectory} -body {
2554 file mkdir d1/d2/d3
2555 file link d1/l2 d1/d2
2556 } -returnCodes error -cleanup {
2557 catch {file delete -force d1}
2558 cd [workingDirectory]
2559 } -result {could not create new link "d1/l2": target "d1/d2" doesn't exist}
2560 test fCmd-28.21 {file link: relative paths} -setup {
2561 cd [temporaryDirectory]
2562 } -constraints {unix linkDirectory} -body {
2563 file mkdir d1/d2/d3
2564 file link d1/l2 d2
2565 } -cleanup {
2566 catch {file delete -force d1}
2567 cd [workingDirectory]
2568 } -result d2
2569 test fCmd-28.22 {file link: relative paths} -setup {
2570 cd [temporaryDirectory]
2571 } -constraints {unix linkDirectory} -body {
2572 file mkdir d1/d2/d3
2573 catch {file delete -force d1/l2}
2574 file link d1/l2 d2/d3
2575 } -cleanup {
2576 catch {file delete -force d1}
2577 cd [workingDirectory]
2578 } -result d2/d3
2579 try {
2580 cd [temporaryDirectory]
2581 file delete -force abc.link
2582 file delete -force d1/d2
2583 file delete -force d1
2584 } finally {
2585 cd [workingDirectory]
2586 }
2587 removeFile abc2.file
2588 removeFile abc.file
2589 removeDirectory abc2.dir
2590 removeDirectory abc.dir
2591
2592 test fCmd-29.1 {weird memory corruption fault} -body {
2593 open [file join ~a_totally_bogus_user_id/foo bar]
2594 } -returnCodes error -match glob -result *
2595
2596 test fCmd-30.1 {file writable on 'My Documents'} -setup {
2597 # Get the localized version of the folder name by looking in the registry.
2598 set mydocsname [registry get {HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders} Personal]
2599 } -constraints {win reg} -body {
2600 file writable $mydocsname
2601 } -result 1
2602 test fCmd-30.2 {file readable on 'NTUSER.DAT'} -constraints {win} -body {
2603 expr {[info exists env(USERPROFILE)]
2604 && [file exists $env(USERPROFILE)/NTUSER.DAT]
2605 && [file readable $env(USERPROFILE)/NTUSER.DAT]}
2606 } -result 1
2607 # At least one CI environment (GitHub Actions) is set up with the page file in
2608 # an unusual location; skip the test if that is so.
2609 test fCmd-30.3 {file readable on 'pagefile.sys'} -constraints {
2610 win notContinuousIntegration
2611 } -body {
2612 set r {}
2613 if {[info exists env(SystemDrive)]} {
2614 set path $env(SystemDrive)/pagefile.sys
2615 lappend r exists [file exists $path]
2616 lappend r readable [file readable $path]
2617 lappend r stat [catch {file stat $path a} e] $e
2618 }
2619 return $r
2620 } -result {exists 1 readable 0 stat 0 {}}
2621
2622 # cleanup
2623 cleanup
2624 if {[testConstraint unix]} {
2625 removeDirectory tcl[pid] /tmp
2626 }
2627 ::tcltest::cleanupTests
2628 return
2629
2630 # Local Variables:
2631 # mode: tcl
2632 # fill-column: 78
2633 # End: