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

/Src/gnu/tcl/tests/error.test

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