186 lines
5.5 KiB
Plaintext
186 lines
5.5 KiB
Plaintext
|
# Commands covered: error, catch
|
||
|
#
|
||
|
# 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.
|
||
|
# All rights reserved.
|
||
|
#
|
||
|
# Permission is hereby granted, without written agreement and without
|
||
|
# license or royalty fees, to use, copy, modify, and distribute this
|
||
|
# software and its documentation for any purpose, provided that the
|
||
|
# above copyright notice and the following two paragraphs appear in
|
||
|
# all copies of this software.
|
||
|
#
|
||
|
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
||
|
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
||
|
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
||
|
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
#
|
||
|
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
||
|
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
|
# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||
|
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
||
|
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||
|
#
|
||
|
# $Header: /user6/ouster/tcl/tests/RCS/error.test,v 1.12 93/02/06 15:54:01 ouster Exp $ (Berkeley)
|
||
|
|
||
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
||
|
|
||
|
proc foo {} {
|
||
|
global errorInfo
|
||
|
set a [catch {format [error glorp2]} b]
|
||
|
error {Human-generated}
|
||
|
}
|
||
|
|
||
|
proc foo2 {} {
|
||
|
global errorInfo
|
||
|
set a [catch {format [error glorp2]} b]
|
||
|
error {Human-generated} $errorInfo
|
||
|
}
|
||
|
|
||
|
# Catch errors occurring in commands and errors from "error" command
|
||
|
|
||
|
test error-1.1 {simple errors from commands} {
|
||
|
catch {format [string compare]} b
|
||
|
} 1
|
||
|
|
||
|
test error-1.2 {simple errors from commands} {
|
||
|
catch {format [string compare]} b
|
||
|
set b
|
||
|
} {wrong # args: should be "string compare string1 string2"}
|
||
|
|
||
|
test error-1.3 {simple errors from commands} {
|
||
|
catch {format [string compare]} b
|
||
|
set errorInfo
|
||
|
} {wrong # args: should be "string compare string1 string2"
|
||
|
while executing
|
||
|
"string compare"
|
||
|
invoked from within
|
||
|
"format [string compare]..."}
|
||
|
|
||
|
test error-1.4 {simple errors from commands} {
|
||
|
catch {error glorp} b
|
||
|
} 1
|
||
|
|
||
|
test error-1.5 {simple errors from commands} {
|
||
|
catch {error glorp} b
|
||
|
set b
|
||
|
} glorp
|
||
|
|
||
|
test error-1.6 {simple errors from commands} {
|
||
|
catch {catch a b c} b
|
||
|
} 1
|
||
|
|
||
|
test error-1.7 {simple errors from commands} {
|
||
|
catch {catch a b c} b
|
||
|
set b
|
||
|
} {wrong # args: should be "catch command ?varName?"}
|
||
|
|
||
|
test error-2.1 {simple errors from commands} {
|
||
|
catch catch
|
||
|
} 1
|
||
|
|
||
|
# Check errors nested in procedures. Also check the optional argument
|
||
|
# to "error" to generate a new error trace.
|
||
|
|
||
|
test error-2.1 {errors in nested procedures} {
|
||
|
catch foo b
|
||
|
} 1
|
||
|
|
||
|
test error-2.2 {errors in nested procedures} {
|
||
|
catch foo b
|
||
|
set b
|
||
|
} {Human-generated}
|
||
|
|
||
|
test error-2.3 {errors in nested procedures} {
|
||
|
catch foo b
|
||
|
set errorInfo
|
||
|
} {Human-generated
|
||
|
while executing
|
||
|
"error {Human-generated}"
|
||
|
(procedure "foo" line 4)
|
||
|
invoked from within
|
||
|
"foo"}
|
||
|
|
||
|
test error-2.4 {errors in nested procedures} {
|
||
|
catch foo2 b
|
||
|
} 1
|
||
|
|
||
|
test error-2.5 {errors in nested procedures} {
|
||
|
catch foo2 b
|
||
|
set b
|
||
|
} {Human-generated}
|
||
|
|
||
|
test error-2.6 {errors in nested procedures} {
|
||
|
catch foo2 b
|
||
|
set errorInfo
|
||
|
} {glorp2
|
||
|
while executing
|
||
|
"error glorp2"
|
||
|
invoked from within
|
||
|
"format [error glorp2]..."
|
||
|
(procedure "foo2" line 1)
|
||
|
invoked from within
|
||
|
"foo2"}
|
||
|
|
||
|
# Error conditions related to "catch".
|
||
|
|
||
|
test error-3.1 {errors in catch command} {
|
||
|
list [catch {catch} msg] $msg
|
||
|
} {1 {wrong # args: should be "catch command ?varName?"}}
|
||
|
test error-3.2 {errors in catch command} {
|
||
|
list [catch {catch a b c} msg] $msg
|
||
|
} {1 {wrong # args: should be "catch command ?varName?"}}
|
||
|
test error-3.3 {errors in catch command} {
|
||
|
catch {unset a}
|
||
|
set a(0) 22
|
||
|
list [catch {catch {format 44} a} msg] $msg
|
||
|
} {1 {couldn't save command result in variable}}
|
||
|
catch {unset a}
|
||
|
|
||
|
# More tests related to errorInfo and errorCode
|
||
|
|
||
|
test error-4.1 {errorInfo and errorCode variables} {
|
||
|
list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
|
||
|
} {1 msg1 msg2 msg3}
|
||
|
test error-4.2 {errorInfo and errorCode variables} {
|
||
|
list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
|
||
|
} {1 msg1 {msg1
|
||
|
while executing
|
||
|
"error msg1 {} msg3"} msg3}
|
||
|
test error-4.3 {errorInfo and errorCode variables} {
|
||
|
list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
|
||
|
} {1 msg1 {msg1
|
||
|
while executing
|
||
|
"error msg1 {}"} NONE}
|
||
|
test error-4.4 {errorInfo and errorCode variables} {
|
||
|
set errorCode bogus
|
||
|
list [catch {error msg1} msg] $msg $errorInfo $errorCode
|
||
|
} {1 msg1 {msg1
|
||
|
while executing
|
||
|
"error msg1"} NONE}
|
||
|
test error-4.5 {errorInfo and errorCode variables} {
|
||
|
set errorCode bogus
|
||
|
list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
|
||
|
} {1 msg1 msg2 {}}
|
||
|
|
||
|
# Errors in error command itself
|
||
|
|
||
|
test error-5.1 {errors in error command} {
|
||
|
list [catch {error} msg] $msg
|
||
|
} {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
|
||
|
test error-5.2 {errors in error command} {
|
||
|
list [catch {error a b c d} msg] $msg
|
||
|
} {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
|
||
|
|
||
|
# Make sure that catch resets error information
|
||
|
|
||
|
test error-6.1 {catch must reset error state} {
|
||
|
catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
|
||
|
list $errorCode $errorInfo
|
||
|
} {NONE 1}
|
||
|
|
||
|
return ""
|