diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2009-03-24 09:30:06 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2009-03-24 09:30:06 (GMT) |
commit | 08383aee88a03fe8cc880c10b9fc242fe3804ebd (patch) | |
tree | b0a931039f6aab48be0e24f11010a7c0420e3db7 /tests/upvar.test | |
parent | 1d1487bad788b9e5db9a68b1a397db54e23c2875 (diff) | |
download | tcl-08383aee88a03fe8cc880c10b9fc242fe3804ebd.zip tcl-08383aee88a03fe8cc880c10b9fc242fe3804ebd.tar.gz tcl-08383aee88a03fe8cc880c10b9fc242fe3804ebd.tar.bz2 |
Fix [Bug 2673163]
Diffstat (limited to 'tests/upvar.test')
-rw-r--r-- | tests/upvar.test | 113 |
1 files changed, 54 insertions, 59 deletions
diff --git a/tests/upvar.test b/tests/upvar.test index 9e1b2d9..86a5a20 100644 --- a/tests/upvar.test +++ b/tests/upvar.test @@ -1,17 +1,17 @@ # Commands covered: 'upvar', 'namespace upvar' # -# This file contains a collection of tests for one or more of the Tcl -# built-in commands. Sourcing this file into Tcl runs the tests and -# generates output for errors. No output means no errors were found. +# This file contains a collection of tests for one or more of the Tcl built-in +# commands. Sourcing this file into Tcl runs the tests and generates output +# for errors. No output means no errors were found. # # Copyright (c) 1991-1993 The Regents of the University of California. # Copyright (c) 1994 Sun Microsystems, Inc. # Copyright (c) 1998-1999 by Scriptics Corporation. # -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# See the file "license.terms" for information on usage and redistribution of +# this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: upvar.test,v 1.18 2008/10/14 18:49:47 dgp Exp $ +# RCS: @(#) $Id: upvar.test,v 1.19 2009/03/24 09:30:07 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -19,7 +19,7 @@ if {[lsearch [namespace children] ::tcltest] == -1} { } testConstraint testupvar [llength [info commands testupvar]] - + test upvar-1.1 {reading variables with upvar} { proc p1 {a b} {set c 22; set d 33; p2} proc p2 {} {upvar a x1 b x2 c x3 d x4; set a abc; list $x1 $x2 $x3 $x4 $a} @@ -290,58 +290,64 @@ test upvar-7.5 {potential memory leak when deleting variable table} { leak } {} -test upvar-8.1 {errors in upvar command} { - list [catch upvar msg] $msg -} {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}} -test upvar-8.2 {errors in upvar command} { - list [catch {upvar 1} msg] $msg -} {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}} -test upvar-8.3 {errors in upvar command} { +test upvar-8.1 {errors in upvar command} -returnCodes error -body { + upvar +} -result {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"} +test upvar-8.2 {errors in upvar command} -returnCodes error -body { + upvar 1 +} -result {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"} +test upvar-8.2.1 {upvar with numeric first argument} { + apply {{} {set 0 ok; apply {{} {upvar 0 x; return $x}}}} +} ok +test upvar-8.3 {errors in upvar command} -returnCodes error -body { proc p1 {} {upvar a b c} - list [catch p1 msg] $msg -} {1 {wrong # args: should be "upvar ?level? otherVar localVar ?otherVar localVar ...?"}} -test upvar-8.4 {errors in upvar command} { + p1 +} -result {bad level "a"} +test upvar-8.4 {errors in upvar command} -returnCodes error -body { proc p1 {} {upvar 0 b b} - list [catch p1 msg] $msg -} {1 {can't upvar from variable to itself}} -test upvar-8.5 {errors in upvar command} { + p1 +} -result {can't upvar from variable to itself} +test upvar-8.5 {errors in upvar command} -returnCodes error -body { proc p1 {} {upvar 0 a b; upvar 0 b a} - list [catch p1 msg] $msg -} {1 {can't upvar from variable to itself}} -test upvar-8.6 {errors in upvar command} { + p1 +} -result {can't upvar from variable to itself} +test upvar-8.6 {errors in upvar command} -returnCodes error -body { proc p1 {} {set a 33; upvar b a} - list [catch p1 msg] $msg -} {1 {variable "a" already exists}} -test upvar-8.7 {errors in upvar command} { + p1 +} -result {variable "a" already exists} +test upvar-8.7 {errors in upvar command} -returnCodes error -body { proc p1 {} {trace variable a w foo; upvar b a} - list [catch p1 msg] $msg -} {1 {variable "a" has traces: can't use for upvar}} + p1 +} -result {variable "a" has traces: can't use for upvar} test upvar-8.8 {create nested array with upvar} -body { proc p1 {} {upvar x(a) b; set b(2) 44} catch {unset x} - list [catch p1 msg] $msg -} -cleanup { + p1 +} -returnCodes error -cleanup { unset x -} -result {1 {can't set "b(2)": variable isn't array}} -test upvar-8.9 {upvar won't create namespace variable that refers to procedure variable} { +} -result {can't set "b(2)": variable isn't array} +test upvar-8.9 {upvar won't create namespace variable that refers to procedure variable} -setup { catch {namespace delete {*}[namespace children :: test_ns_*]} catch {rename MakeLink ""} namespace eval ::test_ns_1 {} +} -returnCodes error -body { proc MakeLink {a} { - namespace eval ::test_ns_1 { + namespace eval ::test_ns_1 { upvar a a - } - unset ::test_ns_1::a + } + unset ::test_ns_1::a } - list [catch {MakeLink 1} msg] $msg -} {1 {bad variable name "a": upvar won't create namespace variable that refers to procedure variable}} -test upvar-8.10 {upvar will create element alias for new array element} { + MakeLink 1 +} -result {bad variable name "a": upvar won't create namespace variable that refers to procedure variable} +test upvar-8.10 {upvar will create element alias for new array element} -setup { catch {unset upvarArray} +} -body { array set upvarArray {} catch {upvar 0 upvarArray(elem) upvarArrayElemAlias} -} {0} -test upvar-8.11 {upvar will not create a variable that looks like an array} -body { +} -result {0} +test upvar-8.11 {upvar will not create a variable that looks like an array} -setup { catch {unset upvarArray} +} -body { array set upvarArray {} upvar 0 upvarArray(elem) upvarArrayElemAlias(elem) } -returnCodes 1 -match glob -result * @@ -407,23 +413,19 @@ test upvar-9.7 {Tcl_UpVar procedure} testupvar { } {1234} catch {unset a} - # # Tests for 'namespace upvar'. As the implementation is essentially the same as -# for 'upvar', we only test that the variables are linked correctly. Ie, we -# assume that the behaviour of variables once the link is established has +# for 'upvar', we only test that the variables are linked correctly, i.e., we +# assume that the behaviour of variables once the link is established has # already been tested above. # -# # Clear out any namespaces called test_ns_* catch {namespace delete {*}[namespace children :: test_ns_*]} - namespace eval test_ns_0 { variable x test_ns_0 } - -set x test_global +set ::x test_global test upvar-NS-1.1 {nsupvar links to correct variable} \ -body { @@ -434,7 +436,6 @@ test upvar-NS-1.1 {nsupvar links to correct variable} \ } \ -result {test_ns_0} \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.2 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -447,7 +448,6 @@ test upvar-NS-1.2 {nsupvar links to correct variable} \ } \ -result {test_ns_0} \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.3 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -458,7 +458,6 @@ test upvar-NS-1.3 {nsupvar links to correct variable} \ -result {namespace "test_ns_0" not found in "::test_ns_1"} \ -returnCodes error \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.4 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -472,7 +471,6 @@ test upvar-NS-1.4 {nsupvar links to correct variable} \ -result {namespace "test_ns_0" not found in "::test_ns_1"} \ -returnCodes error \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.5 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -484,7 +482,6 @@ test upvar-NS-1.5 {nsupvar links to correct variable} \ -result {can't read "w": no such variable} \ -returnCodes error \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.6 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -499,7 +496,6 @@ test upvar-NS-1.6 {nsupvar links to correct variable} \ -result {can't read "w": no such variable} \ -returnCodes error \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.7 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -512,7 +508,6 @@ test upvar-NS-1.7 {nsupvar links to correct variable} \ } \ -result {test_ns_1::test_ns_0} \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.8 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -528,7 +523,6 @@ test upvar-NS-1.8 {nsupvar links to correct variable} \ } \ -result {test_ns_1::test_ns_0} \ -cleanup {namespace delete test_ns_1} - test upvar-NS-1.9 {nsupvar links to correct variable} \ -body { namespace eval test_ns_1 { @@ -547,7 +541,6 @@ test upvar-NS-1.9 {nsupvar links to correct variable} \ test upvar-NS-2.1 {TIP 323} -returnCodes error -body { namespace upvar } -result {wrong # args: should be "namespace upvar ns ?otherVar myVar ...?"} - test upvar-NS-2.2 {TIP 323} -setup { namespace eval test_ns_1 {} } -body { @@ -555,9 +548,11 @@ test upvar-NS-2.2 {TIP 323} -setup { } -cleanup { namespace delete test_ns_1 } -result {} - - - + # cleanup ::tcltest::cleanupTests return + +# Local Variables: +# mode: tcl +# End: |