OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [error.test] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# 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.1.1.1 2002-01-16 10:25:35 markom Exp $
14
 
15
if {[string compare test [info procs test]] == 1} then {source defs}
16
 
17
proc foo {} {
18
    global errorInfo
19
    set a [catch {format [error glorp2]} b]
20
    error {Human-generated}
21
}
22
 
23
proc 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
 
31
test error-1.1 {simple errors from commands} {
32
    catch {format [string compare]} b
33
} 1
34
 
35
test 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
 
40
test 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
 
47
test error-1.4 {simple errors from commands} {
48
    catch {error glorp} b
49
} 1
50
 
51
test error-1.5 {simple errors from commands} {
52
    catch {error glorp} b
53
    set b
54
} glorp
55
 
56
test error-1.6 {simple errors from commands} {
57
    catch {catch a b c} b
58
} 1
59
 
60
test 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
 
65
test 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
 
79
test error-2.1 {errors in nested procedures} {
80
    catch foo b
81
} 1
82
 
83
test error-2.2 {errors in nested procedures} {
84
    catch foo b
85
    set b
86
} {Human-generated}
87
 
88
test 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
 
98
test error-2.4 {errors in nested procedures} {
99
    catch foo2 b
100
} 1
101
 
102
test error-2.5 {errors in nested procedures} {
103
    catch foo2 b
104
    set b
105
} {Human-generated}
106
 
107
test 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
 
119
test error-3.1 {errors in catch command} {
120
    list [catch {catch} msg] $msg
121
} {1 {wrong # args: should be "catch command ?varName?"}}
122
test 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?"}}
125
test 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}}
130
catch {unset a}
131
 
132
# More tests related to errorInfo and errorCode
133
 
134
test error-4.1 {errorInfo and errorCode variables} {
135
    list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
136
} {1 msg1 msg2 msg3}
137
test 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}
142
test 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}
147
test 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}
153
test 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
 
160
test error-5.1 {errors in error command} {
161
    list [catch {error} msg] $msg
162
} {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
163
test 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
 
169
test 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
 
174
catch {rename p ""}
175
return ""

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.