📄 cmdah.test
字号:
# The file tests the tclCmdAH.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-1998 by 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: cmdAH.test,v 1.30 2003/01/09 10:38:32 vincentdarley Exp $if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 namespace import -force ::tcltest::*}tcltest::testConstraint testchmod [string equal testchmod [info commands testchmod]]global envset cmdAHwd [pwd]catch {set platform [testgetplatform]}test cmdAH-0.1 {Tcl_BreakObjCmd, errors} { list [catch {break foo} msg] $msg} {1 {wrong # args: should be "break"}}test cmdAH-0.2 {Tcl_BreakObjCmd, success} { list [catch {break} msg] $msg} {3 {}}# Tcl_CaseObjCmd is tested in case.testtest cmdAH-1.1 {Tcl_CatchObjCmd, errors} { list [catch {catch} msg] $msg} {1 {wrong # args: should be "catch command ?varName?"}}test cmdAH-1.2 {Tcl_CatchObjCmd, errors} { list [catch {catch foo bar baz} msg] $msg} {1 {wrong # args: should be "catch command ?varName?"}}test cmdAH-2.1 {Tcl_CdObjCmd} { list [catch {cd foo bar} msg] $msg} {1 {wrong # args: should be "cd ?dirName?"}}set foodir [file join [temporaryDirectory] foo]test cmdAH-2.2 {Tcl_CdObjCmd} { file delete -force $foodir file mkdir $foodir cd $foodir set result [file tail [pwd]] cd .. file delete $foodir set result} footest cmdAH-2.3 {Tcl_CdObjCmd} { global env set oldpwd [pwd] set temp $env(HOME) set env(HOME) $oldpwd file delete -force $foodir file mkdir $foodir cd $foodir cd ~ set result [string equal [pwd] $oldpwd] file delete $foodir set env(HOME) $temp set result} 1test cmdAH-2.4 {Tcl_CdObjCmd} { global env set oldpwd [pwd] set temp $env(HOME) set env(HOME) $oldpwd file delete -force $foodir file mkdir $foodir cd $foodir cd set result [string equal [pwd] $oldpwd] file delete $foodir set env(HOME) $temp set result} 1test cmdAH-2.5 {Tcl_CdObjCmd} { list [catch {cd ~~} msg] $msg} {1 {user "~" doesn't exist}}test cmdAH-2.6 {Tcl_CdObjCmd} { list [catch {cd _foobar} msg] $msg} {1 {couldn't change working directory to "_foobar": no such file or directory}}test cmdAH-2.7 {Tcl_ConcatObjCmd} { concat} {}test cmdAH-2.8 {Tcl_ConcatObjCmd} { concat a} atest cmdAH-2.9 {Tcl_ConcatObjCmd} { concat a {b c}} {a b c}test cmdAH-3.1 {Tcl_ContinueObjCmd, errors} { list [catch {continue foo} msg] $msg} {1 {wrong # args: should be "continue"}}test cmdAH-3.2 {Tcl_ContinueObjCmd, success} { list [catch {continue} msg] $msg} {4 {}}test cmdAH-4.1 {Tcl_EncodingObjCmd} { list [catch {encoding} msg] $msg} {1 {wrong # args: should be "encoding option ?arg ...?"}}test cmdAH-4.2 {Tcl_EncodingObjCmd} { list [catch {encoding foo} msg] $msg} {1 {bad option "foo": must be convertfrom, convertto, names, or system}}test cmdAH-4.3 {Tcl_EncodingObjCmd} { list [catch {encoding convertto} msg] $msg} {1 {wrong # args: should be "encoding convertto ?encoding? data"}}test cmdAH-4.4 {Tcl_EncodingObjCmd} { list [catch {encoding convertto foo bar} msg] $msg} {1 {unknown encoding "foo"}}test cmdAH-4.5 {Tcl_EncodingObjCmd} { set system [encoding system] encoding system jis0208 set x [encoding convertto \u4e4e] encoding system $system set x} 8Ctest cmdAH-4.6 {Tcl_EncodingObjCmd} { set system [encoding system] encoding system identity set x [encoding convertto jis0208 \u4e4e] encoding system $system set x} 8Ctest cmdAH-4.7 {Tcl_EncodingObjCmd} { list [catch {encoding convertfrom} msg] $msg} {1 {wrong # args: should be "encoding convertfrom ?encoding? data"}}test cmdAH-4.8 {Tcl_EncodingObjCmd} { list [catch {encoding convertfrom foo bar} msg] $msg} {1 {unknown encoding "foo"}}test cmdAH-4.9 {Tcl_EncodingObjCmd} { set system [encoding system] encoding system jis0208 set x [encoding convertfrom 8C] encoding system $system set x} \u4e4etest cmdAH-4.10 {Tcl_EncodingObjCmd} { set system [encoding system] encoding system identity set x [encoding convertfrom jis0208 8C] encoding system $system set x} \u4e4etest cmdAH-4.11 {Tcl_EncodingObjCmd} { list [catch {encoding names foo} msg] $msg} {1 {wrong # args: should be "encoding names"}}test cmdAH-4.12 {Tcl_EncodingObjCmd} { list [catch {encoding system foo bar} msg] $msg} {1 {wrong # args: should be "encoding system ?encoding?"}}test cmdAH-4.13 {Tcl_EncodingObjCmd} { set system [encoding system] encoding system identity set x [encoding system] encoding system $system set x} identitytest cmdAH-5.1 {Tcl_FileObjCmd} { list [catch file msg] $msg} {1 {wrong # args: should be "file option ?arg ...?"}}test cmdAH-5.2 {Tcl_FileObjCmd} { list [catch {file x} msg] $msg} {1 {bad option "x": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}test cmdAH-5.3 {Tcl_FileObjCmd} { list [catch {file exists} msg] $msg} {1 {wrong # args: should be "file exists name"}}test cmdAH-5.4 {Tcl_FileObjCmd} { list [catch {file exists ""} msg] $msg} {0 0}#volumetest cmdAH-6.1 {Tcl_FileObjCmd: volumes} { list [catch {file volumes x} msg] $msg } {1 {wrong # args: should be "file volumes"}}test cmdAH-6.2 {Tcl_FileObjCmd: volumes} { set volumeList [file volumes] if { [llength $volumeList] == 0 } { set result 0 } else { set result 1 } } {1}test cmdAH-6.3 {Tcl_FileObjCmd: volumes} {macOrUnix} { set volumeList [file volumes] catch [list glob -nocomplain [lindex $volumeList 0]*]} {0}test cmdAH-6.4 {Tcl_FileObjCmd: volumes} {pcOnly} { set volumeList [string tolower [file volumes]] list [catch {lsearch $volumeList "c:/"} element] [expr $element != -1] [catch {list glob -nocomplain [lindex $volumeList $element]*}]} {0 1 0}test cmdAH-6.5 {cd} {unixOnly nonPortable} { set dir [pwd] cd / set res [pwd] cd $dir set res} {/}# attributestest cmdAH-7.1 {Tcl_FileObjCmd - file attrs} { set foofile [makeFile abcde foo.file] catch {file delete -force $foofile} close [open $foofile w] set res [catch {file attributes $foofile}] # We used [makeFile] so we undo with [removeFile] removeFile $foofile set res} {0}# dirnameif {[info commands testsetplatform] == {}} { puts "This application hasn't been compiled with the \"testsetplatform\"" puts "command, so I can't test Tcl_FileObjCmd etc."} else {test cmdAH-8.1 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname a b} msg] $msg} {1 {wrong # args: should be "file dirname name"}}test cmdAH-8.2 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname /a/b} /atest cmdAH-8.3 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname {}} .test cmdAH-8.4 {Tcl_FileObjCmd: dirname} { testsetplatform mac file dirname {}} :test cmdAH-8.5 {Tcl_FileObjCmd: dirname} { testsetplatform win file dirname {}} .test cmdAH-8.6 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname .def} .test cmdAH-8.7 {Tcl_FileObjCmd: dirname} { testsetplatform mac file dirname a} :test cmdAH-8.8 {Tcl_FileObjCmd: dirname} { testsetplatform win file dirname a} .test cmdAH-8.9 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname a/b/c.d} a/btest cmdAH-8.10 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname a/b.c/d} a/b.ctest cmdAH-8.11 {Tcl_FileObjCmd: dirname} { testsetplatform unix file dirname /.} /test cmdAH-8.12 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname /} msg] $msg} {0 /}test cmdAH-8.13 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname /foo} msg] $msg} {0 /}test cmdAH-8.14 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname //foo} msg] $msg} {0 /}test cmdAH-8.15 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname //foo/bar} msg] $msg} {0 /foo}test cmdAH-8.16 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname {//foo\/bar/baz}} msg] $msg} {0 {/foo\/bar}}test cmdAH-8.17 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname {//foo\/bar/baz/blat}} msg] $msg} {0 {/foo\/bar/baz}}test cmdAH-8.18 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname /foo//} msg] $msg} {0 /}test cmdAH-8.19 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname ./a} msg] $msg} {0 .}test cmdAH-8.20 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname a/.a} msg] $msg} {0 a}test cmdAH-8.21 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname c:foo} msg] $msg} {0 c:}test cmdAH-8.22 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname c:} msg] $msg} {0 c:}test cmdAH-8.23 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname c:/} msg] $msg} {0 c:/}test cmdAH-8.24 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname {c:\foo}} msg] $msg} {0 c:/}test cmdAH-8.25 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname {//foo/bar/baz}} msg] $msg} {0 //foo/bar}test cmdAH-8.26 {Tcl_FileObjCmd: dirname} { testsetplatform windows list [catch {file dirname {//foo/bar}} msg] $msg} {0 //foo/bar}test cmdAH-8.27 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname :} msg] $msg} {0 :}test cmdAH-8.28 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname :Foo} msg] $msg} {0 :}test cmdAH-8.29 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname Foo:} msg] $msg} {0 Foo:}test cmdAH-8.30 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname Foo:bar} msg] $msg} {0 Foo:}test cmdAH-8.31 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname :Foo:bar} msg] $msg} {0 :Foo}test cmdAH-8.32 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname ::} msg] $msg} {0 :}test cmdAH-8.33 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname :::} msg] $msg} {0 ::}test cmdAH-8.34 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname /foo/bar/} msg] $msg} {0 foo:}test cmdAH-8.35 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname /foo/bar} msg] $msg} {0 foo:}test cmdAH-8.36 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname /foo} msg] $msg} {0 foo:}test cmdAH-8.37 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname foo} msg] $msg} {0 :}test cmdAH-8.38 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname ~/foo} msg] $msg} {0 ~}test cmdAH-8.39 {Tcl_FileObjCmd: dirname} { testsetplatform unix list [catch {file dirname ~bar/foo} msg] $msg} {0 ~bar}test cmdAH-8.40 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname ~bar/foo} msg] $msg} {0 ~bar:}test cmdAH-8.41 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname ~/foo} msg] $msg} {0 ~:}test cmdAH-8.42 {Tcl_FileObjCmd: dirname} { testsetplatform mac list [catch {file dirname ~:baz} msg] $msg} {0 ~:}test cmdAH-8.43 {Tcl_FileObjCmd: dirname} { global env set temp $env(HOME) set env(HOME) "/home/test" testsetplatform unix set result [list [catch {file dirname ~} msg] $msg] set env(HOME) $temp set result} {0 /home}test cmdAH-8.44 {Tcl_FileObjCmd: dirname} { global env set temp $env(HOME) set env(HOME) "~" testsetplatform unix set result [list [catch {file dirname ~} msg] $msg] set env(HOME) $temp set result} {0 ~}test cmdAH-8.45 {Tcl_FileObjCmd: dirname} { global env set temp $env(HOME) set env(HOME) "/home/test" testsetplatform windows set result [list [catch {file dirname ~} msg] $msg] set env(HOME) $temp set result} {0 /home}test cmdAH-8.46 {Tcl_FileObjCmd: dirname} { global env set temp $env(HOME)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -