📄 winfcmd.test
字号:
# This file tests the tclWinFCmd.c file.## This file contains a collection of tests for one or more of the Tcl# built-in commands. Sourcing this file into Tcl runs the tests and# generates output for errors. No output means no errors were found.## Copyright (c) 1996-1997 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## SCCS: @(#) winFCmd.test 1.11 97/10/10 11:50:05#if {[string compare test [info procs test]] == 1} then {source defs}if {$tcl_platform(platform) != "windows"} { return}proc createfile {file {string a}} { set f [open $file w] puts -nonewline $f $string close $f return $string}proc contents {file} { set f [open $file r] set r [read $f] close $f set r}proc cleanup {args} { foreach p ". $args" { set x "" catch { set x [glob [file join $p tf*] [file join $p td*]] } if {$x != ""} { catch {eval file delete -force -- $x} } }}set testConfig(cdrom) 0set testConfig(exdev) 0set testConfig(UNCPath} 0# find a CD-ROM so we can test read-only filesystems.set cdrom {}set nodrive x:foreach p {d e f g h i j k l m n o p q r s t u v w x y z} { set name ${p}:/dummy~~.fil if [catch {set fd [open $name w]}] { set err [lindex $errorCode 1] if {$cdrom == "" && $err == "EACCES"} { set cdrom ${p}: } if {$err == "ENOENT"} { set nodrive ${p}: } } else { close $fd file delete $name }}proc findfile {dir} { foreach p [glob $dir/*] { if {[file type $p] == "file"} { return $p } } foreach p [glob $dir/*] { if {[file type $p] == "directory"} { set f [findfile $p] if {$f != ""} { return $f } } } return ""}if {$cdrom == ""} { puts "Couldn't find a CD-ROM. Skipping tests that access CD-ROM." puts "If you have a CD-ROM, insert a data disk and rerun tests."} else { set testConfig(cdrom) 1 set cdfile [findfile $cdrom]}if {[file exists c:/] && [file exists d:/]} { catch {file delete d:/tf1} if {[catch {close [open d:/tf1 w]}] == 0} { file delete d:/tf1 set testConfig(exdev) 1 }}if {[file exists //bisque/icepick]} { set testConfig(UNCPath) 1}file delete -force -- td1set foo [catch {open td1 w} testfile]if {$foo} { set testConfig(longFileNames) 0} else { close $testfile set testConfig(longFileNames) 1 file delete -force -- td1}# A really long file name# length of longname is 1216 chars, which should be greater than any static# buffer or allowable filename.set longname "abcdefghihjllmnopqrstuvwxyz01234567890"append longname $longnameappend longname $longnameappend longname $longnameappend longname $longnameappend longname $longname# Uses the "testfile" command instead of the "file" command. The "file"# command provides several layers of sanity checks on the arguments and# it can be difficult to actually forward "insane" arguments to the# low-level posix emulation layer.test winFCmd-1.1 {TclpRenameFile: errno: EACCES} {cdrom} { list [catch {testfile mv $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-1.2 {TclpRenameFile: errno: EEXIST} { cleanup file mkdir td1/td2/td3 file mkdir td2 list [catch {testfile mv td2 td1/td2} msg] $msg} {1 EEXIST} test winFCmd-1.3 {TclpRenameFile: errno: EINVAL} {!$testConfig(win32s) || ("[lindex [file split [pwd]] end]" == "C:/")} { # Don't run this test under Win32s on a drive mounted from an NT # machine; it causes the NT machine to die. cleanup list [catch {testfile mv / td1} msg] $msg} {1 EINVAL}test winFCmd-1.4 {TclpRenameFile: errno: EINVAL} { cleanup file mkdir td1 list [catch {testfile mv td1 td1/td2} msg] $msg} {1 EINVAL}test winFCmd-1.5 {TclpRenameFile: errno: EISDIR} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv tf1 td1} msg] $msg} {1 EISDIR}test winFCmd-1.6 {TclpRenameFile: errno: ENOENT} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT}test winFCmd-1.7 {TclpRenameFile: errno: ENOENT} { cleanup list [catch {testfile mv "" tf2} msg] $msg} {1 ENOENT}test winFCmd-1.8 {TclpRenameFile: errno: ENOENT} { cleanup createfile tf1 list [catch {testfile mv tf1 ""} msg] $msg} {1 ENOENT}test winFCmd-1.9 {TclpRenameFile: errno: ENOTDIR} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR}test winFCmd-1.10 {TclpRenameFile: errno: EXDEV} {exdev} { file delete -force d:/tf1 file mkdir c:/tf1 set msg [list [catch {testfile mv c:/tf1 d:/tf1} msg] $msg] file delete -force c:/tf1 set msg} {1 EXDEV}test winFCmd-1.11 {TclpRenameFile: errno: EACCES} { cleanup set fd [open tf1 w] set msg [list [catch {testfile mv tf1 tf2} msg] $msg] close $fd set msg} {1 EACCES}test winFCmd-1.12 {TclpRenameFile: errno: EACCES} { cleanup createfile tf1 set fd [open tf2 w] set msg [list [catch {testfile mv tf1 tf2} msg] $msg] close $fd set msg} {1 EACCES}test winFCmd-1.13 {TclpRenameFile: errno: EACCES} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EACCES}test winFCmd-1.14 {TclpRenameFile: errno: EACCES} {95} { cleanup createfile tf1 list [catch {testfile mv tf1 nul} msg] $msg} {1 EACCES}test winFCmd-1.15 {TclpRenameFile: errno: EEXIST} {nt} { cleanup createfile tf1 list [catch {testfile mv tf1 nul} msg] $msg} {1 EEXIST}test winFCmd-1.16 {TclpRenameFile: MoveFile() != FALSE} { cleanup createfile tf1 tf1 testfile mv tf1 tf2 list [file exists tf1] [contents tf2]} {0 tf1}test winFCmd-1.17 {TclpRenameFile: MoveFile() == FALSE} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT} test winFCmd-1.18 {TclpRenameFile: srcAttr == -1} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT} test winFCmd-1.19 {TclpRenameFile: errno == EACCES} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EACCES}# under 95, this would actually succed and move the current dir out from # under yourself.test winFCmd-1.20 {TclpRenameFile: src is dir} {!95} { cleanup file delete /tf1 list [catch {testfile mv [pwd] /tf1} msg] $msg} {1 EACCES}test winFCmd-1.21 {TclpRenameFile: obscenely long src} {!win32s} { # Really long file names cause all the file system calls to lock up, # endlessly throwing an access violation and retrying the operation. list [catch {testfile mv $longname tf1} msg] $msg} {1 ENAMETOOLONG}test winFCmd-1.22 {TclpRenameFile: obscenely long dst} {nt} { # return ENOENT if name is too long! cleanup createfile tf1 list [catch {testfile mv tf1 $longname} msg] $msg} {1 ENOENT}test winFCmd-1.23 {TclpRenameFile: obscenely long dst} {95} { cleanup createfile tf1 list [catch {testfile mv tf1 $longname} msg] $msg} {1 ENAMETOOLONG}test winFCmd-1.24 {TclpRenameFile: move dir into self} { cleanup file mkdir td1 list [catch {testfile mv [pwd]/td1 td1/td2} msg] $msg} {1 EINVAL}test winFCmd-1.25 {TclpRenameFile: move a root dir} {!$testConfig(win32s) || ("[lindex [file split [pwd]] end]" == "C:/")} { # Don't run this test under Win32s on a drive mounted from an NT # machine; it causes the NT machine to die. cleanup list [catch {testfile mv / c:/} msg] $msg} {1 EINVAL}test winFCmd-1.26 {TclpRenameFile: cross file systems} {cdrom} { cleanup file mkdir td1 list [catch {testfile mv td1 $cdrom/td1} msg] $msg} {1 EXDEV} test winFCmd-1.27 {TclpRenameFile: readonly fs} {cdrom} { cleanup list [catch {testfile mv $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-1.28 {TclpRenameFile: open file} { cleanup set fd [open tf1 w] set msg [list [catch {testfile mv tf1 tf2} msg] $msg] close $fd set msg} {1 EACCES} test winFCmd-1.29 {TclpRenameFile: errno == EEXIST} { cleanup createfile tf1 createfile tf2 testfile mv tf1 tf2 list [file exist tf1] [file exist tf2]} {0 1}test winFCmd-1.30 {TclpRenameFile: src is dir} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR} test winFCmd-1.31 {TclpRenameFile: dst is dir} { cleanup file mkdir td1 file mkdir td2/td2 list [catch {testfile mv td1 td2} msg] $msg} {1 EEXIST}test winFCmd-1.32 {TclpRenameFile: TclpRemoveDirectory fails} { cleanup file mkdir td1 file mkdir td2/td2 list [catch {testfile mv td1 td2} msg] $msg} {1 EEXIST}test winFCmd-1.33 {TclpRenameFile: TclpRemoveDirectory succeeds} { cleanup file mkdir td1/td2 file mkdir td2 testfile mv td1 td2 list [file exist td1] [file exist td2] [file exist td2/td2]} {0 1 1}test winFCmd-1.34 {TclpRenameFile: After removing dst dir, MoveFile fails} {exdev} { file mkdir d:/td1 testchmod 000 d:/td1 set msg [list [catch {testfile mv c:/windows d:/td1} msg] $msg] set msg "$msg [file writable d:/td1]" file delete d:/td1 set msg} {1 EXDEV 0}test winFCmd-1.35 {TclpRenameFile: src is dir, dst is not} { file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR}test winFCmd-1.36 {TclpRenameFile: src is not dir, dst is} { file mkdir td1 createfile tf1 list [catch {testfile mv tf1 td1} msg] $msg} {1 EISDIR}test winFCmd-1.37 {TclpRenameFile: src and dst not dir} { createfile tf1 tf1 createfile tf2 tf2 testfile mv tf1 tf2 contents tf2} {tf1}test winFCmd-1.38 {TclpRenameFile: need to restore temp file} { # Can't figure out how to cause this. # Need a file that can't be copied.} {}test winFCmd-2.1 {TclpCopyFile: errno: EACCES} {cdrom} { cleanup list [catch {testfile cp $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-2.2 {TclpCopyFile: errno: EISDIR} { cleanup file mkdir td1 list [catch {testfile cp td1 tf1} msg] $msg} {1 EISDIR}test winFCmd-2.3 {TclpCopyFile: errno: EISDIR} { cleanup createfile tf1 file mkdir td1 list [catch {testfile cp tf1 td1} msg] $msg} {1 EISDIR}test winFCmd-2.4 {TclpCopyFile: errno: ENOENT} { cleanup list [catch {testfile cp tf1 tf2} msg] $msg} {1 ENOENT}test winFCmd-2.5 {TclpCopyFile: errno: ENOENT} { cleanup list [catch {testfile cp "" tf2} msg] $msg} {1 ENOENT}test winFCmd-2.6 {TclpCopyFile: errno: ENOENT} { cleanup createfile tf1 list [catch {testfile cp tf1 ""} msg] $msg} {1 ENOENT}test winFCmd-2.7 {TclpCopyFile: errno: EACCES} {!nt} { cleanup createfile tf1 set fd [open tf2 w] set msg [list [catch {testfile cp tf1 tf2} msg] $msg] close $fd set msg} {1 EACCES}test winFCmd-2.8 {TclpCopyFile: errno: EACCES} {nt} { cleanup list [catch {testfile cp nul tf1} msg] $msg} {1 EACCES}test winFCmd-2.9 {TclpCopyFile: errno: ENOENT} {95} { cleanup list [catch {testfile cp nul tf1} msg] $msg} {1 ENOENT}test winFCmd-2.10 {TclpCopyFile: CopyFile succeeds} { cleanup createfile tf1 tf1 testfile cp tf1 tf2 list [contents tf1] [contents tf2]} {tf1 tf1}test winFCmd-2.11 {TclpCopyFile: CopyFile succeeds} { cleanup createfile tf1 tf1 createfile tf2 tf2 testfile cp tf1 tf2 list [contents tf1] [contents tf2]} {tf1 tf1}test winFCmd-2.12 {TclpCopyFile: CopyFile succeeds} { cleanup createfile tf1 tf1 testchmod 000 tf1 testfile cp tf1 tf2 list [contents tf2] [file writable tf2]} {tf1 0}test winFCmd-2.13 {TclpCopyFile: CopyFile fails} { cleanup createfile tf1 file mkdir td1 list [catch {testfile cp tf1 td1} msg] $msg} {1 EISDIR} test winFCmd-2.14 {TclpCopyFile: errno == EACCES} { cleanup file mkdir td1 list [catch {testfile cp td1 tf1} msg] $msg} {1 EISDIR}test winFCmd-2.15 {TclpCopyFile: src is directory} { cleanup file mkdir td1 list [catch {testfile cp td1 tf1} msg] $msg} {1 EISDIR}test winFCmd-2.16 {TclpCopyFile: dst is directory} { cleanup createfile tf1 file mkdir td1 list [catch {testfile cp tf1 td1} msg] $msg} {1 EISDIR}test winFCmd-2.17 {TclpCopyFile: dst is readonly} { cleanup createfile tf1 tf1 createfile tf2 tf2 testchmod 000 tf2 testfile cp tf1 tf2 list [file writable tf2] [contents tf2]} {1 tf1}test winFCmd-2.18 {TclpCopyFile: still can't copy onto dst} {95} { cleanup createfile tf1 createfile tf2 testchmod 000 tf2 set fd [open tf2] set msg [list [catch {testfile cp tf1 tf2} msg] $msg] close $fd set msg "$msg [file writable tf2]"} {1 EACCES 0} test winFCmd-3.1 {TclpDeleteFile: errno: EACCES} {cdrom} { list [catch {testfile rm $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-3.2 {TclpDeleteFile: errno: EISDIR} { cleanup file mkdir td1 list [catch {testfile rm td1} msg] $msg} {1 EISDIR} test winFCmd-3.3 {TclpDeleteFile: errno: ENOENT} { cleanup list [catch {testfile rm tf1} msg] $msg} {1 ENOENT}test winFCmd-3.4 {TclpDeleteFile: errno: ENOENT} { cleanup list [catch {testfile rm ""} msg] $msg} {1 ENOENT}test winFCmd-3.5 {TclpDeleteFile: errno: EACCES} { cleanup set fd [open tf1 w] set msg [list [catch {testfile rm tf1} msg] $msg] close $fd set msg} {1 EACCES}test winFCmd-3.6 {TclpDeleteFile: errno: EACCES} { cleanup list [catch {testfile rm nul} msg] $msg} {1 EACCES}test winFCmd-3.7 {TclpDeleteFile: DeleteFile succeeds} { cleanup createfile tf1 testfile rm tf1 file exist tf1} {0}test winFCmd-3.8 {TclpDeleteFile: DeleteFile fails} { cleanup file mkdir td1 list [catch {testfile rm td1} msg] $msg} {1 EISDIR}test winFCmd-3.9 {TclpDeleteFile: errno == EACCES} {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -