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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [proc.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file contains tests for the tclProc.c source file. Tests appear in
2
# the same order as the C code that they test. The set of tests is
3
# currently incomplete since it includes only new tests, in particular
4
# tests for code changed for the addition of Tcl namespaces. Other
5
# procedure-related tests appear in other test files such as proc-old.test.
6
#
7
# Sourcing this file into Tcl runs the tests and generates output for
8
# errors.  No output means no errors were found.
9
#
10
# Copyright (c) 1997 Sun Microsystems, Inc.
11
#
12
# See the file "license.terms" for information on usage and redistribution
13
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14
#
15
# RCS: @(#) $Id: proc.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
16
 
17
if {[string compare test [info procs test]] == 1} then {source defs}
18
 
19
catch {eval namespace delete [namespace children :: test_ns_*]}
20
catch {rename p ""}
21
catch {rename {} ""}
22
catch {unset msg}
23
 
24
test proc-1.1 {Tcl_ProcObjCmd, put proc in namespace specified in name, if any} {
25
    catch {eval namespace delete [namespace children :: test_ns_*]}
26
    namespace eval test_ns_1 {
27
        namespace eval baz {}
28
    }
29
    proc test_ns_1::baz::p {} {
30
        return "p in [namespace current]"
31
    }
32
    list [test_ns_1::baz::p] \
33
         [namespace eval test_ns_1 {baz::p}] \
34
         [info commands test_ns_1::baz::*]
35
} {{p in ::test_ns_1::baz} {p in ::test_ns_1::baz} ::test_ns_1::baz::p}
36
test proc-1.2 {Tcl_ProcObjCmd, namespace specified in proc name must exist} {
37
    catch {eval namespace delete [namespace children :: test_ns_*]}
38
    list [catch {proc test_ns_1::baz::p {} {}} msg] $msg
39
} {1 {can't create procedure "test_ns_1::baz::p": unknown namespace}}
40
test proc-1.3 {Tcl_ProcObjCmd, empty proc name} {
41
    catch {eval namespace delete [namespace children :: test_ns_*]}
42
    proc :: {} {
43
        return "empty called"
44
    }
45
    list [::] \
46
         [info body {}]
47
} {{empty called} {
48
        return "empty called"
49
    }}
50
test proc-1.4 {Tcl_ProcObjCmd, simple proc name and proc defined in namespace} {
51
    catch {eval namespace delete [namespace children :: test_ns_*]}
52
    namespace eval test_ns_1 {
53
        namespace eval baz {
54
            proc p {} {
55
                return "p in [namespace current]"
56
            }
57
        }
58
    }
59
    list [test_ns_1::baz::p] \
60
         [info commands test_ns_1::baz::*]
61
} {{p in ::test_ns_1::baz} ::test_ns_1::baz::p}
62
test proc-1.5 {Tcl_ProcObjCmd, qualified proc name and proc defined in namespace} {
63
    catch {eval namespace delete [namespace children :: test_ns_*]}
64
    namespace eval test_ns_1::baz {}
65
    namespace eval test_ns_1 {
66
        proc baz::p {} {
67
            return "p in [namespace current]"
68
        }
69
    }
70
    list [test_ns_1::baz::p] \
71
         [info commands test_ns_1::baz::*] \
72
         [namespace eval test_ns_1::baz {namespace which p}]
73
} {{p in ::test_ns_1::baz} ::test_ns_1::baz::p ::test_ns_1::baz::p}
74
test proc-1.6 {Tcl_ProcObjCmd, namespace code ignores single ":"s in middle or end of command names} {
75
    catch {eval namespace delete [namespace children :: test_ns_*]}
76
    namespace eval test_ns_1 {
77
        proc q: {} {return "q:"}
78
        proc value:at: {} {return "value:at:"}
79
    }
80
    list [namespace eval test_ns_1 {q:}] \
81
         [namespace eval test_ns_1 {value:at:}] \
82
         [test_ns_1::q:] \
83
         [test_ns_1::value:at:] \
84
         [lsort [info commands test_ns_1::*]] \
85
         [namespace eval test_ns_1 {namespace which q:}] \
86
         [namespace eval test_ns_1 {namespace which value:at:}]
87
} {q: value:at: q: value:at: {::test_ns_1::q: ::test_ns_1::value:at:} ::test_ns_1::q: ::test_ns_1::value:at:}
88
test proc-1.7 {Tcl_ProcObjCmd, check that formal parameter names are not array elements} {
89
    catch {rename p ""}
90
    list [catch {proc p {a(1) a(2)} {
91
            set z [expr $a(1)+$a(2)]
92
            puts "$z=z, $a(1)=$a(1)"
93
        }} msg] $msg
94
} {1 {procedure "p" has formal parameter "a(1)" that is an array element}}
95
 
96
test proc-2.1 {TclFindProc, simple proc name and proc not in namespace} {
97
    catch {eval namespace delete [namespace children :: test_ns_*]}
98
    catch {rename p ""}
99
    proc p {} {return "p in [namespace current]"}
100
    info body p
101
} {return "p in [namespace current]"}
102
test proc-2.2 {TclFindProc, simple proc name and proc defined in namespace} {
103
    catch {eval namespace delete [namespace children :: test_ns_*]}
104
    namespace eval test_ns_1 {
105
        namespace eval baz {
106
            proc p {} {return "p in [namespace current]"}
107
        }
108
    }
109
    namespace eval test_ns_1::baz {info body p}
110
} {return "p in [namespace current]"}
111
test proc-2.3 {TclFindProc, qualified proc name and proc defined in namespace} {
112
    catch {eval namespace delete [namespace children :: test_ns_*]}
113
    namespace eval test_ns_1::baz {}
114
    namespace eval test_ns_1 {
115
        proc baz::p {} {return "p in [namespace current]"}
116
    }
117
    namespace eval test_ns_1 {info body baz::p}
118
} {return "p in [namespace current]"}
119
test proc-2.4 {TclFindProc, global proc and executing in namespace} {
120
    catch {eval namespace delete [namespace children :: test_ns_*]}
121
    catch {rename p ""}
122
    proc p {} {return "global p"}
123
    namespace eval test_ns_1::baz {info body p}
124
} {return "global p"}
125
 
126
test proc-3.1 {TclObjInterpProc, proc defined and executing in same namespace} {
127
    catch {eval namespace delete [namespace children :: test_ns_*]}
128
    proc p {} {return "p in [namespace current]"}
129
    p
130
} {p in ::}
131
test proc-3.2 {TclObjInterpProc, proc defined and executing in same namespace} {
132
    catch {eval namespace delete [namespace children :: test_ns_*]}
133
    namespace eval test_ns_1::baz {
134
        proc p {} {return "p in [namespace current]"}
135
        p
136
    }
137
} {p in ::test_ns_1::baz}
138
test proc-3.3 {TclObjInterpProc, proc defined and executing in different namespaces} {
139
    catch {eval namespace delete [namespace children :: test_ns_*]}
140
    catch {rename p ""}
141
    proc p {} {return "p in [namespace current]"}
142
    namespace eval test_ns_1::baz {
143
        p
144
    }
145
} {p in ::}
146
test proc-3.4 {TclObjInterpProc, procs execute in the namespace in which they were defined unless renamed into new namespace} {
147
    catch {eval namespace delete [namespace children :: test_ns_*]}
148
    catch {rename p ""}
149
    namespace eval test_ns_1::baz {
150
        proc p {} {return "p in [namespace current]"}
151
        rename ::test_ns_1::baz::p ::p
152
        list [p] [namespace which p]
153
    }
154
} {{p in ::} ::p}
155
test proc-3.5 {TclObjInterpProc, any old result is reset before appending error msg about missing arguments} {
156
    proc p {x} {info commands 3m}
157
    list [catch {p} msg] $msg
158
} {1 {no value given for parameter "x" to "p"}}
159
 
160
catch {eval namespace delete [namespace children :: test_ns_*]}
161
catch {rename p ""}
162
catch {rename {} ""}
163
catch {unset msg}
164
 
165
if {[catch {package require procbodytest}]} {
166
    puts "This application couldn't load the \"procbodytest\" package, so I"
167
    puts "can't test creation of procs whose bodies have type \"procbody\"."
168
    return
169
}
170
 
171
catch {rename p ""}
172
catch {rename t ""}
173
 
174
# Note that the test require that procedures whose body is used to create
175
# procbody objects must be executed before the procbodytest::proc command
176
# is executed, so that the Proc struct is populated correctly (CompiledLocals
177
# are added at compile time).
178
 
179
test proc-4.1 {TclCreateProc, procbody obj} {
180
    catch {
181
        proc p x {return "$x:$x"}
182
        set rv [p P]
183
        procbodytest::proc t x p
184
        lappend rv [t T]
185
        set rv
186
    } result
187
    catch {rename p ""}
188
    catch {rename t ""}
189
    set result
190
} {P:P T:T}
191
 
192
test proc-4.2 {TclCreateProc, procbody obj, use compiled locals} {
193
    catch {
194
        proc p x {
195
            set y [string tolower $x]
196
            return "$x:$y"
197
        }
198
        set rv [p P]
199
        procbodytest::proc t x p
200
        lappend rv [t T]
201
        set rv
202
    } result
203
    catch {rename p ""}
204
    catch {rename t ""}
205
    set result
206
} {P:p T:t}
207
 
208
test proc-4.3 {TclCreateProc, procbody obj, too many args} {
209
    catch {
210
        proc p x {
211
            set y [string tolower $x]
212
            return "$x:$y"
213
        }
214
        set rv [p P]
215
        procbodytest::proc t {x x1 x2} p
216
        lappend rv [t T]
217
        set rv
218
    } result
219
    catch {rename p ""}
220
    catch {rename t ""}
221
    set result
222
} {procedure "t": arg list contains 3 entries, precompiled header expects 1}
223
 
224
test proc-4.4 {TclCreateProc, procbody obj, inconsitent arg name} {
225
    catch {
226
        proc p {x y z} {
227
            set v [join [list $x $y $z]]
228
            set w [string tolower $v]
229
            return "$v:$w"
230
        }
231
        set rv [p P Q R]
232
        procbodytest::proc t {x x1 z} p
233
        lappend rv [t S T U]
234
        set rv
235
    } result
236
    catch {rename p ""}
237
    catch {rename t ""}
238
    set result
239
} {procedure "t": formal parameter 1 is inconsistent with precompiled body}
240
 
241
test proc-4.5 {TclCreateProc, procbody obj, inconsitent arg default type} {
242
    catch {
243
        proc p {x y {z Z}} {
244
            set v [join [list $x $y $z]]
245
            set w [string tolower $v]
246
            return "$v:$w"
247
        }
248
        set rv [p P Q R]
249
        procbodytest::proc t {x y z} p
250
        lappend rv [t S T U]
251
        set rv
252
    } result
253
    catch {rename p ""}
254
    catch {rename t ""}
255
    set result
256
} {procedure "t": formal parameter 2 is inconsistent with precompiled body}
257
 
258
test proc-4.6 {TclCreateProc, procbody obj, inconsitent arg default type} {
259
    catch {
260
        proc p {x y z} {
261
            set v [join [list $x $y $z]]
262
            set w [string tolower $v]
263
            return "$v:$w"
264
        }
265
        set rv [p P Q R]
266
        procbodytest::proc t {x y {z Z}} p
267
        lappend rv [t S T U]
268
        set rv
269
    } result
270
    catch {rename p ""}
271
    catch {rename t ""}
272
    set result
273
} {procedure "t": formal parameter 2 is inconsistent with precompiled body}
274
 
275
test proc-4.7 {TclCreateProc, procbody obj, inconsitent arg default value} {
276
    catch {
277
        proc p {x y {z Z}} {
278
            set v [join [list $x $y $z]]
279
            set w [string tolower $v]
280
            return "$v:$w"
281
        }
282
        set rv [p P Q R]
283
        procbodytest::proc t {x y {z ZZ}} p
284
        lappend rv [t S T U]
285
        set rv
286
    } result
287
    catch {rename p ""}
288
    catch {rename t ""}
289
    set result
290
} {procedure "t": formal parameter "z" has default value inconsistent with precompiled body}
291
 
292
catch {rename p ""}
293
catch {rename t ""}

powered by: WebSVN 2.1.0

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