📄 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.# Copyright (c) 1998-1999 by Scriptics Corporation.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## RCS: @(#) $Id: winFCmd.test,v 1.20 2002/10/04 08:25:14 dkf Exp $#if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::*}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 -directory $p tf* td*] } if {$x != ""} { catch {eval file delete -force -- $x} } }}if {[string equal $tcl_platform(platform) "windows"]} { if {[string equal $tcl_platform(os) "Windows NT"] \ && [string equal [string index $tcl_platform(osVersion) 0] "5"]} { tcltest::testConstraint win2000orXP 1 tcltest::testConstraint winOlderThan2000 0 } else { tcltest::testConstraint win2000orXP 0 tcltest::testConstraint winOlderThan2000 1 }} else { tcltest::testConstraint win2000orXP 0 tcltest::testConstraint winOlderThan2000 0}set ::tcltest::testConstraints(cdrom) 0set ::tcltest::testConstraints(exdev) 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 != ""} { set ::tcltest::testConstraints(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 ::tcltest::testConstraints(exdev) 1 }}file delete -force -- td1set foo [catch {open td1 w} testfile]if {$foo} { set ::tcltest::testConstraints(longFileNames) 0} else { close $testfile set ::tcltest::testConstraints(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} {pcOnly cdrom} { list [catch {testfile mv $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-1.2 {TclpRenameFile: errno: EEXIST} {pcOnly} { 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} {pcOnly} { cleanup list [catch {testfile mv / td1} msg] $msg} {1 EINVAL}test winFCmd-1.4 {TclpRenameFile: errno: EINVAL} {pcOnly} { cleanup file mkdir td1 list [catch {testfile mv td1 td1/td2} msg] $msg} {1 EINVAL}test winFCmd-1.5 {TclpRenameFile: errno: EISDIR} {pcOnly} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv tf1 td1} msg] $msg} {1 EISDIR}test winFCmd-1.6 {TclpRenameFile: errno: ENOENT} {pcOnly} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT}test winFCmd-1.7 {TclpRenameFile: errno: ENOENT} {pcOnly} { cleanup list [catch {testfile mv "" tf2} msg] $msg} {1 ENOENT}test winFCmd-1.8 {TclpRenameFile: errno: ENOENT} {pcOnly} { cleanup createfile tf1 list [catch {testfile mv tf1 ""} msg] $msg} {1 ENOENT}test winFCmd-1.9 {TclpRenameFile: errno: ENOTDIR} {pcOnly} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR}test winFCmd-1.10 {TclpRenameFile: errno: EXDEV} {pcOnly 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} {pcOnly} { 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} {pcOnly} { 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} {pcOnly win2000orXP} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EINVAL}test winFCmd-1.13.1 {TclpRenameFile: errno: EACCES} {pcOnly winOlderThan2000} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EACCES}test winFCmd-1.14 {TclpRenameFile: errno: EACCES} {pcOnly 95} { cleanup createfile tf1 list [catch {testfile mv tf1 nul} msg] $msg} {1 EACCES}test winFCmd-1.15 {TclpRenameFile: errno: EEXIST} {pcOnly nt} { cleanup createfile tf1 list [catch {testfile mv tf1 nul} msg] $msg} {1 EEXIST}test winFCmd-1.16 {TclpRenameFile: MoveFile() != FALSE} {pcOnly} { cleanup createfile tf1 tf1 testfile mv tf1 tf2 list [file exists tf1] [contents tf2]} {0 tf1}test winFCmd-1.17 {TclpRenameFile: MoveFile() == FALSE} {pcOnly} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT} test winFCmd-1.18 {TclpRenameFile: srcAttr == -1} {pcOnly} { cleanup list [catch {testfile mv tf1 tf2} msg] $msg} {1 ENOENT} test winFCmd-1.19 {TclpRenameFile: errno == EACCES} {pcOnly win2000orXP} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EINVAL}test winFCmd-1.19.1 {TclpRenameFile: errno == EACCES} {pcOnly winOlderThan2000} { cleanup list [catch {testfile mv nul tf1} msg] $msg} {1 EACCES}test winFCmd-1.20 {TclpRenameFile: src is dir} {pcOnly nt} { # under 95, this would actually succeed and move the current dir out from # under the current process! cleanup file delete /tf1 list [catch {testfile mv [pwd] /tf1} msg] $msg} {1 EACCES}test winFCmd-1.21 {TclpRenameFile: long src} {pcOnly} { cleanup list [catch {testfile mv $longname tf1} msg] $msg} {1 ENAMETOOLONG}test winFCmd-1.22 {TclpRenameFile: long dst} {pcOnly} { cleanup createfile tf1 list [catch {testfile mv tf1 $longname} msg] $msg} {1 ENAMETOOLONG}test winFCmd-1.23 {TclpRenameFile: move dir into self} {pcOnly} { cleanup file mkdir td1 list [catch {testfile mv [pwd]/td1 td1/td2} msg] $msg} {1 EINVAL}test winFCmd-1.24 {TclpRenameFile: move a root dir} {pcOnly} { cleanup list [catch {testfile mv / c:/} msg] $msg} {1 EINVAL}test winFCmd-1.25 {TclpRenameFile: cross file systems} {pcOnly cdrom} { cleanup file mkdir td1 list [catch {testfile mv td1 $cdrom/td1} msg] $msg} {1 EXDEV} test winFCmd-1.26 {TclpRenameFile: readonly fs} {pcOnly cdrom} { cleanup list [catch {testfile mv $cdfile $cdrom/dummy~~.fil} msg] $msg} {1 EACCES}test winFCmd-1.27 {TclpRenameFile: open file} {pcOnly} { 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.28 {TclpRenameFile: errno == EEXIST} {pcOnly} { cleanup createfile tf1 createfile tf2 testfile mv tf1 tf2 list [file exists tf1] [file exists tf2]} {0 1}test winFCmd-1.29 {TclpRenameFile: src is dir} {pcOnly} { cleanup file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR} test winFCmd-1.30 {TclpRenameFile: dst is dir} {pcOnly} { cleanup file mkdir td1 file mkdir td2/td2 list [catch {testfile mv td1 td2} msg] $msg} {1 EEXIST}test winFCmd-1.31 {TclpRenameFile: TclpRemoveDirectory fails} {pcOnly} { cleanup file mkdir td1 file mkdir td2/td2 list [catch {testfile mv td1 td2} msg] $msg} {1 EEXIST}test winFCmd-1.32 {TclpRenameFile: TclpRemoveDirectory succeeds} {pcOnly} { cleanup file mkdir td1/td2 file mkdir td2 testfile mv td1 td2 list [file exists td1] [file exists td2] [file exists td2/td2]} {0 1 1}test winFCmd-1.33 {TclpRenameFile: After removing dst dir, MoveFile fails} \ {pcOnly exdev} { file mkdir d:/td1 testchmod 000 d:/td1 file mkdir c:/tf1 set msg [list [catch {testfile mv c:/tf1 d:/td1} msg] $msg] set msg "$msg [file writable d:/td1]" file delete d:/td1 file delete -force c:/tf1 set msg} {1 EXDEV 0}test winFCmd-1.34 {TclpRenameFile: src is dir, dst is not} {pcOnly} { file mkdir td1 createfile tf1 list [catch {testfile mv td1 tf1} msg] $msg} {1 ENOTDIR}test winFCmd-1.35 {TclpRenameFile: src is not dir, dst is} {pcOnly} { file mkdir td1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -