[25] | 1 | # This file contains tests for the tclExecute.c source file. Tests appear |
---|
| 2 | # in the same order as the C code that they test. The set of tests is |
---|
| 3 | # currently incomplete since it currently includes only new tests for |
---|
| 4 | # code changed for the addition of Tcl namespaces. Other execution- |
---|
| 5 | # related tests appear in several other test files including |
---|
| 6 | # namespace.test, basic.test, eval.test, for.test, etc. |
---|
| 7 | # |
---|
| 8 | # Sourcing this file into Tcl runs the tests and generates output for |
---|
| 9 | # errors. 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 |
---|
| 15 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 16 | # |
---|
| 17 | # RCS: @(#) $Id: execute.test,v 1.27 2008/03/07 19:04:10 dgp Exp $ |
---|
| 18 | |
---|
| 19 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
| 20 | package require tcltest 2 |
---|
| 21 | namespace import -force ::tcltest::* |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 25 | catch {rename foo ""} |
---|
| 26 | catch {unset x} |
---|
| 27 | catch {unset y} |
---|
| 28 | catch {unset msg} |
---|
| 29 | |
---|
| 30 | testConstraint testobj [expr { |
---|
| 31 | [llength [info commands testobj]] |
---|
| 32 | && [llength [info commands testdoubleobj]] |
---|
| 33 | && [llength [info commands teststringobj]] |
---|
| 34 | }] |
---|
| 35 | |
---|
| 36 | testConstraint longIs32bit [expr {int(0x80000000) < 0}] |
---|
| 37 | testConstraint testexprlongobj [llength [info commands testexprlongobj]] |
---|
| 38 | |
---|
| 39 | # Tests for the omnibus TclExecuteByteCode function: |
---|
| 40 | |
---|
| 41 | # INST_DONE not tested |
---|
| 42 | # INST_PUSH1 not tested |
---|
| 43 | # INST_PUSH4 not tested |
---|
| 44 | # INST_POP not tested |
---|
| 45 | # INST_DUP not tested |
---|
| 46 | # INST_CONCAT1 not tested |
---|
| 47 | # INST_INVOKE_STK4 not tested |
---|
| 48 | # INST_INVOKE_STK1 not tested |
---|
| 49 | # INST_EVAL_STK not tested |
---|
| 50 | # INST_EXPR_STK not tested |
---|
| 51 | |
---|
| 52 | # INST_LOAD_SCALAR1 |
---|
| 53 | |
---|
| 54 | test execute-1.1 {TclExecuteByteCode, INST_LOAD_SCALAR1, small opnd} { |
---|
| 55 | proc foo {} { |
---|
| 56 | set x 1 |
---|
| 57 | return $x |
---|
| 58 | } |
---|
| 59 | foo |
---|
| 60 | } 1 |
---|
| 61 | test execute-1.2 {TclExecuteByteCode, INST_LOAD_SCALAR1, large opnd} { |
---|
| 62 | # Bug: 2243 |
---|
| 63 | set body {} |
---|
| 64 | for {set i 0} {$i < 129} {incr i} { |
---|
| 65 | append body "set x$i x\n" |
---|
| 66 | } |
---|
| 67 | append body { |
---|
| 68 | set y 1 |
---|
| 69 | return $y |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | proc foo {} $body |
---|
| 73 | foo |
---|
| 74 | } 1 |
---|
| 75 | test execute-1.3 {TclExecuteByteCode, INST_LOAD_SCALAR1, error} { |
---|
| 76 | proc foo {} { |
---|
| 77 | set x 1 |
---|
| 78 | unset x |
---|
| 79 | return $x |
---|
| 80 | } |
---|
| 81 | list [catch {foo} msg] $msg |
---|
| 82 | } {1 {can't read "x": no such variable}} |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | # INST_LOAD_SCALAR4 |
---|
| 86 | |
---|
| 87 | test execute-2.1 {TclExecuteByteCode, INST_LOAD_SCALAR4, simple case} { |
---|
| 88 | set body {} |
---|
| 89 | for {set i 0} {$i < 256} {incr i} { |
---|
| 90 | append body "set x$i x\n" |
---|
| 91 | } |
---|
| 92 | append body { |
---|
| 93 | set y 1 |
---|
| 94 | return $y |
---|
| 95 | } |
---|
| 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 | |
---|
| 111 | proc foo {} $body |
---|
| 112 | list [catch {foo} msg] $msg |
---|
| 113 | } {1 {can't read "y": no such variable}} |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | # INST_LOAD_SCALAR_STK not tested |
---|
| 117 | # INST_LOAD_ARRAY4 not tested |
---|
| 118 | # INST_LOAD_ARRAY1 not tested |
---|
| 119 | # INST_LOAD_ARRAY_STK not tested |
---|
| 120 | # INST_LOAD_STK not tested |
---|
| 121 | # INST_STORE_SCALAR4 not tested |
---|
| 122 | # INST_STORE_SCALAR1 not tested |
---|
| 123 | # INST_STORE_SCALAR_STK not tested |
---|
| 124 | # INST_STORE_ARRAY4 not tested |
---|
| 125 | # INST_STORE_ARRAY1 not tested |
---|
| 126 | # INST_STORE_ARRAY_STK not tested |
---|
| 127 | # INST_STORE_STK not tested |
---|
| 128 | # INST_INCR_SCALAR1 not tested |
---|
| 129 | # INST_INCR_SCALAR_STK not tested |
---|
| 130 | # INST_INCR_STK not tested |
---|
| 131 | # INST_INCR_ARRAY1 not tested |
---|
| 132 | # INST_INCR_ARRAY_STK not tested |
---|
| 133 | # INST_INCR_SCALAR1_IMM not tested |
---|
| 134 | # INST_INCR_SCALAR_STK_IMM not tested |
---|
| 135 | # INST_INCR_STK_IMM not tested |
---|
| 136 | # INST_INCR_ARRAY1_IMM not tested |
---|
| 137 | # INST_INCR_ARRAY_STK_IMM not tested |
---|
| 138 | # INST_JUMP1 not tested |
---|
| 139 | # INST_JUMP4 not tested |
---|
| 140 | # INST_JUMP_TRUE4 not tested |
---|
| 141 | # INST_JUMP_TRUE1 not tested |
---|
| 142 | # INST_JUMP_FALSE4 not tested |
---|
| 143 | # INST_JUMP_FALSE1 not tested |
---|
| 144 | # INST_LOR not tested |
---|
| 145 | # INST_LAND not tested |
---|
| 146 | # INST_EQ not tested |
---|
| 147 | # INST_NEQ not tested |
---|
| 148 | # INST_LT not tested |
---|
| 149 | # INST_GT not tested |
---|
| 150 | # INST_LE not tested |
---|
| 151 | # INST_GE not tested |
---|
| 152 | # INST_MOD not tested |
---|
| 153 | # INST_LSHIFT not tested |
---|
| 154 | # INST_RSHIFT not tested |
---|
| 155 | # INST_BITOR not tested |
---|
| 156 | # INST_BITXOR not tested |
---|
| 157 | # INST_BITAND not tested |
---|
| 158 | |
---|
| 159 | # INST_ADD is partially tested: |
---|
| 160 | test execute-3.1 {TclExecuteByteCode, INST_ADD, op1 is int} {testobj} { |
---|
| 161 | set x [testintobj set 0 1] |
---|
| 162 | expr {$x + 1} |
---|
| 163 | } 2 |
---|
| 164 | test execute-3.2 {TclExecuteByteCode, INST_ADD, op1 is double} {testobj} { |
---|
| 165 | set x [testdoubleobj set 0 1] |
---|
| 166 | expr {$x + 1} |
---|
| 167 | } 2.0 |
---|
| 168 | test execute-3.3 {TclExecuteByteCode, INST_ADD, op1 is double with string} {testobj} { |
---|
| 169 | set x [testintobj set 0 1] |
---|
| 170 | testobj convert 0 double |
---|
| 171 | expr {$x + 1} |
---|
| 172 | } 2 |
---|
| 173 | test execute-3.4 {TclExecuteByteCode, INST_ADD, op1 is string int} {testobj} { |
---|
| 174 | set x [teststringobj set 0 1] |
---|
| 175 | expr {$x + 1} |
---|
| 176 | } 2 |
---|
| 177 | test execute-3.5 {TclExecuteByteCode, INST_ADD, op1 is string double} {testobj} { |
---|
| 178 | set x [teststringobj set 0 1.0] |
---|
| 179 | expr {$x + 1} |
---|
| 180 | } 2.0 |
---|
| 181 | test execute-3.6 {TclExecuteByteCode, INST_ADD, op1 is non-numeric} {testobj} { |
---|
| 182 | set x [teststringobj set 0 foo] |
---|
| 183 | list [catch {expr {$x + 1}} msg] $msg |
---|
| 184 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
| 185 | test execute-3.7 {TclExecuteByteCode, INST_ADD, op2 is int} {testobj} { |
---|
| 186 | set x [testintobj set 0 1] |
---|
| 187 | expr {1 + $x} |
---|
| 188 | } 2 |
---|
| 189 | test execute-3.8 {TclExecuteByteCode, INST_ADD, op2 is double} {testobj} { |
---|
| 190 | set x [testdoubleobj set 0 1] |
---|
| 191 | expr {1 + $x} |
---|
| 192 | } 2.0 |
---|
| 193 | test execute-3.9 {TclExecuteByteCode, INST_ADD, op2 is double with string} {testobj} { |
---|
| 194 | set x [testintobj set 0 1] |
---|
| 195 | testobj convert 0 double |
---|
| 196 | expr {1 + $x} |
---|
| 197 | } 2 |
---|
| 198 | test execute-3.10 {TclExecuteByteCode, INST_ADD, op2 is string int} {testobj} { |
---|
| 199 | set x [teststringobj set 0 1] |
---|
| 200 | expr {1 + $x} |
---|
| 201 | } 2 |
---|
| 202 | test execute-3.11 {TclExecuteByteCode, INST_ADD, op2 is string double} {testobj} { |
---|
| 203 | set x [teststringobj set 0 1.0] |
---|
| 204 | expr {1 + $x} |
---|
| 205 | } 2.0 |
---|
| 206 | test execute-3.12 {TclExecuteByteCode, INST_ADD, op2 is non-numeric} {testobj} { |
---|
| 207 | set x [teststringobj set 0 foo] |
---|
| 208 | list [catch {expr {1 + $x}} msg] $msg |
---|
| 209 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
| 210 | |
---|
| 211 | # INST_SUB is partially tested: |
---|
| 212 | test execute-3.13 {TclExecuteByteCode, INST_SUB, op1 is int} {testobj} { |
---|
| 213 | set x [testintobj set 0 1] |
---|
| 214 | expr {$x - 1} |
---|
| 215 | } 0 |
---|
| 216 | test execute-3.14 {TclExecuteByteCode, INST_SUB, op1 is double} {testobj} { |
---|
| 217 | set x [testdoubleobj set 0 1] |
---|
| 218 | expr {$x - 1} |
---|
| 219 | } 0.0 |
---|
| 220 | test execute-3.15 {TclExecuteByteCode, INST_SUB, op1 is double with string} {testobj} { |
---|
| 221 | set x [testintobj set 0 1] |
---|
| 222 | testobj convert 0 double |
---|
| 223 | expr {$x - 1} |
---|
| 224 | } 0 |
---|
| 225 | test execute-3.16 {TclExecuteByteCode, INST_SUB, op1 is string int} {testobj} { |
---|
| 226 | set x [teststringobj set 0 1] |
---|
| 227 | expr {$x - 1} |
---|
| 228 | } 0 |
---|
| 229 | test execute-3.17 {TclExecuteByteCode, INST_SUB, op1 is string double} {testobj} { |
---|
| 230 | set x [teststringobj set 0 1.0] |
---|
| 231 | expr {$x - 1} |
---|
| 232 | } 0.0 |
---|
| 233 | test execute-3.18 {TclExecuteByteCode, INST_SUB, op1 is non-numeric} {testobj} { |
---|
| 234 | set x [teststringobj set 0 foo] |
---|
| 235 | list [catch {expr {$x - 1}} msg] $msg |
---|
| 236 | } {1 {can't use non-numeric string as operand of "-"}} |
---|
| 237 | test execute-3.19 {TclExecuteByteCode, INST_SUB, op2 is int} {testobj} { |
---|
| 238 | set x [testintobj set 0 1] |
---|
| 239 | expr {1 - $x} |
---|
| 240 | } 0 |
---|
| 241 | test execute-3.20 {TclExecuteByteCode, INST_SUB, op2 is double} {testobj} { |
---|
| 242 | set x [testdoubleobj set 0 1] |
---|
| 243 | expr {1 - $x} |
---|
| 244 | } 0.0 |
---|
| 245 | test execute-3.21 {TclExecuteByteCode, INST_SUB, op2 is double with string} {testobj} { |
---|
| 246 | set x [testintobj set 0 1] |
---|
| 247 | testobj convert 0 double |
---|
| 248 | expr {1 - $x} |
---|
| 249 | } 0 |
---|
| 250 | test execute-3.22 {TclExecuteByteCode, INST_SUB, op2 is string int} {testobj} { |
---|
| 251 | set x [teststringobj set 0 1] |
---|
| 252 | expr {1 - $x} |
---|
| 253 | } 0 |
---|
| 254 | test execute-3.23 {TclExecuteByteCode, INST_SUB, op2 is string double} {testobj} { |
---|
| 255 | set x [teststringobj set 0 1.0] |
---|
| 256 | expr {1 - $x} |
---|
| 257 | } 0.0 |
---|
| 258 | test execute-3.24 {TclExecuteByteCode, INST_SUB, op2 is non-numeric} {testobj} { |
---|
| 259 | set x [teststringobj set 0 foo] |
---|
| 260 | list [catch {expr {1 - $x}} msg] $msg |
---|
| 261 | } {1 {can't use non-numeric string as operand of "-"}} |
---|
| 262 | |
---|
| 263 | # INST_MULT is partially tested: |
---|
| 264 | test execute-3.25 {TclExecuteByteCode, INST_MULT, op1 is int} {testobj} { |
---|
| 265 | set x [testintobj set 1 1] |
---|
| 266 | expr {$x * 1} |
---|
| 267 | } 1 |
---|
| 268 | test execute-3.26 {TclExecuteByteCode, INST_MULT, op1 is double} {testobj} { |
---|
| 269 | set x [testdoubleobj set 1 2.0] |
---|
| 270 | expr {$x * 1} |
---|
| 271 | } 2.0 |
---|
| 272 | test execute-3.27 {TclExecuteByteCode, INST_MULT, op1 is double with string} {testobj} { |
---|
| 273 | set x [testintobj set 1 2] |
---|
| 274 | testobj convert 1 double |
---|
| 275 | expr {$x * 1} |
---|
| 276 | } 2 |
---|
| 277 | test execute-3.28 {TclExecuteByteCode, INST_MULT, op1 is string int} {testobj} { |
---|
| 278 | set x [teststringobj set 1 1] |
---|
| 279 | expr {$x * 1} |
---|
| 280 | } 1 |
---|
| 281 | test execute-3.29 {TclExecuteByteCode, INST_MULT, op1 is string double} {testobj} { |
---|
| 282 | set x [teststringobj set 1 1.0] |
---|
| 283 | expr {$x * 1} |
---|
| 284 | } 1.0 |
---|
| 285 | test execute-3.30 {TclExecuteByteCode, INST_MULT, op1 is non-numeric} {testobj} { |
---|
| 286 | set x [teststringobj set 1 foo] |
---|
| 287 | list [catch {expr {$x * 1}} msg] $msg |
---|
| 288 | } {1 {can't use non-numeric string as operand of "*"}} |
---|
| 289 | test execute-3.31 {TclExecuteByteCode, INST_MULT, op2 is int} {testobj} { |
---|
| 290 | set x [testintobj set 1 1] |
---|
| 291 | expr {1 * $x} |
---|
| 292 | } 1 |
---|
| 293 | test execute-3.32 {TclExecuteByteCode, INST_MULT, op2 is double} {testobj} { |
---|
| 294 | set x [testdoubleobj set 1 2.0] |
---|
| 295 | expr {1 * $x} |
---|
| 296 | } 2.0 |
---|
| 297 | test execute-3.33 {TclExecuteByteCode, INST_MULT, op2 is double with string} {testobj} { |
---|
| 298 | set x [testintobj set 1 2] |
---|
| 299 | testobj convert 1 double |
---|
| 300 | expr {1 * $x} |
---|
| 301 | } 2 |
---|
| 302 | test execute-3.34 {TclExecuteByteCode, INST_MULT, op2 is string int} {testobj} { |
---|
| 303 | set x [teststringobj set 1 1] |
---|
| 304 | expr {1 * $x} |
---|
| 305 | } 1 |
---|
| 306 | test execute-3.35 {TclExecuteByteCode, INST_MULT, op2 is string double} {testobj} { |
---|
| 307 | set x [teststringobj set 1 1.0] |
---|
| 308 | expr {1 * $x} |
---|
| 309 | } 1.0 |
---|
| 310 | test execute-3.36 {TclExecuteByteCode, INST_MULT, op2 is non-numeric} {testobj} { |
---|
| 311 | set x [teststringobj set 1 foo] |
---|
| 312 | list [catch {expr {1 * $x}} msg] $msg |
---|
| 313 | } {1 {can't use non-numeric string as operand of "*"}} |
---|
| 314 | |
---|
| 315 | # INST_DIV is partially tested: |
---|
| 316 | test execute-3.37 {TclExecuteByteCode, INST_DIV, op1 is int} {testobj} { |
---|
| 317 | set x [testintobj set 1 1] |
---|
| 318 | expr {$x / 1} |
---|
| 319 | } 1 |
---|
| 320 | test execute-3.38 {TclExecuteByteCode, INST_DIV, op1 is double} {testobj} { |
---|
| 321 | set x [testdoubleobj set 1 2.0] |
---|
| 322 | expr {$x / 1} |
---|
| 323 | } 2.0 |
---|
| 324 | test execute-3.39 {TclExecuteByteCode, INST_DIV, op1 is double with string} {testobj} { |
---|
| 325 | set x [testintobj set 1 2] |
---|
| 326 | testobj convert 1 double |
---|
| 327 | expr {$x / 1} |
---|
| 328 | } 2 |
---|
| 329 | test execute-3.40 {TclExecuteByteCode, INST_DIV, op1 is string int} {testobj} { |
---|
| 330 | set x [teststringobj set 1 1] |
---|
| 331 | expr {$x / 1} |
---|
| 332 | } 1 |
---|
| 333 | test execute-3.41 {TclExecuteByteCode, INST_DIV, op1 is string double} {testobj} { |
---|
| 334 | set x [teststringobj set 1 1.0] |
---|
| 335 | expr {$x / 1} |
---|
| 336 | } 1.0 |
---|
| 337 | test execute-3.42 {TclExecuteByteCode, INST_DIV, op1 is non-numeric} {testobj} { |
---|
| 338 | set x [teststringobj set 1 foo] |
---|
| 339 | list [catch {expr {$x / 1}} msg] $msg |
---|
| 340 | } {1 {can't use non-numeric string as operand of "/"}} |
---|
| 341 | test execute-3.43 {TclExecuteByteCode, INST_DIV, op2 is int} {testobj} { |
---|
| 342 | set x [testintobj set 1 1] |
---|
| 343 | expr {2 / $x} |
---|
| 344 | } 2 |
---|
| 345 | test execute-3.44 {TclExecuteByteCode, INST_DIV, op2 is double} {testobj} { |
---|
| 346 | set x [testdoubleobj set 1 1.0] |
---|
| 347 | expr {2 / $x} |
---|
| 348 | } 2.0 |
---|
| 349 | test execute-3.45 {TclExecuteByteCode, INST_DIV, op2 is double with string} {testobj} { |
---|
| 350 | set x [testintobj set 1 1] |
---|
| 351 | testobj convert 1 double |
---|
| 352 | expr {2 / $x} |
---|
| 353 | } 2 |
---|
| 354 | test execute-3.46 {TclExecuteByteCode, INST_DIV, op2 is string int} {testobj} { |
---|
| 355 | set x [teststringobj set 1 1] |
---|
| 356 | expr {2 / $x} |
---|
| 357 | } 2 |
---|
| 358 | test execute-3.47 {TclExecuteByteCode, INST_DIV, op2 is string double} {testobj} { |
---|
| 359 | set x [teststringobj set 1 1.0] |
---|
| 360 | expr {2 / $x} |
---|
| 361 | } 2.0 |
---|
| 362 | test execute-3.48 {TclExecuteByteCode, INST_DIV, op2 is non-numeric} {testobj} { |
---|
| 363 | set x [teststringobj set 1 foo] |
---|
| 364 | list [catch {expr {1 / $x}} msg] $msg |
---|
| 365 | } {1 {can't use non-numeric string as operand of "/"}} |
---|
| 366 | |
---|
| 367 | # INST_UPLUS is partially tested: |
---|
| 368 | test execute-3.49 {TclExecuteByteCode, INST_UPLUS, op is int} {testobj} { |
---|
| 369 | set x [testintobj set 1 1] |
---|
| 370 | expr {+ $x} |
---|
| 371 | } 1 |
---|
| 372 | test execute-3.50 {TclExecuteByteCode, INST_UPLUS, op is double} {testobj} { |
---|
| 373 | set x [testdoubleobj set 1 1.0] |
---|
| 374 | expr {+ $x} |
---|
| 375 | } 1.0 |
---|
| 376 | test execute-3.51 {TclExecuteByteCode, INST_UPLUS, op is double with string} {testobj} { |
---|
| 377 | set x [testintobj set 1 1] |
---|
| 378 | testobj convert 1 double |
---|
| 379 | expr {+ $x} |
---|
| 380 | } 1 |
---|
| 381 | test execute-3.52 {TclExecuteByteCode, INST_UPLUS, op is string int} {testobj} { |
---|
| 382 | set x [teststringobj set 1 1] |
---|
| 383 | expr {+ $x} |
---|
| 384 | } 1 |
---|
| 385 | test execute-3.53 {TclExecuteByteCode, INST_UPLUS, op is string double} {testobj} { |
---|
| 386 | set x [teststringobj set 1 1.0] |
---|
| 387 | expr {+ $x} |
---|
| 388 | } 1.0 |
---|
| 389 | test execute-3.54 {TclExecuteByteCode, INST_UPLUS, op is non-numeric} {testobj} { |
---|
| 390 | set x [teststringobj set 1 foo] |
---|
| 391 | list [catch {expr {+ $x}} msg] $msg |
---|
| 392 | } {1 {can't use non-numeric string as operand of "+"}} |
---|
| 393 | |
---|
| 394 | # INST_UMINUS is partially tested: |
---|
| 395 | test execute-3.55 {TclExecuteByteCode, INST_UMINUS, op is int} {testobj} { |
---|
| 396 | set x [testintobj set 1 1] |
---|
| 397 | expr {- $x} |
---|
| 398 | } -1 |
---|
| 399 | test execute-3.56 {TclExecuteByteCode, INST_UMINUS, op is double} {testobj} { |
---|
| 400 | set x [testdoubleobj set 1 1.0] |
---|
| 401 | expr {- $x} |
---|
| 402 | } -1.0 |
---|
| 403 | test execute-3.57 {TclExecuteByteCode, INST_UMINUS, op is double with string} {testobj} { |
---|
| 404 | set x [testintobj set 1 1] |
---|
| 405 | testobj convert 1 double |
---|
| 406 | expr {- $x} |
---|
| 407 | } -1 |
---|
| 408 | test execute-3.58 {TclExecuteByteCode, INST_UMINUS, op is string int} {testobj} { |
---|
| 409 | set x [teststringobj set 1 1] |
---|
| 410 | expr {- $x} |
---|
| 411 | } -1 |
---|
| 412 | test execute-3.59 {TclExecuteByteCode, INST_UMINUS, op is string double} {testobj} { |
---|
| 413 | set x [teststringobj set 1 1.0] |
---|
| 414 | expr {- $x} |
---|
| 415 | } -1.0 |
---|
| 416 | test execute-3.60 {TclExecuteByteCode, INST_UMINUS, op is non-numeric} {testobj} { |
---|
| 417 | set x [teststringobj set 1 foo] |
---|
| 418 | list [catch {expr {- $x}} msg] $msg |
---|
| 419 | } {1 {can't use non-numeric string as operand of "-"}} |
---|
| 420 | |
---|
| 421 | # INST_LNOT is partially tested: |
---|
| 422 | test execute-3.61 {TclExecuteByteCode, INST_LNOT, op is int} {testobj} { |
---|
| 423 | set x [testintobj set 1 2] |
---|
| 424 | expr {! $x} |
---|
| 425 | } 0 |
---|
| 426 | test execute-3.62 {TclExecuteByteCode, INST_LNOT, op is int} {testobj} { |
---|
| 427 | set x [testintobj set 1 0] |
---|
| 428 | expr {! $x} |
---|
| 429 | } 1 |
---|
| 430 | test execute-3.63 {TclExecuteByteCode, INST_LNOT, op is double} {testobj} { |
---|
| 431 | set x [testdoubleobj set 1 1.0] |
---|
| 432 | expr {! $x} |
---|
| 433 | } 0 |
---|
| 434 | test execute-3.64 {TclExecuteByteCode, INST_LNOT, op is double} {testobj} { |
---|
| 435 | set x [testdoubleobj set 1 0.0] |
---|
| 436 | expr {! $x} |
---|
| 437 | } 1 |
---|
| 438 | test execute-3.65 {TclExecuteByteCode, INST_LNOT, op is double with string} {testobj} { |
---|
| 439 | set x [testintobj set 1 1] |
---|
| 440 | testobj convert 1 double |
---|
| 441 | expr {! $x} |
---|
| 442 | } 0 |
---|
| 443 | test execute-3.66 {TclExecuteByteCode, INST_LNOT, op is double with string} {testobj} { |
---|
| 444 | set x [testintobj set 1 0] |
---|
| 445 | testobj convert 1 double |
---|
| 446 | expr {! $x} |
---|
| 447 | } 1 |
---|
| 448 | test execute-3.67 {TclExecuteByteCode, INST_LNOT, op is string int} {testobj} { |
---|
| 449 | set x [teststringobj set 1 1] |
---|
| 450 | expr {! $x} |
---|
| 451 | } 0 |
---|
| 452 | test execute-3.68 {TclExecuteByteCode, INST_LNOT, op is string int} {testobj} { |
---|
| 453 | set x [teststringobj set 1 0] |
---|
| 454 | expr {! $x} |
---|
| 455 | } 1 |
---|
| 456 | test execute-3.69 {TclExecuteByteCode, INST_LNOT, op is string double} {testobj} { |
---|
| 457 | set x [teststringobj set 1 1.0] |
---|
| 458 | expr {! $x} |
---|
| 459 | } 0 |
---|
| 460 | test execute-3.70 {TclExecuteByteCode, INST_LNOT, op is string double} {testobj} { |
---|
| 461 | set x [teststringobj set 1 0.0] |
---|
| 462 | expr {! $x} |
---|
| 463 | } 1 |
---|
| 464 | test execute-3.71 {TclExecuteByteCode, INST_LNOT, op is non-numeric} {testobj} { |
---|
| 465 | set x [teststringobj set 1 foo] |
---|
| 466 | list [catch {expr {! $x}} msg] $msg |
---|
| 467 | } {1 {can't use non-numeric string as operand of "!"}} |
---|
| 468 | |
---|
| 469 | # INST_BITNOT not tested |
---|
| 470 | # INST_CALL_BUILTIN_FUNC1 not tested |
---|
| 471 | # INST_CALL_FUNC1 not tested |
---|
| 472 | |
---|
| 473 | # INST_TRY_CVT_TO_NUMERIC is partially tested: |
---|
| 474 | test execute-3.72 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is int} {testobj} { |
---|
| 475 | set x [testintobj set 1 1] |
---|
| 476 | expr {$x} |
---|
| 477 | } 1 |
---|
| 478 | test execute-3.73 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is double} {testobj} { |
---|
| 479 | set x [testdoubleobj set 1 1.0] |
---|
| 480 | expr {$x} |
---|
| 481 | } 1.0 |
---|
| 482 | test execute-3.74 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is double with string} {testobj} { |
---|
| 483 | set x [testintobj set 1 1] |
---|
| 484 | testobj convert 1 double |
---|
| 485 | expr {$x} |
---|
| 486 | } 1 |
---|
| 487 | test execute-3.75 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is string int} {testobj} { |
---|
| 488 | set x [teststringobj set 1 1] |
---|
| 489 | expr {$x} |
---|
| 490 | } 1 |
---|
| 491 | test execute-3.76 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is string double} {testobj} { |
---|
| 492 | set x [teststringobj set 1 1.0] |
---|
| 493 | expr {$x} |
---|
| 494 | } 1.0 |
---|
| 495 | test execute-3.77 {TclExecuteByteCode, INST_TRY_CVT_TO_NUMERIC, op is non-numeric} {testobj} { |
---|
| 496 | set x [teststringobj set 1 foo] |
---|
| 497 | expr {$x} |
---|
| 498 | } foo |
---|
| 499 | |
---|
| 500 | # INST_BREAK not tested |
---|
| 501 | # INST_CONTINUE not tested |
---|
| 502 | # INST_FOREACH_START4 not tested |
---|
| 503 | # INST_FOREACH_STEP4 not tested |
---|
| 504 | # INST_BEGIN_CATCH4 not tested |
---|
| 505 | # INST_END_CATCH not tested |
---|
| 506 | # INST_PUSH_RESULT not tested |
---|
| 507 | # INST_PUSH_RETURN_CODE not tested |
---|
| 508 | |
---|
| 509 | test execute-4.1 {Tcl_GetCommandFromObj, convert to tclCmdNameType} { |
---|
| 510 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 511 | catch {unset x} |
---|
| 512 | catch {unset y} |
---|
| 513 | namespace eval test_ns_1 { |
---|
| 514 | namespace export cmd1 |
---|
| 515 | proc cmd1 {args} {return "cmd1: $args"} |
---|
| 516 | proc cmd2 {args} {return "cmd2: $args"} |
---|
| 517 | } |
---|
| 518 | namespace eval test_ns_1::test_ns_2 { |
---|
| 519 | namespace import ::test_ns_1::* |
---|
| 520 | } |
---|
| 521 | set x "test_ns_1::" |
---|
| 522 | set y "test_ns_2::" |
---|
| 523 | list [namespace which -command ${x}${y}cmd1] \ |
---|
| 524 | [catch {namespace which -command ${x}${y}cmd2} msg] $msg \ |
---|
| 525 | [catch {namespace which -command ${x}${y}:cmd2} msg] $msg |
---|
| 526 | } {::test_ns_1::test_ns_2::cmd1 0 {} 0 {}} |
---|
| 527 | test execute-4.2 {Tcl_GetCommandFromObj, check if cached tclCmdNameType is invalid} { |
---|
| 528 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 529 | catch {rename foo ""} |
---|
| 530 | catch {unset l} |
---|
| 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 | set l |
---|
| 548 | } {::foo ::test_ns_1::foo} |
---|
| 549 | test execute-4.3 {Tcl_GetCommandFromObj, command never found} { |
---|
| 550 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 551 | catch {rename foo ""} |
---|
| 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 | } {::test_ns_1::foo {} 0 {}} |
---|
| 566 | |
---|
| 567 | test execute-5.1 {SetCmdNameFromAny, set cmd name to empty heap string if NULL} { |
---|
| 568 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 569 | catch {unset l} |
---|
| 570 | proc {} {} {return {}} |
---|
| 571 | {} |
---|
| 572 | set l {} |
---|
| 573 | lindex {} 0 |
---|
| 574 | {} |
---|
| 575 | } {} |
---|
| 576 | |
---|
| 577 | test execute-6.1 {UpdateStringOfCmdName: called for duplicate of empty cmdName object} { |
---|
| 578 | proc {} {} {} |
---|
| 579 | proc { } {} {} |
---|
| 580 | proc p {} { |
---|
| 581 | set x {} |
---|
| 582 | $x |
---|
| 583 | append x { } |
---|
| 584 | $x |
---|
| 585 | } |
---|
| 586 | p |
---|
| 587 | } {} |
---|
| 588 | test execute-6.2 {Evaluate an expression in a variable; compile the first time, do not the second} { |
---|
| 589 | set w {3*5} |
---|
| 590 | proc a {obj} {expr $obj} |
---|
| 591 | set res "[a $w]:[a $w]" |
---|
| 592 | } {15:15} |
---|
| 593 | test execute-6.3 {Tcl_ExprObj: don't use cached script bytecode [Bug 1899164]} -setup { |
---|
| 594 | proc 0+0 {} {return SCRIPT} |
---|
| 595 | } -body { |
---|
| 596 | set e { 0+0 } |
---|
| 597 | if 1 $e |
---|
| 598 | if 1 {expr $e} |
---|
| 599 | } -cleanup { |
---|
| 600 | rename 0+0 {} |
---|
| 601 | } -result 0 |
---|
| 602 | test execute-6.4 {TclCompEvalObj: don't use cached expr bytecode [Bug 1899164]} -setup { |
---|
| 603 | proc 0+0 {} {return SCRIPT} |
---|
| 604 | } -body { |
---|
| 605 | set e { 0+0 } |
---|
| 606 | if 1 {expr $e} |
---|
| 607 | if 1 $e |
---|
| 608 | } -cleanup { |
---|
| 609 | rename 0+0 {} |
---|
| 610 | } -result SCRIPT |
---|
| 611 | test execute-6.5 {TclCompEvalObj: bytecode epoch validation} { |
---|
| 612 | set script { llength {} } |
---|
| 613 | set result {} |
---|
| 614 | lappend result [if 1 $script] |
---|
| 615 | set origName [namespace which llength] |
---|
| 616 | rename $origName llength.orig |
---|
| 617 | proc $origName {args} {return AHA!} |
---|
| 618 | lappend result [if 1 $script] |
---|
| 619 | rename $origName {} |
---|
| 620 | rename llength.orig $origName |
---|
| 621 | set result |
---|
| 622 | } {0 AHA!} |
---|
| 623 | test execute-6.6 {TclCompEvalObj: proc-body bytecode invalid for script} { |
---|
| 624 | proc foo {} {set a 1} |
---|
| 625 | set a untouched |
---|
| 626 | set result {} |
---|
| 627 | lappend result [foo] $a |
---|
| 628 | lappend result [if 1 [info body foo]] $a |
---|
| 629 | rename foo {} |
---|
| 630 | set result |
---|
| 631 | } {1 untouched 1 1} |
---|
| 632 | test execute-6.7 {TclCompEvalObj: bytecode context validation} { |
---|
| 633 | set script { llength {} } |
---|
| 634 | namespace eval foo { |
---|
| 635 | proc llength {args} {return AHA!} |
---|
| 636 | } |
---|
| 637 | set result {} |
---|
| 638 | lappend result [if 1 $script] |
---|
| 639 | lappend result [namespace eval foo $script] |
---|
| 640 | namespace delete foo |
---|
| 641 | set result |
---|
| 642 | } {0 AHA!} |
---|
| 643 | test execute-6.8 {TclCompEvalObj: bytecode name resolution epoch validation} { |
---|
| 644 | set script { llength {} } |
---|
| 645 | set result {} |
---|
| 646 | lappend result [namespace eval foo $script] |
---|
| 647 | namespace eval foo { |
---|
| 648 | proc llength {args} {return AHA!} |
---|
| 649 | } |
---|
| 650 | lappend result [namespace eval foo $script] |
---|
| 651 | namespace delete foo |
---|
| 652 | set result |
---|
| 653 | } {0 AHA!} |
---|
| 654 | test execute-6.9 {TclCompEvalObj: bytecode interp validation} { |
---|
| 655 | set script { llength {} } |
---|
| 656 | interp create slave |
---|
| 657 | slave eval {proc llength args {return AHA!}} |
---|
| 658 | set result {} |
---|
| 659 | lappend result [if 1 $script] |
---|
| 660 | lappend result [slave eval $script] |
---|
| 661 | interp delete slave |
---|
| 662 | set result |
---|
| 663 | } {0 AHA!} |
---|
| 664 | test execute-6.10 {TclCompEvalObj: bytecode interp validation} { |
---|
| 665 | set script { llength {} } |
---|
| 666 | interp create slave |
---|
| 667 | set result {} |
---|
| 668 | lappend result [slave eval $script] |
---|
| 669 | interp delete slave |
---|
| 670 | interp create slave |
---|
| 671 | lappend result [slave eval $script] |
---|
| 672 | interp delete slave |
---|
| 673 | set result |
---|
| 674 | } {0 0} |
---|
| 675 | test execute-6.11 {Tcl_ExprObj: exprcode interp validation} testexprlongobj { |
---|
| 676 | set e { [llength {}]+1 } |
---|
| 677 | set result {} |
---|
| 678 | interp create slave |
---|
| 679 | load {} Tcltest slave |
---|
| 680 | interp alias {} e slave testexprlongobj |
---|
| 681 | lappend result [e $e] |
---|
| 682 | interp delete slave |
---|
| 683 | interp create slave |
---|
| 684 | load {} Tcltest slave |
---|
| 685 | interp alias {} e slave testexprlongobj |
---|
| 686 | lappend result [e $e] |
---|
| 687 | interp delete slave |
---|
| 688 | set result |
---|
| 689 | } {{This is a result: 1} {This is a result: 1}} |
---|
| 690 | test execute-6.12 {Tcl_ExprObj: exprcode interp validation} { |
---|
| 691 | set e { [llength {}]+1 } |
---|
| 692 | set result {} |
---|
| 693 | interp create slave |
---|
| 694 | interp alias {} e slave expr |
---|
| 695 | lappend result [e $e] |
---|
| 696 | interp delete slave |
---|
| 697 | interp create slave |
---|
| 698 | interp alias {} e slave expr |
---|
| 699 | lappend result [e $e] |
---|
| 700 | interp delete slave |
---|
| 701 | set result |
---|
| 702 | } {1 1} |
---|
| 703 | test execute-6.13 {Tcl_ExprObj: exprcode epoch validation} { |
---|
| 704 | set e { [llength {}]+1 } |
---|
| 705 | set result {} |
---|
| 706 | lappend result [expr $e] |
---|
| 707 | set origName [namespace which llength] |
---|
| 708 | rename $origName llength.orig |
---|
| 709 | proc $origName {args} {return 1} |
---|
| 710 | lappend result [expr $e] |
---|
| 711 | rename $origName {} |
---|
| 712 | rename llength.orig $origName |
---|
| 713 | set result |
---|
| 714 | } {1 2} |
---|
| 715 | test execute-6.14 {Tcl_ExprObj: exprcode context validation} { |
---|
| 716 | set e { [llength {}]+1 } |
---|
| 717 | namespace eval foo { |
---|
| 718 | proc llength {args} {return 1} |
---|
| 719 | } |
---|
| 720 | set result {} |
---|
| 721 | lappend result [expr $e] |
---|
| 722 | lappend result [namespace eval foo {expr $e}] |
---|
| 723 | namespace delete foo |
---|
| 724 | set result |
---|
| 725 | } {1 2} |
---|
| 726 | test execute-6.15 {Tcl_ExprObj: exprcode name resolution epoch validation} { |
---|
| 727 | set e { [llength {}]+1 } |
---|
| 728 | set result {} |
---|
| 729 | lappend result [namespace eval foo {expr $e}] |
---|
| 730 | namespace eval foo { |
---|
| 731 | proc llength {args} {return 1} |
---|
| 732 | } |
---|
| 733 | lappend result [namespace eval foo {expr $e}] |
---|
| 734 | namespace delete foo |
---|
| 735 | set result |
---|
| 736 | } {1 2} |
---|
| 737 | test execute-6.16 {Tcl_ExprObj: exprcode interp validation} { |
---|
| 738 | set e { [llength {}]+1 } |
---|
| 739 | interp create slave |
---|
| 740 | interp alias {} e slave expr |
---|
| 741 | slave eval {proc llength args {return 1}} |
---|
| 742 | set result {} |
---|
| 743 | lappend result [expr $e] |
---|
| 744 | lappend result [e $e] |
---|
| 745 | interp delete slave |
---|
| 746 | set result |
---|
| 747 | } {1 2} |
---|
| 748 | test execute-6.17 {Tcl_ExprObj: exprcode context validation} { |
---|
| 749 | set e { $v } |
---|
| 750 | proc foo e {set v 0; expr $e} |
---|
| 751 | proc bar e {set v 1; expr $e} |
---|
| 752 | set result {} |
---|
| 753 | lappend result [foo $e] |
---|
| 754 | lappend result [bar $e] |
---|
| 755 | rename foo {} |
---|
| 756 | rename bar {} |
---|
| 757 | set result |
---|
| 758 | } {0 1} |
---|
| 759 | test execute-6.18 {Tcl_ExprObj: exprcode context validation} { |
---|
| 760 | set e { [llength $v] } |
---|
| 761 | proc foo e {set v {}; expr $e} |
---|
| 762 | proc bar e {set v v; expr $e} |
---|
| 763 | set result {} |
---|
| 764 | lappend result [foo $e] |
---|
| 765 | lappend result [bar $e] |
---|
| 766 | rename foo {} |
---|
| 767 | rename bar {} |
---|
| 768 | set result |
---|
| 769 | } {0 1} |
---|
| 770 | |
---|
| 771 | test execute-7.0 {Wide int handling in INST_JUMP_FALSE/LAND} { |
---|
| 772 | set x 0x100000000 |
---|
| 773 | expr {$x && 1} |
---|
| 774 | } 1 |
---|
| 775 | test execute-7.1 {Wide int handling in INST_JUMP_FALSE/LAND} { |
---|
| 776 | expr {0x100000000 && 1} |
---|
| 777 | } 1 |
---|
| 778 | test execute-7.2 {Wide int handling in INST_JUMP_FALSE/LAND} { |
---|
| 779 | expr {1 && 0x100000000} |
---|
| 780 | } 1 |
---|
| 781 | test execute-7.3 {Wide int handling in INST_JUMP_FALSE/LAND} { |
---|
| 782 | expr {wide(0x100000000) && 1} |
---|
| 783 | } 1 |
---|
| 784 | test execute-7.4 {Wide int handling in INST_JUMP_FALSE/LAND} { |
---|
| 785 | expr {1 && wide(0x100000000)} |
---|
| 786 | } 1 |
---|
| 787 | test execute-7.5 {Wide int handling in INST_EQ} { |
---|
| 788 | expr {4 == (wide(1)+wide(3))} |
---|
| 789 | } 1 |
---|
| 790 | test execute-7.6 {Wide int handling in INST_EQ and [incr]} { |
---|
| 791 | set x 399999999999 |
---|
| 792 | expr {400000000000 == [incr x]} |
---|
| 793 | } 1 |
---|
| 794 | # wide ints have more bits of precision than doubles, but we convert anyway |
---|
| 795 | test execute-7.7 {Wide int handling in INST_EQ and [incr]} { |
---|
| 796 | set x [expr {wide(1)<<62}] |
---|
| 797 | set y [expr {$x+1}] |
---|
| 798 | expr {double($x) == double($y)} |
---|
| 799 | } 1 |
---|
| 800 | test execute-7.8 {Wide int conversions can change sign} longIs32bit { |
---|
| 801 | set x 0x80000000 |
---|
| 802 | expr {int($x) < wide($x)} |
---|
| 803 | } 1 |
---|
| 804 | test execute-7.9 {Wide int handling in INST_MOD} { |
---|
| 805 | expr {(wide(1)<<60) % ((wide(47)<<45)-1)} |
---|
| 806 | } 316659348800185 |
---|
| 807 | test execute-7.10 {Wide int handling in INST_MOD} { |
---|
| 808 | expr {((wide(1)<<60)-1) % 0x400000000} |
---|
| 809 | } 17179869183 |
---|
| 810 | test execute-7.11 {Wide int handling in INST_LSHIFT} { |
---|
| 811 | expr wide(42)<<30 |
---|
| 812 | } 45097156608 |
---|
| 813 | test execute-7.12 {Wide int handling in INST_LSHIFT} { |
---|
| 814 | expr 12345678901<<3 |
---|
| 815 | } 98765431208 |
---|
| 816 | test execute-7.13 {Wide int handling in INST_RSHIFT} { |
---|
| 817 | expr 0x543210febcda9876>>7 |
---|
| 818 | } 47397893236700464 |
---|
| 819 | test execute-7.14 {Wide int handling in INST_RSHIFT} { |
---|
| 820 | expr wide(0x9876543210febcda)>>7 |
---|
| 821 | } -58286587177206407 |
---|
| 822 | test execute-7.15 {Wide int handling in INST_BITOR} { |
---|
| 823 | expr wide(0x9876543210febcda) | 0x543210febcda9876 |
---|
| 824 | } -2560765885044310786 |
---|
| 825 | test execute-7.16 {Wide int handling in INST_BITXOR} { |
---|
| 826 | expr wide(0x9876543210febcda) ^ 0x543210febcda9876 |
---|
| 827 | } -3727778945703861076 |
---|
| 828 | test execute-7.17 {Wide int handling in INST_BITAND} { |
---|
| 829 | expr wide(0x9876543210febcda) & 0x543210febcda9876 |
---|
| 830 | } 1167013060659550290 |
---|
| 831 | test execute-7.18 {Wide int handling in INST_ADD} { |
---|
| 832 | expr wide(0x7fffffff)+wide(0x7fffffff) |
---|
| 833 | } 4294967294 |
---|
| 834 | test execute-7.19 {Wide int handling in INST_ADD} { |
---|
| 835 | expr 0x7fffffff+wide(0x7fffffff) |
---|
| 836 | } 4294967294 |
---|
| 837 | test execute-7.20 {Wide int handling in INST_ADD} { |
---|
| 838 | expr wide(0x7fffffff)+0x7fffffff |
---|
| 839 | } 4294967294 |
---|
| 840 | test execute-7.21 {Wide int handling in INST_ADD} { |
---|
| 841 | expr double(0x7fffffff)+wide(0x7fffffff) |
---|
| 842 | } 4294967294.0 |
---|
| 843 | test execute-7.22 {Wide int handling in INST_ADD} { |
---|
| 844 | expr wide(0x7fffffff)+double(0x7fffffff) |
---|
| 845 | } 4294967294.0 |
---|
| 846 | test execute-7.23 {Wide int handling in INST_SUB} { |
---|
| 847 | expr 0x123456789a-0x20406080a |
---|
| 848 | } 69530054800 |
---|
| 849 | test execute-7.24 {Wide int handling in INST_MULT} { |
---|
| 850 | expr 0x123456789a*193 |
---|
| 851 | } 15090186251290 |
---|
| 852 | test execute-7.25 {Wide int handling in INST_DIV} { |
---|
| 853 | expr 0x123456789a/193 |
---|
| 854 | } 405116546 |
---|
| 855 | test execute-7.26 {Wide int handling in INST_UPLUS} { |
---|
| 856 | set x 0x123456871234568 |
---|
| 857 | expr {+ $x} |
---|
| 858 | } 81985533099853160 |
---|
| 859 | test execute-7.27 {Wide int handling in INST_UMINUS} { |
---|
| 860 | set x 0x123456871234568 |
---|
| 861 | expr {- $x} |
---|
| 862 | } -81985533099853160 |
---|
| 863 | test execute-7.28 {Wide int handling in INST_LNOT} { |
---|
| 864 | set x 0x123456871234568 |
---|
| 865 | expr {! $x} |
---|
| 866 | } 0 |
---|
| 867 | test execute-7.29 {Wide int handling in INST_BITNOT} { |
---|
| 868 | set x 0x123456871234568 |
---|
| 869 | expr {~ $x} |
---|
| 870 | } -81985533099853161 |
---|
| 871 | test execute-7.30 {Wide int handling in function call} { |
---|
| 872 | set x 0x12345687123456 |
---|
| 873 | incr x |
---|
| 874 | expr {log($x) == log(double($x))} |
---|
| 875 | } 1 |
---|
| 876 | test execute-7.31 {Wide int handling in abs()} { |
---|
| 877 | set x 0xa23456871234568 |
---|
| 878 | incr x |
---|
| 879 | set y 0x123456871234568 |
---|
| 880 | concat [expr {abs($x)}] [expr {abs($y)}] |
---|
| 881 | } {730503879441204585 81985533099853160} |
---|
| 882 | test execute-7.32 {Wide int handling} longIs32bit { |
---|
| 883 | expr {int(1024 * 1024 * 1024 * 1024)} |
---|
| 884 | } 0 |
---|
| 885 | test execute-7.33 {Wide int handling} longIs32bit { |
---|
| 886 | expr {int(0x1 * 1024 * 1024 * 1024 * 1024)} |
---|
| 887 | } 0 |
---|
| 888 | test execute-7.34 {Wide int handling} { |
---|
| 889 | expr {wide(0x1) * 1024 * 1024 * 1024 * 1024} |
---|
| 890 | } 1099511627776 |
---|
| 891 | |
---|
| 892 | test execute-8.1 {Stack protection} -setup { |
---|
| 893 | # If [Bug #804681] has not been properly |
---|
| 894 | # taken care of, this should segfault |
---|
| 895 | proc whatever args {llength $args} |
---|
| 896 | trace add variable ::errorInfo {write unset} whatever |
---|
| 897 | } -body { |
---|
| 898 | expr {1+9/0} |
---|
| 899 | } -cleanup { |
---|
| 900 | trace remove variable ::errorInfo {write unset} whatever |
---|
| 901 | rename whatever {} |
---|
| 902 | } -returnCodes error -match glob -result * |
---|
| 903 | |
---|
| 904 | test execute-8.2 {Stack restoration} -body { |
---|
| 905 | # Test for [Bug #816641], correct restoration |
---|
| 906 | # of the stack top after the stack is grown |
---|
| 907 | proc f {args} { f bee bop } |
---|
| 908 | catch f msg |
---|
| 909 | set msg |
---|
| 910 | } -setup { |
---|
| 911 | # Avoid crashes when system stack size is limited (thread-enabled!) |
---|
| 912 | set limit [interp recursionlimit {}] |
---|
| 913 | interp recursionlimit {} 100 |
---|
| 914 | } -cleanup { |
---|
| 915 | interp recursionlimit {} $limit |
---|
| 916 | } -result {too many nested evaluations (infinite loop?)} |
---|
| 917 | |
---|
| 918 | test execute-8.3 {Stack restoration} -body { |
---|
| 919 | # Test for [Bug #1055676], correct restoration |
---|
| 920 | # of the stack top after the epoch is bumped and |
---|
| 921 | # the stack is grown in a call from a nested evaluation |
---|
| 922 | set arglst [string repeat "a " 1000] |
---|
| 923 | proc f {args} "f $arglst" |
---|
| 924 | proc run {} { |
---|
| 925 | # bump the interp's epoch |
---|
| 926 | rename ::set ::dummy |
---|
| 927 | rename ::dummy ::set |
---|
| 928 | catch f msg |
---|
| 929 | set msg |
---|
| 930 | } |
---|
| 931 | run |
---|
| 932 | } -setup { |
---|
| 933 | # Avoid crashes when system stack size is limited (thread-enabled!) |
---|
| 934 | set limit [interp recursionlimit {}] |
---|
| 935 | interp recursionlimit {} 100 |
---|
| 936 | } -cleanup { |
---|
| 937 | interp recursionlimit {} $limit |
---|
| 938 | } -result {too many nested evaluations (infinite loop?)} |
---|
| 939 | |
---|
| 940 | test execute-9.1 {Interp result resetting [Bug 1522803]} { |
---|
| 941 | set c 0 |
---|
| 942 | catch { |
---|
| 943 | catch {set foo} |
---|
| 944 | expr {1/$c} |
---|
| 945 | } |
---|
| 946 | if {[string match *foo* $::errorInfo]} { |
---|
| 947 | set result "Bad errorInfo: $::errorInfo" |
---|
| 948 | } else { |
---|
| 949 | set result SUCCESS |
---|
| 950 | } |
---|
| 951 | set result |
---|
| 952 | } SUCCESS |
---|
| 953 | |
---|
| 954 | # cleanup |
---|
| 955 | if {[info commands testobj] != {}} { |
---|
| 956 | testobj freeallvars |
---|
| 957 | } |
---|
| 958 | catch {namespace delete {*}[namespace children :: test_ns_*]} |
---|
| 959 | catch {rename foo ""} |
---|
| 960 | catch {rename p ""} |
---|
| 961 | catch {rename {} ""} |
---|
| 962 | catch {rename { } ""} |
---|
| 963 | catch {unset x} |
---|
| 964 | catch {unset y} |
---|
| 965 | catch {unset msg} |
---|
| 966 | ::tcltest::cleanupTests |
---|
| 967 | return |
---|
| 968 | |
---|
| 969 | # Local Variables: |
---|
| 970 | # mode: tcl |
---|
| 971 | # End: |
---|