1 # Commands covered: uplevel
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: uplevel.test,v 1.6 2000/04/10 17:19:05 ericm Exp $
16 source [file dirname [info script]]/testing.tcl
22 proc newset {name value} {
23 uplevel set $name $value
24 uplevel 1 {uplevel 1 {set xyz 22}}
30 test uplevel-1.1 {simple operation} {
34 test uplevel-1.2 {command is another uplevel command} {
61 test uplevel-2.1 {relative and absolute uplevel} {set a} 333
62 test uplevel-2.2 {relative and absolute uplevel} {set a1} 444
63 test uplevel-2.3 {relative and absolute uplevel} {set b} 111
64 test uplevel-2.4 {relative and absolute uplevel} {set b1} 222
65 test uplevel-2.5 {relative and absolute uplevel} {set x} 555
66 test uplevel-2.6 {relative and absolute uplevel} {set y} 666
68 test uplevel-3.1 {uplevel to same level} {
73 test uplevel-3.2 {uplevel to same level} {
77 test uplevel-3.3 {uplevel to same level} {
79 proc a1 {} {set y 55; uplevel 0 set y 66; return $y}
82 test uplevel-3.4 {uplevel to same level} {
84 proc a1 {} {set y 55; uplevel #1 set y}
88 test uplevel-4.1 {error check: non-existent level} {
89 list [catch c1 msg] $msg
90 } {1 {bad level "#2"}}
91 test uplevel-4.2 {error check: non-existent level} {
92 proc c2 {} {uplevel 3 {set a b}}
93 list [catch c2 msg] $msg
95 test uplevel-4.3 {error check: not enough args} {
96 list [catch uplevel msg] $msg
97 } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
98 test uplevel-4.4 {error check: not enough args} {
99 proc upBug {} {uplevel 1}
100 list [catch upBug msg] $msg
101 } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
112 test uplevel-5.1 {info level} {set x} 1
113 test uplevel-5.2 {info level} {set y} a3
115 test uplevel-6.1 {uplevel #0} {
120 test uplevel-6.2 {uplevel #bad} {
121 catch {uplevel #bad set x 1}