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