sl@0
|
1 |
# The tests in this file cover the procedures in tclCmdMZ.c.
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1991-1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1994 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id: cmdMZ.test,v 1.13.2.3 2004/02/25 23:38:16 dgp Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest 2.1
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
# Tcl_PwdObjCmd
|
sl@0
|
22 |
|
sl@0
|
23 |
test cmdMZ-1.1 {Tcl_PwdObjCmd} {
|
sl@0
|
24 |
list [catch {pwd a} msg] $msg
|
sl@0
|
25 |
} {1 {wrong # args: should be "pwd"}}
|
sl@0
|
26 |
test cmdMZ-1.2 {Tcl_PwdObjCmd: simple pwd} {
|
sl@0
|
27 |
catch pwd
|
sl@0
|
28 |
} 0
|
sl@0
|
29 |
test cmdMZ-1.3 {Tcl_PwdObjCmd: simple pwd} {
|
sl@0
|
30 |
expr [string length pwd]>0
|
sl@0
|
31 |
} 1
|
sl@0
|
32 |
test cmdMZ-1.4 {Tcl_PwdObjCmd: failure} {unixOnly nonPortable} {
|
sl@0
|
33 |
# This test fails on various unix platforms (eg Linux) where
|
sl@0
|
34 |
# permissions caching causes this to fail. The caching is strictly
|
sl@0
|
35 |
# incorrect, but we have no control over that.
|
sl@0
|
36 |
set foodir [file join [temporaryDirectory] foo]
|
sl@0
|
37 |
file delete -force $foodir
|
sl@0
|
38 |
file mkdir $foodir
|
sl@0
|
39 |
set cwd [pwd]
|
sl@0
|
40 |
cd $foodir
|
sl@0
|
41 |
file attr . -permissions 000
|
sl@0
|
42 |
set result [list [catch {pwd} msg] $msg]
|
sl@0
|
43 |
cd $cwd
|
sl@0
|
44 |
file delete -force $foodir
|
sl@0
|
45 |
set result
|
sl@0
|
46 |
} {1 {error getting working directory name: permission denied}}
|
sl@0
|
47 |
|
sl@0
|
48 |
# The tests for Tcl_RegexpObjCmd, Tcl_RegsubObjCmd are in regexp.test
|
sl@0
|
49 |
|
sl@0
|
50 |
# Tcl_RenameObjCmd
|
sl@0
|
51 |
|
sl@0
|
52 |
test cmdMZ-2.1 {Tcl_RenameObjCmd: error conditions} {
|
sl@0
|
53 |
list [catch {rename r1} msg] $msg $errorCode
|
sl@0
|
54 |
} {1 {wrong # args: should be "rename oldName newName"} NONE}
|
sl@0
|
55 |
test cmdMZ-2.2 {Tcl_RenameObjCmd: error conditions} {
|
sl@0
|
56 |
list [catch {rename r1 r2 r3} msg] $msg $errorCode
|
sl@0
|
57 |
} {1 {wrong # args: should be "rename oldName newName"} NONE}
|
sl@0
|
58 |
test cmdMZ-2.3 {Tcl_RenameObjCmd: success} {
|
sl@0
|
59 |
catch {rename r2 {}}
|
sl@0
|
60 |
proc r1 {} {return "r1"}
|
sl@0
|
61 |
rename r1 r2
|
sl@0
|
62 |
r2
|
sl@0
|
63 |
} {r1}
|
sl@0
|
64 |
test cmdMZ-2.4 {Tcl_RenameObjCmd: success} {
|
sl@0
|
65 |
proc r1 {} {return "r1"}
|
sl@0
|
66 |
rename r1 {}
|
sl@0
|
67 |
list [catch {r1} msg] $msg
|
sl@0
|
68 |
} {1 {invalid command name "r1"}}
|
sl@0
|
69 |
|
sl@0
|
70 |
# The tests for Tcl_ReturnObjCmd are in proc-old.test
|
sl@0
|
71 |
# The tests for Tcl_ScanObjCmd are in scan.test
|
sl@0
|
72 |
|
sl@0
|
73 |
# Tcl_SourceObjCmd
|
sl@0
|
74 |
|
sl@0
|
75 |
test cmdMZ-3.1 {Tcl_SourceObjCmd: error conditions} {macOnly} {
|
sl@0
|
76 |
list [catch {source} msg] $msg
|
sl@0
|
77 |
} {1 {wrong # args: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
|
sl@0
|
78 |
test cmdMZ-3.2 {Tcl_SourceObjCmd: error conditions} {macOnly} {
|
sl@0
|
79 |
list [catch {source a b} msg] $msg
|
sl@0
|
80 |
} {1 {bad argument: should be "source fileName" or "source -rsrc name ?fileName?" or "source -rsrcid id ?fileName?"}}
|
sl@0
|
81 |
test cmdMZ-3.3 {Tcl_SourceObjCmd: error conditions} {unixOrPc} {
|
sl@0
|
82 |
list [catch {source} msg] $msg
|
sl@0
|
83 |
} {1 {wrong # args: should be "source fileName"}}
|
sl@0
|
84 |
test cmdMZ-3.4 {Tcl_SourceObjCmd: error conditions} {unixOrPc} {
|
sl@0
|
85 |
list [catch {source a b} msg] $msg
|
sl@0
|
86 |
} {1 {wrong # args: should be "source fileName"}}
|
sl@0
|
87 |
|
sl@0
|
88 |
proc ListGlobMatch {expected actual} {
|
sl@0
|
89 |
if {[llength $expected] != [llength $actual]} {
|
sl@0
|
90 |
return 0
|
sl@0
|
91 |
}
|
sl@0
|
92 |
foreach e $expected a $actual {
|
sl@0
|
93 |
if {![string match $e $a]} {
|
sl@0
|
94 |
return 0
|
sl@0
|
95 |
}
|
sl@0
|
96 |
}
|
sl@0
|
97 |
return 1
|
sl@0
|
98 |
}
|
sl@0
|
99 |
customMatch listGlob ListGlobMatch
|
sl@0
|
100 |
|
sl@0
|
101 |
test cmdMZ-3.5 {Tcl_SourceObjCmd: error in script} -setup {
|
sl@0
|
102 |
set file [makeFile {
|
sl@0
|
103 |
set x 146
|
sl@0
|
104 |
error "error in sourced file"
|
sl@0
|
105 |
set y $x
|
sl@0
|
106 |
} source.file]
|
sl@0
|
107 |
} -body {
|
sl@0
|
108 |
list [catch {source $file} msg] $msg $errorInfo
|
sl@0
|
109 |
} -cleanup {
|
sl@0
|
110 |
removeFile source.file
|
sl@0
|
111 |
} -match listGlob -result {1 {error in sourced file} {error in sourced file
|
sl@0
|
112 |
while executing
|
sl@0
|
113 |
"error "error in sourced file""
|
sl@0
|
114 |
(file "*" line 3)
|
sl@0
|
115 |
invoked from within
|
sl@0
|
116 |
"source $file"}}
|
sl@0
|
117 |
test cmdMZ-3.6 {Tcl_SourceObjCmd: simple script} {
|
sl@0
|
118 |
set file [makeFile {list result} source.file]
|
sl@0
|
119 |
set result [source $file]
|
sl@0
|
120 |
removeFile source.file
|
sl@0
|
121 |
set result
|
sl@0
|
122 |
} result
|
sl@0
|
123 |
|
sl@0
|
124 |
# Tcl_SplitObjCmd
|
sl@0
|
125 |
|
sl@0
|
126 |
test cmdMZ-4.1 {Tcl_SplitObjCmd: split errors} {
|
sl@0
|
127 |
list [catch split msg] $msg $errorCode
|
sl@0
|
128 |
} {1 {wrong # args: should be "split string ?splitChars?"} NONE}
|
sl@0
|
129 |
test cmdMZ-4.2 {Tcl_SplitObjCmd: split errors} {
|
sl@0
|
130 |
list [catch {split a b c} msg] $msg $errorCode
|
sl@0
|
131 |
} {1 {wrong # args: should be "split string ?splitChars?"} NONE}
|
sl@0
|
132 |
test cmdMZ-4.3 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
133 |
split "a\n b\t\r c\n "
|
sl@0
|
134 |
} {a {} b {} {} c {} {}}
|
sl@0
|
135 |
test cmdMZ-4.4 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
136 |
split "word 1xyzword 2zword 3" xyz
|
sl@0
|
137 |
} {{word 1} {} {} {word 2} {word 3}}
|
sl@0
|
138 |
test cmdMZ-4.5 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
139 |
split "12345" {}
|
sl@0
|
140 |
} {1 2 3 4 5}
|
sl@0
|
141 |
test cmdMZ-4.6 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
142 |
split "a\}b\[c\{\]\$"
|
sl@0
|
143 |
} "a\\}b\\\[c\\{\\\]\\\$"
|
sl@0
|
144 |
test cmdMZ-4.7 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
145 |
split {} {}
|
sl@0
|
146 |
} {}
|
sl@0
|
147 |
test cmdMZ-4.8 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
148 |
split {}
|
sl@0
|
149 |
} {}
|
sl@0
|
150 |
test cmdMZ-4.9 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
151 |
split { }
|
sl@0
|
152 |
} {{} {} {} {}}
|
sl@0
|
153 |
test cmdMZ-4.10 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
154 |
proc foo {} {
|
sl@0
|
155 |
set x {}
|
sl@0
|
156 |
foreach f [split {]\n} {}] {
|
sl@0
|
157 |
append x $f
|
sl@0
|
158 |
}
|
sl@0
|
159 |
return $x
|
sl@0
|
160 |
}
|
sl@0
|
161 |
foo
|
sl@0
|
162 |
} {]\n}
|
sl@0
|
163 |
test cmdMZ-4.11 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
164 |
proc foo {} {
|
sl@0
|
165 |
set x ab\000c
|
sl@0
|
166 |
set y [split $x {}]
|
sl@0
|
167 |
return $y
|
sl@0
|
168 |
}
|
sl@0
|
169 |
foo
|
sl@0
|
170 |
} "a b \000 c"
|
sl@0
|
171 |
test cmdMZ-4.12 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
172 |
split "a0ab1b2bbb3\000c4" ab\000c
|
sl@0
|
173 |
} {{} 0 {} 1 2 {} {} 3 {} 4}
|
sl@0
|
174 |
test cmdMZ-4.13 {Tcl_SplitObjCmd: basic split commands} {
|
sl@0
|
175 |
# if not UTF-8 aware, result is "a {} {} b qw\xe5 {} N wq"
|
sl@0
|
176 |
split "a\u4e4eb qw\u5e4e\x4e wq" " \u4e4e"
|
sl@0
|
177 |
} "a b qw\u5e4eN wq"
|
sl@0
|
178 |
|
sl@0
|
179 |
# The tests for Tcl_StringObjCmd are in string.test
|
sl@0
|
180 |
# The tests for Tcl_SubstObjCmd are in subst.test
|
sl@0
|
181 |
# The tests for Tcl_SwitchObjCmd are in switch.test
|
sl@0
|
182 |
|
sl@0
|
183 |
test cmdMZ-5.1 {Tcl_TimeObjCmd: basic format of command} {
|
sl@0
|
184 |
list [catch {time} msg] $msg
|
sl@0
|
185 |
} {1 {wrong # args: should be "time command ?count?"}}
|
sl@0
|
186 |
test cmdMZ-5.2 {Tcl_TimeObjCmd: basic format of command} {
|
sl@0
|
187 |
list [catch {time a b c} msg] $msg
|
sl@0
|
188 |
} {1 {wrong # args: should be "time command ?count?"}}
|
sl@0
|
189 |
test cmdMZ-5.3 {Tcl_TimeObjCmd: basic format of command} {
|
sl@0
|
190 |
list [catch {time a b} msg] $msg
|
sl@0
|
191 |
} {1 {expected integer but got "b"}}
|
sl@0
|
192 |
test cmdMZ-5.4 {Tcl_TimeObjCmd: nothing happens with negative iteration counts} {
|
sl@0
|
193 |
time bogusCmd -12456
|
sl@0
|
194 |
} {0 microseconds per iteration}
|
sl@0
|
195 |
test cmdMZ-5.5 {Tcl_TimeObjCmd: result format} {
|
sl@0
|
196 |
regexp {^\d+ microseconds per iteration} [time {format 1}]
|
sl@0
|
197 |
} 1
|
sl@0
|
198 |
test cmdMZ-5.6 {Tcl_TimeObjCmd: slower commands take longer} {
|
sl@0
|
199 |
expr {[lindex [time {after 2}] 0] < [lindex [time {after 1000}] 0]}
|
sl@0
|
200 |
} 1
|
sl@0
|
201 |
test cmdMZ-5.7 {Tcl_TimeObjCmd: errors generate right trace} {
|
sl@0
|
202 |
list [catch {time {error foo}} msg] $msg $::errorInfo
|
sl@0
|
203 |
} {1 foo {foo
|
sl@0
|
204 |
while executing
|
sl@0
|
205 |
"error foo"
|
sl@0
|
206 |
invoked from within
|
sl@0
|
207 |
"time {error foo}"}}
|
sl@0
|
208 |
|
sl@0
|
209 |
# The tests for Tcl_TraceObjCmd and TraceVarProc are in trace.test
|
sl@0
|
210 |
# The tests for Tcl_WhileObjCmd are in while.test
|
sl@0
|
211 |
|
sl@0
|
212 |
# cleanup
|
sl@0
|
213 |
::tcltest::cleanupTests
|
sl@0
|
214 |
return
|