os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/fCmd.test
First public contribution.
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.
9 # Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiaries. All rights reserved.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: fCmd.test,v 1.26.2.9 2007/05/17 14:18:42 dgp Exp $
17 if {[lsearch [namespace children] ::tcltest] == -1} {
18 package require tcltest 2
19 namespace import -force ::tcltest::*
22 tcltest::testConstraint testsetplatform [string equal testsetplatform [info commands testsetplatform]]
23 tcltest::testConstraint testchmod [string equal testchmod [info commands testchmod]]
24 tcltest::testConstraint notNetworkFilesystem 0
25 testConstraint 95or98 [expr {[testConstraint 95] || [testConstraint 98]}]
26 testConstraint 2000orNewer [expr {![testConstraint 95or98]}]
28 # Several tests require need to match results against the unix username
30 if {$tcl_platform(platform) == "unix"} {
31 catch {set user [exec whoami]}
33 catch {regexp {^[^(]*\(([^)]*)\)} [exec id] dummy user}
40 proc createfile {file {string a}} {
42 puts -nonewline $f $string
50 # Ensures that file "file" contains only the string "matchString"
51 # returns 0 if the file does not exist, or has a different content
53 proc checkcontent {file matchString} {
56 set fileString [read $f]
61 return [string match $matchString $fileString]
66 if {[file isdirectory $path]} {
68 foreach p [glob -directory $path *] {
76 if {$::tcl_platform(platform) == "macintosh"} {
81 foreach p [concat $wd $args] {
84 set x [glob -directory $p tf* td*]
87 if {[catch {file delete -force -- $file}]} {
89 catch {file delete -force -- $file}
95 proc contents {file} {
102 cd [temporaryDirectory]
104 set ::tcltest::testConstraints(fileSharing) 0
105 set ::tcltest::testConstraints(notFileSharing) 1
107 if {$tcl_platform(platform) == "macintosh"} {
108 catch {file delete -force foo.dir}
110 if {[catch {file attributes foo.dir -readonly 1}] == 0} {
111 set ::tcltest::testConstraints(fileSharing) 1
112 set ::tcltest::testConstraints(notFileSharing) 0
114 file delete -force foo.dir
117 set ::tcltest::testConstraints(xdev) 0
119 if {$tcl_platform(platform) == "unix"} {
120 if {[catch {set m1 [exec df .]; set m2 [exec df /tmp]}] == 0} {
121 set m1 [string range $m1 0 [expr [string first " " $m1]-1]]
122 set m2 [string range $m2 0 [expr [string first " " $m2]-1]]
123 if {$m1 != "" && $m2 != "" && $m1 != $m2 && [file exists $m1] && [file exists $m2]} {
124 set ::tcltest::testConstraints(xdev) 1
129 set root [lindex [file split [pwd]] 0]
131 # A really long file name
132 # length of long is 1216 chars, which should be greater than any static
133 # buffer or allowable filename.
135 set long "abcdefghihjllmnopqrstuvwxyz01234567890"
142 test fCmd-1.1 {TclFileRenameCmd} {notRoot} {
149 test fCmd-2.1 {TclFileCopyCmd} {notRoot} {
156 test fCmd-3.1 {FileCopyRename: FileForceOption fails} {notRoot} {
157 list [catch {file rename -xyz} msg] $msg
158 } {1 {bad option "-xyz": should be -force or --}}
159 test fCmd-3.2 {FileCopyRename: not enough args} {notRoot} {
160 list [catch {file rename xyz} msg] $msg
161 } {1 {wrong # args: should be "file rename ?options? source ?source ...? target"}}
162 test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} {notRoot} {
163 list [catch {file rename xyz ~_totally_bogus_user} msg] $msg
164 } {1 {user "_totally_bogus_user" doesn't exist}}
165 test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} {notRoot} {
167 list [catch {file copy tf1 ~} msg] $msg
168 } {1 {error copying "tf1": no such file or directory}}
169 test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} {notRoot} {
171 list [catch {file rename tf1 tf2 tf3} msg] $msg
172 } {1 {error renaming: target "tf3" is not a directory}}
173 test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} \
177 list [catch {file rename tf1 tf2 tf3} msg] $msg
178 } {1 {error renaming: target "tf3" is not a directory}}
179 test fCmd-3.7 {FileCopyRename: target exists & is directory} {notRoot} {
184 contents [file join td1 tf1]
186 test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
188 list [catch {file rename tf1 tf2 tf3} msg] $msg
189 } {1 {error renaming: target "tf3" is not a directory}}
190 test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
192 list [catch {file copy -force -- tf1 tf2 tf3} msg] $msg
193 } {1 {error copying: target "tf3" is not a directory}}
194 test fCmd-3.10 {FileCopyRename: just 2 arguments} {notRoot} {
200 test fCmd-3.11 {FileCopyRename: just 2 arguments} {notRoot} {
203 file rename -force -force -- tf1 tf2
206 test fCmd-3.12 {FileCopyRename: move each source: 1 source} {notRoot} {
211 contents [file join td1 tf1]
213 test fCmd-3.13 {FileCopyRename: move each source: multiple sources} {notRoot} {
220 file rename tf1 tf2 tf3 tf4 td1
221 list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
222 [contents [file join td1 tf3]] [contents [file join td1 tf4]]
224 test fCmd-3.14 {FileCopyRename: FileBasename fails} {notRoot} {
227 list [catch {file rename ~_totally_bogus_user td1} msg] $msg
228 } {1 {user "_totally_bogus_user" doesn't exist}}
229 test fCmd-3.15 {FileCopyRename: source[0] == '\0'} {notRoot unixOrPc} {
232 list [catch {file rename / td1} msg] $msg
233 } {1 {error renaming "/" to "td1": file already exists}}
234 test fCmd-3.16 {FileCopyRename: break on first error} {notRoot} {
241 createfile [file join td1 tf3]
242 list [catch {file rename tf1 tf2 tf3 tf4 td1} msg] $msg
243 } [subst {1 {error renaming "tf3" to "[file join td1 tf3]": file already exists}}]
245 test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} {notRoot} {
250 test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} {notRoot} {
252 file mkdir td1 td2 td3
255 test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} {notRoot} {
258 catch {file mkdir td1 td2 tf1 td3 td4}
259 glob td1 td2 tf1 td3 td4
261 test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} {notRoot} {
263 list [catch {file mkdir ~_totally_bogus_user} msg] $msg
264 } {1 {user "_totally_bogus_user" doesn't exist}}
265 test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\0'} \
268 list [catch {file mkdir ""} msg] $msg
269 } {1 {can't create directory "": no such file or directory}}
270 test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} {notRoot} {
275 test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} {notRoot} {
277 file mkdir [file join td1 td2 td3 td4]
278 glob td1 [file join td1 td2]
279 } "td1 [file join td1 td2]"
280 test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} {notRoot} {
283 set x [file exists td1]
285 list $x [file exists td1]
287 test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} {notRoot} {
290 list [catch {file mkdir tf1} msg] $msg
291 } [subst {1 {can't create directory "[file join tf1]": file already exists}}]
292 test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} {notRoot} {
295 set x [file exists td1]
297 list $x [file exists td1]
299 test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} \
300 {unixOnly notRoot testchmod} {
302 file mkdir td1/td2/td3
303 testchmod 000 td1/td2
304 set msg [list [catch {file mkdir td1/td2/td3/td4} msg] $msg]
305 testchmod 755 td1/td2
307 } {1 {can't create directory "td1/td2/td3": permission denied}}
308 test fCmd-4.12 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} {macOnly} {
310 list [catch {file mkdir nonexistentvolume:} msg] $msg
311 } {1 {can't create directory "nonexistentvolume:": invalid argument}}
312 test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} {notRoot} {
314 set x [file exists td1]
316 list $x [file exists td1]
318 test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} \
321 file delete -force foo
323 file attr foo -perm 040000
324 set result [list [catch {file mkdir foo/tf1} msg] $msg]
325 file delete -force foo
327 } {1 {can't create directory "foo/tf1": permission denied}}
328 test fCmd-4.15 {TclFileMakeDirsCmd: TclpCreateDirectory fails} {macOnly} {
329 list [catch {file mkdir ${root}:} msg] $msg
330 } [subst {1 {can't create directory "${root}:": no such file or directory}}]
331 test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} {notRoot} {
337 test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} {notRoot} {
338 list [catch {file delete -xyz} msg] $msg
339 } {1 {bad option "-xyz": should be -force or --}}
340 test fCmd-5.2 {TclFileDeleteCmd: not enough args} {notRoot} {
341 list [catch {file delete -force -force} msg] $msg
342 } {1 {wrong # args: should be "file delete ?options? file ?file ...?"}}
343 test fCmd-5.3 {TclFileDeleteCmd: 1 file} {notRoot} {
351 test fCmd-5.4 {TclFileDeleteCmd: multiple files} {notRoot} {
356 set x [list [file exists tf1] [file exists tf2] [file exists td1]]
357 file delete tf1 td1 tf2
358 lappend x [file exists tf1] [file exists tf2] [file exists tf3]
360 test fCmd-5.5 {TclFileDeleteCmd: stop at first error} {notRoot unixOrPc} {
365 catch {file delete tf1 td1 $root tf2}
366 list [file exists tf1] [file exists tf2] [file exists td1]
368 test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} {notRoot} {
369 list [catch {file delete ~_totally_bogus_user} msg] $msg
370 } {1 {user "_totally_bogus_user" doesn't exist}}
371 test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} {notRoot} {
372 catch {file delete ~/tf1}
376 test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} {notRoot} {
378 set x [file exists tf1]
380 list $x [file exists tf1]
382 test fCmd-5.9 {TclFileDeleteCmd: is directory} {notRoot} {
388 test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} {notRoot} {
390 file mkdir [file join td1 td2]
391 list [catch {file delete td1} msg] $msg
392 } {1 {error deleting "td1": directory not empty}}
393 test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} {notRoot} {
396 file mkdir [file join td1 td2]
397 cd [file join td1 td2]
398 set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
400 lappend res [file exists td1] $msg
402 test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} {unixOnly} {
404 file mkdir [file join td1 td2]
405 #exec chmod u-rwx [file join td1 td2]
406 file attributes [file join td1 td2] -permissions u+rwx
407 set res [list [catch {file delete -force td1} msg]]
408 lappend res [file exists td1] $msg
411 test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot} {
412 # can't test this, because it's caught by FileCopyRename
414 test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot} {
415 # can't test this, because it's caught by FileCopyRename
417 test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} {notRoot} {
419 list [catch {file rename tf1 tf2} msg] $msg
420 } {1 {error renaming "tf1": no such file or directory}}
421 test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} {notRoot} {
427 test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} {notRoot} {
433 test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} {unixOnly notRoot testchmod} {
438 set msg [list [catch {file rename tf1 td1} msg] $msg]
441 } {1 {error renaming "tf1" to "td1/tf1": permission denied}}
442 test fCmd-6.7 {CopyRenameOneFile: errno != ENOENT} {pcOnly 95} {
445 list [catch {file rename tf1 $long} msg] $msg
446 } [subst {1 {error renaming "tf1" to "$long": file name too long}}]
447 test fCmd-6.8 {CopyRenameOneFile: errno != ENOENT} {macOnly} {
450 list [catch {file rename tf1 $long} msg] $msg
451 } [subst {1 {error renaming "tf1" to "$long": file name too long}}]
452 test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} {unixOnly notRoot} {
458 test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 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.11 {CopyRenameOneFile: force == 0} {notRoot} {
468 list [catch {file rename tf1 tf2} msg] $msg
469 } {1 {error renaming "tf1" to "tf2": file already exists}}
470 test fCmd-6.12 {CopyRenameOneFile: force != 0} {notRoot} {
474 file rename -force tf1 tf2
477 test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} {notRoot} {
481 createfile [file join td2 td1]
482 list [catch {file rename -force td1 td2} msg] $msg
483 } [subst {1 {can't overwrite file "[file join td2 td1]" with directory "td1"}}]
484 test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} {notRoot} {
487 file mkdir [file join td1 tf1]
488 list [catch {file rename -force tf1 td1} msg] $msg
489 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
490 test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} {notRoot notNetworkFilesystem} {
492 file mkdir [file join td1 td2]
494 createfile [file join td2 tf1]
495 file rename -force td2 td1
496 file exists [file join td1 td2 tf1]
498 test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} {notRoot} {
500 file mkdir [file join td1 td2]
501 createfile [file join td1 td2 tf1]
503 list [catch {file rename -force td2 td1} msg] $msg
504 } [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
506 test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} {notRoot} {
508 list [catch {file rename -force $root tf1} msg] $msg
509 } [subst {1 {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}}]
510 test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} {notRoot} {
512 file mkdir [file join td1 td2]
513 createfile [file join td1 td2 tf1]
515 list [catch {file rename -force td2 td1} msg] $msg
516 } [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
517 test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {unixOnly notRoot} {
523 test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} {pcOnly} {
524 catch {file delete -force c:/tcl8975@ d:/tcl8975@}
525 file mkdir c:/tcl8975@
526 if [catch {file rename c:/tcl8975@ d:/}] {
529 set msg [glob c:/tcl8975@ d:/tcl8975@]
530 file delete -force d:/tcl8975@
532 file delete -force c:/tcl8975@
535 test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} \
542 test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} \
549 test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} \
550 {unixOnly notRoot xdev} {
552 file mkdir td1/td2/td3
553 file attributes td1 -permissions 0000
554 set msg [list [catch {file rename td1 /tmp} msg] $msg]
555 file attributes td1 -permissions 0755
557 } {1 {error renaming "td1": permission denied}}
558 test fCmd-6.24 {CopyRenameOneFile: error uses original name} \
562 set td1name [file join [file dirname ~] [file tail ~] td1]
563 file attributes $td1name -permissions 0000
564 set msg [list [catch {file copy ~/td1 td1} msg] $msg]
565 file attributes $td1name -permissions 0755
566 file delete -force ~/td1
568 } {1 {error copying "~/td1": permission denied}}
569 test fCmd-6.25 {CopyRenameOneFile: error uses original name} \
574 set td1name [file join [file dirname ~] [file tail ~] td1]
575 file attributes $td1name -permissions 0000
576 set msg [list [catch {file copy td2 ~/td1} msg] $msg]
577 file attributes $td1name -permissions 0755
578 file delete -force ~/td1
580 } {1 {error copying "td2" to "~/td1/td2": permission denied}}
581 test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} \
585 set td2name [file join [file dirname ~] [file tail ~] td1 td2]
586 file attributes $td2name -permissions 0000
587 set msg [list [catch {file copy ~/td1 td1} msg] $msg]
588 file attributes $td2name -permissions 0755
589 file delete -force ~/td1
591 } "1 {error copying \"~/td1\" to \"td1\": \"[file join [file dirname ~] [file tail ~] td1 td2]\": permission denied}"
592 test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} \
593 {unixOnly notRoot xdev} {
595 file mkdir td1/td2/td3
597 createfile /tmp/td1/tf1
598 list [catch {file rename -force td1 /tmp} msg] $msg
599 } {1 {error renaming "td1" to "/tmp/td1": file already exists}}
600 test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} \
601 {unixOnly notRoot xdev} {
603 file mkdir td1/td2/td3
604 file attributes td1/td2/td3 -permissions 0000
605 set msg [list [catch {file rename td1 /tmp} msg] $msg]
606 file attributes td1/td2/td3 -permissions 0755
608 } {1 {error renaming "td1" to "/tmp/td1": "td1/td2/td3": permission denied}}
609 test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} \
610 {unixOnly notRoot xdev} {
612 file mkdir td1/td2/td3
616 test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} \
620 file attr foo -perm 040555
621 set catchResult [catch {file rename foo/bar /tmp} msg]
622 set msg [lindex [split $msg :] end]
623 catch {file delete /tmp/bar}
624 catch {file attr foo -perm 040777}
625 catch {file delete -force foo}
626 list $catchResult $msg
627 } {1 { permission denied}}
628 test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} \
629 {unixOnly notRoot xdev} {
632 createfile /tmp/td1/tf1
633 file rename /tmp/td1/tf1 tf1
634 list [file exists /tmp/td1/tf1] [file exists tf1]
636 test fCmd-6.32 {CopyRenameOneFile: copy} {notRoot} {
638 list [catch {file copy tf1 tf2} msg] $msg
639 } {1 {error copying "tf1": no such file or directory}}
642 test fCmd-7.1 {FileForceOption: none} {notRoot} {
644 file mkdir [file join tf1 tf2]
645 list [catch {file delete tf1} msg] $msg
646 } {1 {error deleting "tf1": directory not empty}}
647 test fCmd-7.2 {FileForceOption: -force} {notRoot} {
649 file mkdir [file join tf1 tf2]
650 file delete -force tf1
652 test fCmd-7.3 {FileForceOption: --} {notRoot} {
656 test fCmd-7.4 {FileForceOption: bad option} {notRoot} {
658 set msg [list [catch {file delete -tf1} msg] $msg]
661 } {1 {bad option "-tf1": should be -force or --}}
662 test fCmd-7.5 {FileForceOption: multiple times through loop} {notRoot} {
665 file delete -force -force -- -- -force
666 list [catch {glob -- -- -force} msg] $msg
667 } {1 {no files matched glob patterns "-- -force"}}
669 test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
670 {unixOnly notRoot knownBug} {
671 # Labelled knownBug because it is dangerous [Bug: 3881]
673 file attr td1 -perm 040000
674 set result [list [catch {file rename ~$user td1} msg] $msg]
675 file delete -force td1
677 } "1 {error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied}"
678 test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} {
679 string equal [file tail ~$user] ~$user
681 test fCmd-8.3 {file copy and path translation: ensure correct error} {
682 list [catch {file copy ~ [file join this file doesnt exist]} res] $res
684 "error copying \"~\" to \"[file join this file doesnt exist]\":\
685 no such file or directory"]
687 test fCmd-9.1 {file rename: comprehensive: EACCES} {unixOnly notRoot} {
691 file attr td2 -perm 040000
692 set result [list [catch {file rename td1 td2/} msg] $msg]
693 file delete -force td2
694 file delete -force td1
696 } {1 {error renaming "td1" to "td2/td1": permission denied}}
697 test fCmd-9.2 {file rename: comprehensive: source doesn't exist} {notRoot} {
699 list [catch {file rename tf1 tf2} msg] $msg
700 } {1 {error renaming "tf1": no such file or directory}}
701 test fCmd-9.3 {file rename: comprehensive: file to new name} {notRoot testchmod} {
708 list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
710 test fCmd-9.4 {file rename: comprehensive: dir to new name} {unixOrPc notRoot testchmod} {
716 list [lsort [glob td*]] [file writable td3] [file writable td4]
718 test fCmd-9.5 {file rename: comprehensive: file to self} {notRoot testchmod} {
723 file rename -force tf1 tf1
724 file rename -force tf2 tf2
725 list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
727 test fCmd-9.6 {file rename: comprehensive: dir to self} {notRoot unixOrPc testchmod} {
732 file rename -force td1 .
733 file rename -force td2 .
734 list [lsort [glob td*]] [file writable td1] [file writable td2]
736 test fCmd-9.7 {file rename: comprehensive: file to existing file} {notRoot testchmod} {
752 set msg [list [catch {file rename tf1 tf2} msg] $msg]
753 file rename -force tfs1 tfd1
754 file rename -force tfs2 tfd2
755 file rename -force tfs3 tfd3
756 file rename -force tfs4 tfd4
757 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
758 } {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
759 test fCmd-9.8 {file rename: comprehensive: dir to empty dir} {notRoot testchmod notNetworkFilesystem} {
760 # Under unix, you can rename a read-only directory, but you can't
761 # move it into another directory.
765 file mkdir [file join td2 td1]
770 file mkdir [file join tdd1 tds1]
771 file mkdir [file join tdd2 tds2]
772 file mkdir [file join tdd3 tds3]
773 file mkdir [file join tdd4 tds4]
774 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
778 if {$tcl_platform(platform) != "macintosh"} {
779 testchmod 555 [file join tdd2 tds2]
780 testchmod 555 [file join tdd4 tds4]
782 set msg [list [catch {file rename td1 td2} msg] $msg]
783 file rename -force tds1 tdd1
784 file rename -force tds2 tdd2
785 file rename -force tds3 tdd3
786 file rename -force tds4 tdd4
787 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
788 set w3 [file writable [file join tdd3 tds3]]
789 set w4 [file writable [file join tdd4 tds4]]
794 list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
795 [file writable [file join tdd2 tds2]] $w3 $w4
796 } [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
797 test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} {notRoot testchmod} {
801 file mkdir [file join tdd1 tds1 xxx]
802 file mkdir [file join tdd2 tds2 xxx]
803 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
806 set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
807 set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
808 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
809 set w2 [file writable tds2]
813 list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
814 } [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}]
815 test fCmd-9.10 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
821 file rename tf1 [file join td1 tf3]
822 file rename tf2 [file join td1 tf4]
823 list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \
824 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
825 } [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}]
826 test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} {notRoot testchmod} {
831 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
834 file rename td1 [file join td3 td3]
835 file rename td2 [file join td3 td4]
836 if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
837 set w4 [file writable [file join td3 td4]]
841 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
842 [file writable [file join td3 td3]] $w4
843 } [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
844 test fCmd-9.12 {file rename: comprehensive: target exists} {notRoot testchmod notNetworkFilesystem} {
846 file mkdir [file join td1 td2] [file join td2 td1]
847 if {$tcl_platform(platform) != "macintosh"} {
848 testchmod 555 [file join td2 td1]
850 file mkdir [file join td3 td4] [file join td4 td3]
851 file rename -force td3 td4
852 set msg [list [file exists td3] [file exists [file join td4 td3 td4]] \
853 [catch {file rename td1 td2} msg] $msg]
854 if {$tcl_platform(platform) != "macintosh"} {
855 testchmod 755 [file join td2 td1]
858 } [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
859 test fCmd-9.13 {file rename: comprehensive: can't overwrite target} {notRoot} {
861 file mkdir [file join td1 td2] [file join td2 td1 td4]
862 list [catch {file rename -force td1 td2} msg] $msg
863 } [subst {1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
864 test fCmd-9.14 {file rename: comprehensive: dir into self} {notRoot} {
867 list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
868 } [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
869 test fCmd-9.15 {file rename: comprehensive: source and target incompatible} \
874 list [catch {file rename -force td1 tf1} msg] $msg
875 } {1 {can't overwrite file "tf1" with directory "td1"}}
876 test fCmd-9.16 {file rename: comprehensive: source and target incompatible} \
881 list [catch {file rename -force tf1 td1} msg] $msg
882 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
884 test fCmd-10.1 {file copy: comprehensive: source doesn't exist} {notRoot} {
886 list [catch {file copy tf1 tf2} msg] $msg
887 } {1 {error copying "tf1": no such file or directory}}
888 test fCmd-10.2 {file copy: comprehensive: file to new name} {notRoot testchmod} {
895 list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
896 } {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
897 test fCmd-10.3 {file copy: comprehensive: dir to new name} {notRoot unixOrPc 95or98 testchmod} {
899 file mkdir [file join td1 tdx]
900 file mkdir [file join td2 tdy]
904 set msg [list [lsort [glob td*]] [glob -directory td3 t*] \
905 [glob -directory td4 t*] [file writable td3] [file writable td4]]
906 if {$tcl_platform(platform) != "macintosh"} {
911 } [subst {{td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0}]
912 test fCmd-10.3.1 {file copy: comprehensive: dir to new name} {notRoot pc 2000orNewer testchmod} {
913 # On Windows with ACLs, copying a directory is defined like this
915 file mkdir [file join td1 tdx]
916 file mkdir [file join td2 tdy]
920 set msg [list [lsort [glob td*]] [glob -directory td3 t*] \
921 [glob -directory td4 t*] [file writable td3] [file writable td4]]
925 } [subst {{td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 1}]
926 test fCmd-10.4 {file copy: comprehensive: file to existing file} {notRoot testchmod} {
942 set msg [list [catch {file copy tf1 tf2} msg] $msg]
943 file copy -force tfs1 tfd1
944 file copy -force tfs2 tfd2
945 file copy -force tfs3 tfd3
946 file copy -force tfs4 tfd4
947 list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
948 } {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
949 test fCmd-10.5 {file copy: comprehensive: dir to empty dir} {notRoot testchmod} {
952 file mkdir [file join td2 td1]
957 file mkdir [file join tdd1 tds1]
958 file mkdir [file join tdd2 tds2]
959 file mkdir [file join tdd3 tds3]
960 file mkdir [file join tdd4 tds4]
961 if {$tcl_platform(platform) != "macintosh"} {
964 testchmod 555 [file join tdd2 tds2]
965 testchmod 555 [file join tdd4 tds4]
967 set a1 [list [catch {file copy td1 td2} msg] $msg]
968 set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
969 set a3 [catch {file copy -force tds2 tdd2}]
970 set a4 [catch {file copy -force tds3 tdd3}]
971 set a5 [catch {file copy -force tds4 tdd4}]
972 list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5
973 } [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}]
974 test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} \
975 {notRoot unixOrPc testchmod} {
979 file mkdir [file join tdd1 tds1 xxx]
980 file mkdir [file join tdd2 tds2 xxx]
982 set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
983 set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
984 list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
985 } [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}]
986 test fCmd-10.7 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
992 file copy tf1 [file join td1 tf3]
993 file copy tf2 [file join td1 tf4]
994 list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
995 [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
996 } [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
997 test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} \
998 {notRoot unixOrPc 95or98 testchmod} {
1004 file copy td1 [file join td3 td3]
1005 file copy td2 [file join td3 td4]
1006 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1007 [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1008 } [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
1009 test fCmd-10.8.1 {file rename: comprehensive: dir to new name and dir} \
1010 {notRoot pc 2000orNewer testchmod} {
1011 # On Windows with ACLs, copying a directory is defined like this
1017 file copy td1 [file join td3 td3]
1018 file copy td2 [file join td3 td4]
1019 list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1020 [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1021 } [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 1}]
1022 test fCmd-10.9 {file copy: comprehensive: source and target incompatible} \
1027 list [catch {file copy -force td1 tf1} msg] $msg
1028 } {1 {can't overwrite file "tf1" with directory "td1"}}
1029 test fCmd-10.10 {file copy: comprehensive: source and target incompatible} \
1032 file mkdir [file join td1 tf1]
1034 list [catch {file copy -force tf1 td1} msg] $msg
1035 } [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
1036 test fCmd-10.11 {file copy: copy to empty file name} {
1039 list [catch {file copy tf1 ""} msg] $msg
1040 } {1 {error copying "tf1" to "": no such file or directory}}
1041 test fCmd-10.12 {file rename: rename to empty file name} {
1044 list [catch {file rename tf1 ""} msg] $msg
1045 } {1 {error renaming "tf1" to "": no such file or directory}}
1050 test fCmd-11.1 {TclFileRenameCmd: -- option } {notRoot} {
1051 catch {file delete -force -- -tfa1}
1052 set s [createfile -tfa1]
1053 file rename -- -tfa1 tfa2
1054 set result [expr [checkcontent tfa2 $s] && ![file exists -tfa1]]
1059 test fCmd-11.2 {TclFileRenameCmd: bad option } {notRoot} {
1060 catch {file delete -force -- tfa1}
1061 set s [createfile tfa1]
1062 set r1 [catch {file rename -x tfa1 tfa2}]
1063 set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
1068 test fCmd-11.3 {TclFileRenameCmd: bad \# args} {
1069 catch {file rename -- }
1072 test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} {notRoot} {
1076 set result [catch {file rename tfa ~/foobar }]
1081 test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} {notRoot} {
1082 catch {file delete -force -- tfa1 tfa2 tfa3}
1086 set result [catch {file rename tfa1 tfa2 tfa3}]
1087 file delete tfa1 tfa2 tfa3
1091 test fCmd-11.6 {TclFileRenameCmd: : single file into directory} {notRoot} {
1092 catch {file delete -force -- tfa1 tfad}
1093 set s [createfile tfa1]
1095 file rename tfa1 tfad
1096 set result [expr [checkcontent tfad/tfa1 $s] && ![file exists tfa1]]
1097 file delete -force tfad
1101 test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} {notRoot} {
1102 catch {file delete -force -- tfa1 tfa2 tfad}
1103 set s1 [createfile tfa1 ]
1104 set s2 [createfile tfa2 ]
1106 file rename tfa1 tfa2 tfad
1107 set r1 [checkcontent tfad/tfa1 $s1]
1108 set r2 [checkcontent tfad/tfa2 $s2]
1110 set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfa2]]
1112 file delete -force tfad
1116 test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} {notRoot} {
1117 catch {file delete -force -- tfa tfad}
1118 set s [createfile tfa ]
1121 set r1 [catch {file rename tfa tfad}]
1122 set r2 [checkcontent tfa $s]
1123 set r3 [file isdir tfad]
1124 set result [expr $r1 && $r2 && $r3 ]
1125 file delete -force tfa tfad
1130 # Coverage tests for renamefile() ;
1132 test fCmd-12.1 {renamefile: source filename translation failing} {notRoot} {
1136 set result [catch {file rename ~/tfa1 tfa2}]
1141 test fCmd-12.2 {renamefile: src filename translation failing} {notRoot} {
1145 set s [createfile tfa1]
1147 set result [catch {file rename tfa1 ~/tfa2 tfad}]
1149 file delete -force tfad
1153 test fCmd-12.3 {renamefile: stat failing on source} {notRoot} {
1154 catch {file delete -force -- tfa1 tfa2}
1155 set r1 [catch {file rename tfa1 tfa2}]
1156 expr {$r1 && ![file exists tfa1] && ![file exists tfa2]}
1159 test fCmd-12.4 {renamefile: error renaming file to directory} {notRoot} {
1160 catch {file delete -force -- tfa tfad}
1161 set s1 [createfile tfa ]
1164 set r1 [catch {file rename tfa tfad}]
1165 set r2 [checkcontent tfa $s1]
1166 set r3 [file isdir tfad/tfa]
1167 set result [expr $r1 && $r2 && $r3]
1168 file delete -force tfa tfad
1172 test fCmd-12.5 {renamefile: error renaming directory to file} {notRoot} {
1173 catch {file delete -force -- tfa tfad}
1176 set s [createfile tfad/tfa]
1177 set r1 [catch {file rename tfa tfad}]
1178 set r2 [checkcontent tfad/tfa $s]
1179 set r3 [file isdir tfad]
1180 set r4 [file isdir tfa]
1181 set result [expr $r1 && $r2 && $r3 && $r4 ]
1182 file delete -force tfa tfad
1186 test fCmd-12.6 {renamefile: TclRenameFile succeeding} {notRoot} {
1187 catch {file delete -force -- tfa1 tfa2}
1188 set s [createfile tfa1]
1189 file rename tfa1 tfa2
1190 set result [expr [checkcontent tfa2 $s] && ![file exists tfa1]]
1195 test fCmd-12.7 {renamefile: renaming directory into offspring} {notRoot} {
1196 catch {file delete -force -- tfad}
1199 set result [catch {file rename tfad tfad/dir}]
1200 file delete -force tfad
1204 test fCmd-12.8 {renamefile: generic error} {unixOnly notRoot} {
1205 catch {file delete -force -- tfa}
1208 file attributes tfa -permissions 0555
1209 set result [catch {file rename tfa/dir tfa2}]
1210 file attributes tfa -permissions 0777
1211 file delete -force tfa
1216 test fCmd-12.9 {renamefile: moving a file across volumes} {unixOnly notRoot} {
1217 catch {file delete -force -- tfa /tmp/tfa}
1218 set s [createfile tfa ]
1219 file rename tfa /tmp
1220 set result [expr [checkcontent /tmp/tfa $s] && ![file exists tfa]]
1221 file delete /tmp/tfa
1225 test fCmd-12.10 {renamefile: moving a directory across volumes } \
1226 {unixOnly notRoot} {
1227 catch {file delete -force -- tfad /tmp/tfad}
1229 set s [createfile tfad/a ]
1230 file rename tfad /tmp
1231 set restul [expr [checkcontent /tmp/tfad/a $s] && ![file exists tfad]]
1232 file delete -force /tmp/tfad
1237 # Coverage tests for TclCopyFilesCmd()
1239 test fCmd-13.1 {TclCopyFilesCmd: -force option} {notRoot} {
1240 catch {file delete -force -- tfa1}
1241 set s [createfile tfa1]
1242 file copy -force tfa1 tfa2
1243 set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
1244 file delete tfa1 tfa2
1248 test fCmd-13.2 {TclCopyFilesCmd: -- option} {notRoot} {
1249 catch {file delete -force -- tfa1}
1250 set s [createfile -tfa1]
1251 file copy -- -tfa1 tfa2
1252 set result [expr [checkcontent tfa2 $s] && [checkcontent -tfa1 $s]]
1253 file delete -- -tfa1 tfa2
1257 test fCmd-13.3 {TclCopyFilesCmd: bad option} {notRoot} {
1258 catch {file delete -force -- tfa1}
1259 set s [createfile tfa1]
1260 set r1 [catch {file copy -x tfa1 tfa2}]
1261 set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
1266 test fCmd-13.4 {TclCopyFilesCmd: bad \# args} {notRoot} {
1267 catch {file copy -- }
1270 test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} {
1274 set result [catch {file copy tfa ~/foobar }]
1279 test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} {notRoot} {
1280 catch {file delete -force -- tfa1 tfa2 tfa3}
1284 set result [catch {file copy tfa1 tfa2 tfa3}]
1285 file delete tfa1 tfa2 tfa3
1289 test fCmd-13.7 {TclCopyFilesCmd: single file into directory} {notRoot} {
1290 catch {file delete -force -- tfa1 tfad}
1291 set s [createfile tfa1]
1294 set result [expr [checkcontent tfad/tfa1 $s] && [checkcontent tfa1 $s]]
1295 file delete -force tfad tfa1
1299 test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} {notRoot} {
1300 catch {file delete -force -- tfa1 tfa2 tfad}
1301 set s1 [createfile tfa1 ]
1302 set s2 [createfile tfa2 ]
1304 file copy tfa1 tfa2 tfad
1305 set r1 [checkcontent tfad/tfa1 $s1]
1306 set r2 [checkcontent tfad/tfa2 $s2]
1307 set r3 [checkcontent tfa1 $s1]
1308 set r4 [checkcontent tfa2 $s2]
1309 set result [expr $r1 && $r2 && $r3 && $r4 ]
1311 file delete -force tfad tfa1 tfa2
1315 test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} {notRoot} {
1316 catch {file delete -force -- tfa tfad}
1317 set s [createfile tfa ]
1320 set r1 [catch {file copy tfa tfad}]
1321 set r2 [expr [checkcontent tfa $s] && [file isdir tfad/tfa]]
1322 set r3 [file isdir tfad]
1323 set result [expr $r1 && $r2 && $r3 ]
1324 file delete -force tfa tfad
1329 # Coverage tests for copyfile()
1331 test fCmd-14.1 {copyfile: source filename translation failing} {notRoot} {
1335 set result [catch {file copy ~/tfa1 tfa2}]
1340 test fCmd-14.2 {copyfile: dst filename translation failing} {notRoot} {
1344 set s [createfile tfa1]
1346 set r1 [catch {file copy tfa1 ~/tfa2 tfad}]
1347 set result [expr $r1 && [checkcontent tfad/tfa1 $s]]
1349 file delete -force tfa1 tfad
1353 test fCmd-14.3 {copyfile: stat failing on source} {notRoot} {
1354 catch {file delete -force -- tfa1 tfa2}
1355 set r1 [catch {file copy tfa1 tfa2}]
1356 expr $r1 && ![file exists tfa1] && ![file exists tfa2]
1359 test fCmd-14.4 {copyfile: error copying file to directory} {notRoot} {
1360 catch {file delete -force -- tfa tfad}
1361 set s1 [createfile tfa ]
1364 set r1 [catch {file copy tfa tfad}]
1365 set r2 [checkcontent tfa $s1]
1366 set r3 [file isdir tfad]
1367 set r4 [file isdir tfad/tfa]
1368 set result [expr $r1 && $r2 && $r3 && $r4 ]
1369 file delete -force tfa tfad
1373 test fCmd-14.5 {copyfile: error copying directory to file} {notRoot} {
1374 catch {file delete -force -- tfa tfad}
1377 set s [createfile tfad/tfa]
1378 set r1 [catch {file copy tfa tfad}]
1379 set r2 [checkcontent tfad/tfa $s]
1380 set r3 [file isdir tfad]
1381 set r4 [file isdir tfa]
1382 set result [expr $r1 && $r2 && $r3 && $r4 ]
1383 file delete -force tfa tfad
1387 test fCmd-14.6 {copyfile: copy file succeeding} {notRoot} {
1388 catch {file delete -force -- tfa tfa2}
1389 set s [createfile tfa]
1391 set result [expr [checkcontent tfa $s] && [checkcontent tfa2 $s]]
1392 file delete tfa tfa2
1396 test fCmd-14.7 {copyfile: copy directory succeeding} {notRoot} {
1397 catch {file delete -force -- tfa tfa2}
1399 set s [createfile tfa/file]
1401 set result [expr [checkcontent tfa/file $s] && [checkcontent tfa2/file $s]]
1402 file delete -force tfa tfa2
1406 test fCmd-14.8 {copyfile: copy directory failing} {unixOnly notRoot} {
1407 catch {file delete -force -- tfa}
1408 file mkdir tfa/dir/a/b/c
1409 file attributes tfa/dir -permissions 0000
1410 set r1 [catch {file copy tfa tfa2}]
1411 file attributes tfa/dir -permissions 0777
1413 file delete -force tfa tfa2
1418 # Coverage tests for TclMkdirCmd()
1420 test fCmd-15.1 {TclMakeDirsCmd: target filename translation failing} {notRoot} {
1424 set result [catch {file mkdir ~/tfa}]
1429 # Can Tcl_SplitPath return argc == 0? If so them we need a
1430 # test for that code.
1432 test fCmd-15.2 {TclMakeDirsCmd - one directory } {notRoot} {
1433 catch {file delete -force -- tfa}
1435 set result [file isdirectory tfa]
1440 test fCmd-15.3 {TclMakeDirsCmd: - two directories} {notRoot} {
1441 catch {file delete -force -- tfa1 tfa2}
1442 file mkdir tfa1 tfa2
1443 set result [expr [file isdirectory tfa1] && [file isdirectory tfa2]]
1444 file delete tfa1 tfa2
1448 test fCmd-15.4 {TclMakeDirsCmd - stat failing} {unixOnly notRoot} {
1449 catch {file delete -force -- tfa}
1452 file attributes tfa -permissions 0000
1453 set result [catch {file mkdir tfa/file}]
1454 file attributes tfa -permissions 0777
1455 file delete -force tfa
1459 test fCmd-15.5 {TclMakeDirsCmd: - making a directory several levels deep} \
1461 catch {file delete -force -- tfa}
1462 file mkdir tfa/a/b/c
1463 set result [file isdir tfa/a/b/c]
1464 file delete -force tfa
1469 test fCmd-15.6 {TclMakeDirsCmd: - trying to overwrite a file} {notRoot} {
1470 catch {file delete -force -- tfa}
1471 set s [createfile tfa]
1472 set r1 [catch {file mkdir tfa}]
1473 set r2 [file isdir tfa]
1474 set r3 [file exists tfa]
1475 set result [expr $r1 && !$r2 && $r3 && [checkcontent tfa $s]]
1480 test fCmd-15.7 {TclMakeDirsCmd - making several directories} {notRoot} {
1481 catch {file delete -force -- tfa1 tfa2}
1482 file mkdir tfa1 tfa2/a/b/c
1483 set result [expr [file isdir tfa1] && [file isdir tfa2/a/b/c]]
1484 file delete -force tfa1 tfa2
1488 test fCmd-15.8 {TclFileMakeDirsCmd: trying to create an existing dir} {notRoot} {
1491 set result [file isdir tfa]
1497 # Coverage tests for TclDeleteFilesCommand()
1498 test fCmd-16.1 {test the -- argument} {notRoot} {
1499 catch {file delete -force -- tfa}
1505 test fCmd-16.2 {test the -force and -- arguments} {notRoot} {
1506 catch {file delete -force -- tfa}
1508 file delete -force -- tfa
1512 test fCmd-16.3 {test bad option} {notRoot} {
1513 catch {file delete -force -- tfa}
1515 set result [catch {file delete -dog tfa}]
1520 test fCmd-16.4 {test not enough args} {notRoot} {
1524 test fCmd-16.5 {test not enough args with options} {notRoot} {
1525 catch {file delete --}
1528 test fCmd-16.6 {delete: source filename translation failing} {notRoot} {
1532 set result [catch {file delete ~/tfa}]
1537 test fCmd-16.7 {remove a non-empty directory without -force } {notRoot} {
1538 catch {file delete -force -- tfa}
1541 set result [catch {file delete tfa }]
1542 file delete -force tfa
1546 test fCmd-16.8 {remove a normal file } {notRoot} {
1547 catch {file delete -force -- tfa}
1550 set result [catch {file delete tfa }]
1551 file delete -force tfa
1555 test fCmd-16.9 {error while deleting file } {unixOnly notRoot} {
1556 catch {file delete -force -- tfa}
1559 file attributes tfa -permissions 0555
1560 set result [catch {file delete tfa/a }]
1562 ####### If any directory in a tree that is being removed does not
1563 ####### have write permission, the process will fail!
1564 ####### This is also the case with "rm -rf"
1566 file attributes tfa -permissions 0777
1567 file delete -force tfa
1571 test fCmd-16.10 {deleting multiple files} {notRoot} {
1572 catch {file delete -force -- tfa1 tfa2}
1575 file delete tfa1 tfa2
1576 expr ![file exists tfa1] && ![file exists tfa2]
1579 test fCmd-16.11 {TclFileDeleteCmd: removing a nonexistant file} {notRoot} {
1580 catch {file delete -force -- tfa}
1585 # More coverage tests for mkpath()
1586 test fCmd-17.1 {mkdir stat failing on target but not ENOENT} {unixOnly notRoot} {
1587 catch {file delete -force -- tfa1}
1589 file attributes tfa1 -permissions 0555
1590 set result [catch {file mkdir tfa1/tfa2}]
1591 file attributes tfa1 -permissions 0777
1592 file delete -force tfa1
1596 test fCmd-17.2 {mkdir several levels deep - relative } {notRoot} {
1597 catch {file delete -force -- tfa}
1599 set result [file isdir tfa/a/b ]
1600 file delete tfa/a/b tfa/a tfa
1604 test fCmd-17.3 {mkdir several levels deep - absolute } {notRoot} {
1605 catch {file delete -force -- tfa}
1606 set f [file join [pwd] tfa a ]
1608 set result [file isdir $f ]
1609 file delete $f [file join [pwd] tfa]
1614 # Functionality tests for TclFileRenameCmd()
1617 test fCmd-18.1 {TclFileRenameCmd: rename (first form) in the same directory} \
1619 catch {file delete -force -- tfad}
1622 set s [createfile foo ]
1624 file rename bar ./foo
1625 file rename ./foo bar
1626 file rename ./bar ./foo
1627 file rename foo ../dir/bar
1628 file rename ../dir/bar ./foo
1629 file rename ../../tfad/dir/foo ../../tfad/dir/bar
1630 file rename [file join [pwd] bar] foo
1631 file rename foo [file join [pwd] bar]
1632 set result [expr [checkcontent bar $s] && ![file exists foo]]
1634 file delete -force tfad
1638 test fCmd-18.2 {TclFileRenameCmd: single dir to nonexistant} {notRoot} {
1639 catch {file delete -force -- tfa1 tfa2}
1641 file rename tfa1 tfa2
1642 set result [expr [file exists tfa2] && ![file exists tfa1]]
1647 test fCmd-18.3 {TclFileRenameCmd: mixed dirs and files into directory} {notRoot} {
1648 catch {file delete -force -- tfa1 tfad1 tfad2}
1649 set s [createfile tfa1 ]
1650 file mkdir tfad1 tfad2
1651 file rename tfa1 tfad1 tfad2
1652 set r1 [checkcontent tfad2/tfa1 $s]
1653 set r2 [file isdir tfad2/tfad1]
1654 set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfad1]]
1655 file delete tfad2/tfa1
1656 file delete -force tfad2
1660 test fCmd-18.4 {TclFileRenameCmd: attempt to replace non-dir with dir} {notRoot} {
1661 catch {file delete -force -- tfa tfad}
1662 set s [createfile tfa ]
1664 set r1 [catch {file rename tfad tfa}]
1665 set r2 [checkcontent tfa $s]
1666 set r3 [file isdir tfad]
1667 set result [expr $r1 && $r2 && $r3 ]
1668 file delete tfa tfad
1672 test fCmd-18.5 {TclFileRenameCmd: attempt to replace dir with non-dir} {notRoot} {
1673 catch {file delete -force -- tfa tfad}
1674 set s [createfile tfa ]
1676 set r1 [catch {file rename tfa tfad}]
1677 set r2 [checkcontent tfa $s]
1678 set r3 [file isdir tfad/tfa]
1679 set result [expr $r1 && $r2 && $r3 ]
1680 file delete -force tfa tfad
1685 # On Windows there is no easy way to determine if two files are the same
1687 test fCmd-18.6 {TclFileRenameCmd: rename a file to itself} {macOrUnix notRoot} {
1688 catch {file delete -force -- tfa}
1689 set s [createfile tfa]
1690 set r1 [catch {file rename tfa tfa}]
1691 set result [expr $r1 && [checkcontent tfa $s]]
1696 test fCmd-18.7 {TclFileRenameCmd: rename dir on top of another empty dir w/o -force} \
1698 catch {file delete -force -- tfa tfad}
1699 file mkdir tfa tfad/tfa
1700 set r1 [catch {file rename tfa tfad}]
1701 set result [expr $r1 && [file isdir tfa]]
1702 file delete -force tfa tfad
1706 test fCmd-18.8 {TclFileRenameCmd: rename dir on top of another empty dir w/ -force} \
1707 {notRoot notNetworkFilesystem} {
1708 catch {file delete -force -- tfa tfad}
1709 file mkdir tfa tfad/tfa
1710 file rename -force tfa tfad
1711 set result [expr ![file isdir tfa]]
1712 file delete -force tfad
1716 test fCmd-18.9 {TclFileRenameCmd: rename dir on top of a non-empty dir w/o -force} \
1718 catch {file delete -force -- tfa tfad}
1719 file mkdir tfa tfad/tfa/file
1720 set r1 [catch {file rename tfa tfad}]
1721 set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
1722 file delete -force tfa tfad
1726 test fCmd-18.10 {TclFileRenameCmd: rename dir on top of a non-empty dir w/ -force} \
1727 {notRoot notNetworkFilesystem} {
1728 catch {file delete -force -- tfa tfad}
1729 file mkdir tfa tfad/tfa/file
1730 set r1 [catch {file rename -force tfa tfad}]
1731 set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
1732 file delete -force tfa tfad
1736 test fCmd-18.11 {TclFileRenameCmd: rename a non-existant file} {notRoot} {
1737 catch {file delete -force -- tfa1}
1738 set r1 [catch {file rename tfa1 tfa2}]
1739 set result [expr $r1 && ![file exists tfa1] && ![file exists tfa2]]
1742 test fCmd-18.12 {TclFileRenameCmd : rename a symbolic link to file} \
1743 {unixOnly notRoot} {
1744 catch {file delete -force -- tfa1 tfa2 tfa3}
1746 set s [createfile tfa1]
1747 file link -symbolic tfa2 tfa1
1748 file rename tfa2 tfa3
1749 set t [file type tfa3]
1750 set result [expr {$t eq "link"}]
1751 file delete tfa1 tfa3
1755 test fCmd-18.13 {TclFileRenameCmd : rename a symbolic link to dir} \
1756 {unixOnly notRoot} {
1757 catch {file delete -force -- tfa1 tfa2 tfa3}
1760 file link -symbolic tfa2 tfa1
1761 file rename tfa2 tfa3
1762 set t [file type tfa3]
1763 set result [expr {$t eq "link"}]
1764 file delete tfa1 tfa3
1768 test fCmd-18.14 {TclFileRenameCmd : rename a path with sym link} \
1769 {unixOnly notRoot} {
1770 catch {file delete -force -- tfa1 tfa2 tfa3}
1772 file mkdir tfa1/a/b/c/d
1774 set f [file join [pwd] tfa1/a/b]
1775 set f2 [file join [pwd] {tfa2/b alias}]
1776 file link -symbolic $f2 $f
1777 file rename {tfa2/b alias/c} tfa3
1778 set r1 [file isdir tfa3]
1779 set r2 [file exists tfa1/a/b/c]
1780 set result [expr $r1 && !$r2]
1781 file delete -force tfa1 tfa2 tfa3
1785 test fCmd-18.15 {TclFileRenameCmd : rename a file to a symlink dir} \
1786 {unixOnly notRoot} {
1787 catch {file delete -force -- tfa1 tfa2 tfalink}
1790 set s [createfile tfa2]
1791 file link -symbolic tfalink tfa1
1793 file rename tfa2 tfalink
1794 set result [checkcontent tfa1/tfa2 $s ]
1795 file delete -force tfa1 tfalink
1799 test fCmd-18.16 {TclFileRenameCmd: rename a dangling symlink} {unixOnly notRoot} {
1800 catch {file delete -force -- tfa1 tfalink}
1803 file link -symbolic tfalink tfa1
1805 file rename tfalink tfa2
1806 set result [expr [string compare [file type tfa2] "link"] == 0]
1813 # Coverage tests for TclUnixRmdir
1815 test fCmd-19.1 {remove empty directory} {notRoot} {
1816 catch {file delete -force -- tfa}
1822 test fCmd-19.2 {rmdir error besides EEXIST} {unixOnly notRoot} {
1823 catch {file delete -force -- tfa}
1826 file attributes tfa -permissions 0555
1827 set result [catch {file delete tfa/a}]
1828 file attributes tfa -permissions 0777
1829 file delete -force tfa
1833 test fCmd-19.3 {recursive remove} {notRoot} {
1834 catch {file delete -force -- tfa}
1837 file delete -force tfa
1842 # TclUnixDeleteFile and TraversalDelete are covered by tests from the
1843 # TclDeleteFilesCmd suite
1848 # Coverage tests for TraverseUnixTree(), called from TclDeleteFilesCmd
1851 test fCmd-20.1 {TraverseUnixTree : failure opening a subdirectory directory } \
1852 {unixOnly notRoot} {
1853 catch {file delete -force -- tfa}
1856 file attributes tfa/a -permissions 0000
1857 set result [catch {file delete -force tfa}]
1858 file attributes tfa/a -permissions 0777
1859 file delete -force tfa
1863 test fCmd-20.2 {TraverseUnixTree : recursive delete of large directory: Bug 1034337} \
1865 catch {file delete -force -- tfa}
1867 for {set i 1} {$i <= 300} {incr i} {createfile tfa/testfile_$i}
1868 set result [catch {file delete -force tfa} msg]
1869 while {[catch {file delete -force tfa}]} {}
1874 # Feature testing for TclCopyFilesCmd
1876 test fCmd-21.1 {copy : single file to nonexistant } {notRoot} {
1877 catch {file delete -force -- tfa1 tfa2}
1878 set s [createfile tfa1]
1880 set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
1881 file delete tfa1 tfa2
1885 test fCmd-21.2 {copy : single dir to nonexistant } {notRoot} {
1886 catch {file delete -force -- tfa1 tfa2}
1889 set result [expr [file isdir tfa2] && [file isdir tfa1]]
1890 file delete tfa1 tfa2
1894 test fCmd-21.3 {copy : single file into directory } {notRoot} {
1895 catch {file delete -force -- tfa1 tfad}
1896 set s [createfile tfa1]
1899 set result [expr [checkcontent tfad/tfa1 $s] && [checkcontent tfa1 $s]]
1900 file delete -force tfa1 tfad
1904 test fCmd-21.4 {copy : more than one source and target is not a directory} \
1906 catch {file delete -force -- tfa1 tfa2 tfa3}
1910 set result [catch {file copy tfa1 tfa2 tfa3}]
1911 file delete tfa1 tfa2 tfa3
1915 test fCmd-21.5 {copy : multiple files into directory } {notRoot} {
1916 catch {file delete -force -- tfa1 tfa2 tfad}
1917 set s1 [createfile tfa1 ]
1918 set s2 [createfile tfa2 ]
1920 file copy tfa1 tfa2 tfad
1921 set r1 [checkcontent tfad/tfa1 $s1]
1922 set r2 [checkcontent tfad/tfa2 $s2]
1923 set r3 [checkcontent tfa1 $s1]
1924 set r4 [checkcontent tfa2 $s2]
1925 set result [expr $r1 && $r2 && $r3 && $r4]
1926 file delete -force tfa1 tfa2 tfad
1930 test fCmd-21.6 {copy: mixed dirs and files into directory} \
1931 {notRoot notFileSharing} {
1932 catch {file delete -force -- tfa1 tfad1 tfad2}
1933 set s [createfile tfa1 ]
1934 file mkdir tfad1 tfad2
1935 file copy tfa1 tfad1 tfad2
1936 set r1 [checkcontent [file join tfad2 tfa1] $s]
1937 set r2 [file isdir [file join tfad2 tfad1]]
1938 set r3 [checkcontent tfa1 $s]
1939 set result [expr $r1 && $r2 && $r3 && [file isdir tfad1]]
1940 file delete -force tfa1 tfad1 tfad2
1944 test fCmd-21.7.1 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot dontCopyLinks} {
1946 file link -symbolic tfalink tfad1
1948 set result [list [catch {file copy tfalink tfalink2} msg] $msg]
1949 file delete -force tfalink tfalink2
1951 } {1 {error copying "tfalink": the target of this link doesn't exist}}
1952 test fCmd-21.7.2 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot} {
1954 file link -symbolic tfalink tfad1
1956 file copy tfalink tfalink2
1957 set result [string match [file type tfalink2] link]
1958 file delete tfalink tfalink2
1962 test fCmd-21.8.1 {TclCopyFilesCmd: copy a link } {unixOnly notRoot dontCopyLinks} {
1964 file link -symbolic tfalink tfad1
1965 file copy tfalink tfalink2
1966 set r1 [file type tfalink]; # link
1967 set r2 [file type tfalink2]; # directory
1968 set r3 [file isdir tfad1]; # 1
1969 set result [expr {("$r1" == "link") && ("$r2" == "directory") && $r3}]
1970 file delete -force tfad1 tfalink tfalink2
1973 test fCmd-21.8.2 {TclCopyFilesCmd: copy a link } {unixOnly notRoot} {
1975 file link -symbolic tfalink tfad1
1976 file copy tfalink tfalink2
1977 set r1 [file type tfalink]; # link
1978 set r2 [file type tfalink2]; # link
1979 set r3 [file isdir tfad1]; # 1
1980 set result [expr {("$r1" == "link") && ("$r2" == "link") && $r3}]
1981 file delete -force tfad1 tfalink tfalink2
1985 test fCmd-21.9 {TclCopyFilesCmd: copy dir with a link in it} {unixOnly notRoot} {
1987 file link -symbolic tfad1/tfalink "[pwd]/tfad1"
1988 file copy tfad1 tfad2
1989 set result [string match [file type tfad2/tfalink] link]
1990 file delete -force tfad1 tfad2
1994 test fCmd-21.10 {TclFileCopyCmd: copy dir on top of another empty dir w/o -force} \
1996 catch {file delete -force -- tfa tfad}
1997 file mkdir tfa [file join tfad tfa]
1998 set r1 [catch {file copy tfa tfad}]
1999 set result [expr $r1 && [file isdir tfa]]
2000 file delete -force tfa tfad
2004 test fCmd-21.11 {TclFileCopyCmd: copy dir on top of a dir w/o -force} {notRoot} {
2005 catch {file delete -force -- tfa tfad}
2006 file mkdir tfa [file join tfad tfa file]
2007 set r1 [catch {file copy tfa tfad}]
2008 set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
2009 file delete -force tfa tfad
2013 test fCmd-21.12 {TclFileCopyCmd: copy dir on top of a non-empty dir w/ -force} \
2015 catch {file delete -force -- tfa tfad}
2016 file mkdir tfa [file join tfad tfa file]
2017 set r1 [catch {file copy -force tfa tfad}]
2018 set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
2019 file delete -force tfa tfad
2024 # Coverage testing for TclpRenameFile
2026 test fCmd-22.1 {TclpRenameFile: rename and overwrite in a single dir} {notRoot} {
2027 catch {file delete -force -- tfa1 tfa2}
2028 set s [createfile tfa1]
2029 set s2 [createfile tfa2 q]
2031 set r1 [catch {rename tfa1 tfa2}]
2032 file rename -force tfa1 tfa2
2033 set result [expr $r1 && [checkcontent tfa2 $s]]
2034 file delete [glob tfa1 tfa2]
2038 test fCmd-22.2 {TclpRenameFile: attempt to overwrite itself} {macOrUnix notRoot} {
2039 catch {file delete -force -- tfa1}
2040 set s [createfile tfa1]
2041 file rename -force tfa1 tfa1
2042 set result [checkcontent tfa1 $s]
2047 test fCmd-22.3 {TclpRenameFile: rename dir to existing dir} {notRoot} {
2048 catch {file delete -force -- d1 tfad}
2049 file mkdir d1 [file join tfad d1]
2050 set r1 [catch {file rename d1 tfad}]
2051 set result [expr $r1 && [file isdir d1] && [file isdir [file join tfad d1]]]
2052 file delete -force d1 tfad
2056 test fCmd-22.4 {TclpRenameFile: rename dir to dir several levels deep} {notRoot} {
2057 catch {file delete -force -- d1 tfad}
2058 file mkdir d1 [file join tfad a b c]
2059 file rename d1 [file join tfad a b c d1]
2060 set result [expr ![file isdir d1] && [file isdir [file join tfad a b c d1]]]
2061 file delete -force [glob d1 tfad]
2067 # TclMacCopyFile needs to be redone.
2069 test fCmd-22.5 {TclMacCopyFile: copy and overwrite in a single dir} {notRoot} {
2070 catch {file delete -force -- tfa1 tfa2}
2071 set s [createfile tfa1]
2072 set s2 [createfile tfa2 q]
2074 set r1 [catch {file copy tfa1 tfa2}]
2075 file copy -force tfa1 tfa2
2076 set result [expr $r1 && [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
2077 file delete tfa1 tfa2
2082 # TclMacMkdir - basic cases are covered elsewhere.
2083 # Error cases are not covered.
2088 # Error cases are not covered.
2091 test fCmd-23.1 {TclMacRmdir: trying to remove a nonempty directory} {notRoot} {
2092 catch {file delete -force -- tfad}
2094 file mkdir [file join tfad dir]
2096 set result [catch {file delete tfad}]
2097 file delete -force tfad
2103 # Error cases are not covered.
2105 test fCmd-24.1 {TclMacDeleteFile: deleting a normal file} {notRoot} {
2106 catch {file delete -force -- tfa1}
2114 # TclMacCopyDirectory
2115 # Error cases are not covered.
2117 test fCmd-25.1 {TclMacCopyDirectory: copying a normal directory} {notRoot notFileSharing} {
2118 catch {file delete -force -- tfad1 tfad2}
2120 file mkdir [file join tfad1 a b c]
2121 file copy tfad1 tfad2
2122 set result [expr [file isdir [file join tfad1 a b c]] && [file isdir [file join tfad2 a b c]]]
2123 file delete -force tfad1 tfad2
2127 test fCmd-25.2 {TclMacCopyDirectory: copying a short path normal directory} {notRoot notFileSharing} {
2128 catch {file delete -force -- tfad1 tfad2}
2131 file copy tfad1 tfad2
2132 set result [expr [file isdir tfad1] && [file isdir tfad2]]
2133 file delete tfad1 tfad2
2137 test fCmd-25.3 {TclMacCopyDirectory: copying dirs between different dirs} {notRoot notFileSharing} {
2138 catch {file delete -force -- tfad1 tfad2}
2140 file mkdir [file join tfad1 x y z]
2141 file mkdir [file join tfad2 dir]
2142 file copy tfad1 [file join tfad2 dir]
2143 set result [expr [file isdir [file join tfad1 x y z]] && [file isdir [file join tfad2 dir tfad1 x y z]]]
2144 file delete -force tfad1 tfad2
2149 # Functionality tests for TclDeleteFilesCmd
2152 test fCmd-26.1 {TclDeleteFilesCmd: delete symlink} {unixOnly notRoot} {
2153 catch {file delete -force -- tfad1 tfad2}
2156 file link -symbolic tfalink tfad1
2159 set r1 [file isdir tfad1]
2160 set r2 [file exists tfalink]
2162 set result [expr $r1 && !$r2]
2167 test fCmd-26.2 {TclDeleteFilesCmd: delete dir with symlink} {unixOnly notRoot} {
2168 catch {file delete -force -- tfad1 tfad2}
2172 file link -symbolic [file join tfad2 link] tfad1
2173 file delete -force tfad2
2175 set r1 [file isdir tfad1]
2176 set r2 [file exists tfad2]
2178 set result [expr $r1 && !$r2]
2183 test fCmd-26.3 {TclDeleteFilesCmd: delete dangling symlink} {unixOnly notRoot} {
2184 catch {file delete -force -- tfad1 tfad2}
2187 file link -symbolic tfad2 tfad1
2191 set r1 [file exists tfad1]
2192 set r2 [file exists tfad2]
2194 set result [expr !$r1 && !$r2]
2198 test fCmd-27.2 {TclFileAttrsCmd - Tcl_TranslateFileName fails} {testsetplatform} {
2199 set platform [testgetplatform]
2200 testsetplatform unix
2201 list [catch {file attributes ~_totally_bogus_user} msg] $msg [testsetplatform $platform]
2202 } {1 {user "_totally_bogus_user" doesn't exist} {}}
2203 test fCmd-27.3 {TclFileAttrsCmd - all attributes} {
2204 catch {file delete -force -- foo.tmp}
2206 list [catch {file attributes foo.tmp} msg] [expr {[llength $msg] > 0}] [file delete -force -- foo.tmp]
2208 test fCmd-27.4 {TclFileAttrsCmd - getting one option} {
2209 catch {file delete -force -- foo.tmp}
2211 set attrs [file attributes foo.tmp]
2212 list [catch {eval file attributes foo.tmp [lindex $attrs 0]}] [file delete -force -- foo.tmp]
2215 # Find a group that exists on this Unix system, or else skip tests that
2216 # require Unix groups.
2217 if {$tcl_platform(platform) == "unix"} {
2218 ::tcltest::testConstraint foundGroup 0
2220 set groupList [exec groups]
2221 set group [lindex $groupList 0]
2222 ::tcltest::testConstraint foundGroup 1
2225 ::tcltest::testConstraint foundGroup 1
2228 test fCmd-27.5 {TclFileAttrsCmd - setting one option} {foundGroup} {
2229 catch {file delete -force -- foo.tmp}
2231 set attrs [file attributes foo.tmp]
2232 list [catch {eval file attributes foo.tmp [lrange $attrs 0 1]} msg] $msg [file delete -force -- foo.tmp]
2234 test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} {foundGroup} {
2235 catch {file delete -force -- foo.tmp}
2237 set attrs [file attributes foo.tmp]
2238 list [catch {eval file attributes foo.tmp [lrange $attrs 0 3]} msg] $msg [file delete -force -- foo.tmp]
2241 if {[string equal $tcl_platform(platform) "windows"]} {
2242 if {[string index $tcl_platform(osVersion) 0] >= 5 \
2243 && ([lindex [file system [temporaryDirectory]] 1] == "NTFS")} {
2244 tcltest::testConstraint linkDirectory 1
2245 tcltest::testConstraint linkFile 1
2247 tcltest::testConstraint linkDirectory 0
2248 tcltest::testConstraint linkFile 0
2251 tcltest::testConstraint linkFile 1
2252 tcltest::testConstraint linkDirectory 1
2254 if {[string equal $tcl_platform(osSystemName) "Symbian"]} {
2255 tcltest::testConstraint linkDirectory 0
2259 test fCmd-28.1 {file link} {
2260 list [catch {file link} msg] $msg
2261 } {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
2263 test fCmd-28.2 {file link} {
2264 list [catch {file link a b c d} msg] $msg
2265 } {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
2267 test fCmd-28.3 {file link} {
2268 list [catch {file link abc b c} msg] $msg
2269 } {1 {bad switch "abc": must be -symbolic or -hard}}
2271 test fCmd-28.4 {file link} {
2272 list [catch {file link -abc b c} msg] $msg
2273 } {1 {bad switch "-abc": must be -symbolic or -hard}}
2274 cd [workingDirectory]
2276 makeDirectory abc.dir
2277 makeDirectory abc2.dir
2278 makeFile contents abc.file
2279 makeFile contents abc2.file
2281 cd [temporaryDirectory]
2282 test fCmd-28.5 {file link: source already exists} {linkDirectory} {
2283 cd [temporaryDirectory]
2284 set res [list [catch {file link abc.dir abc2.dir} msg] $msg]
2285 cd [workingDirectory]
2287 } {1 {could not create new link "abc.dir": that path already exists}}
2289 test fCmd-28.6 {file link: unsupported operation} {linkDirectory macOrWin} {
2290 cd [temporaryDirectory]
2291 set res [list [catch {file link -hard abc.link abc.dir} msg] $msg]
2292 cd [workingDirectory]
2294 } {1 {could not create new link "abc.link" pointing to "abc.dir": illegal operation on a directory}}
2296 test fCmd-28.7 {file link: source already exists} {linkFile} {
2297 cd [temporaryDirectory]
2298 set res [list [catch {file link abc.file abc2.file} msg] $msg]
2299 cd [workingDirectory]
2301 } {1 {could not create new link "abc.file": that path already exists}}
2303 test fCmd-28.8 {file link} {linkFile winOnly} {
2304 cd [temporaryDirectory]
2305 set res [list [catch {file link -symbolic abc.link abc.file} msg] $msg]
2306 cd [workingDirectory]
2308 } {1 {could not create new link "abc.link" pointing to "abc.file": not a directory}}
2310 test fCmd-28.9 {file link: success with file} {linkFile} {
2311 cd [temporaryDirectory]
2312 file delete -force abc.link
2313 set res [list [catch {file link abc.link abc.file} msg] $msg]
2314 cd [workingDirectory]
2318 cd [temporaryDirectory]
2319 catch {file delete -force abc.link}
2320 cd [workingDirectory]
2322 test fCmd-28.10 {file link: linking to nonexistent path} {linkDirectory} {
2323 cd [temporaryDirectory]
2324 file delete -force abc.link
2325 set res [list [catch {file link abc.link abc2.doesnt} msg] $msg]
2326 cd [workingDirectory]
2328 } {1 {could not create new link "abc.link" since target "abc2.doesnt" doesn't exist}}
2330 test fCmd-28.11 {file link: success with directory} {linkDirectory} {
2331 cd [temporaryDirectory]
2332 file delete -force abc.link
2333 set res [list [catch {file link abc.link abc.dir} msg] $msg]
2334 cd [workingDirectory]
2338 test fCmd-28.12 {file link: cd into a link} {linkDirectory} {
2339 cd [temporaryDirectory]
2340 file delete -force abc.link
2341 file link abc.link abc.dir
2348 # now '$up' should be either $orig or [file dirname abc.dir],
2349 # depending on whether 'cd' actually moves to the destination
2350 # of a link, or simply treats the link as a directory.
2351 # (on windows the former, on unix the latter, I believe)
2352 if {([file normalize $up] != [file normalize $orig]) \
2353 && ([file normalize $up] != [file normalize [file dirname abc.dir]])} {
2354 set res "wrong directory with 'cd $link ; cd ..'"
2358 cd [workingDirectory]
2362 test fCmd-28.13 {file link} {linkDirectory} {
2363 # duplicate link throws error
2364 cd [temporaryDirectory]
2365 set res [list [catch {file link abc.link abc.dir} msg] $msg]
2366 cd [workingDirectory]
2368 } {1 {could not create new link "abc.link": that path already exists}}
2370 test fCmd-28.14 {file link: deletes link not dir} {linkDirectory} {
2371 cd [temporaryDirectory]
2372 file delete -force abc.link
2373 set res [list [file exists abc.link] [file exists abc.dir]]
2374 cd [workingDirectory]
2378 test fCmd-28.15.1 {file link: copies link not dir} {linkDirectory dontCopyLinks} {
2379 cd [temporaryDirectory]
2380 file delete -force abc.link
2381 file link abc.link abc.dir
2382 file copy abc.link abc2.link
2383 # abc2.linkdir was a copy of a link to a dir, so it should end up as
2384 # a directory, not a link (links trace to endpoint).
2385 set res [list [file type abc2.link] [file tail [file link abc.link]]]
2386 cd [workingDirectory]
2388 } {directory abc.dir}
2389 test fCmd-28.15.2 {file link: copies link not dir} {linkDirectory} {
2390 cd [temporaryDirectory]
2391 file delete -force abc.link
2392 file link abc.link abc.dir
2393 file copy abc.link abc2.link
2394 set res [list [file type abc2.link] [file tail [file link abc2.link]]]
2395 cd [workingDirectory]
2399 cd [temporaryDirectory]
2400 file delete -force abc.link
2401 file delete -force abc2.link
2403 file copy abc.file abc.dir
2404 file copy abc2.file abc.dir
2405 cd [workingDirectory]
2407 test fCmd-28.16 {file link: glob inside link} {linkDirectory} {
2408 cd [temporaryDirectory]
2409 file delete -force abc.link
2410 file link abc.link abc.dir
2411 set res [lsort [glob -dir abc.link -tails *]]
2412 cd [workingDirectory]
2414 } [lsort [list abc.file abc2.file]]
2416 test fCmd-28.17 {file link: glob -type l} {linkDirectory} {
2417 cd [temporaryDirectory]
2418 set res [glob -dir [pwd] -type l -tails abc*]
2419 cd [workingDirectory]
2423 test fCmd-28.18 {file link: glob -type d} {linkDirectory} {
2424 cd [temporaryDirectory]
2425 set res [lsort [glob -dir [pwd] -type d -tails abc*]]
2426 cd [workingDirectory]
2428 } [lsort [list abc.link abc.dir abc2.dir]]
2430 test fCmd-29.1 {weird memory corruption fault} {
2431 catch {set res [open [file join ~a_totally_bogus_user_id/foo bar]]}
2434 cd [temporaryDirectory]
2435 file delete -force abc.link
2436 cd [workingDirectory]
2438 removeFile abc2.file
2440 removeDirectory abc2.dir
2441 removeDirectory abc.dir
2445 ::tcltest::cleanupTests