PageRenderTime 34ms CodeModel.GetById 17ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/uClinux-dist/user/tcl/tests/error.test

https://bitbucket.org/__wp__/mb-linux-msli
Unknown | 181 lines | 152 code | 29 blank | 0 comment | 0 complexity | daf9062d149ed5a6cdce0f06fbb45a4b MD5 | raw file
  1# Commands covered:  error, catch
  2#
  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.
  6#
  7# Copyright (c) 1991-1993 The Regents of the University of California.
  8# Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9# Copyright (c) 1998-1999 by Scriptics Corporation.
 10#
 11# See the file "license.terms" for information on usage and redistribution
 12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 13#
 14# RCS: @(#) $Id: error.test,v 1.7 2000/04/10 17:18:58 ericm Exp $
 15
 16if {[lsearch [namespace children] ::tcltest] == -1} {
 17    package require tcltest
 18    namespace import -force ::tcltest::*
 19}
 20
 21proc foo {} {
 22    global errorInfo
 23    set a [catch {format [error glorp2]} b]
 24    error {Human-generated}
 25}
 26
 27proc foo2 {} {
 28    global errorInfo
 29    set a [catch {format [error glorp2]} b]
 30    error {Human-generated} $errorInfo
 31}
 32
 33# Catch errors occurring in commands and errors from "error" command
 34
 35test error-1.1 {simple errors from commands} {
 36    catch {format [string index]} b
 37} 1
 38
 39test error-1.2 {simple errors from commands} {
 40    catch {format [string index]} b
 41    set b
 42} {wrong # args: should be "string index string charIndex"}
 43
 44test error-1.3 {simple errors from commands} {
 45    catch {format [string index]} b
 46    set errorInfo
 47} {wrong # args: should be "string index string charIndex"
 48    while executing
 49"string index"}
 50
 51test error-1.4 {simple errors from commands} {
 52    catch {error glorp} b
 53} 1
 54
 55test error-1.5 {simple errors from commands} {
 56    catch {error glorp} b
 57    set b
 58} glorp
 59
 60test error-1.6 {simple errors from commands} {
 61    catch {catch a b c} b
 62} 1
 63
 64test error-1.7 {simple errors from commands} {
 65    catch {catch a b c} b
 66    set b
 67} {wrong # args: should be "catch command ?varName?"}
 68
 69test error-1.8 {simple errors from commands} {nonPortable} {
 70    # This test is non-portable: it generates a memory fault on
 71    # machines like DEC Alphas (infinite recursion overflows
 72    # stack?)
 73
 74    proc p {} {
 75        uplevel 1 catch p error
 76    }
 77    p
 78} 0
 79
 80# Check errors nested in procedures.  Also check the optional argument
 81# to "error" to generate a new error trace.
 82
 83test error-2.1 {errors in nested procedures} {
 84    catch foo b
 85} 1
 86
 87test error-2.2 {errors in nested procedures} {
 88    catch foo b
 89    set b
 90} {Human-generated}
 91
 92test error-2.3 {errors in nested procedures} {
 93    catch foo b
 94    set errorInfo
 95} {Human-generated
 96    while executing
 97"error {Human-generated}"
 98    (procedure "foo" line 4)
 99    invoked from within
100"foo"}
101
102test error-2.4 {errors in nested procedures} {
103    catch foo2 b
104} 1
105
106test error-2.5 {errors in nested procedures} {
107    catch foo2 b
108    set b
109} {Human-generated}
110
111test error-2.6 {errors in nested procedures} {
112    catch foo2 b
113    set errorInfo
114} {glorp2
115    while executing
116"error glorp2"
117    (procedure "foo2" line 3)
118    invoked from within
119"foo2"}
120
121# Error conditions related to "catch".
122
123test error-3.1 {errors in catch command} {
124    list [catch {catch} msg] $msg
125} {1 {wrong # args: should be "catch command ?varName?"}}
126test error-3.2 {errors in catch command} {
127    list [catch {catch a b c} msg] $msg
128} {1 {wrong # args: should be "catch command ?varName?"}}
129test error-3.3 {errors in catch command} {
130    catch {unset a}
131    set a(0) 22
132    list [catch {catch {format 44} a} msg] $msg
133} {1 {couldn't save command result in variable}}
134catch {unset a}
135
136# More tests related to errorInfo and errorCode
137
138test error-4.1 {errorInfo and errorCode variables} {
139    list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
140} {1 msg1 msg2 msg3}
141test error-4.2 {errorInfo and errorCode variables} {
142    list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
143} {1 msg1 {msg1
144    while executing
145"error msg1 {} msg3"} msg3}
146test error-4.3 {errorInfo and errorCode variables} {
147    list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
148} {1 msg1 {msg1
149    while executing
150"error msg1 {}"} NONE}
151test error-4.4 {errorInfo and errorCode variables} {
152    set errorCode bogus
153    list [catch {error msg1} msg] $msg $errorInfo $errorCode
154} {1 msg1 {msg1
155    while executing
156"error msg1"} NONE}
157test error-4.5 {errorInfo and errorCode variables} {
158    set errorCode bogus
159    list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
160} {1 msg1 msg2 {}}
161
162# Errors in error command itself
163
164test error-5.1 {errors in error command} {
165    list [catch {error} msg] $msg
166} {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
167test error-5.2 {errors in error command} {
168    list [catch {error a b c d} msg] $msg
169} {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
170
171# Make sure that catch resets error information
172
173test error-6.1 {catch must reset error state} {
174    catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
175    list $errorCode $errorInfo
176} {NONE 1}
177
178# cleanup
179catch {rename p ""}
180::tcltest::cleanupTests
181return