summaryrefslogtreecommitdiffstats
path: root/hl
Commit message (Expand)AuthorAgeFilesLines
* [svn-r11431] Purpose:Albert Cheng2005-09-1810-20/+30
* [svn-r11421] Purpose:James Laird2005-09-1610-40/+110
* [svn-r11420] Purpose:James Laird2005-09-1612-0/+38
* [svn-r11418] Purpose:James Laird2005-09-1512-0/+46
* [svn-r11411] Purpose:James Laird2005-09-138-28/+0
* [svn-r11323] Purpose:Albert Cheng2005-08-3110-10/+21
* [svn-r11319] Purpose:James Laird2005-08-3010-10/+10
* [svn-r11304] Purpose:Quincey Koziol2005-08-271-8/+8
* [svn-r11303] Purpose:Albert Cheng2005-08-2610-249/+152
* [svn-r11245] Purpose:Quincey Koziol2005-08-1335-2417/+2417
* [svn-r11213] Purpose:Albert Cheng2005-08-0810-70/+20
* [svn-r11208] Purpose:Albert Cheng2005-08-0810-550/+630
* [svn-r11185] Purpose:James Laird2005-08-0212-69/+84
* [svn-r11179] Purpose:James Laird2005-08-0111-65/+132
* [svn-r11144] Purpose:Quincey Koziol2005-07-231-1/+1
* [svn-r11115] Purpose:Fang Guo2005-07-222-3/+603
* [svn-r11114] Purpose:Fang Guo2005-07-221-0/+96
* [svn-r11113] Purpose:Fang Guo2005-07-221-3/+3
* [svn-r11112] Purpose:Fang Guo2005-07-222-32/+32
* [svn-r11111] Purpose:Fang Guo2005-07-221-53/+53
* [svn-r11110] Purpose:Fang Guo2005-07-221-13/+13
* [svn-r11109] Purpose:Fang Guo2005-07-221-12/+12
* [svn-r11095] Purpose:James Laird2005-07-2110-150/+529
* [svn-r11092] Purpose:MuQun Yang2005-07-201-1/+1
* [svn-r11091] Purpose:Pedro Vicente Nunes2005-07-202-21/+21
* [svn-r11042] Purpose:Quincey Koziol2005-07-0710-70/+70
* [svn-r11034] Purpose:Albert Cheng2005-07-0710-40/+20
* [svn-r11013] Purpose:James Laird2005-07-0110-70/+70
* [svn-r11008] Purpose:James Laird2005-06-3012-880/+816
* [svn-r10997] Purpose: Small bug fixElena Pourmal2005-06-282-2/+2
* [svn-r10986] Purpose: MaintenanceElena Pourmal2005-06-242-130/+130
* [svn-r10984] Elena Pourmal2005-06-241-1/+1
* [svn-r10977] Purpose: Bug fixElena Pourmal2005-06-2411-466/+522
* [svn-r10970] Purpose: New feature/bug #350 fixElena Pourmal2005-06-229-55/+209
* [svn-r10858] Purpose:Albert Cheng2005-06-0410-40/+150
* [svn-r10849] Purpose:Albert Cheng2005-06-0210-10/+30
* [svn-r10840] Purpose:James Laird2005-06-0210-60/+360
* [svn-r10801] Purpose:James Laird2005-05-251-1/+1
* [svn-r10748] Purpose:Pedro Vicente Nunes2005-05-161-2/+0
* [svn-r10747] Purpose:Pedro Vicente Nunes2005-05-1613-1186/+1742
* [svn-r10736] Purpose:Quincey Koziol2005-05-074-19/+5
* [svn-r10729] Purpose:James Laird2005-05-051-6/+7
* [svn-r10706] Purpose:MuQun Yang2005-05-021-0/+1
* [svn-r10668] Purpose:James Laird2005-04-261-221/+0
* [svn-r10667] Purpose:James Laird2005-04-262-2/+5
* [svn-r10628] Purpose:Quincey Koziol2005-04-181-4/+0
* [svn-r10587] Purpose:James Laird2005-04-112-2/+6
* [svn-r10571] Purpose:James Laird2005-04-071-39/+39
* [svn-r10570] Purpose: MaintenanceElena Pourmal2005-04-0710-40/+0
* [svn-r10551] Purpose:Pedro Vicente Nunes2005-04-051-94/+89
hold_trunk'>on_hold_trunk Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/tests/error.test
blob: 0cca88f42342825e4c3f8ec55fb2f8a7cac54161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# 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.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: error.test,v 1.12 2004/09/30 23:06:49 dgp Exp $

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

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 index]} b
} 1

test error-1.2 {simple errors from commands} {
    catch {format [string index]} b
    set b
} {wrong # args: should be "string index string charIndex"}

test error-1.3 {simple errors from commands} {
    catch {format [string index]} b
    set errorInfo
    # this used to return '... while executing ...', but
    # string index is fully compiled as of 8.4a3
} {wrong # args: should be "string index string charIndex"
    while executing
"string index"}

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 d} b
} 1

test error-1.7 {simple errors from commands} {
    catch {catch a b c d} b
    set b
} {wrong # args: should be "catch script ?resultVarName? ?optionVarName?"}

test error-1.8 {simple errors from commands} {nonPortable} {
    # This test is non-portable: it generates a memory fault on
    # machines like DEC Alphas (infinite recursion overflows
    # stack?)

    proc p {} {
        uplevel 1 catch p error
    }
    p
} 0

# 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"
    (procedure "foo2" line 3)
    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 script ?resultVarName? ?optionVarName?"}}
test error-3.2 {errors in catch command} {
    list [catch {catch a b c} msg] $msg
} {0 1}
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}
test error-6.2 {catch must reset error state} {
    catch {error outer [catch {return -level 0 -code error -errorcode BUG}]}
    list $errorCode $errorInfo
} {NONE 1}
test error-6.3 {catch must reset error state} {
    set errorCode BUG
    catch {error outer [catch set]}
    list $errorCode $errorInfo
} {NONE 1}
test error-6.4 {catch must reset error state} {
    catch {error [catch {error foo bar baz}] 1}
    list $errorCode $errorInfo
} {NONE 1}
test error-6.5 {catch must reset error state} {
    catch {error [catch {return -level 0 -code error -errorcode BUG}] 1}
    list $errorCode $errorInfo
} {NONE 1}
test error-6.6 {catch must reset error state} {
    catch {return -level 0 -code error -errorinfo [catch {error foo bar baz}]}
    list $errorCode $errorInfo
} {NONE 1}
test error-6.7 {catch must reset error state} {
    proc foo {} {
	return -code error -errorinfo [catch {error foo bar baz}]
    }
    catch foo
    list $errorCode
} {NONE}
test error-6.8 {catch must reset error state} {
    catch {return -level 0 -code error [catch {error foo bar baz}]}
    list $errorCode
} {NONE}
test error-6.9 {catch must reset error state} {
    proc foo {} {
	return -code error [catch {error foo bar baz}]
    }
    catch foo
    list $errorCode
} {NONE}

# cleanup
catch {rename p ""}
::tcltest::cleanupTests
return