# UplevelCmd.test --
#
#	Tests the implementation of the UplevelCmd.java file.
#
# Copyright (c) 1997 by Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# SCCS: @(#) UplevelCmd.test 1.2 98/01/14 16:38:53

# Note: This test file must be sourced from the parent directory
#       or else the defs file may not be properly loaded.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import -force ::tcltest::*
}

setupJavaPackage

test UplevelCmd-1.1 {UplevelCmd.cmdProc} {
    list [catch {uplevel} msg] $msg
} {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}

test UplevelCmd-1.2 {UplevelCmd.cmdProc} {
    list [catch {uplevel set x 10} msg] $msg
} {1 {bad level "set"}}

test UplevelCmd-1.3 {UplevelCmd.cmdProc} {
    proc foo {} {
	uplevel set x 10
    }
    set x 0
    list [catch {foo} msg] $msg $x
} {0 10 10}

test UplevelCmd-1.4 {UplevelCmd.cmdProc} {
    list [catch {uplevel #0} msg] $msg
} {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}

test UplevelCmd-1.5 {UplevelCmd.cmdProc} {
    proc foo {} {
	uplevel #0
    }
    list [catch {foo} msg] $msg
} {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}

test UplevelCmd-2.1 {UplevelCmd.cmdProc, concat objects only when necessary} {
    set x {jtest ref $x}
    list [uplevel #0 $x] [jtest ref $x]
} {4 2}

test UplevelCmd-2.2 {UplevelCmd.cmdProc, concat objects only when necessary} {
    proc foo {} {
	global x
	set x {jtest ref $x}
	list [uplevel $x] [jtest ref $x]
    }
    foo
} {4 2}

test UplevelCmd-3.1 {UplevelCmd.cmdProc, error info} {
    list [catch {uplevel #0 error xx} msg] $msg $errorInfo
} {1 xx {xx
    while executing
"error xx"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 error xx"}}

test UplevelCmd-3.2 {UplevelCmd.cmdProc, error info} {
    proc foo {code} {
	return -code $code xx
    }
    set errorInfo ""
    list [catch {uplevel #0 foo return} msg] $msg $errorInfo
} {2 xx {}} 

test UplevelCmd-3.3 {UplevelCmd.cmdProc, error info} {
    proc foo {code} {
	return -code $code xx
    }
    set errorInfo ""
    list [catch {uplevel #0 foo break} msg] $msg $errorInfo
} {3 xx {}} 

test UplevelCmd-3.4 {UplevelCmd.cmdProc, error info} {
    proc foo {code} {
	return -code $code xx
    }
    set errorInfo ""
    list [catch {uplevel #0 foo 1234} msg] $msg $errorInfo
} {1234 xx {}} 
