1 # This file tests the tclFCmd.c file.
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1996-1997 Sun Microsystems, Inc.
8 # Copyright (c) 1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest 2
18 namespace import -force ::tcltest::*
21 tcltest::testConstraint testsetplatform [string equal testsetplatform [info commands testsetplatform]]
22 tcltest::testConstraint testchmod [string equal testchmod [info commands testchmod]]
24 # Several tests require need to match results against the unix username
26 if {$tcl_platform(platform) == "unix"} {
27 catch {set user [exec whoami]}
29 catch {regexp {^[^(]*\(([^)]*)\)} [exec id] dummy user}
36 proc createfile {file {string a}} {
38 puts -nonewline $f $string
46 # Ensures that file "file" contains only the string "matchString"
47 # returns 0 if the file does not exist, or has a different content
49 proc checkcontent {file matchString} {
52 set fileString [read $f]
57 return [string match $matchString $fileString]
62 if {[file isdirectory $path]} {
64 foreach p [glob -directory $path *] {
72 if {$::tcl_platform(platform) == "macintosh"} {
77 foreach p [concat $wd $args] {
80 set x [glob -directory $p tf* td*]
83 if {[catch {file delete -force -- $file}]} {
85 catch {file delete -force -- $file}
91 proc contents {file} {
98 set ::tcltest::testConstraints(fileSharing) 0
99 set ::tcltest::testConstraints(notFileSharing) 1
101 if {$tcl_platform(platform) == "macintosh"} {
102 catch {file delete -force foo.dir}
104 if {[catch {file attributes foo.dir -readonly 1}] == 0} {
105 set ::tcltest::testConstraints(fileSharing) 1
106 set ::tcltest::testConstraints(notFileSharing) 0
108 file delete -force foo.dir
111 set ::tcltest::testConstraints(xdev) 0
113 if {$tcl_platform(platform) == "unix"} {
114 if {[catch {set m1 [exec df .]; set m2 [exec df /tmp]}] == 0} {
115 set m1 [string range $m1 0 [expr [string first " " $m1]-1]]
116 set m2 [string range $m2 0 [expr [string first " " $m2]-1]]
117 if {$m1 != "" && $m2 != "" && $m1 != $m2 && [file exists $m1] && [file exists $m2]} {
118 set ::tcltest::testConstraints(xdev) 1
123 set root [lindex [file split [pwd]] 0]
125 # A really long file name
126 # length of long is 1216 chars, which should be greater than any static
127 # buffer or allowable filename.
129 set long "abcdefghihjllmnopqrstuvwxyz01234567890"
136 test fCmd-1.1 {TclFileRenameCmd} {notRoot} {
143 test fCmd-2.1 {TclFileCopyCmd} {notRoot} {
150 test fCmd-3.1 {FileCopyRename: FileForceOption fails} {notRoot} {
151 list [catch {file rename -xyz} msg] $msg
152 } {1 {bad option "-xyz": should be -force or --}}
153 test fCmd-3.2 {FileCopyRename: not enough args} {notRoot} {
154 list [catch {file rename xyz} msg] $msg
155 } {1 {wrong # args: should be "file rename ?options? source ?source ...? target"}}
156 test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} {notRoot} {
157 list [catch {file rename xyz ~_totally_bogus_user} msg] $msg
158 } {1 {user "_totally_bogus_user" doesn't exist}}
159 test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} {notRoot} {
161 list [catch {file copy tf1 ~} msg] $msg
162 } {1 {error copying "tf1": no such file or directory}}
163 test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} {notRoot} {
165 list [catch {file rename tf1 tf2 tf3} msg] $msg
166 } {1 {error renaming: target "tf3" is not a directory}}
167 test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} \
171 list [catch {file rename tf1 tf2 tf3} msg] $msg
172 } {1 {error renaming: target "tf3" is not a directory}}
173 test fCmd-3.7 {FileCopyRename: target exists & is directory} {notRoot} {
178 contents [file join td1 tf1]
180 test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
182 list [catch {file rename tf1 tf2 tf3} msg] $msg
183 } {1 {error renaming: target "tf3" is not a directory}}
184 test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
186 list [catch {file copy -force -- tf1 tf2 tf3} msg] $msg
187 } {1 {error copying: target "tf3" is not a directory}}
188 test fCmd-3.10 {FileCopyRename: just 2 arguments} {notRoot} {
194 test fCmd-3.11 {FileCopyRename: just 2 arguments} {notRoot} {
197 file rename -force -force -- tf1 tf2
200 test fCmd-3.12 {FileCopyRename: move each source: 1 source} {notRoot} {
205 contents [file join td1 tf1]
207 test fCmd-3.13 {FileCopyRename: move each source: multiple sources} {notRoot} {
214 file rename tf1 tf2 tf3 tf4 td1
215 list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
216 [contents [file join td1 tf3]] [contents [file join td1 tf4]]
218 test fCmd-3.14 {FileCopyRename: FileBasename fails} {notRoot} {
221 list [catch {file rename ~_totally_bogus_user td1} msg] $msg
222 } {1 {user "_totally_bogus_user" doesn't exist}}
223 test fCmd-3.15 {FileCopyRename: source[0] == '\0'} {notRoot unixOrPc} {
226 list [catch {file rename / td1} msg] $msg
227 } {1 {error renaming "/" to "td1": file already exists}}
228 test fCmd-3.16 {FileCopyRename: break on first error} {notRoot} {
235 createfile [file join td1 tf3]
236 list [catch {file rename tf1 tf2 tf3 tf4 td1} msg] $msg
237 } [subst {1 {error renaming "tf3" to "[file join td1 tf3]": file already exists}}]
239 test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} {notRoot} {
244 test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} {notRoot} {
246 file mkdir td1 td2 td3
249 test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} {notRoot} {
252 catch {file mkdir td1 td2 tf1 td3 td4}
253 glob td1 td2 tf1 td3 td4
255 test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} {notRoot} {
257 list [catch {file mkdir ~_totally_bogus_user} msg] $msg
258 } {1 {user "_totally_bogus_user" doesn't exist}}
259 test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\0'} \
262 list [catch {file mkdir ""} msg] $msg
263 } {1 {can't create directory "": no such file or directory}}
264 test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} {notRoot} {
269 test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} {notRoot} {
271 file mkdir [file join td1 td2 td3 td4]
272 glob td1 [file join td1 td2]
273 } "td1 [file join td1 td2]"
274 test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} {notRoot} {
277 set x [file exists td1]
279 list $x [file exists td1]
281 test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} {notRoot} {
284 list [catch {file mkdir tf1} msg] $msg
285 } [subst {1 {can't create directory "[file join tf1]": file already exists}}]
286 test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} {notRoot} {
289 set x [file exists td1]
291 list $x [file exists td1]
293 test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} \
294 {unixOnly notRoot testchmod} {
296 file mkdir td1/td2/td3
297 testchmod 000 td1/td2
298 set msg [list [catch {file mkdir td1/td2/td3/td4} msg] $msg]
299 testchmod 755 td1/td2
301 } {1 {can't create directory "td1/td2/td3": permission denied}}
302 test fCmd-4.12 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} {macOnly} {
304 list [catch {file mkdir nonexistentvolume:} msg] $msg
305 } {1 {can't create directory "nonexistentvolume:": invalid argument}}
306 test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} {notRoot} {
308 set x [file exists td1]
310 list $x [file exists td1]
312 test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} \
315 file delete -force foo
317 file attr foo -perm 040000
318 set result [list [catch {file mkdir foo/tf1} msg] $msg]
319 file delete -force foo
321 } {1 {can't create directory "foo/tf1": permission denied}}
322 test fCmd-4.15 {TclFileMakeDirsCmd: TclpCreateDirectory fails} {macOnly} {
323 list [catch {file mkdir ${root}:} msg] $msg
324 } [subst {1 {can't create directory "${root}:": no such file or directory}}]
325 test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} {notRoot} {
331 test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} {notRoot} {
332 list [catch {file delete -xyz} msg] $msg
333 } {1 {bad option "-xyz": should be -force or --}}
334 test fCmd-5.2 {TclFileDeleteCmd: not enough args} {notRoot} {
335 list [catch {file delete -force -force} msg] $msg
336 } {1 {wrong # args: should be "file delete ?options? file ?file ...?"}}
337 test fCmd-5.3 {TclFileDeleteCmd: 1 file} {notRoot} {
345 test fCmd-5.4 {TclFileDeleteCmd: multiple files} {notRoot} {
350 set x [list [file exists tf1] [file exists tf2] [file exists td1]]
351 file delete tf1 td1 tf2
352 lappend x [file exists tf1] [file exists tf2] [file exists tf3]
354 test fCmd-5.5 {TclFileDeleteCmd: stop at first error} {notRoot unixOrPc} {
359 catch {file delete tf1 td1 $root tf2}
360 list [file exists tf1] [file exists tf2] [file exists td1]
362 test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} {notRoot} {
363 list [catch {file delete ~_totally_bogus_user} msg] $msg
364 } {1 {user "_totally_bogus_user" doesn't exist}}
365 test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} {notRoot} {
366 catch {file delete ~/tf1}
370 test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} {notRoot} {
372 set x [file exists tf1]
374 list $x [file exists tf1]
376 test fCmd-5.9 {TclFileDeleteCmd: is directory} {notRoot} {
382 test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} {notRoot} {
384 file mkdir [file join td1 td2]
385 list [catch {file delete td1} msg] $msg
386 } {1 {error deleting "td1": directory not empty}}
387 test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} {notRoot} {
390 file mkdir [file join td1 td2]
391 cd [file join td1 td2]
392 set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
394 lappend res [file exists td1] $msg
396 test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} {unixOnly} {
398 file mkdir [file join td1 td2]
399 #exec chmod u-rwx [file join td1 td2]
400 file attributes [file join td1 td2] -permissions u+rwx
401 set res [list [catch {file delete -force td1} msg]]
402 lappend res [file exists td1] $msg
405 test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot} {
406 # can't test this, because it's caught by FileCopyRename
408 test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot} {
409 # can't test this, because it's caught by FileCopyRename
411 test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} {notRoot} {
413 list [catch {file rename tf1 tf2} msg] $msg
414 } {1 {error renaming "tf1": no such file or directory}}
415 test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} {notRoot} {
421 test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} {notRoot} {
427 test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} {unixOnly notRoot testchmod} {
432 set msg [list [catch {file rename tf1 td1} msg] $msg]
435 } {1 {error renaming "tf1" to "td1/tf1": permission denied}}
436 test fCmd-6.7 {CopyRenameOneFile: errno != ENOENT} {pcOnly 95} {
439 list [catch {file rename tf1 $long} msg] $msg
440 } [subst {1 {error renaming "tf1" to "$long": file name too long}}]
441 test fCmd-6.8 {CopyRenameOneFile: errno != ENOENT} {macOnly} {
444 list [catch {file rename tf1 $long} msg] $msg
445 } [subst {1 {error renaming "tf1" to "$long": file name too long}}]
446 test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} {unixOnly notRoot} {
452 test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 0} {notRoot} {
456 list [catch {file rename tf1 tf2} msg] $msg
457 } {1 {error renaming "tf1" to "tf2": file already exists}}
458 test fCmd-6.11 {CopyRenameOneFile: force == 0} {notRoot} {
462 list [catch {file rename tf1 tf2} msg] $msg
463 } {1 {error renaming "tf1" to "tf2": file already exists}}
464 test fCmd-6.12 {CopyRenameOneFile: force != 0} {notRoot} {
468 file rename -force tf1 tf2
471 test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} {notRoot} {
475 createfile [file join td2 td1]
476 list [catch {file rename -force td1 td2} msg] $msg
477 } [subst {1 {can't overwrite file "[file join td2 td1]" with directory "td1"}}]
478 test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} {notRoot} {
481 file mkdir [file join td1 tf1]
482 list [catch {file rename -force tf1 td1} msg] $msg
483 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
484 test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} {notRoot} {
486 file mkdir [file join td1 td2]
488 createfile [file join td2 tf1]
489 file rename -force td2 td1
490 file exists [file join td1 td2 tf1]
492 test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} {notRoot} {
494 file mkdir [file join td1 td2]
495 createfile [file join td1 td2 tf1]
497 list [catch {file rename -force td2 td1} msg] $msg
498 } [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
500 test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} {notRoot} {
502 list [catch {file rename -force $root tf1} msg] $msg
503 } [subst {1 {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}}]
504 test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} {notRoot} {
506 file mkdir [file join td1 td2]
507 createfile [file join td1 td2 tf1]
509 list [catch {file rename -force td2 td1} msg] $msg
510 } [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
511 test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {unixOnly notRoot} {
517 test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} {pcOnly} {
518 catch {file delete -force c:/tcl8975@ d:/tcl8975@}
519 file mkdir c:/tcl8975@
520 if [catch {file rename c:/tcl8975@ d:/}] {
523 set msg [glob c:/tcl8975@ d:/tcl8975@]
524 file delete -force d:/tcl8975@
526 file delete -force c:/tcl8975@
529 test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} \
536 test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} \
543 test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} \
544 {unixOnly notRoot xdev} {
546 file mkdir td1/td2/td3
547 file attributes td1 -permissions 0000
548 set msg [list [catch {file rename td1 /tmp} msg] $msg]
549 file attributes td1 -permissions 0755
551 } {1 {error renaming "td1": permission denied}}
552 test fCmd-6.24 {CopyRenameOneFile: error uses original name} \
556 set td1name [file join [file dirname ~] [file tail ~] td1]
557 file attributes $td1name -permissions 0000
558 set msg [list [catch {file copy ~/td1 td1} msg] $msg]
559 file attributes $td1name -permissions 0755
560 file delete -force ~/td1
562 } {1 {error copying "~/td1": permission denied}}
563 test fCmd-6.25 {CopyRenameOneFile: error uses original name} \
568 set td1name [file join [file dirname ~] [file tail ~] td1]
569 file attributes $td1name -permissions 0000
570 set msg [list [catch {file copy td2 ~/td1} msg] $msg]
571 file attributes $td1name -permissions 0755
572 file delete -force ~/td1
574 } {1 {error copying "td2" to "~/td1/td2": permission denied}}
575 test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} \
579 set td2name [file join [file dirname ~] [file tail ~] td1 td2]
580 file attributes $td2name -permissions 0000
581 set msg [list [catch {file copy ~/td1 td1} msg] $msg]
582 file attributes $td2name -permissions 0755
583 file delete -force ~/td1
585 } "1 {error copying \"~/td1\" to \"td1\": \"[file join [file dirname ~] [file tail ~] td1 td2]\": permission denied}"
586 test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} \
587 {unixOnly notRoot xdev} {
589 file mkdir td1/td2/td3
591 createfile /tmp/td1/tf1
592 list [catch {file rename -force td1 /tmp} msg] $msg
593 } {1 {error renaming "td1" to "/tmp/td1": file already exists}}
594 test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} \
595 {unixOnly notRoot xdev} {
597 file mkdir td1/td2/td3
598 file attributes td1/td2/td3 -permissions 0000
599 set msg [list [catch {file rename td1 /tmp} msg] $msg]
600 file attributes td1/td2/td3 -permissions 0755
602 } {1 {error renaming "td1" to "/tmp/td1": "td1/td2/td3": permission denied}}
603 test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} \
604 {unixOnly notRoot xdev} {
606 file mkdir td1/td2/td3
610 test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} \
614 file attr foo -perm 040555
615 set catchResult [catch {file rename foo/bar /tmp} msg]
616 set msg [lindex [split $msg :] end]
617 catch {file delete /tmp/bar}
618 catch {file attr foo -perm 040777}
619 catch {file delete -force foo}
620 list $catchResult $msg
621 } {1 { permission denied}}
622 test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} \
623 {unixOnly notRoot xdev} {
626 createfile /tmp/td1/tf1
627 file rename /tmp/td1/tf1 tf1
628 list [file exists /tmp/td1/tf1] [file exists tf1]
630 test fCmd-6.32 {CopyRenameOneFile: copy} {notRoot} {
632 list [catch {file copy tf1 tf2} msg] $msg
633 } {1 {error copying "tf1": no such file or directory}}
636 test fCmd-7.1 {FileForceOption: none} {notRoot} {
638 file mkdir [file join tf1 tf2]
639 list [catch {file delete tf1} msg] $msg
640 } {1 {error deleting "tf1": directory not empty}}
641 test fCmd-7.2 {FileForceOption: -force} {notRoot} {
643 file mkdir [file join tf1 tf2]
644 file delete -force tf1
646 test fCmd-7.3 {FileForceOption: --} {notRoot} {
650 test fCmd-7.4 {FileForceOption: bad option} {notRoot} {
652 set msg [list [catch {file delete -tf1} msg] $msg]
655 } {1 {bad option "-tf1": should be -force or --}}
656 test fCmd-7.5 {FileForceOption: multiple times through loop} {notRoot} {
659 file delete -force -force -- -- -force
660 list [catch {glob -- -- -force} msg] $msg
661 } {1 {no files matched glob patterns "-- -force"}}
663 test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
664 {unixOnly notRoot knownBug} {
665 # Labelled knownBug because it is dangerous [Bug: 3881]
667 file attr td1 -perm 040000
668 set result [list [catch {file rename ~$user td1} msg] $msg]
669 file delete -force td1
671 } "1 {error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied}"
672 test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
677 test fCmd-9.1 {file rename: comprehensive: EACCES} {unixOnly notRoot} {
681 file attr td2 -perm 040000
682 set result [list [catch {file rename td1 td2/} msg] $msg]
683 file delete -force td2
684 file delete -force td1
686 } {1 {error renaming "td1" to "td2/td1": permission denied}}
687 test fCmd-9.2 {file rename: comprehensive: source doesn't exist} {notRoot} {
689 list [catch {file rename tf1 tf2} msg] $msg
690 } {1 {error renaming "tf1": no such file or directory}}
691 test fCmd-9.3 {file rename: comprehensive: file to new name} {notRoot testchmod} {
698 list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
700 test fCmd-9.4 {file rename: comprehensive: dir to new name} {unixOrPc notRoot testchmod} {
706 list [lsort [glob td*]] [file writable td3] [file writable td4]
708 test fCmd-9.5 {file rename: comprehensive: file to self} {notRoot testchmod} {
713 file rename -force tf1 tf1
714 file rename -force tf2 tf2
715 list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
717 test fCmd-9.6 {file rename: comprehensive: dir to self} {notRoot unixOrPc testchmod} {
722 file rename -force td1 .
723 file rename -force td2 .
724 list [lsort [glob td*]] [file writable td1] [file writable td2]
726 test fCmd-9.7 {file rename: comprehensive: file to existing file} {notRoot testchmod} {
742 set msg [list [catch {file rename tf1 tf2} msg] $msg]
743 file rename -force tfs1 tfd1
744 file rename -force tfs2 tfd2
745 file rename -force tfs3 tfd3
746 file rename -force tfs4 tfd4
747 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
748 } {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
749 test fCmd-9.8 {file rename: comprehensive: dir to empty dir} {notRoot testchmod} {
750 # Under unix, you can rename a read-only directory, but you can't
751 # move it into another directory.
755 file mkdir [file join td2 td1]
760 file mkdir [file join tdd1 tds1]
761 file mkdir [file join tdd2 tds2]
762 file mkdir [file join tdd3 tds3]
763 file mkdir [file join tdd4 tds4]
764 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
768 if {$tcl_platform(platform) != "macintosh"} {
769 testchmod 555 [file join tdd2 tds2]
770 testchmod 555 [file join tdd4 tds4]
772 set msg [list [catch {file rename td1 td2} msg] $msg]
773 file rename -force tds1 tdd1
774 file rename -force tds2 tdd2
775 file rename -force tds3 tdd3
776 file rename -force tds4 tdd4
777 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
778 set w3 [file writable [file join tdd3 tds3]]
779 set w4 [file writable [file join tdd4 tds4]]
784 list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
785 [file writable [file join tdd2 tds2]] $w3 $w4
786 } [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
787 test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} {notRoot testchmod} {
791 file mkdir [file join tdd1 tds1 xxx]
792 file mkdir [file join tdd2 tds2 xxx]
793 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
796 set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
797 set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
798 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
799 set w2 [file writable tds2]
803 list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
804 } [subst {{tdd1 tdd2 tds1 tds2} {1 {error renaming "tds1" to "[file join tdd1 tds1]": file already exists}} {1 {error renaming "tds2" to "[file join tdd2 tds2]": file already exists}} 1 0}]
805 test fCmd-9.10 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
811 file rename tf1 [file join td1 tf3]
812 file rename tf2 [file join td1 tf4]
813 list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \
814 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
815 } [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}]
816 test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} {notRoot testchmod} {
821 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
824 file rename td1 [file join td3 td3]
825 file rename td2 [file join td3 td4]
826 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
827 set w4 [file writable [file join td3 td4]]
831 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
832 [file writable [file join td3 td3]] $w4
833 } [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
834 test fCmd-9.12 {file rename: comprehensive: target exists} {notRoot testchmod} {
836 file mkdir [file join td1 td2] [file join td2 td1]
837 if {$tcl_platform(platform) != "macintosh"} {
838 testchmod 555 [file join td2 td1]
840 file mkdir [file join td3 td4] [file join td4 td3]
841 file rename -force td3 td4
842 set msg [list [file exists td3] [file exists [file join td4 td3 td4]] \
843 [catch {file rename td1 td2} msg] $msg]
844 if {$tcl_platform(platform) != "macintosh"} {
845 testchmod 755 [file join td2 td1]
848 } [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
849 test fCmd-9.13 {file rename: comprehensive: can't overwrite target} {notRoot} {
851 file mkdir [file join td1 td2] [file join td2 td1 td4]
852 list [catch {file rename -force td1 td2} msg] $msg
853 } [subst {1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
854 test fCmd-9.14 {file rename: comprehensive: dir into self} {notRoot} {
857 list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
858 } [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
859 test fCmd-9.15 {file rename: comprehensive: source and target incompatible} \
864 list [catch {file rename -force td1 tf1} msg] $msg
865 } {1 {can't overwrite file "tf1" with directory "td1"}}
866 test fCmd-9.16 {file rename: comprehensive: source and target incompatible} \
871 list [catch {file rename -force tf1 td1} msg] $msg
872 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
874 test fCmd-10.1 {file copy: comprehensive: source doesn't exist} {notRoot} {
876 list [catch {file copy tf1 tf2} msg] $msg
877 } {1 {error copying "tf1": no such file or directory}}
878 test fCmd-10.2 {file copy: comprehensive: file to new name} {notRoot testchmod} {
885 list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
886 } {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
887 test fCmd-10.3 {file copy: comprehensive: dir to new name} {notRoot unixOrPc testchmod} {
889 file mkdir [file join td1 tdx]
890 file mkdir [file join td2 tdy]
894 set msg [list [lsort [glob td*]] [glob -directory td3 t*] \
895 [glob -directory td4 t*] [file writable td3] [file writable td4]]
896 if {$tcl_platform(platform) != "macintosh"} {
901 } [subst {{td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0}]
902 test fCmd-10.4 {file copy: comprehensive: file to existing file} {notRoot testchmod} {
918 set msg [list [catch {file copy tf1 tf2} msg] $msg]
919 file copy -force tfs1 tfd1
920 file copy -force tfs2 tfd2
921 file copy -force tfs3 tfd3
922 file copy -force tfs4 tfd4
923 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
924 } {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
925 test fCmd-10.5 {file copy: comprehensive: dir to empty dir} {notRoot testchmod} {
928 file mkdir [file join td2 td1]
933 file mkdir [file join tdd1 tds1]
934 file mkdir [file join tdd2 tds2]
935 file mkdir [file join tdd3 tds3]
936 file mkdir [file join tdd4 tds4]
937 if {$tcl_platform(platform) != "macintosh"} {
940 testchmod 555 [file join tdd2 tds2]
941 testchmod 555 [file join tdd4 tds4]
943 set a1 [list [catch {file copy td1 td2} msg] $msg]
944 set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
945 set a3 [catch {file copy -force tds2 tdd2}]
946 set a4 [catch {file copy -force tds3 tdd3}]
947 set a5 [catch {file copy -force tds4 tdd4}]
948 list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5
949 } [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}]
950 test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} \
951 {notRoot unixOrPc testchmod} {
955 file mkdir [file join tdd1 tds1 xxx]
956 file mkdir [file join tdd2 tds2 xxx]
958 set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
959 set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
960 list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
961 } [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}]
962 test fCmd-10.7 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
968 file copy tf1 [file join td1 tf3]
969 file copy tf2 [file join td1 tf4]
970 list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
971 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
972 } [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
973 test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} \
974 {notRoot unixOrPc testchmod} {
980 file copy td1 [file join td3 td3]
981 file copy td2 [file join td3 td4]
982 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
983 [file writable [file join td3 td3]] [file writable [file join td3 td4]]
984 } [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
985 test fCmd-10.9 {file copy: comprehensive: source and target incompatible} \
990 list [catch {file copy -force td1 tf1} msg] $msg
991 } {1 {can't overwrite file "tf1" with directory "td1"}}
992 test fCmd-10.10 {file copy: comprehensive: source and target incompatible} \
995 file mkdir [file join td1 tf1]
997 list [catch {file copy -force tf1 td1} msg] $msg
998 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
1003 test fCmd-11.1 {TclFileRenameCmd: -- option } {notRoot} {
1004 catch {file delete -force -- -tfa1}
1005 set s [createfile -tfa1]
1006 file rename -- -tfa1 tfa2
1007 set result [expr [checkcontent tfa2 $s] && ![file exists -tfa1]]
1012 test fCmd-11.2 {TclFileRenameCmd: bad option } {notRoot} {
1013 catch {file delete -force -- tfa1}
1014 set s [createfile tfa1]
1015 set r1 [catch {file rename -x tfa1 tfa2}]
1016 set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
1021 test fCmd-11.3 {TclFileRenameCmd: bad \# args} {
1022 catch {file rename -- }
1025 test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} {notRoot} {
1029 set result [catch {file rename tfa ~/foobar }]
1034 test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} {notRoot} {
1035 catch {file delete -force -- tfa1 tfa2 tfa3}
1039 set result [catch {file rename tfa1 tfa2 tfa3}]
1040 file delete tfa1 tfa2 tfa3
1044 test fCmd-11.6 {TclFileRenameCmd: : single file into directory} {notRoot} {
1045 catch {file delete -force -- tfa1 tfad}
1046 set s [createfile tfa1]
1048 file rename tfa1 tfad
1049 set result [expr [checkcontent tfad/tfa1 $s] && ![file exists tfa1]]
1050 file delete -force tfad
1054 test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} {notRoot} {
1055 catch {file delete -force -- tfa1 tfa2 tfad}
1056 set s1 [createfile tfa1 ]
1057 set s2 [createfile tfa2 ]
1059 file rename tfa1 tfa2 tfad
1060 set r1 [checkcontent tfad/tfa1 $s1]
1061 set r2 [checkcontent tfad/tfa2 $s2]
1063 set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfa2]]
1065 file delete -force tfad
1069 test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} {notRoot} {
1070 catch {file delete -force -- tfa tfad}
1071 set s [createfile tfa ]
1074 set r1 [catch {file rename tfa tfad}]
1075 set r2 [checkcontent tfa $s]
1076 set r3 [file isdir tfad]
1077 set result [expr $r1 && $r2 && $r3 ]
1078 file delete -force tfa tfad
1083 # Coverage tests for renamefile() ;
1085 test fCmd-12.1 {renamefile: source filename translation failing} {notRoot} {
1089 set result [catch {file rename ~/tfa1 tfa2}]
1094 test fCmd-12.2 {renamefile: src filename translation failing} {notRoot} {
1098 set s [createfile tfa1]
1100 set result [catch {file rename tfa1 ~/tfa2 tfad}]
1102 file delete -force tfad
1106 test fCmd-12.3 {renamefile: stat failing on source} {notRoot} {
1107 catch {file delete -force -- tfa1 tfa2}
1108 set r1 [catch {file rename tfa1 tfa2}]
1109 expr {$r1 && ![file exists tfa1] && ![file exists tfa2]}
1112 test fCmd-12.4 {renamefile: error renaming file to directory} {notRoot} {
1113 catch {file delete -force -- tfa tfad}
1114 set s1 [createfile tfa ]
1117 set r1 [catch {file rename tfa tfad}]
1118 set r2 [checkcontent tfa $s1]
1119 set r3 [file isdir tfad/tfa]
1120 set result [expr $r1 && $r2 && $r3]
1121 file delete -force tfa tfad
1125 test fCmd-12.5 {renamefile: error renaming directory to file} {notRoot} {
1126 catch {file delete -force -- tfa tfad}
1129 set s [createfile tfad/tfa]
1130 set r1 [catch {file rename tfa tfad}]
1131 set r2 [checkcontent tfad/tfa $s]
1132 set r3 [file isdir tfad]
1133 set r4 [file isdir tfa]
1134 set result [expr $r1 && $r2 && $r3 && $r4 ]
1135 file delete -force tfa tfad
1139 test fCmd-12.6 {renamefile: TclRenameFile succeeding} {notRoot} {
1140 catch {file delete -force -- tfa1 tfa2}
1141 set s [createfile tfa1]
1142 file rename tfa1 tfa2
1143 set result [expr [checkcontent tfa2 $s] && ![file exists tfa1]]
1148 test fCmd-12.7 {renamefile: renaming directory into offspring} {notRoot} {
1149 catch {file delete -force -- tfad}
1152 set result [catch {file rename tfad tfad/dir}]
1153 file delete -force tfad
1157 test fCmd-12.8 {renamefile: generic error} {unixOnly notRoot} {
1158 catch {file delete -force -- tfa}
1161 file attributes tfa -permissions 0555
1162 set result [catch {file rename tfa/dir tfa2}]
1163 file attributes tfa -permissions 0777
1164 file delete -force tfa
1169 test fCmd-12.9 {renamefile: moving a file across volumes} {unixOnly notRoot} {
1170 catch {file delete -force -- tfa /tmp/tfa}
1171 set s [createfile tfa ]
1172 file rename tfa /tmp
1173 set result [expr [checkcontent /tmp/tfa $s] && ![file exists tfa]]
1174 file delete /tmp/tfa
1178 test fCmd-12.10 {renamefile: moving a directory across volumes } \
1179 {unixOnly notRoot} {
1180 catch {file delete -force -- tfad /tmp/tfad}
1182 set s [createfile tfad/a ]
1183 file rename tfad /tmp
1184 set restul [expr [checkcontent /tmp/tfad/a $s] && ![file exists tfad]]
1185 file delete -force /tmp/tfad
1190 # Coverage tests for TclCopyFilesCmd()
1192 test fCmd-13.1 {TclCopyFilesCmd: -force option} {notRoot} {
1193 catch {file delete -force -- tfa1}
1194 set s [createfile tfa1]
1195 file copy -force tfa1 tfa2
1196 set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
1197 file delete tfa1 tfa2
1201 test fCmd-13.2 {TclCopyFilesCmd: -- option} {notRoot} {
1202 catch {file delete -force -- tfa1}
1203 set s [createfile -tfa1]
1204 file copy -- -tfa1 tfa2
1205 set result [expr [checkcontent tfa2 $s] && [checkcontent -tfa1 $s]]
1206 file delete -- -tfa1 tfa2
1210 test fCmd-13.3 {TclCopyFilesCmd: bad option} {notRoot} {
1211 catch {file delete -force -- tfa1}
1212 set s [createfile tfa1]
1213 set r1 [catch {file copy -x tfa1 tfa2}]
1214 set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
1219 test fCmd-13.4 {TclCopyFilesCmd: bad \# args} {notRoot} {
1220 catch {file copy -- }
1223 test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} {
1227 set result [catch {file copy tfa ~/foobar }]
1232 test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} {notRoot} {
1233 catch {file delete -force -- tfa1 tfa2 tfa3}
1237 set result [catch {file copy tfa1 tfa2 tfa3}]
1238 file delete tfa1 tfa2 tfa3
1242 test fCmd-13.7 {TclCopyFilesCmd: single file into directory} {notRoot} {
1243 catch {file delete -force -- tfa1 tfad}
1244 set s [createfile tfa1]
1247 set result [expr [checkcontent tfad/tfa1 $s] && [checkcontent tfa1 $s]]
1248 file delete -force tfad tfa1
1252 test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} {notRoot} {
1253 catch {file delete -force -- tfa1 tfa2 tfad}
1254 set s1 [createfile tfa1 ]
1255 set s2 [createfile tfa2 ]
1257 file copy tfa1 tfa2 tfad
1258 set r1 [checkcontent tfad/tfa1 $s1]
1259 set r2 [checkcontent tfad/tfa2 $s2]
1260 set r3 [checkcontent tfa1 $s1]
1261 set r4 [checkcontent tfa2 $s2]
1262 set result [expr $r1 && $r2 && $r3 && $r4 ]
1264 file delete -force tfad tfa1 tfa2
1268 test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} {notRoot} {
1269 catch {file delete -force -- tfa tfad}
1270 set s [createfile tfa ]
1273 set r1 [catch {file copy tfa tfad}]
1274 set r2 [expr [checkcontent tfa $s] && [file isdir tfad/tfa]]
1275 set r3 [file isdir tfad]
1276 set result [expr $r1 && $r2 && $r3 ]
1277 file delete -force tfa tfad
1282 # Coverage tests for copyfile()
1284 test fCmd-14.1 {copyfile: source filename translation failing} {notRoot} {
1288 set result [catch {file copy ~/tfa1 tfa2}]
1293 test fCmd-14.2 {copyfile: dst filename translation failing} {notRoot} {
1297 set s [createfile tfa1]
1299 set r1 [catch {file copy tfa1 ~/tfa2 tfad}]
1300 set result [expr $r1 && [checkcontent tfad/tfa1 $s]]
1302 file delete -force tfa1 tfad
1306 test fCmd-14.3 {copyfile: stat failing on source} {notRoot} {
1307 catch {file delete -force -- tfa1 tfa2}
1308 set r1 [catch {file copy tfa1 tfa2}]
1309 expr $r1 && ![file exists tfa1] && ![file exists tfa2]
1312 test fCmd-14.4 {copyfile: error copying file to directory} {notRoot} {
1313 catch {file delete -force -- tfa tfad}
1314 set s1 [createfile tfa ]
1317 set r1 [catch {file copy tfa tfad}]
1318 set r2 [checkcontent tfa $s1]
1319 set r3 [file isdir tfad]
1320 set r4 [file isdir tfad/tfa]
1321 set result [expr $r1 && $r2 && $r3 && $r4 ]
1322 file delete -force tfa tfad
1326 test fCmd-14.5 {copyfile: error copying directory to file} {notRoot} {
1327 catch {file delete -force -- tfa tfad}
1330 set s [createfile tfad/tfa]
1331 set r1 [catch {file copy tfa tfad}]
1332 set r2 [checkcontent tfad/tfa $s]
1333 set r3 [file isdir tfad]
1334 set r4 [file isdir tfa]
1335 set result [expr $r1 && $r2 && $r3 && $r4 ]
1336 file delete -force tfa tfad
1340 test fCmd-14.6 {copyfile: copy file succeeding} {notRoot} {
1341 catch {file delete -force -- tfa tfa2}
1342 set s [createfile tfa]
1344 set result [expr [checkcontent tfa $s] && [checkcontent tfa2 $s]]
1345 file delete tfa tfa2
1349 test fCmd-14.7 {copyfile: copy directory succeeding} {notRoot} {
1350 catch {file delete -force -- tfa tfa2}
1352 set s [createfile tfa/file]
1354 set result [expr [checkcontent tfa/file $s] && [checkcontent tfa2/file $s]]
1355 file delete -force tfa tfa2
1359 test fCmd-14.8 {copyfile: copy directory failing} {unixOnly notRoot} {
1360 catch {file delete -force -- tfa}
1361 file mkdir tfa/dir/a/b/c
1362 file attributes tfa/dir -permissions 0000
1363 set r1 [catch {file copy tfa tfa2}]
1364 file attributes tfa/dir -permissions 0777
1366 file delete -force tfa tfa2
1371 # Coverage tests for TclMkdirCmd()
1373 test fCmd-15.1 {TclMakeDirsCmd: target filename translation failing} {notRoot} {
1377 set result [catch {file mkdir ~/tfa}]
1382 # Can Tcl_SplitPath return argc == 0? If so them we need a
1383 # test for that code.
1385 test fCmd-15.2 {TclMakeDirsCmd - one directory } {notRoot} {
1386 catch {file delete -force -- tfa}
1388 set result [file isdirectory tfa]
1393 test fCmd-15.3 {TclMakeDirsCmd: - two directories} {notRoot} {
1394 catch {file delete -force -- tfa1 tfa2}
1395 file mkdir tfa1 tfa2
1396 set result [expr [file isdirectory tfa1] && [file isdirectory tfa2]]
1397 file delete tfa1 tfa2
1401 test fCmd-15.4 {TclMakeDirsCmd - stat failing} {unixOnly notRoot} {
1402 catch {file delete -force -- tfa}
1405 file attributes tfa -permissions 0000
1406 set result [catch {file mkdir tfa/file}]
1407 file attributes tfa -permissions 0777
1408 file delete -force tfa
1412 test fCmd-15.5 {TclMakeDirsCmd: - making a directory several levels deep} \
1414 catch {file delete -force -- tfa}
1415 file mkdir tfa/a/b/c
1416 set result [file isdir tfa/a/b/c]
1417 file delete -force tfa
1422 test fCmd-15.6 {TclMakeDirsCmd: - trying to overwrite a file} {notRoot} {
1423 catch {file delete -force -- tfa}
1424 set s [createfile tfa]
1425 set r1 [catch {file mkdir tfa}]
1426 set r2 [file isdir tfa]
1427 set r3 [file exists tfa]
1428 set result [expr $r1 && !$r2 && $r3 && [checkcontent tfa $s]]
1433 test fCmd-15.7 {TclMakeDirsCmd - making several directories} {notRoot} {
1434 catch {file delete -force -- tfa1 tfa2}
1435 file mkdir tfa1 tfa2/a/b/c
1436 set result [expr [file isdir tfa1] && [file isdir tfa2/a/b/c]]
1437 file delete -force tfa1 tfa2
1441 test fCmd-15.8 {TclFileMakeDirsCmd: trying to create an existing dir} {notRoot} {
1444 set result [file isdir tfa]
1450 # Coverage tests for TclDeleteFilesCommand()
1451 test fCmd-16.1 {test the -- argument} {notRoot} {
1452 catch {file delete -force -- tfa}
1458 test fCmd-16.2 {test the -force and -- arguments} {notRoot} {
1459 catch {file delete -force -- tfa}
1461 file delete -force -- tfa
1465 test fCmd-16.3 {test bad option} {notRoot} {
1466 catch {file delete -force -- tfa}
1468 set result [catch {file delete -dog tfa}]
1473 test fCmd-16.4 {test not enough args} {notRoot} {
1477 test fCmd-16.5 {test not enough args with options} {notRoot} {
1478 catch {file delete --}
1481 test fCmd-16.6 {delete: source filename translation failing} {notRoot} {
1485 set result [catch {file delete ~/tfa}]
1490 test fCmd-16.7 {remove a non-empty directory without -force } {notRoot} {
1491 catch {file delete -force -- tfa}
1494 set result [catch {file delete tfa }]
1495 file delete -force tfa
1499 test fCmd-16.8 {remove a normal file } {notRoot} {
1500 catch {file delete -force -- tfa}
1503 set result [catch {file delete tfa }]
1504 file delete -force tfa
1508 test fCmd-16.9 {error while deleting file } {unixOnly notRoot} {
1509 catch {file delete -force -- tfa}
1512 file attributes tfa -permissions 0555
1513 set result [catch {file delete tfa/a }]
1515 ####### If any directory in a tree that is being removed does not
1516 ####### have write permission, the process will fail!
1517 ####### This is also the case with "rm -rf"
1519 file attributes tfa -permissions 0777
1520 file delete -force tfa
1524 test fCmd-16.10 {deleting multiple files} {notRoot} {
1525 catch {file delete -force -- tfa1 tfa2}
1528 file delete tfa1 tfa2
1529 expr ![file exists tfa1] && ![file exists tfa2]
1532 test fCmd-16.11 {TclFileDeleteCmd: removing a nonexistant file} {notRoot} {
1533 catch {file delete -force -- tfa}
1538 # More coverage tests for mkpath()
1539 test fCmd-17.1 {mkdir stat failing on target but not ENOENT} {unixOnly notRoot} {
1540 catch {file delete -force -- tfa1}
1542 file attributes tfa1 -permissions 0555
1543 set result [catch {file mkdir tfa1/tfa2}]
1544 file attributes tfa1 -permissions 0777
1545 file delete -force tfa1
1549 test fCmd-17.2 {mkdir several levels deep - relative } {notRoot} {
1550 catch {file delete -force -- tfa}
1552 set result [file isdir tfa/a/b ]
1553 file delete tfa/a/b tfa/a tfa
1557 test fCmd-17.3 {mkdir several levels deep - absolute } {notRoot} {
1558 catch {file delete -force -- tfa}
1559 set f [file join [pwd] tfa a ]
1561 set result [file isdir $f ]
1562 file delete $f [file join [pwd] tfa]
1567 # Functionality tests for TclFileRenameCmd()
1570 test fCmd-18.1 {TclFileRenameCmd: rename (first form) in the same directory} \
1572 catch {file delete -force -- tfad}
1575 set s [createfile foo ]
1577 file rename bar ./foo
1578 file rename ./foo bar
1579 file rename ./bar ./foo
1580 file rename foo ../dir/bar
1581 file rename ../dir/bar ./foo
1582 file rename ../../tfad/dir/foo ../../tfad/dir/bar
1583 file rename [file join [pwd] bar] foo
1584 file rename foo [file join [pwd] bar]
1585 set result [expr [checkcontent bar $s] && ![file exists foo]]
1587 file delete -force tfad
1591 test fCmd-18.2 {TclFileRenameCmd: single dir to nonexistant} {notRoot} {
1592 catch {file delete -force -- tfa1 tfa2}
1594 file rename tfa1 tfa2
1595 set result [expr [file exists tfa2] && ![file exists tfa1]]
1600 test fCmd-18.3 {TclFileRenameCmd: mixed dirs and files into directory} {notRoot} {
1601 catch {file delete -force -- tfa1 tfad1 tfad2}
1602 set s [createfile tfa1 ]
1603 file mkdir tfad1 tfad2
1604 file rename tfa1 tfad1 tfad2
1605 set r1 [checkcontent tfad2/tfa1 $s]
1606 set r2 [file isdir tfad2/tfad1]
1607 set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfad1]]
1608 file delete tfad2/tfa1
1609 file delete -force tfad2
1613 test fCmd-18.4 {TclFileRenameCmd: attempt to replace non-dir with dir} {notRoot} {
1614 catch {file delete -force -- tfa tfad}
1615 set s [createfile tfa ]
1617 set r1 [catch {file rename tfad tfa}]
1618 set r2 [checkcontent tfa $s]
1619 set r3 [file isdir tfad]
1620 set result [expr $r1 && $r2 && $r3 ]
1621 file delete tfa tfad
1625 test fCmd-18.5 {TclFileRenameCmd: attempt to replace dir with non-dir} {notRoot} {
1626 catch {file delete -force -- tfa tfad}
1627 set s [createfile tfa ]
1629 set r1 [catch {file rename tfa tfad}]
1630 set r2 [checkcontent tfa $s]
1631 set r3 [file isdir tfad/tfa]
1632 set result [expr $r1 && $r2 && $r3 ]
1633 file delete -force tfa tfad
1638 # On Windows there is no easy way to determine if two files are the same
1640 test fCmd-18.6 {TclFileRenameCmd: rename a file to itself} {macOrUnix notRoot} {
1641 catch {file delete -force -- tfa}
1642 set s [createfile tfa]
1643 set r1 [catch {file rename tfa tfa}]
1644 set result [expr $r1 && [checkcontent tfa $s]]
1649 test fCmd-18.7 {TclFileRenameCmd: rename dir on top of another empty dir w/o -force} \
1651 catch {file delete -force -- tfa tfad}
1652 file mkdir tfa tfad/tfa
1653 set r1 [catch {file rename tfa tfad}]
1654 set result [expr $r1 && [file isdir tfa]]
1655 file delete -force tfa tfad
1659 test fCmd-18.8 {TclFileRenameCmd: rename dir on top of another empty dir w/ -force} \
1661 catch {file delete -force -- tfa tfad}
1662 file mkdir tfa tfad/tfa
1663 file rename -force tfa tfad
1664 set result [expr ![file isdir tfa]]
1665 file delete -force tfad
1669 test fCmd-18.9 {TclFileRenameCmd: rename dir on top of a non-empty dir w/o -force} \
1671 catch {file delete -force -- tfa tfad}
1672 file mkdir tfa tfad/tfa/file
1673 set r1 [catch {file rename tfa tfad}]
1674 set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
1675 file delete -force tfa tfad
1679 test fCmd-18.10 {TclFileRenameCmd: rename dir on top of a non-empty dir w/ -force} \
1681 catch {file delete -force -- tfa tfad}
1682 file mkdir tfa tfad/tfa/file
1683 set r1 [catch {file rename -force tfa tfad}]
1684 set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
1685 file delete -force tfa tfad
1689 test fCmd-18.11 {TclFileRenameCmd: rename a non-existant file} {notRoot} {
1690 catch {file delete -force -- tfa1}
1691 set r1 [catch {file rename tfa1 tfa2}]
1692 set result [expr $r1 && ![file exists tfa1] && ![file exists tfa2]]
1695 test fCmd-18.12 {TclFileRenameCmd : rename a symbolic link to file} \
1696 {unixOnly notRoot} {
1697 catch {file delete -force -- tfa1 tfa2 tfa3}
1699 set s [createfile tfa1]
1700 file link -symbolic tfa2 tfa1
1701 file rename tfa2 tfa3
1702 set t [file type tfa3]
1703 set result [expr {$t eq "link"}]
1704 file delete tfa1 tfa3
1708 test fCmd-18.13 {TclFileRenameCmd : rename a symbolic link to dir} \
1709 {unixOnly notRoot} {
1710 catch {file delete -force -- tfa1 tfa2 tfa3}
1713 file link -symbolic tfa2 tfa1
1714 file rename tfa2 tfa3
1715 set t [file type tfa3]
1716 set result [expr {$t eq "link"}]
1717 file delete tfa1 tfa3
1721 test fCmd-18.14 {TclFileRenameCmd : rename a path with sym link} \
1722 {unixOnly notRoot} {
1723 catch {file delete -force -- tfa1 tfa2 tfa3}
1725 file mkdir tfa1/a/b/c/d
1727 set f [file join [pwd] tfa1/a/b]
1728 set f2 [file join [pwd] {tfa2/b alias}]
1729 file link -symbolic $f2 $f
1730 file rename {tfa2/b alias/c} tfa3
1731 set r1 [file isdir tfa3]
1732 set r2 [file exists tfa1/a/b/c]
1733 set result [expr $r1 && !$r2]
1734 file delete -force tfa1 tfa2 tfa3
1738 test fCmd-18.15 {TclFileRenameCmd : rename a file to a symlink dir} \
1739 {unixOnly notRoot} {
1740 catch {file delete -force -- tfa1 tfa2 tfalink}
1743 set s [createfile tfa2]
1744 file link -symbolic tfalink tfa1
1746 file rename tfa2 tfalink
1747 set result [checkcontent tfa1/tfa2 $s ]
1748 file delete -force tfa1 tfalink
1752 test fCmd-18.16 {TclFileRenameCmd: rename a dangling symlink} {unixOnly notRoot} {
1753 catch {file delete -force -- tfa1 tfalink}
1756 file link -symbolic tfalink tfa1
1758 file rename tfalink tfa2
1759 set result [expr [string compare [file type tfa2] "link"] == 0]
1766 # Coverage tests for TclUnixRmdir
1768 test fCmd-19.1 {remove empty directory} {notRoot} {
1769 catch {file delete -force -- tfa}
1775 test fCmd-19.2 {rmdir error besides EEXIST} {unixOnly notRoot} {
1776 catch {file delete -force -- tfa}
1779 file attributes tfa -permissions 0555
1780 set result [catch {file delete tfa/a}]
1781 file attributes tfa -permissions 0777
1782 file delete -force tfa
1786 test fCmd-19.3 {recursive remove} {notRoot} {
1787 catch {file delete -force -- tfa}
1790 file delete -force tfa
1795 # TclUnixDeleteFile and TraversalDelete are covered by tests from the
1796 # TclDeleteFilesCmd suite
1801 # Coverage tests for TraverseUnixTree(), called from TclDeleteFilesCmd
1804 test fCmd-20.1 {TraverseUnixTree : failure opening a subdirectory directory } \
1805 {unixOnly notRoot} {
1806 catch {file delete -force -- tfa}
1809 file attributes tfa/a -permissions 0000
1810 set result [catch {file delete -force tfa}]
1811 file attributes tfa/a -permissions 0777
1812 file delete -force tfa
1818 # Feature testing for TclCopyFilesCmd
1820 test fCmd-21.1 {copy : single file to nonexistant } {notRoot} {
1821 catch {file delete -force -- tfa1 tfa2}
1822 set s [createfile tfa1]
1824 set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
1825 file delete tfa1 tfa2
1829 test fCmd-21.2 {copy : single dir to nonexistant } {notRoot} {
1830 catch {file delete -force -- tfa1 tfa2}
1833 set result [expr [file isdir tfa2] && [file isdir tfa1]]
1834 file delete tfa1 tfa2
1838 test fCmd-21.3 {copy : single file into directory } {notRoot} {
1839 catch {file delete -force -- tfa1 tfad}
1840 set s [createfile tfa1]
1843 set result [expr [checkcontent tfad/tfa1 $s] && [checkcontent tfa1 $s]]
1844 file delete -force tfa1 tfad
1848 test fCmd-21.4 {copy : more than one source and target is not a directory} \
1850 catch {file delete -force -- tfa1 tfa2 tfa3}
1854 set result [catch {file copy tfa1 tfa2 tfa3}]
1855 file delete tfa1 tfa2 tfa3
1859 test fCmd-21.5 {copy : multiple files into directory } {notRoot} {
1860 catch {file delete -force -- tfa1 tfa2 tfad}
1861 set s1 [createfile tfa1 ]
1862 set s2 [createfile tfa2 ]
1864 file copy tfa1 tfa2 tfad
1865 set r1 [checkcontent tfad/tfa1 $s1]
1866 set r2 [checkcontent tfad/tfa2 $s2]
1867 set r3 [checkcontent tfa1 $s1]
1868 set r4 [checkcontent tfa2 $s2]
1869 set result [expr $r1 && $r2 && $r3 && $r4]
1870 file delete -force tfa1 tfa2 tfad
1874 test fCmd-21.6 {copy: mixed dirs and files into directory} \
1875 {notRoot notFileSharing} {
1876 catch {file delete -force -- tfa1 tfad1 tfad2}
1877 set s [createfile tfa1 ]
1878 file mkdir tfad1 tfad2
1879 file copy tfa1 tfad1 tfad2
1880 set r1 [checkcontent [file join tfad2 tfa1] $s]
1881 set r2 [file isdir [file join tfad2 tfad1]]
1882 set r3 [checkcontent tfa1 $s]
1883 set result [expr $r1 && $r2 && $r3 && [file isdir tfad1]]
1884 file delete -force tfa1 tfad1 tfad2
1888 test fCmd-21.7.1 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot dontCopyLinks} {
1890 file link -symbolic tfalink tfad1
1892 set result [list [catch {file copy tfalink tfalink2} msg] $msg]
1893 file delete -force tfalink tfalink2
1895 } {1 {error copying "tfalink": the target of this link doesn't exist}}
1896 test fCmd-21.7.2 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot} {
1898 file link -symbolic tfalink tfad1
1900 file copy tfalink tfalink2
1901 set result [string match [file type tfalink2] link]
1902 file delete tfalink tfalink2
1906 test fCmd-21.8.1 {TclCopyFilesCmd: copy a link } {unixOnly notRoot dontCopyLinks} {
1908 file link -symbolic tfalink tfad1
1909 file copy tfalink tfalink2
1910 set r1 [file type tfalink]; # link
1911 set r2 [file type tfalink2]; # directory
1912 set r3 [file isdir tfad1]; # 1
1913 set result [expr {("$r1" == "link") && ("$r2" == "directory") && $r3}]
1914 file delete -force tfad1 tfalink tfalink2
1917 test fCmd-21.8.2 {TclCopyFilesCmd: copy a link } {unixOnly notRoot} {
1919 file link -symbolic tfalink tfad1
1920 file copy tfalink tfalink2
1921 set r1 [file type tfalink]; # link
1922 set r2 [file type tfalink2]; # link
1923 set r3 [file isdir tfad1]; # 1
1924 set result [expr {("$r1" == "link") && ("$r2" == "link") && $r3}]
1925 file delete -force tfad1 tfalink tfalink2
1929 test fCmd-21.9 {TclCopyFilesCmd: copy dir with a link in it} {unixOnly notRoot} {
1931 file link -symbolic tfad1/tfalink "[pwd]/tfad1"
1932 file copy tfad1 tfad2
1933 set result [string match [file type tfad2/tfalink] link]
1934 file delete -force tfad1 tfad2
1938 test fCmd-21.10 {TclFileCopyCmd: copy dir on top of another empty dir w/o -force} \
1940 catch {file delete -force -- tfa tfad}
1941 file mkdir tfa [file join tfad tfa]
1942 set r1 [catch {file copy tfa tfad}]
1943 set result [expr $r1 && [file isdir tfa]]
1944 file delete -force tfa tfad
1948 test fCmd-21.11 {TclFileCopyCmd: copy dir on top of a dir w/o -force} {notRoot} {
1949 catch {file delete -force -- tfa tfad}
1950 file mkdir tfa [file join tfad tfa file]
1951 set r1 [catch {file copy tfa tfad}]
1952 set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
1953 file delete -force tfa tfad
1957 test fCmd-21.12 {TclFileCopyCmd: copy dir on top of a non-empty dir w/ -force} \
1959 catch {file delete -force -- tfa tfad}
1960 file mkdir tfa [file join tfad tfa file]
1961 set r1 [catch {file copy -force tfa tfad}]
1962 set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
1963 file delete -force tfa tfad
1968 # Coverage testing for TclpRenameFile
1970 test fCmd-22.1 {TclpRenameFile: rename and overwrite in a single dir} {notRoot} {
1971 catch {file delete -force -- tfa1 tfa2}
1972 set s [createfile tfa1]
1973 set s2 [createfile tfa2 q]
1975 set r1 [catch {rename tfa1 tfa2}]
1976 file rename -force tfa1 tfa2
1977 set result [expr $r1 && [checkcontent tfa2 $s]]
1978 file delete [glob tfa1 tfa2]
1982 test fCmd-22.2 {TclpRenameFile: attempt to overwrite itself} {macOrUnix notRoot} {
1983 catch {file delete -force -- tfa1}
1984 set s [createfile tfa1]
1985 file rename -force tfa1 tfa1
1986 set result [checkcontent tfa1 $s]
1991 test fCmd-22.3 {TclpRenameFile: rename dir to existing dir} {notRoot} {
1992 catch {file delete -force -- d1 tfad}
1993 file mkdir d1 [file join tfad d1]
1994 set r1 [catch {file rename d1 tfad}]
1995 set result [expr $r1 && [file isdir d1] && [file isdir [file join tfad d1]]]
1996 file delete -force d1 tfad
2000 test fCmd-22.4 {TclpRenameFile: rename dir to dir several levels deep} {notRoot} {
2001 catch {file delete -force -- d1 tfad}
2002 file mkdir d1 [file join tfad a b c]
2003 file rename d1 [file join tfad a b c d1]
2004 set result [expr ![file isdir d1] && [file isdir [file join tfad a b c d1]]]
2005 file delete -force [glob d1 tfad]
2011 # TclMacCopyFile needs to be redone.
2013 test fCmd-22.5 {TclMacCopyFile: copy and overwrite in a single dir} {notRoot} {
2014 catch {file delete -force -- tfa1 tfa2}
2015 set s [createfile tfa1]
2016 set s2 [createfile tfa2 q]
2018 set r1 [catch {file copy tfa1 tfa2}]
2019 file copy -force tfa1 tfa2
2020 set result [expr $r1 && [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
2021 file delete tfa1 tfa2
2026 # TclMacMkdir - basic cases are covered elsewhere.
2027 # Error cases are not covered.
2032 # Error cases are not covered.
2035 test fCmd-23.1 {TclMacRmdir: trying to remove a nonempty directory} {notRoot} {
2036 catch {file delete -force -- tfad}
2038 file mkdir [file join tfad dir]
2040 set result [catch {file delete tfad}]
2041 file delete -force tfad
2047 # Error cases are not covered.
2049 test fCmd-24.1 {TclMacDeleteFile: deleting a normal file} {notRoot} {
2050 catch {file delete -force -- tfa1}
2058 # TclMacCopyDirectory
2059 # Error cases are not covered.
2061 test fCmd-25.1 {TclMacCopyDirectory: copying a normal directory} {notRoot notFileSharing} {
2062 catch {file delete -force -- tfad1 tfad2}
2064 file mkdir [file join tfad1 a b c]
2065 file copy tfad1 tfad2
2066 set result [expr [file isdir [file join tfad1 a b c]] && [file isdir [file join tfad2 a b c]]]
2067 file delete -force tfad1 tfad2
2071 test fCmd-25.2 {TclMacCopyDirectory: copying a short path normal directory} {notRoot notFileSharing} {
2072 catch {file delete -force -- tfad1 tfad2}
2075 file copy tfad1 tfad2
2076 set result [expr [file isdir tfad1] && [file isdir tfad2]]
2077 file delete tfad1 tfad2
2081 test fCmd-25.3 {TclMacCopyDirectory: copying dirs between different dirs} {notRoot notFileSharing} {
2082 catch {file delete -force -- tfad1 tfad2}
2084 file mkdir [file join tfad1 x y z]
2085 file mkdir [file join tfad2 dir]
2086 file copy tfad1 [file join tfad2 dir]
2087 set result [expr [file isdir [file join tfad1 x y z]] && [file isdir [file join tfad2 dir tfad1 x y z]]]
2088 file delete -force tfad1 tfad2
2093 # Functionality tests for TclDeleteFilesCmd
2096 test fCmd-26.1 {TclDeleteFilesCmd: delete symlink} {unixOnly notRoot} {
2097 catch {file delete -force -- tfad1 tfad2}
2100 file link -symbolic tfalink tfad1
2103 set r1 [file isdir tfad1]
2104 set r2 [file exists tfalink]
2106 set result [expr $r1 && !$r2]
2111 test fCmd-26.2 {TclDeleteFilesCmd: delete dir with symlink} {unixOnly notRoot} {
2112 catch {file delete -force -- tfad1 tfad2}
2116 file link -symbolic [file join tfad2 link] tfad1
2117 file delete -force tfad2
2119 set r1 [file isdir tfad1]
2120 set r2 [file exists tfad2]
2122 set result [expr $r1 && !$r2]
2127 test fCmd-26.3 {TclDeleteFilesCmd: delete dangling symlink} {unixOnly notRoot} {
2128 catch {file delete -force -- tfad1 tfad2}
2131 file link -symbolic tfad2 tfad1
2135 set r1 [file exists tfad1]
2136 set r2 [file exists tfad2]
2138 set result [expr !$r1 && !$r2]
2142 test fCmd-27.2 {TclFileAttrsCmd - Tcl_TranslateFileName fails} {testsetplatform} {
2143 set platform [testgetplatform]
2144 testsetplatform unix
2145 list [catch {file attributes ~_totally_bogus_user} msg] $msg [testsetplatform $platform]
2146 } {1 {user "_totally_bogus_user" doesn't exist} {}}
2147 test fCmd-27.3 {TclFileAttrsCmd - all attributes} {
2148 catch {file delete -force -- foo.tmp}
2150 list [catch {file attributes foo.tmp} msg] [expr {[llength $msg] > 0}] [file delete -force -- foo.tmp]
2152 test fCmd-27.4 {TclFileAttrsCmd - getting one option} {
2153 catch {file delete -force -- foo.tmp}
2155 set attrs [file attributes foo.tmp]
2156 list [catch {eval file attributes foo.tmp [lindex $attrs 0]}] [file delete -force -- foo.tmp]
2159 # Find a group that exists on this Unix system, or else skip tests that
2160 # require Unix groups.
2161 if {$tcl_platform(platform) == "unix"} {
2162 ::tcltest::testConstraint foundGroup 0
2164 set groupList [exec groups]
2165 set group [lindex $groupList 0]
2166 ::tcltest::testConstraint foundGroup 1
2169 ::tcltest::testConstraint foundGroup 1
2172 test fCmd-27.5 {TclFileAttrsCmd - setting one option} {foundGroup} {
2173 catch {file delete -force -- foo.tmp}
2175 set attrs [file attributes foo.tmp]
2176 list [catch {eval file attributes foo.tmp [lrange $attrs 0 1]} msg] $msg [file delete -force -- foo.tmp]
2178 test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} {foundGroup} {
2179 catch {file delete -force -- foo.tmp}
2181 set attrs [file attributes foo.tmp]
2182 list [catch {eval file attributes foo.tmp [lrange $attrs 0 3]} msg] $msg [file delete -force -- foo.tmp]
2185 if {[string equal $tcl_platform(platform) "windows"]} {
2186 if {[string index $tcl_platform(osVersion) 0] >= 5 \
2187 && ([lindex [file system [temporaryDirectory]] 1] == "NTFS")} {
2188 tcltest::testConstraint linkDirectory 1
2189 tcltest::testConstraint linkFile 1
2191 tcltest::testConstraint linkDirectory 0
2192 tcltest::testConstraint linkFile 0
2195 tcltest::testConstraint linkFile 1
2196 tcltest::testConstraint linkDirectory 1
2199 test fCmd-28.1 {file link} {
2200 list [catch {file link} msg] $msg
2201 } {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
2203 test fCmd-28.2 {file link} {
2204 list [catch {file link a b c d} msg] $msg
2205 } {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
2207 test fCmd-28.3 {file link} {
2208 list [catch {file link abc b c} msg] $msg
2209 } {1 {bad switch "abc": must be -symbolic or -hard}}
2211 test fCmd-28.4 {file link} {
2212 list [catch {file link -abc b c} msg] $msg
2213 } {1 {bad switch "-abc": must be -symbolic or -hard}}
2215 makeDirectory abc.dir
2216 makeDirectory abc2.dir
2217 makeFile contents abc.file
2218 makeFile contents abc2.file
2220 cd [temporaryDirectory]
2221 test fCmd-28.5 {file link: source already exists} {linkDirectory} {
2222 cd [temporaryDirectory]
2223 set res [list [catch {file link abc.dir abc2.dir} msg] $msg]
2224 cd [workingDirectory]
2226 } {1 {could not create new link "abc.dir": that path already exists}}
2228 test fCmd-28.6 {file link: unsupported operation} {linkDirectory macOrWin} {
2229 cd [temporaryDirectory]
2230 set res [list [catch {file link -hard abc.link abc.dir} msg] $msg]
2231 cd [workingDirectory]
2233 } {1 {could not create new link "abc.link" pointing to "abc.dir": illegal operation on a directory}}
2235 test fCmd-28.7 {file link: source already exists} {linkFile} {
2236 cd [temporaryDirectory]
2237 set res [list [catch {file link abc.file abc2.file} msg] $msg]
2238 cd [workingDirectory]
2240 } {1 {could not create new link "abc.file": that path already exists}}
2242 test fCmd-28.8 {file link} {linkFile winOnly} {
2243 cd [temporaryDirectory]
2244 set res [list [catch {file link -symbolic abc.link abc.file} msg] $msg]
2245 cd [workingDirectory]
2247 } {1 {could not create new link "abc.link" pointing to "abc.file": not a directory}}
2249 test fCmd-28.9 {file link: success with file} {linkFile} {
2250 cd [temporaryDirectory]
2251 file delete -force abc.link
2252 set res [list [catch {file link abc.link abc.file} msg] $msg]
2253 cd [workingDirectory]
2257 cd [temporaryDirectory]
2258 catch {file delete -force abc.link}
2259 cd [workingDirectory]
2261 test fCmd-28.10 {file link: linking to nonexistent path} {linkDirectory} {
2262 cd [temporaryDirectory]
2263 file delete -force abc.link
2264 set res [list [catch {file link abc.link abc2.doesnt} msg] $msg]
2265 cd [workingDirectory]
2267 } {1 {could not create new link "abc.link" since target "abc2.doesnt" doesn't exist}}
2269 test fCmd-28.11 {file link: success with directory} {linkDirectory} {
2270 cd [temporaryDirectory]
2271 file delete -force abc.link
2272 set res [list [catch {file link abc.link abc.dir} msg] $msg]
2273 cd [workingDirectory]
2277 test fCmd-28.12 {file link: cd into a link} {linkDirectory} {
2278 cd [temporaryDirectory]
2279 file delete -force abc.link
2280 file link abc.link abc.dir
2287 # now '$up' should be either $orig or [file dirname abc.dir],
2288 # depending on whether 'cd' actually moves to the destination
2289 # of a link, or simply treats the link as a directory.
2290 # (on windows the former, on unix the latter, I believe)
2291 if {([file normalize $up] != [file normalize $orig]) \
2292 && ([file normalize $up] != [file normalize [file dirname abc.dir]])} {
2293 set res "wrong directory with 'cd $link ; cd ..'"
2297 cd [workingDirectory]
2301 test fCmd-28.13 {file link} {linkDirectory} {
2302 # duplicate link throws error
2303 cd [temporaryDirectory]
2304 set res [list [catch {file link abc.link abc.dir} msg] $msg]
2305 cd [workingDirectory]
2307 } {1 {could not create new link "abc.link": that path already exists}}
2309 test fCmd-28.14 {file link: deletes link not dir} {linkDirectory} {
2310 cd [temporaryDirectory]
2311 file delete -force abc.link
2312 set res [list [file exists abc.link] [file exists abc.dir]]
2313 cd [workingDirectory]
2317 test fCmd-28.15.1 {file link: copies link not dir} {linkDirectory dontCopyLinks} {
2318 cd [temporaryDirectory]
2319 file delete -force abc.link
2320 file link abc.link abc.dir
2321 file copy abc.link abc2.link
2322 # abc2.linkdir was a copy of a link to a dir, so it should end up as
2323 # a directory, not a link (links trace to endpoint).
2324 set res [list [file type abc2.link] [file tail [file link abc.link]]]
2325 cd [workingDirectory]
2327 } {directory abc.dir}
2328 test fCmd-28.15.2 {file link: copies link not dir} {linkDirectory} {
2329 cd [temporaryDirectory]
2330 file delete -force abc.link
2331 file link abc.link abc.dir
2332 file copy abc.link abc2.link
2333 set res [list [file type abc2.link] [file tail [file link abc2.link]]]
2334 cd [workingDirectory]
2338 cd [temporaryDirectory]
2339 file delete -force abc.link
2340 file delete -force abc2.link
2342 file copy abc.file abc.dir
2343 file copy abc2.file abc.dir
2344 cd [workingDirectory]
2346 test fCmd-28.16 {file link: glob inside link} {linkDirectory} {
2347 cd [temporaryDirectory]
2348 file delete -force abc.link
2349 file link abc.link abc.dir
2350 set res [glob -dir abc.link -tails *]
2351 cd [workingDirectory]
2353 } {abc.file abc2.file}
2355 test fCmd-28.17 {file link: glob -type l} {linkDirectory} {
2356 cd [temporaryDirectory]
2357 set res [glob -dir [pwd] -type l -tails abc*]
2358 cd [workingDirectory]
2362 test fCmd-28.18 {file link: glob -type d} {linkDirectory} {
2363 cd [temporaryDirectory]
2364 set res [lsort [glob -dir [pwd] -type d -tails abc*]]
2365 cd [workingDirectory]
2367 } [lsort [list abc.link abc.dir abc2.dir]]
2369 test fCmd-29.1 {weird memory corruption fault} {
2370 catch {set res [open [file join ~a_totally_bogus_user_id/foo bar]]}
2373 cd [temporaryDirectory]
2374 file delete -force abc.link
2375 cd [workingDirectory]
2377 removeFile abc2.file
2379 removeDirectory abc2.dir
2380 removeDirectory abc.dir
2384 ::tcltest::cleanupTests