1 # This file contains tests for the tclVar.c source file. Tests appear in the
2 # 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 variable-related tests appear in
5 # several other test files including namespace.test, set.test, trace.test, and
8 # Sourcing this file into Tcl runs the tests and generates output for errors.
9 # No output means no errors were found.
11 # Copyright (c) 1997 Sun Microsystems, Inc.
12 # Copyright (c) 1998-1999 by Scriptics Corporation.
14 # See the file "license.terms" for information on usage and redistribution of
15 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
17 if {"::tcltest" ni [namespace children]} {
18 package require tcltest 2.5
19 namespace import -force ::tcltest::*
22 ::tcltest::loadTestedCommands
23 catch [list package require -exact Tcltest [info patchlevel]]
25 testConstraint testupvar [llength [info commands testupvar]]
26 testConstraint testgetvarfullname [llength [info commands testgetvarfullname]]
27 testConstraint testsetnoerr [llength [info commands testsetnoerr]]
28 testConstraint memory [llength [info commands memory]]
29 if {[testConstraint memory]} {
31 return [lindex [split [memory info] \n] 3 3]
33 proc leaktest {script {iterations 3}} {
35 for {set i 0} {$i < $iterations} {incr i} {
40 return [expr {$end - $tmp}]
45 catch {namespace delete test_ns_var}
53 test var-1.1 {TclLookupVar, Array handling} -setup {
56 set x "incr" ;# force no compilation and runtime call to Tcl_IncrCmd
59 list [$x i] $i [$x arr(foo)] $arr(foo)
60 } -result {11 11 38 38}
61 set ::x "global value"
62 namespace eval test_ns_var {
63 variable x "namespace value"
65 test var-1.2 {TclLookupVar, TCL_GLOBAL_ONLY implies global namespace var} {
66 namespace eval test_ns_var {
68 global x ;# specifies TCL_GLOBAL_ONLY to get global x
74 test var-1.3 {TclLookupVar, TCL_NAMESPACE_ONLY implies namespace var} {
75 namespace eval test_ns_var {
77 variable x ;# specifies TCL_NAMESPACE_ONLY to get namespace x
83 test var-1.4 {TclLookupVar, no active call frame implies global namespace var} {
86 test var-1.5 {TclLookupVar, active call frame pushed for namespace eval implies namespace var} {
87 namespace eval test_ns_var {set x}
89 test var-1.6 {TclLookupVar, name starts with :: implies some namespace var} {
90 namespace eval test_ns_var {set ::x}
92 test var-1.7 {TclLookupVar, error finding namespace var} -body {
94 } -returnCodes error -result {can't read "a:::b": no such variable}
95 test var-1.8 {TclLookupVar, error finding namespace var} -body {
97 } -returnCodes error -result {can't read "::foobarfoo": no such variable}
98 test var-1.9 {TclLookupVar, create new namespace var} {
99 namespace eval test_ns_var {
103 test var-1.10 {TclLookupVar, create new namespace var} -setup {
106 namespace eval test_ns_var {
111 test var-1.11 {TclLookupVar, error creating new namespace var} -body {
112 namespace eval test_ns_var {
113 set ::test_ns_var::foo::bar 314159
115 } -returnCodes error -result {can't set "::test_ns_var::foo::bar": parent namespace doesn't exist}
116 test var-1.12 {TclLookupVar, error creating new namespace var} -body {
117 namespace eval test_ns_var {
118 set ::test_ns_var::foo:: 1997
120 } -returnCodes error -result {can't set "::test_ns_var::foo::": parent namespace doesn't exist}
121 test var-1.13 {TclLookupVar, new namespace var is created in a particular namespace} {
122 catch {unset aNeWnAmEiNnS}
123 namespace eval test_ns_var {
124 namespace eval test_ns_var2::test_ns_var3 {
125 set aNeWnAmEiNnS 77777
127 # namespace which builds a name by traversing nsPtr chain to ::
128 namespace which -variable test_ns_var2::test_ns_var3::aNeWnAmEiNnS
130 } {::test_ns_var::test_ns_var2::test_ns_var3::aNeWnAmEiNnS}
131 test var-1.14 {TclLookupVar, namespace code ignores ":"s in middle and end of var names} {
132 namespace eval test_ns_var {
136 list [set :] [set v:] [set x:y:] \
138 [expr {":" in [info vars]}] \
139 [expr {"v:" in [info vars]}] \
140 [expr {"x:y:" in [info vars]}]
142 } {123 456 789 123 456 789 1 1 1}
143 test var-1.15 {TclLookupVar, resurrect variable via upvar to deleted namespace: compiled code path} {
144 namespace eval test_ns_var {
148 variable ::test_ns_var::foo
149 lappend result [catch {set foo} msg] $msg
150 namespace delete ::test_ns_var
151 lappend result [catch {set foo 3} msg] $msg
152 lappend result [catch {set foo(3) 3} msg] $msg
155 } {0 2 1 {can't set "foo": upvar refers to variable in deleted namespace} 1 {can't set "foo(3)": upvar refers to variable in deleted namespace}}
156 test var-1.16 {TclLookupVar, resurrect variable via upvar to deleted namespace: uncompiled code path} {
157 namespace eval test_ns_var {
159 namespace eval subns {
162 upvar 0 subns::foo foo
163 lappend result [catch {set foo} msg] $msg
164 namespace delete subns
165 lappend result [catch {set foo 3} msg] $msg
166 lappend result [catch {set foo(3) 3} msg] $msg
167 namespace delete [namespace current]
170 } {0 2 1 {can't set "foo": upvar refers to variable in deleted namespace} 1 {can't set "foo(3)": upvar refers to variable in deleted namespace}}
171 test var-1.17 {TclLookupVar, resurrect array element via upvar to deleted array: compiled code path} {
172 namespace eval test_ns_var {
175 array set x {1 2 3 4}
177 lappend result [catch {set foo} msg] $msg
179 lappend result [catch {set foo 3} msg] $msg
182 namespace delete [namespace current]
185 } {0 2 1 {can't set "foo": upvar refers to element in deleted array}}
186 test var-1.18 {TclLookupVar, resurrect array element via upvar to deleted array: uncompiled code path} -setup {
187 unset -nocomplain test_ns_var::x
189 namespace eval test_ns_var {
192 array set x {1 2 3 4}
194 lappend result [catch {set foo} msg] $msg
196 lappend result [catch {set foo 3} msg] $msg
197 namespace delete [namespace current]
200 } -result {0 2 1 {can't set "foo": upvar refers to element in deleted array}}
201 test var-1.19 {TclLookupVar, right error message when parsing variable name} -body {
202 [format set] thisvar(doesntexist)
203 } -returnCodes error -result {can't read "thisvar(doesntexist)": no such variable}
204 test var-1.20 {TclLookupVar, regression on utf-8 variable names} -setup {
205 proc p [list \u20ac \xe4] {info vars}
207 # test variable with non-ascii name is available (euro and a-uml chars here):
210 [apply [list [list \u20ac \xe4] {info vars}] 1 2] \
211 [apply [list [list [list \u20ac \u20ac] [list \xe4 \xe4]] {info vars}]] \
214 } -result [lrepeat 3 [list \u20ac \xe4]]
215 test var-1.21 {TclLookupVar, regression on utf-8 variable names} -setup {
216 proc p [list [list \u20ac v\u20ac] [list \xe4 v\xe4]] {list [set \u20ac] [set \xe4]}
218 # test variable with non-ascii name (and default) is resolvable (euro and a-uml chars here):
221 [apply [list [list \u20ac \xe4] {list [set \u20ac] [set \xe4]}] v\u20ac v\xe4] \
222 [apply [list [list [list \u20ac v\u20ac] [list \xe4 v\xe4]] {list [set \u20ac] [set \xe4]}]] \
225 } -result [lrepeat 3 [list v\u20ac v\xe4]]
227 test var-2.1 {Tcl_LappendObjCmd, create var if new} {
232 test var-3.1 {MakeUpvar, TCL_NAMESPACE_ONLY not specified for other var} -setup {
237 global x ;# calls MakeUpvar with TCL_NAMESPACE_ONLY for other var x
242 test var-3.2 {MakeUpvar, other var has TCL_NAMESPACE_ONLY specified} {
243 namespace eval test_ns_var {
247 variable v ;# TCL_NAMESPACE_ONLY specified for other var x
253 test var-3.3 {MakeUpvar, my var has TCL_GLOBAL_ONLY specified} -setup {
255 } -constraints testupvar -body {
258 # create global xx linked to global a
259 testupvar 1 a {} xx global
261 list [p] $xx [set xx 789] $a
262 } -result {{} 123321 789 789}
263 test var-3.4 {MakeUpvar, my var has TCL_NAMESPACE_ONLY specified} -setup {
265 } -constraints testupvar -body {
267 namespace eval test_ns_var {
268 catch {unset ::test_ns_var::vv}
270 # create namespace var vv linked to global a
271 testupvar 1 a {} vv namespace
275 list $test_ns_var::vv [set test_ns_var::vv 123] $a
276 } -result {456 123 123}
277 test var-3.5 {MakeUpvar, no call frame so my var will be in global :: ns} -setup {
283 list [set xxxxx] [set aaaaa]
284 } -result {77777 77777}
285 test var-3.6 {MakeUpvar, active call frame pushed for namespace eval} -setup {
289 namespace eval test_ns_var {
294 test var-3.7 {MakeUpvar, my var has ::s} -setup {
298 upvar #0 a test_ns_var::lnk
299 namespace eval test_ns_var {
303 test var-3.8 {MakeUpvar, my var already exists in global ns} -setup {
313 test var-3.9 {MakeUpvar, my var has invalid ns name} -setup {
315 } -returnCodes error -body {
317 upvar #0 aaaaa test_ns_fred::lnk
320 } -result {can't create "test_ns_fred::lnk": parent namespace doesn't exist}
321 test var-3.10 {MakeUpvar, between namespaces} -body {
324 namespace eval foo upvar bar bar
329 test var-3.11 {MakeUpvar, my var looks like array elem} -setup {
331 } -returnCodes error -body {
333 upvar #0 aaaaa foo(bar)
334 } -result {bad variable name "foo(bar)": can't create a scalar variable that looks like an array element}
336 test var-4.1 {Tcl_GetVariableName, global variable} testgetvarfullname {
339 testgetvarfullname a global
341 test var-4.2 {Tcl_GetVariableName, namespace variable} testgetvarfullname {
342 namespace eval test_ns_var {
344 testgetvarfullname george namespace
346 } ::test_ns_var::george
347 test var-4.3 {Tcl_GetVariableName, variable can't be array element} -setup {
349 } -constraints testgetvarfullname -body {
351 testgetvarfullname a(1) global
352 } -returnCodes error -result {unknown variable "a(1)"}
354 test var-5.1 {Tcl_GetVariableFullName, global variable} -setup {
358 namespace which -variable a
360 test var-5.2 {Tcl_GetVariableFullName, namespace variable} {
361 namespace eval test_ns_var {
363 namespace which -variable martha
365 } {::test_ns_var::martha}
366 test var-5.3 {Tcl_GetVariableFullName, namespace variable} -setup {
367 namespace eval test_ns_var {variable martha}
369 namespace which -variable test_ns_var::martha
370 } -result {::test_ns_var::martha}
372 test var-6.1 {Tcl_GlobalObjCmd, variable is qualified by a namespace name} {
373 namespace eval test_ns_var {
377 global ::test_ns_var::boeing
381 test var-6.2 {Tcl_GlobalObjCmd, variable is qualified by a namespace name} {
382 namespace eval test_ns_var {
383 namespace eval test_ns_nested {
387 global ::test_ns_var::test_ns_nested::java
393 test var-6.3 {Tcl_GlobalObjCmd, variable named {} qualified by a namespace name} {
394 namespace eval ::test_ns_var::test_ns_nested {}
395 set ::test_ns_var::test_ns_nested:: 24
397 global ::test_ns_var::test_ns_nested::
401 test var-6.4 {Tcl_GlobalObjCmd, variable name matching :*} {
402 # Test for Tcl Bug 480176
411 test var-6.5 {Tcl_GlobalObjCmd, no-op case (TIP 323)} {
414 test var-6.6 {Tcl_GlobalObjCmd, no-op case (TIP 323)} {
421 test var-7.1 {Tcl_VariableObjCmd, create and initialize one new ns variable} -setup {
422 catch {namespace delete test_ns_var}
424 namespace eval test_ns_var {
427 list [info vars test_ns_var::*] [set test_ns_var::one]
428 } -result {::test_ns_var::one 1}
429 test var-7.2 {Tcl_VariableObjCmd, if new and no value, leave undefined} {
431 namespace eval test_ns_var {
434 list [info exists test_ns_var::two] [catch {set test_ns_var::two} msg] $msg
435 } {0 1 {can't read "test_ns_var::two": no such variable}}
436 test var-7.3 {Tcl_VariableObjCmd, "define" var already created above} -setup {
437 catch {namespace delete test_ns_var}
438 namespace eval test_ns_var {variable one 1}
440 namespace eval test_ns_var {
443 list [lsort [info vars test_ns_var::*]] \
444 [namespace eval test_ns_var {set two}]
445 } -result [list [lsort {::test_ns_var::two ::test_ns_var::one}] 2]
446 test var-7.4 {Tcl_VariableObjCmd, list of vars} -setup {
447 catch {namespace delete test_ns_var}
448 namespace eval test_ns_var {variable one 1; variable two 2}
450 namespace eval test_ns_var {
451 variable three 3 four 4
453 list [lsort [info vars test_ns_var::*]] \
454 [namespace eval test_ns_var {expr {$three+$four}}]
455 } -result [list [lsort {::test_ns_var::four ::test_ns_var::three ::test_ns_var::two ::test_ns_var::one}] 7]
456 test var-7.5 {Tcl_VariableObjCmd, value for last var is optional} -setup {
464 namespace eval test_ns_var {
468 lappend a $test_ns_var::five \
469 [set test_ns_var::six 6] [set test_ns_var::six] $six
473 } -result {5 5 6 6 666}
474 test var-7.6 {Tcl_VariableObjCmd, variable name can be qualified} -setup {
477 namespace eval test_ns_var {
478 variable ::newvar cheers!
484 test var-7.7 {Tcl_VariableObjCmd, bad var name} -returnCodes error -body {
485 namespace eval test_ns_var {
488 } -result {can't define "sev:::en": parent namespace doesn't exist}
489 test var-7.8 {Tcl_VariableObjCmd, if var already exists and no value is given, leave value unchanged} {
491 namespace eval test_ns_var {
499 test var-7.9 {Tcl_VariableObjCmd, mark as namespace var so var persists until namespace is destroyed or var is unset} -setup {
500 catch {namespace delete test_ns_var2}
503 namespace eval test_ns_var2 {
508 lappend a [lsort [info vars test_ns_var2::*]]
509 lappend a [info exists test_ns_var2::x] [info exists test_ns_var2::y] \
510 [info exists test_ns_var2::z]
511 lappend a [list [catch {set test_ns_var2::y} msg] $msg]
512 lappend a [lsort [info vars test_ns_var2::*]]
513 lappend a [info exists test_ns_var2::y] [info exists test_ns_var2::z]
514 lappend a [set test_ns_var2::y hello]
515 lappend a [info exists test_ns_var2::y] [info exists test_ns_var2::z]
516 lappend a [list [catch {unset test_ns_var2::y} msg] $msg]
517 lappend a [lsort [info vars test_ns_var2::*]]
518 lappend a [info exists test_ns_var2::y] [info exists test_ns_var2::z]
519 lappend a [list [catch {unset test_ns_var2::z} msg] $msg]
520 lappend a [namespace delete test_ns_var2]
521 } -result [list [lsort {::test_ns_var2::x ::test_ns_var2::y ::test_ns_var2::z}] 1 0 0\
522 {1 {can't read "test_ns_var2::y": no such variable}}\
523 [lsort {::test_ns_var2::x ::test_ns_var2::y ::test_ns_var2::z}] 0 0\
526 [lsort {::test_ns_var2::x ::test_ns_var2::z}] 0 0\
527 {1 {can't unset "test_ns_var2::z": no such variable}}\
529 test var-7.10 {Tcl_VariableObjCmd, variable cmd inside proc creates local link var} -setup {
530 namespace eval test_ns_var { variable eight 8 }
532 namespace eval test_ns_var {
535 list [set eight] [info vars]
540 test var-7.11 {Tcl_VariableObjCmd, variable cmd inside proc creates local link var} -setup {
541 namespace eval test_ns_var { variable eight 8 }
543 proc p {} { ;# note this proc is at global :: scope
544 variable test_ns_var::eight
545 list [set eight] [info vars]
549 test var-7.12 {Tcl_VariableObjCmd, variable cmd inside proc creates local link var} {
550 namespace eval test_ns_var {
551 variable {} {My name is empty}
553 proc p {} { ;# note this proc is at global :: scope
554 variable test_ns_var::
555 list [set {}] [info vars]
558 } {{My name is empty} {{}}}
559 test var-7.13 {Tcl_VariableObjCmd, variable named ":"} {
560 namespace eval test_ns_var {
561 variable : {My name is ":"}
564 list [set :] [info vars]
568 } {{My name is ":"} :}
569 test var-7.14 {Tcl_VariableObjCmd, array element parameter} -body {
570 namespace eval test_ns_var { variable arrayvar(1) }
571 } -returnCodes error -result "can't define \"arrayvar(1)\": name refers to an element in an array"
572 test var-7.15 {Tcl_VariableObjCmd, array element parameter} -body {
573 namespace eval test_ns_var {
576 variable arrayvar(1) y
578 } -returnCodes error -result "can't define \"arrayvar(1)\": name refers to an element in an array"
579 test var-7.16 {Tcl_VariableObjCmd, no args (TIP 323)} {
582 test var-7.17 {Tcl_VariableObjCmd, no args (TIP 323)} {
583 namespace eval test_ns_var {
588 test var-8.1 {TclDeleteVars, "unset" traces are called with fully-qualified var names} -setup {
589 catch {namespace delete test_ns_var}
592 namespace eval test_ns_var {
595 proc traceUnset {name1 name2 op} {
597 set info [concat $info [list $name1 $name2 $op]]
599 trace var v u [namespace code traceUnset]
601 list [unset test_ns_var::v] $test_ns_var::info
602 } -result {{} {test_ns_var::v {} u}}
603 test var-8.2 {TclDeleteNamespaceVars, "unset" traces on ns delete are called with fully-qualified var names} -setup {
604 catch {namespace delete test_ns_var}
608 namespace eval test_ns_var {
610 trace var v u ::traceUnset
612 proc traceUnset {name1 name2 op} {
613 set ::info [concat $::info [list $name1 $name2 $op]]
615 list [namespace delete test_ns_var] $::info
616 } -result {{} {::test_ns_var::v {} u}}
618 test var-8.3 {TclDeleteNamespaceVars, mem leak} -constraints memory -setup {
626 trace variable v u ::t
634 test var-9.1 {behaviour of TclGet/SetVar simple get/set} -setup {
637 } -constraints testsetnoerr -body {
639 [set u a; testsetnoerr u] \
642 [unset v; testseterr v b]
643 } -result [list {before get a} {before set b} {before get a} {before set b}]
644 test var-9.2 {behaviour of TclGet/SetVar namespace get/set} -setup {
645 catch {namespace delete ns}
646 } -constraints testsetnoerr -body {
647 namespace eval ns {variable u a; variable v}
649 [testsetnoerr ns::u] \
650 [testsetnoerr ns::v b] \
652 [unset ns::v; testseterr ns::v b]
653 } -result [list {before get a} {before set b} {before get a} {before set b}]
654 test var-9.3 {behaviour of TclGetVar no variable} -setup {
656 } -constraints testsetnoerr -body {
658 [catch {testsetnoerr u} res] $res \
659 [catch {testseterr u} res] $res
660 } -result {1 {before get} 1 {can't read "u": no such variable}}
661 test var-9.4 {behaviour of TclGetVar no namespace variable} -setup {
662 catch {namespace delete ns}
663 } -constraints testsetnoerr -body {
666 [catch {testsetnoerr ns::w} res] $res \
667 [catch {testseterr ns::w} res] $res
668 } -result {1 {before get} 1 {can't read "ns::w": no such variable}}
669 test var-9.5 {behaviour of TclGetVar no namespace} -setup {
670 catch {namespace delete ns}
671 } -constraints testsetnoerr -body {
673 [catch {testsetnoerr ns::u} res] $res \
674 [catch {testseterr ns::v} res] $res
675 } -result {1 {before get} 1 {can't read "ns::v": no such variable}}
676 test var-9.6 {behaviour of TclSetVar no namespace} -setup {
677 catch {namespace delete ns}
678 } -constraints testsetnoerr -body {
680 [catch {testsetnoerr ns::v 1} res] $res \
681 [catch {testseterr ns::v 1} res] $res
682 } -result {1 {before set} 1 {can't set "ns::v": parent namespace doesn't exist}}
683 test var-9.7 {behaviour of TclGetVar array variable} -setup {
685 } -constraints testsetnoerr -body {
688 [catch {testsetnoerr arr} res] $res \
689 [catch {testseterr arr} res] $res
690 } -result {1 {before get} 1 {can't read "arr": variable is array}}
691 test var-9.8 {behaviour of TclSetVar array variable} -setup {
693 } -constraints testsetnoerr -body {
696 [catch {testsetnoerr arr 2} res] $res \
697 [catch {testseterr arr 2} res] $res
698 } -result {1 {before set} 1 {can't set "arr": variable is array}}
699 test var-9.9 {behaviour of TclGetVar read trace success} -setup {
702 } -constraints testsetnoerr -body {
703 proc resetvar {val name elem op} {upvar 1 $name v; set v $val}
705 trace var u r [list resetvar 1]
706 trace var v r [list resetvar 2]
710 } -result {{before get 1} {before get 2}}
711 test var-9.10 {behaviour of TclGetVar read trace error} testsetnoerr {
712 proc writeonly args {error "write-only"}
714 trace var v r writeonly
716 [catch {testsetnoerr v} msg] $msg \
717 [catch {testseterr v} msg] $msg
718 } {1 {before get} 1 {can't read "v": write-only}}
719 test var-9.11 {behaviour of TclSetVar write trace success} -setup {
722 } -constraints testsetnoerr -body {
723 proc doubleval {name elem op} {upvar 1 $name v; set v [expr {2 * $v}]}
725 trace var v w doubleval
726 trace var u w doubleval
730 } -result {{before set 4} {before set 6}}
731 test var-9.12 {behaviour of TclSetVar write trace error} testsetnoerr {
732 proc readonly args {error "read-only"}
734 trace var v w readonly
736 [catch {testsetnoerr v 2} msg] $msg $v \
737 [catch {testseterr v 3} msg] $msg $v
738 } {1 {before set} 2 1 {can't set "v": read-only} 3}
740 test var-10.1 {can't nest arrays with array set} -setup {
742 } -returnCodes error -body {
743 array set arr(x) {a 1 b 2}
744 } -result {can't set "arr(x)": variable isn't array}
745 test var-10.2 {can't nest arrays with array set} -setup {
747 } -returnCodes error -body {
749 } -result {can't set "arr(x)": variable isn't array}
751 test var-11.1 {array unset} -setup {
754 array set a { 1,1 a 1,2 b 2,1 c 2,3 d }
756 lsort -dict [array names a]
758 test var-11.2 {array unset} -setup {
761 array set a { 1,1 a 1,2 b }
765 test var-11.3 {array unset errors} -setup {
767 } -returnCodes error -body {
768 array set a { 1,1 a 1,2 b }
769 array unset a pattern too
770 } -result {wrong # args: should be "array unset arrayName ?pattern?"}
772 test var-12.1 {TclFindCompiledLocals, {} array name} {
783 lsort -dictionary [array names {}]
787 test var-13.1 {Tcl_UnsetVar2, unset array with trace set on element} -setup {
790 proc foo {var ind op} {
796 trace variable t(1) u foo
799 set x "If you see this, it worked"
800 } -result "If you see this, it worked"
801 test var-13.2 {unset array with search, bug 46a2410650} -body {
803 array set a {aa 11 bb 22 cc 33 dd 44 ee 55 ff 66}
804 set s [array startsearch a]
805 unset a([array nextelement a $s])
806 array nextelement a $s
808 } -returnCodes error -result {couldn't find search "s-1-a"}
809 test var-13.3 {unset array with search, SIGSEGV, bug 46a2410650} -body {
811 array set a {aa 11 bb 22 cc 33 dd 44 ee 55 ff 66}
812 set s [array startsearch a]
814 array nextelement a $s
816 } -returnCodes error -result {couldn't find search "s-1-a"}
818 test var-14.1 {array names syntax} -body {
819 array names foo bar baz snafu
820 } -returnCodes 1 -match glob -result *
821 test var-14.2 {array names -glob} -body {
822 array names tcl_platform -glob os
825 test var-15.1 {segfault in [unset], [Bug 735335]} {
831 # Note that the variable name has to be
832 # unused previously for the segfault to
835 namespace eval test A useSomeUnlikelyNameHere
836 namespace eval test unset useSomeUnlikelyNameHere
838 test var-15.2 {compiled unset evaluation order, Bug 3970f54c4e} {
839 apply {{} {unset foo [return ok]}}
842 test var-16.1 {CallVarTraces: save/restore interp error state} {
843 trace add variable ::errorCode write " ;#"
844 catch {error foo bar baz}
845 trace remove variable ::errorCode write " ;#"
849 test var-17.1 {TclArraySet [Bug 1669489]} -setup {
850 unset -nocomplain ::a
853 set elements {1 2 3 4}
854 trace add variable a write "string length \$elements ;#"
855 array set a $elements
858 unset -nocomplain ::a ::elements
860 test var-17.2 {TclArraySet Dict shortcut only on pure value} -setup {
861 unset -nocomplain a d
866 trace add variable a write "[list incr [namespace which -variable foo]];#"
870 unset -nocomplain a d foo
873 test var-18.1 {array unset and unset traces: Bug 2939073} -setup {
877 array set x {e 1 i 1}
878 trace add variable x unset {apply {args {
885 # The next command would crash reliably with memory debugging prior to the
893 test var-19.1 {crash when freeing locals hashtable: Bug 3037525} {
894 proc foo {} { catch {upvar 0 dummy \$index} }
895 foo ; # This crashes without the fix for the bug
899 test var-20.1 {array set compilation correctness: Bug 3603163} -setup {
908 test var-20.2 {array set compilation correctness: Bug 3603163} -setup {
917 test var-20.3 {array set compilation correctness: Bug 3603163} -setup {
925 test var-20.4 {array set compilation correctness: Bug 3603163} -setup {
933 test var-20.5 {array set compilation correctness: Bug 3603163} -setup {
938 eval {array set x {a 1}}
942 test var-20.6 {array set compilation correctness: Bug 3603163} -setup {
947 eval {array set x {}}
951 test var-20.7 {array set compilation correctness: Bug 3603163} -setup {
955 eval {array set ::x {a 1}}
959 test var-20.8 {array set compilation correctness: Bug 3603163} -setup {
963 eval {array set ::x {}}
967 test var-20.9 {[bc1a96407a] array set compiled w/ trace} -setup {
970 unset -nocomplain lambda foo
973 lappend lambda [list array set [namespace which -variable foo] {a 1}]
975 after 0 [list apply $lambda]
976 vwait [namespace which -variable foo]
978 unset -nocomplain lambda foo
980 test var-20.10 {[bc1a96407a] array set don't compile bad varname} -body {
981 apply {{} {set name foo(bar); array set $name {a 1}}}
982 } -returnCodes error -match glob -result *
983 test var-20.11 {array set don't compile bad initializer} -setup {
984 unset -nocomplain foo
985 trace add variable foo array {set foo(bar) baz;#}
987 catch {array set foo bad}
990 unset -nocomplain foo
992 test var-20.12 {array set don't compile bad initializer} -setup {
993 unset -nocomplain ::foo
994 trace add variable ::foo array {set ::foo(bar) baz;#}
998 array set ::foo $value
1003 unset -nocomplain ::foo
1006 test var-21.0 {PushVarNameWord OBOE in compiled unset} -setup {
1007 proc linenumber {} {dict get [info frame -1] line}
1012 } [return [incr n -[linenumber]]]
1015 rename linenumber {}
1018 test var-22.0 {leak in array element unset: Bug a3309d01db} -setup {
1020 lindex [split [memory info] \n] 3 3
1025 foreach n [array names A] {
1031 } -constraints memory -body {
1033 for {set i 0} {$i < 5} {incr i} {
1038 set leakedBytes [expr {$end - $tmp}]
1044 test var-22.1 {leak in localVarName internalrep: Bug 80304238ac} -setup {
1046 lindex [split [memory info] \n] 3 3
1055 doit {foreach foo baz {}}
1059 } -constraints memory -body {
1061 for {set i 0} {$i < 5} {incr i} {
1066 set leakedBytes [expr {$end - $tmp}]
1074 catch {namespace delete ns}
1079 catch {namespace delete test_ns_var}
1080 catch {namespace delete test_ns_var2}
1090 ::tcltest::cleanupTests