PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/tcl6.7/tests/error.test

https://bitbucket.org/tickling/tcl67-ecos
Unknown | 174 lines | 146 code | 28 blank | 0 comment | 0 complexity | 4925d3f8cc6358811154159b7cc81630 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 1991 Regents of the University of California
  8# Permission to use, copy, modify, and distribute this
  9# software and its documentation for any purpose and without
 10# fee is hereby granted, provided that this copyright notice
 11# appears in all copies.  The University of California makes no
 12# representations about the suitability of this software for any
 13# purpose.  It is provided "as is" without express or implied
 14# warranty.
 15#
 16# $Header: /sprite/src/lib/tcl/tests/RCS/error.test,v 1.11 91/08/20 14:18:52 ouster Exp $ (Berkeley)
 17
 18if {[string compare test [info procs test]] == 1} then {source defs}
 19
 20proc foo {} {
 21    global errorInfo
 22    set a [catch {format [error glorp2]} b]
 23    error {Human-generated}
 24}
 25
 26proc foo2 {} {
 27    global errorInfo
 28    set a [catch {format [error glorp2]} b]
 29    error {Human-generated} $errorInfo
 30}
 31
 32# Catch errors occurring in commands and errors from "error" command
 33
 34test error-1.1 {simple errors from commands} {
 35    catch {format [string compare]} b
 36} 1
 37
 38test error-1.2 {simple errors from commands} {
 39    catch {format [string compare]} b
 40    set b
 41} {wrong # args: should be "string compare string1 string2"}
 42
 43test error-1.3 {simple errors from commands} {
 44    catch {format [string compare]} b
 45    set errorInfo
 46} {wrong # args: should be "string compare string1 string2"
 47    while executing
 48"string compare"
 49    invoked from within
 50"format [string compare]..."}
 51
 52test error-1.4 {simple errors from commands} {
 53    catch {error glorp} b
 54} 1
 55
 56test error-1.5 {simple errors from commands} {
 57    catch {error glorp} b
 58    set b
 59} glorp
 60
 61test error-1.6 {simple errors from commands} {
 62    catch {catch a b c} b
 63} 1
 64
 65test error-1.7 {simple errors from commands} {
 66    catch {catch a b c} b
 67    set b
 68} {wrong # args: should be "catch command ?varName?"}
 69
 70test error-2.1 {simple errors from commands} {
 71    catch catch
 72} 1
 73
 74# Check errors nested in procedures.  Also check the optional argument
 75# to "error" to generate a new error trace.
 76
 77test error-2.1 {errors in nested procedures} {
 78    catch foo b
 79} 1
 80
 81test error-2.2 {errors in nested procedures} {
 82    catch foo b
 83    set b
 84} {Human-generated}
 85
 86test error-2.3 {errors in nested procedures} {
 87    catch foo b
 88    set errorInfo
 89} {Human-generated
 90    while executing
 91"error {Human-generated}"
 92    (procedure "foo" line 4)
 93    invoked from within
 94"foo"}
 95
 96test error-2.4 {errors in nested procedures} {
 97    catch foo2 b
 98} 1
 99
100test error-2.5 {errors in nested procedures} {
101    catch foo2 b
102    set b
103} {Human-generated}
104
105test error-2.6 {errors in nested procedures} {
106    catch foo2 b
107    set errorInfo
108} {glorp2
109    while executing
110"error glorp2"
111    invoked from within
112"format [error glorp2]..."
113    (procedure "foo2" line 1)
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
174return ""