1 | # Commands covered: incr |
---|
2 | # |
---|
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. |
---|
6 | # |
---|
7 | # Copyright (c) 1996 Sun Microsystems, Inc. |
---|
8 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
9 | # |
---|
10 | # See the file "license.terms" for information on usage and redistribution |
---|
11 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
12 | # |
---|
13 | # RCS: @(#) $Id: incr.test,v 1.16 2007/12/13 15:26:06 dgp Exp $ |
---|
14 | |
---|
15 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
16 | package require tcltest 2 |
---|
17 | namespace import -force ::tcltest::* |
---|
18 | } |
---|
19 | |
---|
20 | # Basic "incr" operation. |
---|
21 | |
---|
22 | catch {unset x} |
---|
23 | catch {unset i} |
---|
24 | |
---|
25 | test incr-1.1 {TclCompileIncrCmd: missing variable name} { |
---|
26 | list [catch {incr} msg] $msg |
---|
27 | } {1 {wrong # args: should be "incr varName ?increment?"}} |
---|
28 | test incr-1.2 {TclCompileIncrCmd: simple variable name} { |
---|
29 | set i 10 |
---|
30 | list [incr i] $i |
---|
31 | } {11 11} |
---|
32 | test incr-1.3 {TclCompileIncrCmd: error compiling variable name} { |
---|
33 | set i 10 |
---|
34 | catch {incr "i"xxx} msg |
---|
35 | set msg |
---|
36 | } {extra characters after close-quote} |
---|
37 | test incr-1.4 {TclCompileIncrCmd: simple variable name in quotes} { |
---|
38 | set i 17 |
---|
39 | list [incr "i"] $i |
---|
40 | } {18 18} |
---|
41 | test incr-1.5 {TclCompileIncrCmd: simple variable name in braces} { |
---|
42 | catch {unset {a simple var}} |
---|
43 | set {a simple var} 27 |
---|
44 | list [incr {a simple var}] ${a simple var} |
---|
45 | } {28 28} |
---|
46 | test incr-1.6 {TclCompileIncrCmd: simple array variable name} { |
---|
47 | catch {unset a} |
---|
48 | set a(foo) 37 |
---|
49 | list [incr a(foo)] $a(foo) |
---|
50 | } {38 38} |
---|
51 | test incr-1.7 {TclCompileIncrCmd: non-simple (computed) variable name} { |
---|
52 | set x "i" |
---|
53 | set i 77 |
---|
54 | list [incr $x 2] $i |
---|
55 | } {79 79} |
---|
56 | test incr-1.8 {TclCompileIncrCmd: non-simple (computed) variable name} { |
---|
57 | set x "i" |
---|
58 | set i 77 |
---|
59 | list [incr [set x] +2] $i |
---|
60 | } {79 79} |
---|
61 | |
---|
62 | test incr-1.9 {TclCompileIncrCmd: increment given} { |
---|
63 | set i 10 |
---|
64 | list [incr i +07] $i |
---|
65 | } {17 17} |
---|
66 | test incr-1.10 {TclCompileIncrCmd: no increment given} { |
---|
67 | set i 10 |
---|
68 | list [incr i] $i |
---|
69 | } {11 11} |
---|
70 | |
---|
71 | test incr-1.11 {TclCompileIncrCmd: simple global name} { |
---|
72 | proc p {} { |
---|
73 | global i |
---|
74 | set i 54 |
---|
75 | incr i |
---|
76 | } |
---|
77 | p |
---|
78 | } {55} |
---|
79 | test incr-1.12 {TclCompileIncrCmd: simple local name} { |
---|
80 | proc p {} { |
---|
81 | set foo 100 |
---|
82 | incr foo |
---|
83 | } |
---|
84 | p |
---|
85 | } {101} |
---|
86 | test incr-1.13 {TclCompileIncrCmd: simple but new (unknown) local name} { |
---|
87 | proc p {} { |
---|
88 | incr bar |
---|
89 | } |
---|
90 | p |
---|
91 | } 1 |
---|
92 | test incr-1.14 {TclCompileIncrCmd: simple local name, >255 locals} { |
---|
93 | proc 260locals {} { |
---|
94 | # create 260 locals |
---|
95 | set a0 0; set a1 0; set a2 0; set a3 0; set a4 0 |
---|
96 | set a5 0; set a6 0; set a7 0; set a8 0; set a9 0 |
---|
97 | set b0 0; set b1 0; set b2 0; set b3 0; set b4 0 |
---|
98 | set b5 0; set b6 0; set b7 0; set b8 0; set b9 0 |
---|
99 | set c0 0; set c1 0; set c2 0; set c3 0; set c4 0 |
---|
100 | set c5 0; set c6 0; set c7 0; set c8 0; set c9 0 |
---|
101 | set d0 0; set d1 0; set d2 0; set d3 0; set d4 0 |
---|
102 | set d5 0; set d6 0; set d7 0; set d8 0; set d9 0 |
---|
103 | set e0 0; set e1 0; set e2 0; set e3 0; set e4 0 |
---|
104 | set e5 0; set e6 0; set e7 0; set e8 0; set e9 0 |
---|
105 | set f0 0; set f1 0; set f2 0; set f3 0; set f4 0 |
---|
106 | set f5 0; set f6 0; set f7 0; set f8 0; set f9 0 |
---|
107 | set g0 0; set g1 0; set g2 0; set g3 0; set g4 0 |
---|
108 | set g5 0; set g6 0; set g7 0; set g8 0; set g9 0 |
---|
109 | set h0 0; set h1 0; set h2 0; set h3 0; set h4 0 |
---|
110 | set h5 0; set h6 0; set h7 0; set h8 0; set h9 0 |
---|
111 | set i0 0; set i1 0; set i2 0; set i3 0; set i4 0 |
---|
112 | set i5 0; set i6 0; set i7 0; set i8 0; set i9 0 |
---|
113 | set j0 0; set j1 0; set j2 0; set j3 0; set j4 0 |
---|
114 | set j5 0; set j6 0; set j7 0; set j8 0; set j9 0 |
---|
115 | set k0 0; set k1 0; set k2 0; set k3 0; set k4 0 |
---|
116 | set k5 0; set k6 0; set k7 0; set k8 0; set k9 0 |
---|
117 | set l0 0; set l1 0; set l2 0; set l3 0; set l4 0 |
---|
118 | set l5 0; set l6 0; set l7 0; set l8 0; set l9 0 |
---|
119 | set m0 0; set m1 0; set m2 0; set m3 0; set m4 0 |
---|
120 | set m5 0; set m6 0; set m7 0; set m8 0; set m9 0 |
---|
121 | set n0 0; set n1 0; set n2 0; set n3 0; set n4 0 |
---|
122 | set n5 0; set n6 0; set n7 0; set n8 0; set n9 0 |
---|
123 | set o0 0; set o1 0; set o2 0; set o3 0; set o4 0 |
---|
124 | set o5 0; set o6 0; set o7 0; set o8 0; set o9 0 |
---|
125 | set p0 0; set p1 0; set p2 0; set p3 0; set p4 0 |
---|
126 | set p5 0; set p6 0; set p7 0; set p8 0; set p9 0 |
---|
127 | set q0 0; set q1 0; set q2 0; set q3 0; set q4 0 |
---|
128 | set q5 0; set q6 0; set q7 0; set q8 0; set q9 0 |
---|
129 | set r0 0; set r1 0; set r2 0; set r3 0; set r4 0 |
---|
130 | set r5 0; set r6 0; set r7 0; set r8 0; set r9 0 |
---|
131 | set s0 0; set s1 0; set s2 0; set s3 0; set s4 0 |
---|
132 | set s5 0; set s6 0; set s7 0; set s8 0; set s9 0 |
---|
133 | set t0 0; set t1 0; set t2 0; set t3 0; set t4 0 |
---|
134 | set t5 0; set t6 0; set t7 0; set t8 0; set t9 0 |
---|
135 | set u0 0; set u1 0; set u2 0; set u3 0; set u4 0 |
---|
136 | set u5 0; set u6 0; set u7 0; set u8 0; set u9 0 |
---|
137 | set v0 0; set v1 0; set v2 0; set v3 0; set v4 0 |
---|
138 | set v5 0; set v6 0; set v7 0; set v8 0; set v9 0 |
---|
139 | set w0 0; set w1 0; set w2 0; set w3 0; set w4 0 |
---|
140 | set w5 0; set w6 0; set w7 0; set w8 0; set w9 0 |
---|
141 | set x0 0; set x1 0; set x2 0; set x3 0; set x4 0 |
---|
142 | set x5 0; set x6 0; set x7 0; set x8 0; set x9 0 |
---|
143 | set y0 0; set y1 0; set y2 0; set y3 0; set y4 0 |
---|
144 | set y5 0; set y6 0; set y7 0; set y8 0; set y9 0 |
---|
145 | set z0 0; set z1 0; set z2 0; set z3 0; set z4 0 |
---|
146 | set z5 0; set z6 0; set z7 0; set z8 0; set z9 0 |
---|
147 | # now increment the last one (local var index > 255) |
---|
148 | incr z9 |
---|
149 | } |
---|
150 | 260locals |
---|
151 | } {1} |
---|
152 | test incr-1.15 {TclCompileIncrCmd: variable is array} { |
---|
153 | catch {unset a} |
---|
154 | set a(foo) 27 |
---|
155 | set x [incr a(foo) 11] |
---|
156 | catch {unset a} |
---|
157 | set x |
---|
158 | } 38 |
---|
159 | test incr-1.16 {TclCompileIncrCmd: variable is array, elem substitutions} { |
---|
160 | catch {unset a} |
---|
161 | set i 5 |
---|
162 | set a(foo5) 27 |
---|
163 | set x [incr a(foo$i) 11] |
---|
164 | catch {unset a} |
---|
165 | set x |
---|
166 | } 38 |
---|
167 | |
---|
168 | test incr-1.17 {TclCompileIncrCmd: increment given, simple int} { |
---|
169 | set i 5 |
---|
170 | incr i 123 |
---|
171 | } 128 |
---|
172 | test incr-1.18 {TclCompileIncrCmd: increment given, simple int} { |
---|
173 | set i 5 |
---|
174 | incr i -100 |
---|
175 | } -95 |
---|
176 | test incr-1.19 {TclCompileIncrCmd: increment given, but erroneous} -body { |
---|
177 | set i 5 |
---|
178 | catch {incr i [set]} msg |
---|
179 | set ::errorInfo |
---|
180 | } -match glob -result {wrong # args: should be "set varName ?newValue?" |
---|
181 | while *ing |
---|
182 | "set"*} |
---|
183 | test incr-1.20 {TclCompileIncrCmd: increment given, in quotes} { |
---|
184 | set i 25 |
---|
185 | incr i "-100" |
---|
186 | } -75 |
---|
187 | test incr-1.21 {TclCompileIncrCmd: increment given, in braces} { |
---|
188 | set i 24 |
---|
189 | incr i {126} |
---|
190 | } 150 |
---|
191 | test incr-1.22 {TclCompileIncrCmd: increment given, large int} { |
---|
192 | set i 5 |
---|
193 | incr i 200000 |
---|
194 | } 200005 |
---|
195 | test incr-1.23 {TclCompileIncrCmd: increment given, formatted int != int} { |
---|
196 | set i 25 |
---|
197 | incr i 0o00012345 ;# an octal literal |
---|
198 | } 5374 |
---|
199 | test incr-1.24 {TclCompileIncrCmd: increment given, formatted int != int} { |
---|
200 | set i 25 |
---|
201 | catch {incr i 1a} msg |
---|
202 | set msg |
---|
203 | } {expected integer but got "1a"} |
---|
204 | |
---|
205 | test incr-1.25 {TclCompileIncrCmd: too many arguments} { |
---|
206 | set i 10 |
---|
207 | catch {incr i 10 20} msg |
---|
208 | set msg |
---|
209 | } {wrong # args: should be "incr varName ?increment?"} |
---|
210 | |
---|
211 | |
---|
212 | test incr-1.26 {TclCompileIncrCmd: runtime error, bad variable name} { |
---|
213 | unset -nocomplain {"foo} |
---|
214 | incr {"foo} |
---|
215 | } 1 |
---|
216 | test incr-1.27 {TclCompileIncrCmd: runtime error, bad variable name} -body { |
---|
217 | list [catch {incr [set]} msg] $msg $::errorInfo |
---|
218 | } -match glob -result {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" |
---|
219 | while *ing |
---|
220 | "set"*}} |
---|
221 | test incr-1.28 {TclCompileIncrCmd: runtime error, readonly variable} -body { |
---|
222 | proc readonly args {error "variable is read-only"} |
---|
223 | set x 123 |
---|
224 | trace var x w readonly |
---|
225 | list [catch {incr x 1} msg] $msg $::errorInfo |
---|
226 | } -match glob -result {1 {can't set "x": variable is read-only} {*variable is read-only |
---|
227 | while executing |
---|
228 | * |
---|
229 | "incr x 1"}} |
---|
230 | catch {unset x} |
---|
231 | test incr-1.29 {TclCompileIncrCmd: runtime error, bad variable value} { |
---|
232 | set x " - " |
---|
233 | list [catch {incr x 1} msg] $msg |
---|
234 | } {1 {expected integer but got " - "}} |
---|
235 | |
---|
236 | test incr-1.30 {TclCompileIncrCmd: array var, braced (no subs)} { |
---|
237 | catch {unset array} |
---|
238 | set array(\$foo) 4 |
---|
239 | incr {array($foo)} |
---|
240 | } 5 |
---|
241 | |
---|
242 | # Check "incr" and computed command names. |
---|
243 | |
---|
244 | test incr-2.0 {incr and computed command names} { |
---|
245 | set i 5 |
---|
246 | set z incr |
---|
247 | $z i -1 |
---|
248 | set i |
---|
249 | } 4 |
---|
250 | catch {unset x} |
---|
251 | catch {unset i} |
---|
252 | |
---|
253 | test incr-2.1 {incr command (not compiled): missing variable name} { |
---|
254 | set z incr |
---|
255 | list [catch {$z} msg] $msg |
---|
256 | } {1 {wrong # args: should be "incr varName ?increment?"}} |
---|
257 | test incr-2.2 {incr command (not compiled): simple variable name} { |
---|
258 | set z incr |
---|
259 | set i 10 |
---|
260 | list [$z i] $i |
---|
261 | } {11 11} |
---|
262 | test incr-2.3 {incr command (not compiled): error compiling variable name} { |
---|
263 | set z incr |
---|
264 | set i 10 |
---|
265 | catch {$z "i"xxx} msg |
---|
266 | set msg |
---|
267 | } {extra characters after close-quote} |
---|
268 | test incr-2.4 {incr command (not compiled): simple variable name in quotes} { |
---|
269 | set z incr |
---|
270 | set i 17 |
---|
271 | list [$z "i"] $i |
---|
272 | } {18 18} |
---|
273 | test incr-2.5 {incr command (not compiled): simple variable name in braces} { |
---|
274 | set z incr |
---|
275 | catch {unset {a simple var}} |
---|
276 | set {a simple var} 27 |
---|
277 | list [$z {a simple var}] ${a simple var} |
---|
278 | } {28 28} |
---|
279 | test incr-2.6 {incr command (not compiled): simple array variable name} { |
---|
280 | set z incr |
---|
281 | catch {unset a} |
---|
282 | set a(foo) 37 |
---|
283 | list [$z a(foo)] $a(foo) |
---|
284 | } {38 38} |
---|
285 | test incr-2.7 {incr command (not compiled): non-simple (computed) variable name} { |
---|
286 | set z incr |
---|
287 | set x "i" |
---|
288 | set i 77 |
---|
289 | list [$z $x 2] $i |
---|
290 | } {79 79} |
---|
291 | test incr-2.8 {incr command (not compiled): non-simple (computed) variable name} { |
---|
292 | set z incr |
---|
293 | set x "i" |
---|
294 | set i 77 |
---|
295 | list [$z [set x] +2] $i |
---|
296 | } {79 79} |
---|
297 | |
---|
298 | test incr-2.9 {incr command (not compiled): increment given} { |
---|
299 | set z incr |
---|
300 | set i 10 |
---|
301 | list [$z i +07] $i |
---|
302 | } {17 17} |
---|
303 | test incr-2.10 {incr command (not compiled): no increment given} { |
---|
304 | set z incr |
---|
305 | set i 10 |
---|
306 | list [$z i] $i |
---|
307 | } {11 11} |
---|
308 | |
---|
309 | test incr-2.11 {incr command (not compiled): simple global name} { |
---|
310 | proc p {} { |
---|
311 | set z incr |
---|
312 | global i |
---|
313 | set i 54 |
---|
314 | $z i |
---|
315 | } |
---|
316 | p |
---|
317 | } {55} |
---|
318 | test incr-2.12 {incr command (not compiled): simple local name} { |
---|
319 | proc p {} { |
---|
320 | set z incr |
---|
321 | set foo 100 |
---|
322 | $z foo |
---|
323 | } |
---|
324 | p |
---|
325 | } {101} |
---|
326 | test incr-2.13 {incr command (not compiled): simple but new (unknown) local name} { |
---|
327 | proc p {} { |
---|
328 | set z incr |
---|
329 | $z bar |
---|
330 | } |
---|
331 | p |
---|
332 | } 1 |
---|
333 | test incr-2.14 {incr command (not compiled): simple local name, >255 locals} { |
---|
334 | proc 260locals {} { |
---|
335 | set z incr |
---|
336 | # create 260 locals |
---|
337 | set a0 0; set a1 0; set a2 0; set a3 0; set a4 0 |
---|
338 | set a5 0; set a6 0; set a7 0; set a8 0; set a9 0 |
---|
339 | set b0 0; set b1 0; set b2 0; set b3 0; set b4 0 |
---|
340 | set b5 0; set b6 0; set b7 0; set b8 0; set b9 0 |
---|
341 | set c0 0; set c1 0; set c2 0; set c3 0; set c4 0 |
---|
342 | set c5 0; set c6 0; set c7 0; set c8 0; set c9 0 |
---|
343 | set d0 0; set d1 0; set d2 0; set d3 0; set d4 0 |
---|
344 | set d5 0; set d6 0; set d7 0; set d8 0; set d9 0 |
---|
345 | set e0 0; set e1 0; set e2 0; set e3 0; set e4 0 |
---|
346 | set e5 0; set e6 0; set e7 0; set e8 0; set e9 0 |
---|
347 | set f0 0; set f1 0; set f2 0; set f3 0; set f4 0 |
---|
348 | set f5 0; set f6 0; set f7 0; set f8 0; set f9 0 |
---|
349 | set g0 0; set g1 0; set g2 0; set g3 0; set g4 0 |
---|
350 | set g5 0; set g6 0; set g7 0; set g8 0; set g9 0 |
---|
351 | set h0 0; set h1 0; set h2 0; set h3 0; set h4 0 |
---|
352 | set h5 0; set h6 0; set h7 0; set h8 0; set h9 0 |
---|
353 | set i0 0; set i1 0; set i2 0; set i3 0; set i4 0 |
---|
354 | set i5 0; set i6 0; set i7 0; set i8 0; set i9 0 |
---|
355 | set j0 0; set j1 0; set j2 0; set j3 0; set j4 0 |
---|
356 | set j5 0; set j6 0; set j7 0; set j8 0; set j9 0 |
---|
357 | set k0 0; set k1 0; set k2 0; set k3 0; set k4 0 |
---|
358 | set k5 0; set k6 0; set k7 0; set k8 0; set k9 0 |
---|
359 | set l0 0; set l1 0; set l2 0; set l3 0; set l4 0 |
---|
360 | set l5 0; set l6 0; set l7 0; set l8 0; set l9 0 |
---|
361 | set m0 0; set m1 0; set m2 0; set m3 0; set m4 0 |
---|
362 | set m5 0; set m6 0; set m7 0; set m8 0; set m9 0 |
---|
363 | set n0 0; set n1 0; set n2 0; set n3 0; set n4 0 |
---|
364 | set n5 0; set n6 0; set n7 0; set n8 0; set n9 0 |
---|
365 | set o0 0; set o1 0; set o2 0; set o3 0; set o4 0 |
---|
366 | set o5 0; set o6 0; set o7 0; set o8 0; set o9 0 |
---|
367 | set p0 0; set p1 0; set p2 0; set p3 0; set p4 0 |
---|
368 | set p5 0; set p6 0; set p7 0; set p8 0; set p9 0 |
---|
369 | set q0 0; set q1 0; set q2 0; set q3 0; set q4 0 |
---|
370 | set q5 0; set q6 0; set q7 0; set q8 0; set q9 0 |
---|
371 | set r0 0; set r1 0; set r2 0; set r3 0; set r4 0 |
---|
372 | set r5 0; set r6 0; set r7 0; set r8 0; set r9 0 |
---|
373 | set s0 0; set s1 0; set s2 0; set s3 0; set s4 0 |
---|
374 | set s5 0; set s6 0; set s7 0; set s8 0; set s9 0 |
---|
375 | set t0 0; set t1 0; set t2 0; set t3 0; set t4 0 |
---|
376 | set t5 0; set t6 0; set t7 0; set t8 0; set t9 0 |
---|
377 | set u0 0; set u1 0; set u2 0; set u3 0; set u4 0 |
---|
378 | set u5 0; set u6 0; set u7 0; set u8 0; set u9 0 |
---|
379 | set v0 0; set v1 0; set v2 0; set v3 0; set v4 0 |
---|
380 | set v5 0; set v6 0; set v7 0; set v8 0; set v9 0 |
---|
381 | set w0 0; set w1 0; set w2 0; set w3 0; set w4 0 |
---|
382 | set w5 0; set w6 0; set w7 0; set w8 0; set w9 0 |
---|
383 | set x0 0; set x1 0; set x2 0; set x3 0; set x4 0 |
---|
384 | set x5 0; set x6 0; set x7 0; set x8 0; set x9 0 |
---|
385 | set y0 0; set y1 0; set y2 0; set y3 0; set y4 0 |
---|
386 | set y5 0; set y6 0; set y7 0; set y8 0; set y9 0 |
---|
387 | set z0 0; set z1 0; set z2 0; set z3 0; set z4 0 |
---|
388 | set z5 0; set z6 0; set z7 0; set z8 0; set z9 0 |
---|
389 | # now increment the last one (local var index > 255) |
---|
390 | $z z9 |
---|
391 | } |
---|
392 | 260locals |
---|
393 | } {1} |
---|
394 | test incr-2.15 {incr command (not compiled): variable is array} { |
---|
395 | set z incr |
---|
396 | catch {unset a} |
---|
397 | set a(foo) 27 |
---|
398 | set x [$z a(foo) 11] |
---|
399 | catch {unset a} |
---|
400 | set x |
---|
401 | } 38 |
---|
402 | test incr-2.16 {incr command (not compiled): variable is array, elem substitutions} { |
---|
403 | set z incr |
---|
404 | catch {unset a} |
---|
405 | set i 5 |
---|
406 | set a(foo5) 27 |
---|
407 | set x [$z a(foo$i) 11] |
---|
408 | catch {unset a} |
---|
409 | set x |
---|
410 | } 38 |
---|
411 | |
---|
412 | test incr-2.17 {incr command (not compiled): increment given, simple int} { |
---|
413 | set z incr |
---|
414 | set i 5 |
---|
415 | $z i 123 |
---|
416 | } 128 |
---|
417 | test incr-2.18 {incr command (not compiled): increment given, simple int} { |
---|
418 | set z incr |
---|
419 | set i 5 |
---|
420 | $z i -100 |
---|
421 | } -95 |
---|
422 | test incr-2.19 {incr command (not compiled): increment given, but erroneous} -body { |
---|
423 | set z incr |
---|
424 | set i 5 |
---|
425 | catch {$z i [set]} msg |
---|
426 | set ::errorInfo |
---|
427 | } -match glob -result {wrong # args: should be "set varName ?newValue?" |
---|
428 | while *ing |
---|
429 | "set"*} |
---|
430 | test incr-2.20 {incr command (not compiled): increment given, in quotes} { |
---|
431 | set z incr |
---|
432 | set i 25 |
---|
433 | $z i "-100" |
---|
434 | } -75 |
---|
435 | test incr-2.21 {incr command (not compiled): increment given, in braces} { |
---|
436 | set z incr |
---|
437 | set i 24 |
---|
438 | $z i {126} |
---|
439 | } 150 |
---|
440 | test incr-2.22 {incr command (not compiled): increment given, large int} { |
---|
441 | set z incr |
---|
442 | set i 5 |
---|
443 | $z i 200000 |
---|
444 | } 200005 |
---|
445 | test incr-2.23 {incr command (not compiled): increment given, formatted int != int} { |
---|
446 | set z incr |
---|
447 | set i 25 |
---|
448 | $z i 0o00012345 ;# an octal literal |
---|
449 | } 5374 |
---|
450 | test incr-2.24 {incr command (not compiled): increment given, formatted int != int} { |
---|
451 | set z incr |
---|
452 | set i 25 |
---|
453 | catch {$z i 1a} msg |
---|
454 | set msg |
---|
455 | } {expected integer but got "1a"} |
---|
456 | |
---|
457 | test incr-2.25 {incr command (not compiled): too many arguments} { |
---|
458 | set z incr |
---|
459 | set i 10 |
---|
460 | catch {$z i 10 20} msg |
---|
461 | set msg |
---|
462 | } {wrong # args: should be "incr varName ?increment?"} |
---|
463 | |
---|
464 | |
---|
465 | test incr-2.26 {incr command (not compiled): runtime error, bad variable name} { |
---|
466 | unset -nocomplain {"foo} |
---|
467 | set z incr |
---|
468 | $z {"foo} |
---|
469 | } 1 |
---|
470 | test incr-2.27 {incr command (not compiled): runtime error, bad variable name} -body { |
---|
471 | set z incr |
---|
472 | list [catch {$z [set]} msg] $msg $::errorInfo |
---|
473 | } -match glob -result {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" |
---|
474 | while *ing |
---|
475 | "set"*}} |
---|
476 | test incr-2.28 {incr command (not compiled): runtime error, readonly variable} -body { |
---|
477 | set z incr |
---|
478 | proc readonly args {error "variable is read-only"} |
---|
479 | set x 123 |
---|
480 | trace var x w readonly |
---|
481 | list [catch {$z x 1} msg] $msg $::errorInfo |
---|
482 | } -match glob -result {1 {can't set "x": variable is read-only} {*variable is read-only |
---|
483 | while executing |
---|
484 | * |
---|
485 | "$z x 1"}} |
---|
486 | catch {unset x} |
---|
487 | test incr-2.29 {incr command (not compiled): runtime error, bad variable value} { |
---|
488 | set z incr |
---|
489 | set x " - " |
---|
490 | list [catch {$z x 1} msg] $msg |
---|
491 | } {1 {expected integer but got " - "}} |
---|
492 | test incr-2.30 {incr command (not compiled): bad increment} { |
---|
493 | set z incr |
---|
494 | set x 0 |
---|
495 | list [catch {$z x 1a} msg] $msg $::errorInfo |
---|
496 | } {1 {expected integer but got "1a"} {expected integer but got "1a" |
---|
497 | (reading increment) |
---|
498 | invoked from within |
---|
499 | "$z x 1a"}} |
---|
500 | test incr-2.31 {incr command (compiled): bad increment} { |
---|
501 | list [catch {incr x 1a} msg] $msg $::errorInfo |
---|
502 | } {1 {expected integer but got "1a"} {expected integer but got "1a" |
---|
503 | (reading increment) |
---|
504 | invoked from within |
---|
505 | "incr x 1a"}} |
---|
506 | |
---|
507 | test incr-3.1 {increment by wide amount: bytecode route} { |
---|
508 | set x 0 |
---|
509 | incr x 123123123123 |
---|
510 | } 123123123123 |
---|
511 | test incr-3.2 {increment by wide amount: command route} { |
---|
512 | set z incr |
---|
513 | set x 0 |
---|
514 | $z x 123123123123 |
---|
515 | } 123123123123 |
---|
516 | |
---|
517 | test incr-4.1 {increment non-existing array element [Bug 1445454]} -body { |
---|
518 | proc x {} {incr a(1)} |
---|
519 | x |
---|
520 | } -cleanup { |
---|
521 | rename x {} |
---|
522 | } -result 1 |
---|
523 | |
---|
524 | # cleanup |
---|
525 | ::tcltest::cleanupTests |
---|
526 | return |
---|