os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/upvar.test
Update contrib.
1 # Commands covered: upvar
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: upvar.test,v 1.7 2000/04/10 17:19:05 ericm Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
21 test upvar-1.1 {reading variables with upvar} {
22 proc p1 {a b} {set c 22; set d 33; p2}
23 proc p2 {} {upvar a x1 b x2 c x3 d x4; set a abc; list $x1 $x2 $x3 $x4 $a}
26 test upvar-1.2 {reading variables with upvar} {
27 proc p1 {a b} {set c 22; set d 33; p2}
29 proc p3 {} {upvar 2 a x1 b x2 c x3 d x4; set a abc; list $x1 $x2 $x3 $x4 $a}
32 test upvar-1.3 {reading variables with upvar} {
33 proc p1 {a b} {set c 22; set d 33; p2}
36 upvar #1 a x1 b x2 c x3 d x4
38 list $x1 $x2 $x3 $x4 $a
42 test upvar-1.4 {reading variables with upvar} {
55 test upvar-1.5 {reading array elements with upvar} {
56 proc p1 {} {set a(0) zeroth; set a(1) first; p2}
57 proc p2 {} {upvar a(0) x; set x}
61 test upvar-2.1 {writing variables with upvar} {
62 proc p1 {a b} {set c 22; set d 33; p2; list $a $b $c $d}
64 upvar a x1 b x2 c x3 d x4
70 test upvar-2.2 {writing variables with upvar} {
82 test upvar-2.3 {writing variables with upvar} {
92 list [catch {set x1} msg] $msg [catch {set x2} msg] $msg
93 } {0 newbits 0 morebits}
94 test upvar-2.4 {writing array elements with upvar} {
95 proc p1 {} {set a(0) zeroth; set a(1) first; list [p2] $a(0)}
96 proc p2 {} {upvar a(0) x; set x xyzzy}
100 test upvar-3.1 {unsetting variables with upvar} {
101 proc p1 {a b} {set c 22; set d 33; p2; lsort [info vars]}
108 test upvar-3.2 {unsetting variables with upvar} {
109 proc p1 {a b} {set c 22; set d 33; p2; lsort [info vars]}
117 test upvar-3.3 {unsetting variables with upvar} {
127 list [info exists x1] [info exists x2]
129 test upvar-3.4 {unsetting variables with upvar} {
138 list [info exists x1] [catch {set x2} msg] $msg
140 test upvar-3.5 {unsetting array elements with upvar} {
148 proc p2 {} {upvar a(0) x; unset x}
151 test upvar-3.6 {unsetting then resetting array elements with upvar} {
157 list [array names a] [catch {set a(0)} msg] $msg
159 proc p2 {} {upvar a(0) x; unset x; set x 12345}
163 test upvar-4.1 {nested upvars} {
165 proc p1 {a b} {set c 22; set d 33; p2}
166 proc p2 {} {global x1; upvar c x2; p3}
173 test upvar-4.2 {nested upvars} {
175 proc p1 {a b} {set c 22; set d 33; p2; list $a $b $c $d}
176 proc p2 {} {global x1; upvar c x2; p3}
183 } {{14 15 bar 33} foo}
185 proc tproc {args} {global x; set x [list $args [uplevel info vars]]}
186 test upvar-5.1 {traces involving upvars} {
187 proc p1 {a b} {set c 22; set d 33; trace var c rw tproc; p2}
188 proc p2 {} {upvar c x1; set x1 22}
193 test upvar-5.2 {traces involving upvars} {
194 proc p1 {a b} {set c 22; set d 33; trace var c rw tproc; p2}
195 proc p2 {} {upvar c x1; set x1}
200 test upvar-5.3 {traces involving upvars} {
201 proc p1 {a b} {set c 22; set d 33; trace var c rwu tproc; p2}
202 proc p2 {} {upvar c x1; unset x1}
208 test upvar-6.1 {retargeting an upvar} {
218 foreach i [array names x] {
225 } {first second zeroth}
226 test upvar-6.2 {retargeting an upvar} {
237 test upvar-6.3 {retargeting an upvar} {
249 test upvar-7.1 {upvar to same level} {
259 test upvar-7.2 {upvar to same level} {
269 test upvar-7.3 {upvar to same level} {
279 test upvar-7.4 {upvar to same level: tricky problems when deleting variable table} {
280 proc tt {} {upvar #1 toto loc; return $loc}
281 list [catch tt msg] $msg
282 } {1 {can't read "loc": no such variable}}
283 test upvar-7.5 {potential memory leak when deleting variable table} {
285 array set foo {1 2 3 4}
291 test upvar-8.1 {errors in upvar command} {
292 list [catch upvar msg] $msg
293 } {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}}
294 test upvar-8.2 {errors in upvar command} {
295 list [catch {upvar 1} msg] $msg
296 } {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}}
297 test upvar-8.3 {errors in upvar command} {
298 proc p1 {} {upvar a b c}
299 list [catch p1 msg] $msg
300 } {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}}
301 test upvar-8.4 {errors in upvar command} {
302 proc p1 {} {upvar 0 b b}
303 list [catch p1 msg] $msg
304 } {1 {can't upvar from variable to itself}}
305 test upvar-8.5 {errors in upvar command} {
306 proc p1 {} {upvar 0 a b; upvar 0 b a}
307 list [catch p1 msg] $msg
308 } {1 {can't upvar from variable to itself}}
309 test upvar-8.6 {errors in upvar command} {
310 proc p1 {} {set a 33; upvar b a}
311 list [catch p1 msg] $msg
312 } {1 {variable "a" already exists}}
313 test upvar-8.7 {errors in upvar command} {
314 proc p1 {} {trace variable a w foo; upvar b a}
315 list [catch p1 msg] $msg
316 } {1 {variable "a" has traces: can't use for upvar}}
317 test upvar-8.8 {create nested array with upvar} {
318 proc p1 {} {upvar x(a) b; set b(2) 44}
320 list [catch p1 msg] $msg
321 } {1 {can't set "b(2)": variable isn't array}}
322 test upvar-8.9 {upvar won't create namespace variable that refers to procedure variable} {
323 catch {eval namespace delete [namespace children :: test_ns_*]}
324 catch {rename MakeLink ""}
325 namespace eval ::test_ns_1 {}
327 namespace eval ::test_ns_1 {
332 list [catch {MakeLink 1} msg] $msg
333 } {1 {bad variable name "a": upvar won't create namespace variable that refers to procedure variable}}
334 test upvar-8.10 {upvar will create element alias for new array element} {
335 catch {unset upvarArray}
336 array set upvarArray {}
337 catch {upvar 0 upvarArray(elem) upvarArrayElemAlias}
340 if {[info commands testupvar] != {}} {
341 test upvar-9.1 {Tcl_UpVar2 procedure} {
342 list [catch {testupvar xyz a {} x global} msg] $msg
343 } {1 {bad level "xyz"}}
344 test upvar-9.2 {Tcl_UpVar2 procedure} {
348 list [catch {testupvar #0 a 1 x global} msg] $msg
349 } {1 {can't access "a(1)": variable isn't array}}
350 test upvar-9.3 {Tcl_UpVar2 procedure} {
352 testupvar 1 a {} x local
360 test upvar-9.4 {Tcl_UpVar2 procedure} {
362 testupvar 1 a {} _up_ global
363 list [catch {set x} msg] $msg
369 } {1 {can't read "x": no such variable} 44}
370 test upvar-9.5 {Tcl_UpVar2 procedure} {
372 testupvar 1 a b x local
380 test upvar-9.6 {Tcl_UpVar procedure} {
382 testupvar 1 a x local
390 test upvar-9.7 {Tcl_UpVar procedure} {
392 testupvar #0 a(b) x local
404 ::tcltest::cleanupTests