| 1 |
# This file contains tests for the tclExecute.c source file. Tests appear in |
| 2 |
# the same order as the C code that they test. The set of tests is currently |
| 3 |
# incomplete since it currently includes only new tests for code changed for |
| 4 |
# the addition of Tcl namespaces. Other execution-related tests appear in |
| 5 |
# several other test files including namespace.test, basic.test, eval.test, |
| 6 |
# for.test, etc. |
| 7 |
# |
| 8 |
# Sourcing this file into Tcl runs the tests and generates output for errors. |
| 9 |
# No output means no errors were found. |
| 10 |
# |
| 11 |
# Copyright (c) 1997 Sun Microsystems, Inc. |
| 12 |
# Copyright (c) 1998-1999 by Scriptics Corporation. |
| 13 |
# |
| 14 |
# See the file "license.terms" for information on usage and redistribution of |
| 15 |
# this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 |
|
| 17 |
if {"::tcltest" ni [namespace children]} { |
| 18 |
package require tcltest 2.5 |
| 19 |
namespace import -force ::tcltest::* |
| 20 |
} |
| 21 |
|
| 22 |
::tcltest::loadTestedCommands |
| 23 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 24 |
|
| 25 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 26 |
catch {rename foo ""} |
| 27 |
catch {unset x} |
| 28 |
catch {unset y} |
| 29 |
catch {unset msg} |
| 30 |
|
| 31 |
testConstraint testobj [expr { |
| 32 |
[llength [info commands testobj]] |
| 33 |
&& [llength [info commands testdoubleobj]] |
| 34 |
&& [llength [info commands teststringobj]] |
| 35 |
}] |
| 36 |
|
| 37 |
testConstraint longIs32bit [expr {int(0x80000000) < 0}] |
| 38 |
testConstraint testexprlongobj [llength [info commands testexprlongobj]] |
| 39 |
|
| 40 |
|
| 41 |
if {[namespace which -command testbumpinterpepoch] eq ""} { |
| 42 |
proc testbumpinterpepoch {} { rename ::set ::dummy; rename ::dummy ::set } |
| 43 |
} |
| 44 |
|
| 45 |
# Tests for the omnibus TclExecuteByteCode function: |
| 46 |
|
| 47 |
# INST_DONE not tested |
| 48 |
# INST_PUSH1 not tested |
| 49 |
# INST_PUSH4 not tested |
| 50 |
# INST_POP not tested |
| 51 |
# INST_DUP not tested |
| 52 |
# INST_INVOKE_STK4 not tested |
| 53 |
# INST_INVOKE_STK1 not tested |
| 54 |
# INST_EVAL_STK not tested |
| 55 |
# INST_EXPR_STK not tested |
| 56 |
|
| 57 |
# INST_LOAD_SCALAR1 |
| 58 |
test execute-1.1 {TclExecuteByteCode, INST_LOAD_SCALAR1, small opnd} { |
| 59 |
proc foo {} { |
| 60 |
set x 1 |
| 61 |
return $x |
| 62 |
} |
| 63 |
foo |
| 64 |
} 1 |
| 65 |
test execute-1.2 {TclExecuteByteCode, INST_LOAD_SCALAR1, large opnd} { |
| 66 |
# Bug: 2243 |
| 67 |
set body {} |
| 68 |
for {set i 0} {$i < 129} {incr i} { |
| 69 |
append body "set x$i x\n" |
| 70 |
} |
| 71 |
append body { |
| 72 |
set y 1 |
| 73 |
return $y |
| 74 |
} |
| 75 |
proc foo {} $body |
| 76 |
foo |
| 77 |
} 1 |
| 78 |
test execute-1.3 {TclExecuteByteCode, INST_LOAD_SCALAR1, error} { |
| 79 |
proc foo {} { |
| 80 |
set x 1 |
| 81 |
unset x |
| 82 |
return $x |
| 83 |
} |
| 84 |
list [catch {foo} msg] $msg |
| 85 |
} {1 {can't read "x": no such variable}} |
| 86 |
|
| 87 |
# INST_LOAD_SCALAR4 |
| 88 |
test execute-2.1 {TclExecuteByteCode, INST_LOAD_SCALAR4, simple case} { |
| 89 |
set body {} |
| 90 |
for {set i 0} {$i < 256} {incr i} { |
| 91 |
append body "set x$i x\n" |
| 92 |
} |
| 93 |
append body { |
| 94 |
set y 1 |
| 95 |
return $y |
| 96 |
} |
| 97 |
proc foo {} $body |
| 98 |
foo |
| 99 |
} 1 |
| 100 |
test execute-2.2 {TclExecuteByteCode, INST_LOAD_SCALAR4, error} { |
| 101 |
set body {} |
| 102 |
for {set i 0} {$i < 256} {incr i} { |
| 103 |
append body "set x$i x\n" |
| 104 |
} |
| 105 |
append body { |
| 106 |
set y 1 |
| 107 |
unset y |
| 108 |
return $y |
| 109 |
} |
| 110 |
proc foo {} $body |
| 111 |
list [catch {foo} msg] $msg |
| 112 |
} {1 {can't read "y": no such variable}} |
| 113 |
|
| 114 |
# INST_LOAD_SCALAR_STK not tested |
| 115 |
# INST_LOAD_ARRAY4 not tested |
| 116 |
# INST_LOAD_ARRAY1 not tested |
| 117 |
# INST_LOAD_ARRAY_STK not tested |
| 118 |
# INST_LOAD_STK not tested |
| 119 |
# INST_STORE_SCALAR4 not tested |
| 120 |
# INST_STORE_SCALAR1 not tested |
| 121 |
# INST_STORE_SCALAR_STK not tested |
| 122 |
# INST_STORE_ARRAY4 not tested |
| 123 |
# INST_STORE_ARRAY1 not tested |
| 124 |
# INST_STORE_ARRAY_STK not tested |
| 125 |
# INST_STORE_STK not tested |
| 126 |
# INST_INCR_SCALAR1 not tested |
| 127 |
# INST_INCR_SCALAR_STK not tested |
| 128 |
# INST_INCR_STK not tested |
| 129 |
# INST_INCR_ARRAY1 not tested |
| 130 |
# INST_INCR_ARRAY_STK not tested |
| 131 |
# INST_INCR_SCALAR1_IMM not tested |
| 132 |
# INST_INCR_SCALAR_STK_IMM not tested |
| 133 |
# INST_INCR_STK_IMM not tested |
| 134 |
# INST_INCR_ARRAY1_IMM not tested |
| 135 |
# INST_INCR_ARRAY_STK_IMM not tested |
| 136 |
# INST_JUMP1 not tested |
| 137 |
# INST_JUMP4 not tested |
| 138 |
# INST_JUMP_TRUE4 not tested |
| 139 |
# INST_JUMP_TRUE1 not tested |
| 140 |
# INST_JUMP_FALSE4 not tested |
| 141 |
# INST_JUMP_FALSE1 not tested |
| 142 |
# INST_LOR not tested |
| 143 |
# INST_LAND not tested |
| 144 |
# INST_EQ not tested |
| 145 |
# INST_NEQ not tested |
| 146 |
# INST_LT not tested |
| 147 |
# INST_GT not tested |
| 148 |
# INST_LE not tested |
| 149 |
# INST_GE not tested |
| 150 |
# INST_MOD not tested |
| 151 |
# INST_LSHIFT not tested |
| 152 |
# INST_RSHIFT not tested |
| 153 |
# INST_BITOR not tested |
| 154 |
# INST_BITXOR not tested |
| 155 |
# INST_BITAND not tested |
| 156 |
|
| 157 |
# INST_ADD is partially tested: |
| 158 |
test execute-3.1 {TclExecuteByteCode, INST_ADD, op1 is int} {testobj} { |
| 159 |
set x [testintobj set 0 1] |
| 160 |
expr {$x + 1} |
| 161 |
} 2 |
| 162 |
test execute-3.2 {TclExecuteByteCode, INST_ADD, op1 is double} {testobj} { |
| 163 |
set x [testdoubleobj set 0 1] |
| 164 |
expr {$x + 1} |
| 165 |
} 2.0 |
| 166 |
test execute-3.3 {TclExecuteByteCode, INST_ADD, op1 is double with string} {testobj} { |
| 167 |
set x [testintobj set 0 1] |
| 168 |
testobj convert 0 double |
| 169 |
expr {$x + 1} |
| 170 |
} 2 |
| 171 |
test execute-3.4 {TclExecuteByteCode, INST_ADD, op1 is string int} {testobj} { |
| 172 |
set x [teststringobj set 0 1] |
| 173 |
expr {$x + 1} |
| 174 |
} 2 |
| 175 |
test execute-3.5 {TclExecuteByteCode, INST_ADD, op1 is string double} {testobj} { |
| 176 |
set x [teststringobj set 0 1.0] |
| 177 |
expr {$x + 1} |
| 178 |
} 2.0 |
| 179 |
test execute-3.6 {TclExecuteByteCode, INST_ADD, op1 is non-numeric} {testobj} { |
| 180 |
set x [teststringobj set 0 foo] |
| 181 |
list [catch {expr {$x + 1}} msg] $msg |
| 182 |
} {1 {can't use non-numeric string as operand of "+"}} |
| 183 |
test execute-3.7 {TclExecuteByteCode, INST_ADD, op2 is int} {testobj} { |
| 184 |
set x [testintobj set 0 1] |
| 185 |
expr {1 + $x} |
| 186 |
} 2 |
| 187 |
test execute-3.8 {TclExecuteByteCode, INST_ADD, op2 is double} {testobj} { |
| 188 |
set x [testdoubleobj set 0 1] |
| 189 |
expr {1 + $x} |
| 190 |
} 2.0 |
| 191 |
test execute-3.9 {TclExecuteByteCode, INST_ADD, op2 is double with string} {testobj} { |
| 192 |
set x [testintobj set 0 1] |
| 193 |
testobj convert 0 double |
| 194 |
expr {1 + $x} |
| 195 |
} 2 |
| 196 |
test execute-3.10 {TclExecuteByteCode, INST_ADD, op2 is string int} {testobj} { |
| 197 |
set x [teststringobj set 0 1] |
| 198 |
expr {1 + $x} |
| 199 |
} 2 |
| 200 |
test execute-3.11 {TclExecuteByteCode, INST_ADD, op2 is string double} {testobj} { |
| 201 |
set x [teststringobj set 0 1.0] |
| 202 |
expr {1 + $x} |
| 203 |
} 2.0 |
| 204 |
test execute-3.12 {TclExecuteByteCode, INST_ADD, op2 is non-numeric} {testobj} { |
| 205 |
set x [teststringobj set 0 foo] |
| 206 |
list [catch {expr {1 + $x}} msg] $msg |
| 207 |
} {1 {can't use non-numeric string as operand of "+"}} |
| 208 |
|
| 209 |
# INST_SUB is partially tested: |
| 210 |
test execute-3.13 {TclExecuteByteCode, INST_SUB, op1 is int} {testobj} { |
| 211 |
set x [testintobj set 0 1] |
| 212 |
expr {$x - 1} |
| 213 |
} 0 |
| 214 |
test execute-3.14 {TclExecuteByteCode, INST_SUB, op1 is double} {testobj} { |
| 215 |
set x [testdoubleobj set 0 1] |
| 216 |
expr {$x - 1} |
| 217 |
} 0.0 |
| 218 |
test execute-3.15 {TclExecuteByteCode, INST_SUB, op1 is double with string} {testobj} { |
| 219 |
set x [testintobj set 0 1] |
| 220 |
testobj convert 0 double |
| 221 |
expr {$x - 1} |
| 222 |
} 0 |
| 223 |
test execute-3.16 {TclExecuteByteCode, INST_SUB, op1 is string int} {testobj} { |
| 224 |
set x [teststringobj set 0 1] |
| 225 |
expr {$x - 1} |
| 226 |
} 0 |
| 227 |
test execute-3.17 {TclExecuteByteCode, INST_SUB, op1 is string double} {testobj} { |
| 228 |
set x [teststringobj set 0 1.0] |
| 229 |
expr {$x - 1} |
| 230 |
} 0.0 |
| 231 |
test execute-3.18 {TclExecuteByteCode, INST_SUB, op1 is non-numeric} {testobj} { |
| 232 |
set x [teststringobj set 0 foo] |
| 233 |
list [catch {expr {$x - 1}} msg] $msg |
| 234 |
} {1 {can't use non-numeric string as operand of "-"}} |
| 235 |
test execute-3.19 {TclExecuteByteCode, INST_SUB, op2 is int} {testobj} { |
| 236 |
set x [testintobj set 0 1] |
| 237 |
expr {1 - $x} |
| 238 |
} 0 |
| 239 |
test execute-3.20 {TclExecuteByteCode, INST_SUB, op2 is double} {testobj} { |
| 240 |
set x [testdoubleobj set 0 1] |
| 241 |
expr {1 - $x} |
| 242 |
} 0.0 |
| 243 |
test execute-3.21 {TclExecuteByteCode, INST_SUB, op2 is double with string} {testobj} { |
| 244 |
set x [testintobj set 0 1] |
| 245 |
testobj convert 0 double |
| 246 |
expr {1 - $x} |
| 247 |
} 0 |
| 248 |
test execute-3.22 {TclExecuteByteCode, INST_SUB, op2 is string int} {testobj} { |
| 249 |
set x [teststringobj set 0 1] |
| 250 |
expr {1 - $x} |
| 251 |
} 0 |
| 252 |
test execute-3.23 {TclExecuteByteCode, INST_SUB, op2 is string double} {testobj} { |
| 253 |
set x [teststringobj set 0 1.0] |
| 254 |
expr {1 - $x} |
| 255 |
} 0.0 |
| 256 |
test execute-3.24 {TclExecuteByteCode, INST_SUB, op2 is non-numeric} {testobj} { |
| 257 |
set x [teststringobj set 0 foo] |
| 258 |
list [catch {expr {1 - $x}} msg] $msg |
| 259 |
} {1 {can't use non-numeric string as operand of "-"}} |
| 260 |
|
| 261 |
# INST_MULT is partially tested: |
| 262 |
test execute-3.25 {TclExecuteByteCode, INST_MULT, op1 is int} {testobj} { |
| 263 |
set x [testintobj set 1 1] |
| 264 |
expr {$x * 1} |
| 265 |
} 1 |
| 266 |
test execute-3.26 {TclExecuteByteCode, INST_MULT, op1 is double} {testobj} { |
| 267 |
set x [testdoubleobj set 1 2.0] |
| 268 |
expr {$x * 1} |
| 269 |
} 2.0 |
| 270 |
test execute-3.27 {TclExecuteByteCode, INST_MULT, op1 is double with string} {testobj} { |
| 271 |
set x [testintobj set 1 2] |
| 272 |
testobj convert 1 double |
| 273 |
expr {$x * 1} |
| 274 |
} 2 |
| 275 |
test execute-3.28 {TclExecuteByteCode, INST_MULT, op1 is string int} {testobj} { |
| 276 |
set x [teststringobj set 1 1] |
| 277 |
expr {$x * 1} |
| 278 |
} 1 |
| 279 |
test execute-3.29 {TclExecuteByteCode, INST_MULT, op1 is string double} {testobj} { |
| 280 |
set x [teststringobj set 1 1.0] |
| 281 |
expr {$x * 1} |
| 282 |
} 1.0 |
| 283 |
test execute-3.30 {TclExecuteByteCode, INST_MULT, op1 is non-numeric} {testobj} { |
| 284 |
set x [teststringobj set 1 foo] |
| 285 |
list [catch {expr {$x * 1}} msg] $msg |
| 286 |
} {1 {can't use non-numeric string as operand of "*"}} |
| 287 |
test execute-3.31 {TclExecuteByteCode, INST_MULT, op2 is int} {testobj} { |
| 288 |
set x [testintobj set 1 1] |
| 289 |
expr {1 * $x} |
| 290 |
} 1 |
| 291 |
test execute-3.32 {TclExecuteByteCode, INST_MULT, op2 is double} {testobj} { |
| 292 |
set x [testdoubleobj set 1 2.0] |
| 293 |
expr {1 * $x} |
| 294 |
} 2.0 |
| 295 |
test execute-3.33 {TclExecuteByteCode, INST_MULT, op2 is double with string} {testobj} { |
| 296 |
set x [testintobj set 1 2] |
| 297 |
testobj convert 1 double |
| 298 |
expr {1 * $x} |
| 299 |
} 2 |
| 300 |
test execute-3.34 {TclExecuteByteCode, INST_MULT, op2 is string int} {testobj} { |
| 301 |
set x [teststringobj set 1 1] |
| 302 |
expr {1 * $x} |
| 303 |
} 1 |
| 304 |
test execute-3.35 {TclExecuteByteCode, INST_MULT, op2 is string double} {testobj} { |
| 305 |
set x [teststringobj set 1 1.0] |
| 306 |
expr {1 * $x} |
| 307 |
} 1.0 |
| 308 |
test execute-3.36 {TclExecuteByteCode, INST_MULT, op2 is non-numeric} {testobj} { |
| 309 |
set x [teststringobj set 1 foo] |
| 310 |
list [catch {expr {1 * $x}} msg] $msg |
| 311 |
} {1 {can't use non-numeric string as operand of "*"}} |
| 312 |
|
| 313 |
# INST_DIV is partially tested: |
| 314 |
test execute-3.37 {TclExecuteByteCode, INST_DIV, op1 is int} {testobj} { |
| 315 |
set x [testintobj set 1 1] |
| 316 |
expr {$x / 1} |
| 317 |
} 1 |
| 318 |
test execute-3.38 {TclExecuteByteCode, INST_DIV, op1 is double} {testobj} { |
| 319 |
set x [testdoubleobj set 1 2.0] |
| 320 |
expr {$x / 1} |
| 321 |
} 2.0 |
| 322 |
test execute-3.39 {TclExecuteByteCode, INST_DIV, op1 is double with string} {testobj} { |
| 323 |
set x [testintobj set 1 2] |
| 324 |
testobj convert 1 double |
| 325 |
expr {$x / 1} |
| 326 |
} 2 |
| 327 |
test execute-3.40 {TclExecuteByteCode, INST_DIV, op1 is string int} {testobj} { |
| 328 |
set x [teststringobj set 1 1] |
| 329 |
expr {$x / 1} |
| 330 |
} 1 |
| 331 |
test execute-3.41 {TclExecuteByteCode, INST_DIV, op1 is string double} {testobj} { |
| 332 |
set x [teststringobj set 1 1.0] |
| 333 |
expr {$x / 1} |
| 334 |
} 1.0 |
| 335 |
test execute-3.42 {TclExecuteByteCode, INST_DIV, op1 is non-numeric} {testobj} { |
| 336 |
set x [teststringobj set 1 foo] |
| 337 |
list [catch {expr {$x / 1}} msg] $msg |
| 338 |
} {1 {can't use non-numeric string as operand of "/"}} |
| 339 |
test execute-3.43 {TclExecuteByteCode, INST_DIV, op2 is int} {testobj} { |
| 340 |
set x [testintobj set 1 1] |
| 341 |
expr {2 / $x} |
| 342 |
} 2 |
| 343 |
test execute-3.44 {TclExecuteByteCode, INST_DIV, op2 is double} {testobj} { |
| 344 |
set x [testdoubleobj set 1 1.0] |
| 345 |
expr {2 / $x} |
| 346 |
} 2.0 |
| 347 |
test execute-3.45 {TclExecuteByteCode, INST_DIV, op2 is double with string} {testobj} { |
| 348 |
set x [testintobj set 1 1] |
| 349 |
testobj convert 1 double |
| 350 |
expr {2 / $x} |
| 351 |
} 2 |
| 352 |
test execute-3.46 {TclExecuteByteCode, INST_DIV, op2 is string int} {testobj} { |
| 353 |
set x [teststringobj set 1 1] |
| 354 |
expr {2 / $x} |
| 355 |
} 2 |
| 356 |
test execute-3.47 {TclExecuteByteCode, INST_DIV, op2 is string double} {testobj} { |
| 357 |
set x [teststringobj set 1 1.0] |
| 358 |
expr {2 / $x} |
| 359 |
} 2.0 |
| 360 |
test execute-3.48 {TclExecuteByteCode, INST_DIV, op2 is non-numeric} {testobj} { |
| 361 |
set x [teststringobj set 1 foo] |
| 362 |
list [catch {expr {1 / $x}} msg] $msg |
| 363 |
} {1 {can't use non-numeric string as operand of "/"}} |
| 364 |
|
| 365 |
# INST_UPLUS is partially tested: |
| 366 |
test execute-3.49 {TclExecuteByteCode, INST_UPLUS, op is int} {testobj} { |
| 367 |
set x [testintobj set 1 1] |
| 368 |
expr {+ $x} |
| 369 |
} 1 |
| 370 |
test execute-3.50 {TclExecuteByteCode, INST_UPLUS, op is double} {testobj} { |
| 371 |
set x [testdoubleobj set 1 1.0] |
| 372 |
expr {+ $x} |
| 373 |
} 1.0 |
| 374 |
test execute-3.51 {TclExecuteByteCode, INST_UPLUS, op is double with string} {testobj} { |
| 375 |
set x [testintobj set 1 1] |
| 376 |
testobj convert 1 double |
| 377 |
expr {+ $x} |
| 378 |
} 1 |
| 379 |
test execute-3.52 {TclExecuteByteCode, INST_UPLUS, op is string int} {testobj} { |
| 380 |
set x [teststringobj set 1 1] |
| 381 |
expr {+ $x} |
| 382 |
} 1 |
| 383 |
test execute-3.53 {TclExecuteByteCode, INST_UPLUS, op is string double} {testobj} { |
| 384 |
set x [teststringobj set 1 1.0] |
| 385 |
expr {+ $x} |
| 386 |
} 1.0 |
| 387 |
test execute-3.54 {TclExecuteByteCode, INST_UPLUS, op is non-numeric} {testobj} { |
| 388 |
set x [teststringobj set 1 foo] |
| 389 |
list [catch {expr {+ $x}} msg] $msg |
| 390 |
} {1 {can't use non-numeric string as operand of "+"}} |
| 391 |
|
| 392 |
# INST_UMINUS is partially tested: |
| 393 |
test execute-3.55 {TclExecuteByteCode, INST_UMINUS, op is int} {testobj} { |
| 394 |
set x [testintobj set 1 1] |
| 395 |
expr {- $x} |
| 396 |
} -1 |
| 397 |
test execute-3.56 {TclExecuteByteCode, INST_UMINUS, op is double} {testobj} { |
| 398 |
set x [testdoubleobj set 1 1.0] |
| 399 |
expr {- $x} |
| 400 |
} -1.0 |
| 401 |
test execute-3.57 {TclExecuteByteCode, INST_UMINUS, op is double with string} {testobj} { |
| 402 |
set x [testintobj set 1 1] |
| 403 |
testobj convert 1 double |
| 404 |
expr {- $x} |
| 405 |
} -1 |
| 406 |
test execute-3.58 {TclExecuteByteCode, INST_UMINUS, op is string int} {testobj} { |
| 407 |
set x [teststringobj set 1 1] |
| 408 |
expr {- $x} |
| 409 |
} -1 |
| 410 |
test execute-3.59 {TclExecuteByteCode, INST_UMINUS, op is string double} {testobj} { |
| 411 |
set x [teststringobj set 1 1.0] |
| 412 |
expr {- $x} |
| 413 |
} -1.0 |
| 414 |
test execute-3.60 {TclExecuteByteCode, INST_UMINUS, op is non-numeric} {testobj} { |
| 415 |
set x [teststringobj set 1 foo] |
| 416 |
list [catch {expr {- $x}} msg] $msg |
| 417 |
} {1 {can't use non-numeric string as operand of "-"}} |
| 418 |
|
| 419 |
# INST_LNOT is partially tested: |
| 420 |
test execute-3.61 {TclExecuteByteCode, INST_LNOT, op is int} {testobj} { |
| 421 |
set x [testintobj set 1 2] |
| 422 |
expr {! $x} |
| 423 |
} 0 |
| 424 |
test execute-3.62 {TclExecuteByteCode, INST_LNOT, op is int} {testobj} { |
| 425 |
set x [testintobj set 1 0] |
| 426 |
expr {! $x} |
| 427 |
} 1 |
| 428 |
test execute-3.63 {TclExecuteByteCode, INST_LNOT, op is double} {testobj} { |
| 429 |
set x [testdoubleobj set 1 1.0] |
| 430 |
expr {! $x} |
| 431 |
} 0 |
| 432 |
test execute-3.64 {TclExecuteByteCode, INST_LNOT, op is double} {testobj} { |
| 433 |
set x [testdoubleobj set 1 0.0] |
| 434 |
expr {! $x} |
| 435 |
} 1 |
| 436 |
test execute-3.65 {TclExecuteByteCode, INST_LNOT, op is double with string} {testobj} { |
| 437 |
set x [testintobj set 1 1] |
| 438 |
testobj convert 1 double |
| 439 |
expr {! $x} |
| 440 |
} 0 |
| 441 |
test execute-3.66 {TclExecuteByteCode, INST_LNOT, op is double with string} {testobj} { |
| 442 |
set x [testintobj set 1 0] |
| 443 |
testobj convert 1 double |
| 444 |
expr {! $x} |
| 445 |
} 1 |
| 446 |
test execute-3.67 {TclExecuteByteCode, INST_LNOT, op is string int} {testobj} { |
| 447 |
set x [teststringobj set 1 1] |
| 448 |
expr {! $x} |
| 449 |
} 0 |
| 450 |
test execute-3.68 {TclExecuteByteCode, INST_LNOT, op is string int} {testobj} { |
| 451 |
set x [teststringobj set 1 0] |
| 452 |
expr {! $x} |
| 453 |
} 1 |
| 454 |
test execute-3.69 {TclExecuteByteCode, INST_LNOT, op is string double} {testobj} { |
| 455 |
set x [teststringobj set 1 1.0] |
| 456 |
expr {! $x} |
| 457 |
} 0 |
| 458 |
test execute-3.70 {TclExecuteByteCode, INST_LNOT, op is string double} {testobj} { |
| 459 |
set x [teststringobj set 1 0.0] |
| 460 |
expr {! $x} |
| 461 |
} 1 |
| 462 |
test execute-3.71 {TclExecuteByteCode, INST_LNOT, op is non-numeric} {testobj} { |
| 463 |
set x [teststringobj set 1 foo] |
| 464 |
list [catch {expr {! $x}} msg] $msg |
| 465 |
} {1 {can't use non-numeric string as operand of "!"}} |
| 466 |
|
| 467 |
# INST_BITNOT not tested |
| 468 |
# INST_CALL_BUILTIN_FUNC1 not tested |
| 469 |
# INST_CALL_FUNC1 not tested |
| 470 |
|
| 471 |
# INST_TRY_CVT_TO_NUMERIC is partially tested: |
| 472 |
test execute-3.72 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is int} {testobj} { |
| 473 |
set x [testintobj set 1 1] |
| 474 |
expr {$x} |
| 475 |
} 1 |
| 476 |
test execute-3.73 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is double} {testobj} { |
| 477 |
set x [testdoubleobj set 1 1.0] |
| 478 |
expr {$x} |
| 479 |
} 1.0 |
| 480 |
test execute-3.74 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is double with string} {testobj} { |
| 481 |
set x [testintobj set 1 1] |
| 482 |
testobj convert 1 double |
| 483 |
expr {$x} |
| 484 |
} 1 |
| 485 |
test execute-3.75 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is string int} {testobj} { |
| 486 |
set x [teststringobj set 1 1] |
| 487 |
expr {$x} |
| 488 |
} 1 |
| 489 |
test execute-3.76 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is string double} {testobj} { |
| 490 |
set x [teststringobj set 1 1.0] |
| 491 |
expr {$x} |
| 492 |
} 1.0 |
| 493 |
test execute-3.77 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is non-numeric} {testobj} { |
| 494 |
set x [teststringobj set 1 foo] |
| 495 |
expr {$x} |
| 496 |
} foo |
| 497 |
|
| 498 |
# INST_BREAK not tested |
| 499 |
# INST_CONTINUE not tested |
| 500 |
# INST_FOREACH_START4 not tested |
| 501 |
# INST_FOREACH_STEP4 not tested |
| 502 |
# INST_BEGIN_CATCH4 not tested |
| 503 |
# INST_END_CATCH not tested |
| 504 |
# INST_PUSH_RESULT not tested |
| 505 |
# INST_PUSH_RETURN_CODE not tested |
| 506 |
|
| 507 |
test execute-4.1 {Tcl_GetCommandFromObj, convert to tclCmdNameType} -setup { |
| 508 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 509 |
unset -nocomplain x |
| 510 |
unset -nocomplain y |
| 511 |
} -body { |
| 512 |
namespace eval test_ns_1 { |
| 513 |
namespace export cmd1 |
| 514 |
proc cmd1 {args} {return "cmd1: $args"} |
| 515 |
proc cmd2 {args} {return "cmd2: $args"} |
| 516 |
} |
| 517 |
namespace eval test_ns_1::test_ns_2 { |
| 518 |
namespace import ::test_ns_1::* |
| 519 |
} |
| 520 |
set x "test_ns_1::" |
| 521 |
set y "test_ns_2::" |
| 522 |
list [namespace which -command ${x}${y}cmd1] \ |
| 523 |
[catch {namespace which -command ${x}${y}cmd2} msg] $msg \ |
| 524 |
[catch {namespace which -command ${x}${y}:cmd2} msg] $msg |
| 525 |
} -result {::test_ns_1::test_ns_2::cmd1 0 {} 0 {}} |
| 526 |
test execute-4.2 {Tcl_GetCommandFromObj, check if cached tclCmdNameType is invalid} -setup { |
| 527 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 528 |
catch {rename foo ""} |
| 529 |
unset -nocomplain l |
| 530 |
} -body { |
| 531 |
proc foo {} { |
| 532 |
return "global foo" |
| 533 |
} |
| 534 |
namespace eval test_ns_1 { |
| 535 |
proc whichFoo {} { |
| 536 |
return [namespace which -command foo] |
| 537 |
} |
| 538 |
} |
| 539 |
set l "" |
| 540 |
lappend l [test_ns_1::whichFoo] |
| 541 |
namespace eval test_ns_1 { |
| 542 |
proc foo {} { |
| 543 |
return "namespace foo" |
| 544 |
} |
| 545 |
} |
| 546 |
lappend l [test_ns_1::whichFoo] |
| 547 |
} -result {::foo ::test_ns_1::foo} |
| 548 |
test execute-4.3 {Tcl_GetCommandFromObj, command never found} -setup { |
| 549 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 550 |
catch {rename foo ""} |
| 551 |
} -body { |
| 552 |
namespace eval test_ns_1 { |
| 553 |
proc foo {} { |
| 554 |
return "namespace foo" |
| 555 |
} |
| 556 |
} |
| 557 |
namespace eval test_ns_1 { |
| 558 |
proc foo {} { |
| 559 |
return "namespace foo" |
| 560 |
} |
| 561 |
} |
| 562 |
list [namespace eval test_ns_1 {namespace which -command foo}] \ |
| 563 |
[rename test_ns_1::foo ""] \ |
| 564 |
[catch {namespace eval test_ns_1 {namespace which -command foo}} msg] $msg |
| 565 |
} -result {::test_ns_1::foo {} 0 {}} |
| 566 |
|
| 567 |
test execute-5.1 {SetCmdNameFromAny, set cmd name to empty heap string if NULL} -setup { |
| 568 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 569 |
unset -nocomplain l |
| 570 |
} -body { |
| 571 |
proc {} {} {return {}} |
| 572 |
{} |
| 573 |
set l {} |
| 574 |
lindex {} 0 |
| 575 |
{} |
| 576 |
} -result {} |
| 577 |
|
| 578 |
test execute-6.1 {UpdateStringOfCmdName: called for duplicate of empty cmdName object} { |
| 579 |
proc {} {} {} |
| 580 |
proc { } {} {} |
| 581 |
proc p {} { |
| 582 |
set x {} |
| 583 |
$x |
| 584 |
append x { } |
| 585 |
$x |
| 586 |
} |
| 587 |
p |
| 588 |
} {} |
| 589 |
test execute-6.2 {Evaluate an expression in a variable; compile the first time, do not the second} { |
| 590 |
set w {3*5} |
| 591 |
proc a {obj} {expr $obj} |
| 592 |
set res "[a $w]:[a $w]" |
| 593 |
} {15:15} |
| 594 |
test execute-6.3 {Tcl_ExprObj: don't use cached script bytecode [Bug 1899164]} -setup { |
| 595 |
proc 0+0 {} {return SCRIPT} |
| 596 |
} -body { |
| 597 |
set e { 0+0 } |
| 598 |
if 1 $e |
| 599 |
if 1 {expr $e} |
| 600 |
} -cleanup { |
| 601 |
rename 0+0 {} |
| 602 |
} -result 0 |
| 603 |
test execute-6.4 {TclCompEvalObj: don't use cached expr bytecode [Bug 1899164]} -setup { |
| 604 |
proc 0+0 {} {return SCRIPT} |
| 605 |
} -body { |
| 606 |
set e { 0+0 } |
| 607 |
if 1 {expr $e} |
| 608 |
if 1 $e |
| 609 |
} -cleanup { |
| 610 |
rename 0+0 {} |
| 611 |
} -result SCRIPT |
| 612 |
test execute-6.5 {TclCompEvalObj: bytecode epoch validation} -body { |
| 613 |
set script { llength {} } |
| 614 |
set result {} |
| 615 |
lappend result [if 1 $script] |
| 616 |
set origName [namespace which llength] |
| 617 |
rename $origName llength.orig |
| 618 |
proc $origName {args} {return AHA!} |
| 619 |
lappend result [if 1 $script] |
| 620 |
} -cleanup { |
| 621 |
rename $origName {} |
| 622 |
rename llength.orig $origName |
| 623 |
} -result {0 AHA!} |
| 624 |
test execute-6.6 {TclCompEvalObj: proc-body bytecode invalid for script} -body { |
| 625 |
proc foo {} {set a 1} |
| 626 |
set a untouched |
| 627 |
set result {} |
| 628 |
lappend result [foo] $a |
| 629 |
lappend result [if 1 [info body foo]] $a |
| 630 |
} -cleanup { |
| 631 |
rename foo {} |
| 632 |
} -result {1 untouched 1 1} |
| 633 |
test execute-6.7 {TclCompEvalObj: bytecode context validation} -setup { |
| 634 |
namespace eval foo {} |
| 635 |
} -body { |
| 636 |
set script { llength {} } |
| 637 |
namespace eval foo { |
| 638 |
proc llength {args} {return AHA!} |
| 639 |
} |
| 640 |
set result {} |
| 641 |
lappend result [if 1 $script] |
| 642 |
lappend result [namespace eval foo $script] |
| 643 |
} -cleanup { |
| 644 |
namespace delete foo |
| 645 |
} -result {0 AHA!} |
| 646 |
test execute-6.8 {TclCompEvalObj: bytecode name resolution epoch validation} -setup { |
| 647 |
namespace eval foo {} |
| 648 |
} -body { |
| 649 |
set script { llength {} } |
| 650 |
set result {} |
| 651 |
lappend result [namespace eval foo $script] |
| 652 |
namespace eval foo { |
| 653 |
proc llength {args} {return AHA!} |
| 654 |
} |
| 655 |
lappend result [namespace eval foo $script] |
| 656 |
} -cleanup { |
| 657 |
namespace delete foo |
| 658 |
} -result {0 AHA!} |
| 659 |
test execute-6.9 {TclCompEvalObj: bytecode interp validation} -setup { |
| 660 |
interp create child |
| 661 |
} -body { |
| 662 |
set script { llength {} } |
| 663 |
child eval {proc llength args {return AHA!}} |
| 664 |
set result {} |
| 665 |
lappend result [if 1 $script] |
| 666 |
lappend result [child eval $script] |
| 667 |
} -cleanup { |
| 668 |
interp delete child |
| 669 |
} -result {0 AHA!} |
| 670 |
test execute-6.10 {TclCompEvalObj: bytecode interp validation} -body { |
| 671 |
set script { llength {} } |
| 672 |
interp create child |
| 673 |
set result {} |
| 674 |
lappend result [child eval $script] |
| 675 |
interp delete child |
| 676 |
interp create child |
| 677 |
lappend result [child eval $script] |
| 678 |
} -cleanup { |
| 679 |
catch {interp delete child} |
| 680 |
} -result {0 0} |
| 681 |
test execute-6.11 {Tcl_ExprObj: exprcode interp validation} -setup { |
| 682 |
interp create child |
| 683 |
} -constraints testexprlongobj -body { |
| 684 |
set e { [llength {}]+1 } |
| 685 |
set result {} |
| 686 |
load {} Tcltest child |
| 687 |
interp alias {} e child testexprlongobj |
| 688 |
lappend result [e $e] |
| 689 |
interp delete child |
| 690 |
interp create child |
| 691 |
load {} Tcltest child |
| 692 |
interp alias {} e child testexprlongobj |
| 693 |
lappend result [e $e] |
| 694 |
} -cleanup { |
| 695 |
interp delete child |
| 696 |
} -result {{This is a result: 1} {This is a result: 1}} |
| 697 |
test execute-6.12 {Tcl_ExprObj: exprcode interp validation} -setup { |
| 698 |
interp create child |
| 699 |
} -body { |
| 700 |
set e { [llength {}]+1 } |
| 701 |
set result {} |
| 702 |
interp alias {} e child expr |
| 703 |
lappend result [e $e] |
| 704 |
interp delete child |
| 705 |
interp create child |
| 706 |
interp alias {} e child expr |
| 707 |
lappend result [e $e] |
| 708 |
} -cleanup { |
| 709 |
interp delete child |
| 710 |
} -result {1 1} |
| 711 |
test execute-6.13 {Tcl_ExprObj: exprcode epoch validation} -body { |
| 712 |
set e { [llength {}]+1 } |
| 713 |
set result {} |
| 714 |
lappend result [expr $e] |
| 715 |
set origName [namespace which llength] |
| 716 |
rename $origName llength.orig |
| 717 |
proc $origName {args} {return 1} |
| 718 |
lappend result [expr $e] |
| 719 |
} -cleanup { |
| 720 |
rename $origName {} |
| 721 |
rename llength.orig $origName |
| 722 |
} -result {1 2} |
| 723 |
test execute-6.14 {Tcl_ExprObj: exprcode context validation} -setup { |
| 724 |
namespace eval foo {} |
| 725 |
} -body { |
| 726 |
set e { [llength {}]+1 } |
| 727 |
namespace eval foo { |
| 728 |
proc llength {args} {return 1} |
| 729 |
} |
| 730 |
set result {} |
| 731 |
lappend result [expr $e] |
| 732 |
lappend result [namespace eval foo [list expr $e]] |
| 733 |
} -cleanup { |
| 734 |
namespace delete foo |
| 735 |
} -result {1 2} |
| 736 |
test execute-6.15 {Tcl_ExprObj: exprcode name resolution epoch validation} -setup { |
| 737 |
namespace eval foo {} |
| 738 |
} -body { |
| 739 |
set e { [llength {}]+1 } |
| 740 |
set result {} |
| 741 |
lappend result [namespace eval foo [list expr $e]] |
| 742 |
namespace eval foo { |
| 743 |
proc llength {args} {return 1} |
| 744 |
} |
| 745 |
lappend result [namespace eval foo [list expr $e]] |
| 746 |
} -cleanup { |
| 747 |
namespace delete foo |
| 748 |
} -result {1 2} |
| 749 |
test execute-6.16 {Tcl_ExprObj: exprcode interp validation} -setup { |
| 750 |
interp create child |
| 751 |
} -body { |
| 752 |
set e { [llength {}]+1 } |
| 753 |
interp alias {} e child expr |
| 754 |
child eval {proc llength args {return 1}} |
| 755 |
set result {} |
| 756 |
lappend result [expr $e] |
| 757 |
lappend result [e $e] |
| 758 |
} -cleanup { |
| 759 |
interp delete child |
| 760 |
} -result {1 2} |
| 761 |
test execute-6.17 {Tcl_ExprObj: exprcode context validation} -body { |
| 762 |
proc foo e {set v 0; expr $e} |
| 763 |
proc bar e {set v 1; expr $e} |
| 764 |
set e { $v } |
| 765 |
set result {} |
| 766 |
lappend result [foo $e] |
| 767 |
lappend result [bar $e] |
| 768 |
} -cleanup { |
| 769 |
rename foo {} |
| 770 |
rename bar {} |
| 771 |
} -result {0 1} |
| 772 |
test execute-6.18 {Tcl_ExprObj: exprcode context validation} -body { |
| 773 |
proc foo e {set v {}; expr $e} |
| 774 |
proc bar e {set v v; expr $e} |
| 775 |
set e { [llength $v] } |
| 776 |
set result {} |
| 777 |
lappend result [foo $e] |
| 778 |
lappend result [bar $e] |
| 779 |
} -cleanup { |
| 780 |
rename foo {} |
| 781 |
rename bar {} |
| 782 |
} -result {0 1} |
| 783 |
|
| 784 |
test execute-7.0 {Wide int handling in INST_JUMP_FALSE/LAND} { |
| 785 |
set x 0x100000000 |
| 786 |
expr {$x && 1} |
| 787 |
} 1 |
| 788 |
test execute-7.1 {Wide int handling in INST_JUMP_FALSE/LAND} { |
| 789 |
expr {0x100000000 && 1} |
| 790 |
} 1 |
| 791 |
test execute-7.2 {Wide int handling in INST_JUMP_FALSE/LAND} { |
| 792 |
expr {1 && 0x100000000} |
| 793 |
} 1 |
| 794 |
test execute-7.3 {Wide int handling in INST_JUMP_FALSE/LAND} { |
| 795 |
expr {wide(0x100000000) && 1} |
| 796 |
} 1 |
| 797 |
test execute-7.4 {Wide int handling in INST_JUMP_FALSE/LAND} { |
| 798 |
expr {1 && wide(0x100000000)} |
| 799 |
} 1 |
| 800 |
test execute-7.5 {Wide int handling in INST_EQ} { |
| 801 |
expr {4 == (wide(1)+wide(3))} |
| 802 |
} 1 |
| 803 |
test execute-7.6 {Wide int handling in INST_EQ and [incr]} { |
| 804 |
set x 399999999999 |
| 805 |
expr {400000000000 == [incr x]} |
| 806 |
} 1 |
| 807 |
# wide ints have more bits of precision than doubles, but we convert anyway |
| 808 |
test execute-7.7 {Wide int handling in INST_EQ and [incr]} { |
| 809 |
set x [expr {wide(1)<<62}] |
| 810 |
set y [expr {$x+1}] |
| 811 |
expr {double($x) == double($y)} |
| 812 |
} 1 |
| 813 |
test execute-7.8 {Wide int conversions can change sign} longIs32bit { |
| 814 |
set x 0x80000000 |
| 815 |
expr {int($x) < wide($x)} |
| 816 |
} 1 |
| 817 |
test execute-7.9 {Wide int handling in INST_MOD} { |
| 818 |
expr {(wide(1)<<60) % ((wide(47)<<45)-1)} |
| 819 |
} 316659348800185 |
| 820 |
test execute-7.10 {Wide int handling in INST_MOD} { |
| 821 |
expr {((wide(1)<<60)-1) % 0x400000000} |
| 822 |
} 17179869183 |
| 823 |
test execute-7.11 {Wide int handling in INST_LSHIFT} { |
| 824 |
expr {wide(42) << 30} |
| 825 |
} 45097156608 |
| 826 |
test execute-7.12 {Wide int handling in INST_LSHIFT} { |
| 827 |
expr {12345678901 << 3} |
| 828 |
} 98765431208 |
| 829 |
test execute-7.13 {Wide int handling in INST_RSHIFT} { |
| 830 |
expr {0x543210febcda9876 >> 7} |
| 831 |
} 47397893236700464 |
| 832 |
test execute-7.14 {Wide int handling in INST_RSHIFT} { |
| 833 |
expr {wide(0x9876543210febcda) >> 7} |
| 834 |
} -58286587177206407 |
| 835 |
test execute-7.15 {Wide int handling in INST_BITOR} { |
| 836 |
expr {wide(0x9876543210febcda) | 0x543210febcda9876} |
| 837 |
} -2560765885044310786 |
| 838 |
test execute-7.16 {Wide int handling in INST_BITXOR} { |
| 839 |
expr {wide(0x9876543210febcda) ^ 0x543210febcda9876} |
| 840 |
} -3727778945703861076 |
| 841 |
test execute-7.17 {Wide int handling in INST_BITAND} { |
| 842 |
expr {wide(0x9876543210febcda) & 0x543210febcda9876} |
| 843 |
} 1167013060659550290 |
| 844 |
test execute-7.18 {Wide int handling in INST_ADD} { |
| 845 |
expr {wide(0x7fffffff) + wide(0x7fffffff)} |
| 846 |
} 4294967294 |
| 847 |
test execute-7.19 {Wide int handling in INST_ADD} { |
| 848 |
expr {0x7fffffff + wide(0x7fffffff)} |
| 849 |
} 4294967294 |
| 850 |
test execute-7.20 {Wide int handling in INST_ADD} { |
| 851 |
expr {wide(0x7fffffff) + 0x7fffffff} |
| 852 |
} 4294967294 |
| 853 |
test execute-7.21 {Wide int handling in INST_ADD} { |
| 854 |
expr {double(0x7fffffff) + wide(0x7fffffff)} |
| 855 |
} 4294967294.0 |
| 856 |
test execute-7.22 {Wide int handling in INST_ADD} { |
| 857 |
expr {wide(0x7fffffff) + double(0x7fffffff)} |
| 858 |
} 4294967294.0 |
| 859 |
test execute-7.23 {Wide int handling in INST_SUB} { |
| 860 |
expr {0x123456789a - 0x20406080a} |
| 861 |
} 69530054800 |
| 862 |
test execute-7.24 {Wide int handling in INST_MULT} { |
| 863 |
expr {0x123456789a * 193} |
| 864 |
} 15090186251290 |
| 865 |
test execute-7.25 {Wide int handling in INST_DIV} { |
| 866 |
expr {0x123456789a / 193} |
| 867 |
} 405116546 |
| 868 |
test execute-7.26 {Wide int handling in INST_UPLUS} { |
| 869 |
set x 0x123456871234568 |
| 870 |
expr {+ $x} |
| 871 |
} 81985533099853160 |
| 872 |
test execute-7.27 {Wide int handling in INST_UMINUS} { |
| 873 |
set x 0x123456871234568 |
| 874 |
expr {- $x} |
| 875 |
} -81985533099853160 |
| 876 |
test execute-7.28 {Wide int handling in INST_LNOT} { |
| 877 |
set x 0x123456871234568 |
| 878 |
expr {! $x} |
| 879 |
} 0 |
| 880 |
test execute-7.29 {Wide int handling in INST_BITNOT} { |
| 881 |
set x 0x123456871234568 |
| 882 |
expr {~ $x} |
| 883 |
} -81985533099853161 |
| 884 |
test execute-7.30 {Wide int handling in function call} { |
| 885 |
set x 0x12345687123456 |
| 886 |
incr x |
| 887 |
expr {log($x) == log(double($x))} |
| 888 |
} 1 |
| 889 |
test execute-7.31 {Wide int handling in abs()} { |
| 890 |
set x 0xa23456871234568 |
| 891 |
incr x |
| 892 |
set y 0x123456871234568 |
| 893 |
concat [expr {abs($x)}] [expr {abs($y)}] |
| 894 |
} {730503879441204585 81985533099853160} |
| 895 |
test execute-7.32 {Wide int handling} longIs32bit { |
| 896 |
expr {int(1024 * 1024 * 1024 * 1024)} |
| 897 |
} 0 |
| 898 |
test execute-7.33 {Wide int handling} longIs32bit { |
| 899 |
expr {int(0x1 * 1024 * 1024 * 1024 * 1024)} |
| 900 |
} 0 |
| 901 |
test execute-7.34 {Wide int handling} { |
| 902 |
expr {wide(0x1) * 1024 * 1024 * 1024 * 1024} |
| 903 |
} 1099511627776 |
| 904 |
|
| 905 |
test execute-8.1 {Stack protection} -setup { |
| 906 |
# If [Bug #804681] has not been properly taken care of, this should |
| 907 |
# segfault |
| 908 |
proc whatever args {llength $args} |
| 909 |
trace add variable ::errorInfo {write unset} whatever |
| 910 |
} -body { |
| 911 |
expr {1+9/0} |
| 912 |
} -cleanup { |
| 913 |
trace remove variable ::errorInfo {write unset} whatever |
| 914 |
rename whatever {} |
| 915 |
} -returnCodes error -match glob -result * |
| 916 |
test execute-8.2 {Stack restoration} -setup { |
| 917 |
# Avoid crashes when system stack size is limited (thread-enabled!) |
| 918 |
set limit [interp recursionlimit {}] |
| 919 |
interp recursionlimit {} 100 |
| 920 |
} -body { |
| 921 |
# Test for [Bug #816641], correct restoration of the stack top after the |
| 922 |
# stack is grown |
| 923 |
proc f {args} { f bee bop } |
| 924 |
catch f msg |
| 925 |
set msg |
| 926 |
} -cleanup { |
| 927 |
interp recursionlimit {} $limit |
| 928 |
} -result {too many nested evaluations (infinite loop?)} |
| 929 |
test execute-8.3 {Stack restoration} -setup { |
| 930 |
# Avoid crashes when system stack size is limited (thread-enabled!) |
| 931 |
set limit [interp recursionlimit {}] |
| 932 |
interp recursionlimit {} 100 |
| 933 |
} -body { |
| 934 |
# Test for [Bug #1055676], correct restoration of the stack top after the |
| 935 |
# epoch is bumped and the stack is grown in a call from a nested |
| 936 |
# evaluation |
| 937 |
set arglst [string repeat "a " 1000] |
| 938 |
proc f {args} "f $arglst" |
| 939 |
proc run {} { |
| 940 |
# bump the interp's epoch |
| 941 |
testbumpinterpepoch |
| 942 |
catch f msg |
| 943 |
set msg |
| 944 |
} |
| 945 |
run |
| 946 |
} -cleanup { |
| 947 |
interp recursionlimit {} $limit |
| 948 |
} -result {too many nested evaluations (infinite loop?)} |
| 949 |
test execute-8.4 {Compile epoch bump effect on stack trace} -setup { |
| 950 |
proc foo {} { |
| 951 |
error bar |
| 952 |
} |
| 953 |
proc FOO {} { |
| 954 |
catch {error bar} m o |
| 955 |
testbumpinterpepoch |
| 956 |
return -options $o $m |
| 957 |
} |
| 958 |
} -body { |
| 959 |
catch foo m o |
| 960 |
set stack1 [dict get $o -errorinfo] |
| 961 |
catch FOO m o |
| 962 |
set stack2 [string map {FOO foo} [dict get $o -errorinfo]] |
| 963 |
expr {$stack1 eq $stack2 ? {} : "These differ:\n$stack1\n$stack2"} |
| 964 |
} -cleanup { |
| 965 |
rename foo {} |
| 966 |
rename FOO {} |
| 967 |
unset -nocomplain m o stack1 stack2 |
| 968 |
} -result {} |
| 969 |
test execute-8.5 {Bug 2038069} -setup { |
| 970 |
proc demo {} { |
| 971 |
catch [list error FOO] m o |
| 972 |
return $o |
| 973 |
} |
| 974 |
} -body { |
| 975 |
demo |
| 976 |
} -cleanup { |
| 977 |
rename demo {} |
| 978 |
} -match glob -result {-code 1 -level 0 -errorstack * -errorcode NONE -errorinfo {FOO |
| 979 |
while executing |
| 980 |
"error FOO" |
| 981 |
invoked from within |
| 982 |
"catch \[list error FOO\] m o"} -errorline 2} |
| 983 |
|
| 984 |
test execute-8.6 {Compile epoch bump in global level (bug [fa6bf38d07])} -setup { |
| 985 |
interp create child |
| 986 |
child eval { |
| 987 |
package require tcltest 2.5 |
| 988 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 989 |
::tcltest::loadTestedCommands |
| 990 |
if {[namespace which -command testbumpinterpepoch] eq ""} { |
| 991 |
proc testbumpinterpepoch {} { rename ::set ::dummy; rename ::dummy ::set } |
| 992 |
} |
| 993 |
} |
| 994 |
} -body { |
| 995 |
child eval { |
| 996 |
lappend res A; testbumpinterpepoch; lappend res B; return; lappend res C; |
| 997 |
} |
| 998 |
child eval { |
| 999 |
set i 0; while {[incr i] < 3} { |
| 1000 |
lappend res A; testbumpinterpepoch; lappend res B; return; lappend res C; |
| 1001 |
} |
| 1002 |
} |
| 1003 |
child eval { |
| 1004 |
set i 0; while {[incr i] < 3} { |
| 1005 |
lappend res A; testbumpinterpepoch; lappend res B; break; lappend res C; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
child eval { |
| 1009 |
catch { |
| 1010 |
lappend res A; testbumpinterpepoch; lappend res B; error test; lappend res C; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
child eval {set res} |
| 1014 |
} -cleanup { |
| 1015 |
interp delete child |
| 1016 |
} -result [lrepeat 4 A B] |
| 1017 |
test execute-8.7 {Compile epoch bump in global level (bug [fa6bf38d07]), exception case} -setup { |
| 1018 |
interp create child |
| 1019 |
child eval { |
| 1020 |
package require tcltest 2.5 |
| 1021 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 1022 |
::tcltest::loadTestedCommands |
| 1023 |
if {[namespace which -command testbumpinterpepoch] eq ""} { |
| 1024 |
proc testbumpinterpepoch {} { rename ::set ::dummy; rename ::dummy ::set } |
| 1025 |
} |
| 1026 |
} |
| 1027 |
} -body { |
| 1028 |
set res {} |
| 1029 |
lappend res [catch { |
| 1030 |
child eval { |
| 1031 |
lappend res A; testbumpinterpepoch; lappend res B; return -code error test; lappend res C; |
| 1032 |
} |
| 1033 |
} e] $e |
| 1034 |
lappend res [catch { |
| 1035 |
child eval { |
| 1036 |
lappend res A; testbumpinterpepoch; lappend res B; error test; lappend res C; |
| 1037 |
} |
| 1038 |
} e] $e |
| 1039 |
lappend res [catch { |
| 1040 |
child eval { |
| 1041 |
lappend res A; testbumpinterpepoch; lappend res B; return -code return test; lappend res C; |
| 1042 |
} |
| 1043 |
} e] $e |
| 1044 |
lappend res [catch { |
| 1045 |
child eval { |
| 1046 |
lappend res A; testbumpinterpepoch; lappend res B; break; lappend res C; |
| 1047 |
} |
| 1048 |
} e] $e |
| 1049 |
list $res [child eval {set res}] |
| 1050 |
} -cleanup { |
| 1051 |
interp delete child |
| 1052 |
} -result [list {1 test 1 test 2 test 3 {}} [lrepeat 4 A B]] |
| 1053 |
|
| 1054 |
test execute-9.1 {Interp result resetting [Bug 1522803]} { |
| 1055 |
set c 0 |
| 1056 |
catch { |
| 1057 |
catch {error foo} |
| 1058 |
expr {1/$c} |
| 1059 |
} |
| 1060 |
if {[string match *foo* $::errorInfo]} { |
| 1061 |
set result "Bad errorInfo: $::errorInfo" |
| 1062 |
} else { |
| 1063 |
set result SUCCESS |
| 1064 |
} |
| 1065 |
set result |
| 1066 |
} SUCCESS |
| 1067 |
|
| 1068 |
test execute-10.1 {TclExecuteByteCode, INST_CONCAT1, bytearrays} { |
| 1069 |
apply {s {binary scan $s c x; list $x [scan $s$s %c%c]}} \u0130 |
| 1070 |
} {48 {304 304}} |
| 1071 |
test execute-10.2 {Bug 2802881} -setup { |
| 1072 |
interp create child |
| 1073 |
} -body { |
| 1074 |
# If [Bug 2802881] is not fixed, this will segfault |
| 1075 |
child eval { |
| 1076 |
trace add variable ::errorInfo write {expr {$foo} ;#} |
| 1077 |
proc demo {} {a {}{}} |
| 1078 |
demo |
| 1079 |
} |
| 1080 |
} -cleanup { |
| 1081 |
interp delete child |
| 1082 |
} -returnCodes error -match glob -result * |
| 1083 |
test execute-10.3 {Bug 3072640} -setup { |
| 1084 |
proc generate {n} { |
| 1085 |
for {set i 0} {$i < $n} {incr i} { |
| 1086 |
yield $i |
| 1087 |
} |
| 1088 |
} |
| 1089 |
proc t {args} { |
| 1090 |
incr ::foo |
| 1091 |
} |
| 1092 |
set ::foo 0 |
| 1093 |
trace add execution ::generate enterstep ::t |
| 1094 |
} -body { |
| 1095 |
coroutine coro generate 5 |
| 1096 |
trace remove execution ::generate enterstep ::t |
| 1097 |
set ::foo |
| 1098 |
} -cleanup { |
| 1099 |
unset ::foo |
| 1100 |
rename generate {} |
| 1101 |
rename t {} |
| 1102 |
rename coro {} |
| 1103 |
} -result 4 |
| 1104 |
|
| 1105 |
test execute-11.1 {Bug 3142026: GrowEvaluationStack off-by-one} -setup { |
| 1106 |
interp create child |
| 1107 |
} -body { |
| 1108 |
child eval { |
| 1109 |
set x [lrepeat 1320 199] |
| 1110 |
for {set i 0} {$i < 20} {incr i} { |
| 1111 |
lappend x $i |
| 1112 |
lsort -integer $x |
| 1113 |
} |
| 1114 |
# Crashes on failure |
| 1115 |
return ok |
| 1116 |
} |
| 1117 |
} -cleanup { |
| 1118 |
interp delete child |
| 1119 |
} -result ok |
| 1120 |
|
| 1121 |
test execute-11.2 {Bug 268b23df11} -setup { |
| 1122 |
proc zero {} {return 0} |
| 1123 |
proc crash {} {expr {abs([zero])}} |
| 1124 |
proc noop args {} |
| 1125 |
trace add execution crash enterstep noop |
| 1126 |
} -body { |
| 1127 |
crash |
| 1128 |
} -cleanup { |
| 1129 |
trace remove execution crash enterstep noop |
| 1130 |
rename noop {} |
| 1131 |
rename crash {} |
| 1132 |
rename zero {} |
| 1133 |
} -result 0 |
| 1134 |
test execute-11.3 {Bug a0ece9d6d4} -setup { |
| 1135 |
proc crash {} {expr {rand()}} |
| 1136 |
trace add execution crash enterstep {apply {args {info frame -2}}} |
| 1137 |
} -body { |
| 1138 |
string is double [crash] |
| 1139 |
} -cleanup { |
| 1140 |
trace remove execution crash enterstep {apply {args {info frame -2}}} |
| 1141 |
rename crash {} |
| 1142 |
} -result 1 |
| 1143 |
|
| 1144 |
test execute-12.1 {failing multi-lappend to unshared} -setup { |
| 1145 |
unset -nocomplain x y |
| 1146 |
} -body { |
| 1147 |
set x 1 |
| 1148 |
lappend x 2 3 |
| 1149 |
trace add variable x write {apply {args {error boo}}} |
| 1150 |
lappend x 4 5 |
| 1151 |
} -cleanup { |
| 1152 |
unset -nocomplain x y |
| 1153 |
} -returnCodes error -result {can't set "x": boo} |
| 1154 |
test execute-12.2 {failing multi-lappend to shared} -setup { |
| 1155 |
unset -nocomplain x y |
| 1156 |
} -body { |
| 1157 |
set x 1 |
| 1158 |
lappend x 2 3 |
| 1159 |
set y $x |
| 1160 |
trace add variable x write {apply {args {error boo}}} |
| 1161 |
lappend x 4 5 |
| 1162 |
} -cleanup { |
| 1163 |
unset -nocomplain x y |
| 1164 |
} -returnCodes error -result {can't set "x": boo} |
| 1165 |
test execute-12.3 {failing multi-lappend to unshared: LVT} -body { |
| 1166 |
apply {{} { |
| 1167 |
set x 1 |
| 1168 |
lappend x 2 3 |
| 1169 |
trace add variable x write {apply {args {error boo}}} |
| 1170 |
lappend x 4 5 |
| 1171 |
}} |
| 1172 |
} -returnCodes error -result {can't set "x": boo} |
| 1173 |
test execute-12.4 {failing multi-lappend to shared: LVT} -body { |
| 1174 |
apply {{} { |
| 1175 |
set x 1 |
| 1176 |
lappend x 2 3 |
| 1177 |
set y $x |
| 1178 |
trace add variable x write {apply {args {error boo}}} |
| 1179 |
lappend x 4 5 |
| 1180 |
}} |
| 1181 |
} -returnCodes error -result {can't set "x": boo} |
| 1182 |
|
| 1183 |
# cleanup |
| 1184 |
if {[info commands testobj] != {}} { |
| 1185 |
testobj freeallvars |
| 1186 |
} |
| 1187 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1188 |
catch {rename foo ""} |
| 1189 |
catch {rename p ""} |
| 1190 |
catch {rename {} ""} |
| 1191 |
catch {rename { } ""} |
| 1192 |
catch {unset x} |
| 1193 |
catch {unset y} |
| 1194 |
catch {unset msg} |
| 1195 |
::tcltest::cleanupTests |
| 1196 |
return |
| 1197 |
|
| 1198 |
# Local Variables: |
| 1199 |
# mode: tcl |
| 1200 |
# fill-column: 78 |
| 1201 |
# End: |