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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [tests/] [info.test] - Blame information for rev 1773

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

Line No. Rev Author Line
1 578 markom
#
2
# Tests for information accessed by the "info" command
3
# ----------------------------------------------------------------------
4
#   AUTHOR:  Michael J. McLennan
5
#            Bell Labs Innovations for Lucent Technologies
6
#            mmclennan@lucent.com
7
#            http://www.tcltk.com/itcl
8
#
9
#      RCS:  $Id: info.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
10
# ----------------------------------------------------------------------
11
#            Copyright (c) 1993-1998  Lucent Technologies, Inc.
12
# ======================================================================
13
# See the file "license.terms" for information on usage and
14
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
 
16
if {[string compare test [info procs test]] == 1} then {source defs}
17
 
18
# ----------------------------------------------------------------------
19
#  Class definition with one of everything
20
# ----------------------------------------------------------------------
21
test info-1.1 {define a simple class} {
22
    class test_info_base {
23
        method base {} {return "default"}
24
        variable base {}
25
 
26
        method do {args} {eval $args}
27
    }
28
    class test_info {
29
        inherit test_info_base
30
 
31
        constructor {args} {
32
            foreach v [info variable] {
33
                catch {set $v "new-[set $v]"}
34
            }
35
        }
36
        destructor {}
37
 
38
        method defm {} {return "default method"}
39
        public method pubm {x} {return "public method"}
40
        protected method prom {x y} {return "protected method"}
41
        private method prim {x y z} {return "private method"}
42
 
43
        proc defp {} {return "default proc"}
44
        public proc pubp {x} {return "public proc"}
45
        protected proc prop {x y} {return "protected proc"}
46
        private proc prip {x y z} {return "private proc"}
47
 
48
        variable defv "default"
49
        public variable pubv "public" {set pubv "public: $pubv"}
50
        protected variable prov "protected"
51
        private variable priv "private"
52
 
53
        common defc "default"
54
        public common pubc "public"
55
        protected common proc "protected"
56
        private common pric "private"
57
 
58
        method uninitm
59
        proc uninitp {x y}
60
        variable uninitv
61
        common uninitc
62
        set uninitc(0) zero
63
        set uninitc(1) one
64
    }
65
} ""
66
 
67
test info-1.2 {info: errors trigger usage info} {
68
    list [catch {namespace eval test_info {info}} msg] $msg
69
} {1 {wrong # args: should be one of...
70
  info args procname
71
  info body procname
72
  info class
73
  info function ?name? ?-protection? ?-type? ?-name? ?-args? ?-body?
74
  info heritage
75
  info inherit
76
  info variable ?name? ?-protection? ?-type? ?-name? ?-init? ?-value? ?-config?
77
...and others described on the man page}}
78
 
79
test basic-1.3 {info: errors trigger usage info} {
80
    test_info ti
81
    list [catch {ti info} msg] $msg
82
} {1 {wrong # args: should be one of...
83
  info args procname
84
  info body procname
85
  info class
86
  info function ?name? ?-protection? ?-type? ?-name? ?-args? ?-body?
87
  info heritage
88
  info inherit
89
  info variable ?name? ?-protection? ?-type? ?-name? ?-init? ?-value? ?-config?
90
...and others described on the man page}}
91
 
92
# ----------------------------------------------------------------------
93
#  Data members
94
# ----------------------------------------------------------------------
95
test info-2.1 {info: all variables} {
96
    lsort [ti info variable]
97
} {::test_info::defc ::test_info::defv ::test_info::pric ::test_info::priv ::test_info::proc ::test_info::prov ::test_info::pubc ::test_info::pubv ::test_info::this ::test_info::uninitc ::test_info::uninitv ::test_info_base::base}
98
 
99
test info-2.2a {info: public variables} {
100
    ti info variable pubv
101
} {public variable ::test_info::pubv public {set pubv "public: $pubv"} new-public}
102
 
103
test info-2.2b {info: public variables} {
104
    list [ti info variable pubv -protection] \
105
         [ti info variable pubv -type] \
106
         [ti info variable pubv -name] \
107
         [ti info variable pubv -init] \
108
         [ti info variable pubv -config] \
109
         [ti info variable pubv -value] \
110
} {public variable ::test_info::pubv public {set pubv "public: $pubv"} new-public}
111
 
112
test info-2.3a {info: protected variables} {
113
    ti info variable prov
114
} {protected variable ::test_info::prov protected new-protected}
115
 
116
test info-2.3b {info: protected variables} {
117
    list [ti info variable prov -protection] \
118
         [ti info variable prov -type] \
119
         [ti info variable prov -name] \
120
         [ti info variable prov -init] \
121
         [ti info variable prov -value] \
122
} {protected variable ::test_info::prov protected new-protected}
123
 
124
test info-2.4a {info: private variables} {
125
    ti info variable priv
126
} {private variable ::test_info::priv private new-private}
127
 
128
test info-2.4b {info: private variables} {
129
    list [ti info variable priv -protection] \
130
         [ti info variable priv -type] \
131
         [ti info variable priv -name] \
132
         [ti info variable priv -init] \
133
         [ti info variable priv -value] \
134
} {private variable ::test_info::priv private new-private}
135
 
136
test info-2.5 {"this" variable is built in} {
137
    ti info variable this
138
} {protected variable ::test_info::this ::ti ::ti}
139
 
140
test info-2.6 {info: protected/private variables have no "config" code} {
141
    list [ti info variable prov -config] [ti info variable priv -config]
142
} {{} {}}
143
 
144
test info-2.7 {by default, variables are "protected"} {
145
    ti info variable defv
146
} {protected variable ::test_info::defv default new-default}
147
 
148
test info-2.8 {data members may be uninitialized} {
149
    ti info variable uninitv
150
} {protected variable ::test_info::uninitv  }
151
 
152
test info-2.9a {info: public common variables} {
153
    ti info variable pubc
154
} {public common ::test_info::pubc public new-public}
155
 
156
test info-2.9b {info: public common variables} {
157
    list [ti info variable pubc -protection] \
158
         [ti info variable pubc -type] \
159
         [ti info variable pubc -name] \
160
         [ti info variable pubc -init] \
161
         [ti info variable pubc -value] \
162
} {public common ::test_info::pubc public new-public}
163
 
164
test info-2.10a {info: protected common variables} {
165
    ti info variable proc
166
} {protected common ::test_info::proc protected new-protected}
167
 
168
test info-2.10b {info: protected common variables} {
169
    list [ti info variable proc -protection] \
170
         [ti info variable proc -type] \
171
         [ti info variable proc -name] \
172
         [ti info variable proc -init] \
173
         [ti info variable proc -value] \
174
} {protected common ::test_info::proc protected new-protected}
175
 
176
test info-2.11a {info: private common variables} {
177
    ti info variable pric
178
} {private common ::test_info::pric private new-private}
179
 
180
test info-2.11b {info: private common variables} {
181
    list [ti info variable pric -protection] \
182
         [ti info variable pric -type] \
183
         [ti info variable pric -name] \
184
         [ti info variable pric -init] \
185
         [ti info variable pric -value] \
186
} {private common ::test_info::pric private new-private}
187
 
188
test info-2.12 {info: public/protected/private vars have no "config" code} {
189
    list [ti info variable pubc -config] \
190
         [ti info variable proc -config] \
191
         [ti info variable pric -config]
192
} {{} {} {}}
193
 
194
test info-2.13 {by default, variables are "protected"} {
195
    ti info variable defc
196
} {protected common ::test_info::defc default new-default}
197
 
198
test info-2.14 {data members may be uninitialized} {
199
    ti info variable uninitc
200
} {protected common ::test_info::uninitc  }
201
 
202
test info-2.15 {common vars can be initialized within class definition} {
203
    list [namespace eval test_info {lsort [array names uninitc]}] \
204
         [namespace eval test_info {set uninitc(0)}] \
205
         [namespace eval test_info {set uninitc(1)}]
206
} {{0 1} zero one}
207
 
208
test info-2.16 {flag syntax errors} {
209
    list [catch {ti info variable defv -xyzzy} msg] $msg
210
} {1 {bad option "-xyzzy": must be -config, -init, -name, -protection, -type, or -value}}
211
 
212
# ----------------------------------------------------------------------
213
#  Member functions
214
# ----------------------------------------------------------------------
215
test basic-3.1 {info: all functions} {
216
    lsort [ti info function]
217
} {::test_info::constructor ::test_info::defm ::test_info::defp ::test_info::destructor ::test_info::prim ::test_info::prip ::test_info::prom ::test_info::prop ::test_info::pubm ::test_info::pubp ::test_info::uninitm ::test_info::uninitp ::test_info_base::base ::test_info_base::cget ::test_info_base::configure ::test_info_base::do ::test_info_base::isa}
218
 
219
test info-3.2a {info: public methods} {
220
    ti info function pubm
221
} {public method ::test_info::pubm x {return "public method"}}
222
 
223
test info-3.2b {info: public methods} {
224
    list [ti info function pubm -protection] \
225
         [ti info function pubm -type] \
226
         [ti info function pubm -name] \
227
         [ti info function pubm -args] \
228
         [ti info function pubm -body]
229
} {public method ::test_info::pubm x {return "public method"}}
230
 
231
test info-3.3a {info: protected methods} {
232
    ti info function prom
233
} {protected method ::test_info::prom {x y} {return "protected method"}}
234
 
235
test info-3.3b {info: protected methods} {
236
    list [ti info function prom -protection] \
237
         [ti info function prom -type] \
238
         [ti info function prom -name] \
239
         [ti info function prom -args] \
240
         [ti info function prom -body]
241
} {protected method ::test_info::prom {x y} {return "protected method"}}
242
 
243
test info-3.4a {info: private methods} {
244
    ti info function prim
245
} {private method ::test_info::prim {x y z} {return "private method"}}
246
 
247
test info-3.4b {info: private methods} {
248
    list [ti info function prim -protection] \
249
         [ti info function prim -type] \
250
         [ti info function prim -name] \
251
         [ti info function prim -args] \
252
         [ti info function prim -body]
253
} {private method ::test_info::prim {x y z} {return "private method"}}
254
 
255
test info-3.5 {"configure" function is built in} {
256
    ti info function configure
257
} {public method ::test_info_base::configure {?-option? ?value -option value...?} @itcl-builtin-configure}
258
 
259
test info-3.6 {by default, methods are "public"} {
260
    ti info function defm
261
} {public method ::test_info::defm {} {return "default method"}}
262
 
263
test info-3.7 {methods may not have arg lists or bodies defined} {
264
    ti info function uninitm
265
} {public method ::test_info::uninitm  }
266
 
267
test info-3.8a {info: public procs} {
268
    ti info function pubp
269
} {public proc ::test_info::pubp x {return "public proc"}}
270
 
271
test info-3.8b {info: public procs} {
272
    list [ti info function pubp -protection] \
273
         [ti info function pubp -type] \
274
         [ti info function pubp -name] \
275
         [ti info function pubp -args] \
276
         [ti info function pubp -body]
277
} {public proc ::test_info::pubp x {return "public proc"}}
278
 
279
test info-3.9a {info: protected procs} {
280
    ti info function prop
281
} {protected proc ::test_info::prop {x y} {return "protected proc"}}
282
 
283
test info-3.9b {info: protected procs} {
284
    list [ti info function prop -protection] \
285
         [ti info function prop -type] \
286
         [ti info function prop -name] \
287
         [ti info function prop -args] \
288
         [ti info function prop -body]
289
} {protected proc ::test_info::prop {x y} {return "protected proc"}}
290
 
291
test info-3.10a {info: private procs} {
292
    ti info function prip
293
} {private proc ::test_info::prip {x y z} {return "private proc"}}
294
 
295
test info-3.10b {info: private procs} {
296
    list [ti info function prip -protection] \
297
         [ti info function prip -type] \
298
         [ti info function prip -name] \
299
         [ti info function prip -args] \
300
         [ti info function prip -body]
301
} {private proc ::test_info::prip {x y z} {return "private proc"}}
302
 
303
test info-3.11 {by default, procs are "public"} {
304
    ti info function defp
305
} {public proc ::test_info::defp {} {return "default proc"}}
306
 
307
test info-3.12 {procs may not have arg lists or bodies defined} {
308
    ti info function uninitp
309
} {public proc ::test_info::uninitp {x y} }
310
 
311
test info-3.13 {flag syntax errors} {
312
    list [catch {ti info function defm -xyzzy} msg] $msg
313
} {1 {bad option "-xyzzy": must be -args, -body, -name, -protection, or -type}}
314
 
315
# ----------------------------------------------------------------------
316
#  Other object-related queries
317
# ----------------------------------------------------------------------
318
 
319
test info-4.1a {query class (wrong # args)} {
320
    list [catch {ti info class x} result] $result
321
} {1 {wrong # args: should be "info class"}}
322
 
323
test info-4.1b {query most-specific class} {
324
    list [ti info class] [ti do info class]
325
} {::test_info ::test_info}
326
 
327
test info-4.2a {query inheritance info (wrong # args)} {
328
    list [catch {ti info inherit x} result] $result
329
} {1 {wrong # args: should be "info inherit"}}
330
 
331
test info-4.2b {query inheritance info} {
332
    list [ti info inherit] [ti do info inherit]
333
} {::test_info_base {}}
334
 
335
test info-4.3a {query heritage info (wrong # args)} {
336
    list [catch {ti info heritage x} result] $result
337
} {1 {wrong # args: should be "info heritage"}}
338
 
339
test info-4.3b {query heritage info} {
340
    list [ti info heritage] [ti do info heritage]
341
} {{::test_info ::test_info_base} ::test_info_base}
342
 
343
test info-4.4a {query argument list (wrong # args)} {
344
    list [catch {ti info args} result] $result \
345
         [catch {ti info args x y} result] $result
346
} {1 {wrong # args: should be "info args function"} 1 {wrong # args: should be "info args function"}}
347
 
348
test info-4.4b {query argument list} {
349
    ti info args prim
350
} {x y z}
351
 
352
test info-4.4c {query argument list (undefined)} {
353
    ti info args uninitm
354
} {}
355
 
356
test info-4.5a {query body (wrong # args)} {
357
    list [catch {ti info body} result] $result \
358
         [catch {ti info body x y} result] $result
359
} {1 {wrong # args: should be "info body function"} 1 {wrong # args: should be "info body function"}}
360
 
361
test info-4.5b {query body} {
362
    ti info body prim
363
} {return "private method"}
364
 
365
test info-4.5c {query body (undefined)} {
366
    ti info body uninitm
367
} {}
368
 
369
# ----------------------------------------------------------------------
370
#  Other parts of the usual "info" command
371
# ----------------------------------------------------------------------
372
 
373
test info-5.1 {info vars} {
374
    ti do info vars
375
} {args}
376
 
377
test info-5.2 {info exists} {
378
    list [ti do info exists args] [ti do info exists xyzzy]
379
} {1 0}
380
 
381
# ----------------------------------------------------------------------
382
#  Clean up
383
# ----------------------------------------------------------------------
384
delete class test_info test_info_base

powered by: WebSVN 2.1.0

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