~ubuntu-branches/debian/sid/itcl4/sid

« back to all changes in this revision

Viewing changes to tests/inherit.test

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2018-03-06 11:36:54 UTC
  • Revision ID: package-import@ubuntu.com-20180306113654-w3oht8cjhtftrxby
Tags: upstream-4.1.1
ImportĀ upstreamĀ versionĀ 4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Tests for inheritance and scope handling
 
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
#            Copyright (c) 1993-1998  Lucent Technologies, Inc.
 
10
# ======================================================================
 
11
# See the file "license.terms" for information on usage and
 
12
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
13
 
 
14
package require tcltest 2.1
 
15
namespace import ::tcltest::test
 
16
::tcltest::loadTestedCommands
 
17
package require itcl
 
18
 
 
19
# ----------------------------------------------------------------------
 
20
#  Test construction/destruction with inheritance
 
21
# ----------------------------------------------------------------------
 
22
test inherit-1.1 {define classes with constructors/destructors} {
 
23
    variable ::test_cd_watch ""
 
24
    itcl::class test_cd_foo {
 
25
        constructor {x y} {
 
26
            global ::test_cd_watch
 
27
            lappend test_cd_watch "foo: $x $y"
 
28
        }
 
29
        destructor {
 
30
            global ::test_cd_watch
 
31
            lappend test_cd_watch "foo destruct"
 
32
        }
 
33
    }
 
34
    itcl::class test_cd_bar {
 
35
        constructor {args} {
 
36
            global ::test_cd_watch
 
37
            lappend test_cd_watch "bar: $args"
 
38
        }
 
39
        destructor {
 
40
            global ::test_cd_watch
 
41
            lappend test_cd_watch "bar destruct"
 
42
        }
 
43
    }
 
44
    itcl::class test_cd_foobar {
 
45
        inherit test_cd_foo test_cd_bar
 
46
        constructor {x y args} {
 
47
            test_cd_foo::constructor $x $y
 
48
        } {
 
49
            global ::test_cd_watch
 
50
            lappend test_cd_watch "foobar: $x $y ($args)"
 
51
        }
 
52
        destructor {
 
53
            global ::test_cd_watch
 
54
            lappend test_cd_watch "foobar destruct"
 
55
        }
 
56
    }
 
57
    itcl::class test_cd_geek {
 
58
        constructor {} {
 
59
            global ::test_cd_watch
 
60
            lappend test_cd_watch "geek"
 
61
        }
 
62
        destructor {
 
63
            global ::test_cd_watch
 
64
            lappend test_cd_watch "geek destruct"
 
65
        }
 
66
    }
 
67
    itcl::class test_cd_mongrel {
 
68
        inherit test_cd_foobar test_cd_geek
 
69
        constructor {x} {
 
70
            eval test_cd_foobar::constructor 1 2 fred $x
 
71
        } {
 
72
            global ::test_cd_watch
 
73
            lappend test_cd_watch "mongrel: $x"
 
74
        }
 
75
        destructor {
 
76
            global ::test_cd_watch
 
77
            lappend test_cd_watch "mongrel destruct"
 
78
        }
 
79
    }
 
80
    itcl::class test_cd_none {
 
81
        inherit test_cd_bar test_cd_geek
 
82
    }
 
83
    itcl::class test_cd_skip {
 
84
        inherit test_cd_none
 
85
        constructor {} {
 
86
            global ::test_cd_watch
 
87
            lappend test_cd_watch "skip"
 
88
        }
 
89
        destructor {
 
90
            global ::test_cd_watch
 
91
            lappend test_cd_watch "skip destruct"
 
92
        }
 
93
    }
 
94
} {}
 
95
 
 
96
test inherit-1.2 {constructors should be invoked in the proper order} {
 
97
    set ::test_cd_watch ""
 
98
    list [test_cd_mongrel #auto bob] [set ::test_cd_watch]
 
99
} {test_cd_mongrel0 {{foo: 1 2} {bar: } {foobar: 1 2 (fred bob)} geek {mongrel: bob}}}
 
100
 
 
101
test inherit-1.3 {destructors should be invoked in the proper order} {
 
102
    set ::test_cd_watch ""
 
103
    list [itcl::delete object test_cd_mongrel0] [set ::test_cd_watch]
 
104
} {{} {{mongrel destruct} {foobar destruct} {foo destruct} {bar destruct} {geek destruct}}}
 
105
 
 
106
test inherit-1.4 {constructors are optional} {
 
107
    set ::test_cd_watch ""
 
108
    list [test_cd_none #auto] [set ::test_cd_watch]
 
109
} {test_cd_none0 {geek {bar: }}}
 
110
 
 
111
test inherit-1.5 {destructors are optional} {
 
112
    set ::test_cd_watch ""
 
113
    list [itcl::delete object test_cd_none0] [set ::test_cd_watch]
 
114
} {{} {{bar destruct} {geek destruct}}}
 
115
 
 
116
test inherit-1.6 {construction ok if constructors are missing} {
 
117
    set ::test_cd_watch ""
 
118
    list [test_cd_skip #auto] [set ::test_cd_watch]
 
119
} {test_cd_skip0 {geek {bar: } skip}}
 
120
 
 
121
test inherit-1.7 {destruction ok if destructors are missing} {
 
122
    set ::test_cd_watch ""
 
123
    list [itcl::delete object test_cd_skip0] [set ::test_cd_watch]
 
124
} {{} {{skip destruct} {bar destruct} {geek destruct}}}
 
125
 
 
126
 
 
127
test inherit-1.8 {errors during construction are cleaned up and reported} knownBug {
 
128
    global errorInfo test_cd_watch
 
129
    set test_cd_watch ""
 
130
    itcl::body test_cd_bar::constructor {args} {error "bar: failed"}
 
131
    list [catch {test_cd_mongrel #auto bob} msg] $msg \
 
132
        $errorInfo $test_cd_watch
 
133
} {1 {bar: failed} {bar: failed
 
134
    while executing
 
135
"error "bar: failed""
 
136
    while constructing object "::test_cd_mongrel1" in ::test_cd_bar::constructor (body line 1)
 
137
    while constructing object "::test_cd_mongrel1" in ::test_cd_foobar::constructor (body line 1)
 
138
    invoked from within
 
139
"test_cd_foobar::constructor 1 2 fred bob"
 
140
    ("eval" body line 1)
 
141
    invoked from within
 
142
"eval test_cd_foobar::constructor 1 2 fred $x"
 
143
    while constructing object "::test_cd_mongrel1" in ::test_cd_mongrel::constructor (body line 2)
 
144
    invoked from within
 
145
"::itcl::parser::handleClass test_cd_mongrel ::test_cd_mongrel #auto bob"
 
146
    invoked from within
 
147
"test_cd_mongrel #auto bob"} {{foo: 1 2} {mongrel destruct} {foobar destruct} {foo destruct} {bar destruct} {geek destruct}}}
 
148
 
 
149
test inherit-1.9 {errors during destruction prevent object delete} {
 
150
    global errorInfo test_cd_watch
 
151
    itcl::body test_cd_bar::constructor {args} {return "bar: $args"}
 
152
    itcl::body test_cd_bar::destructor {} {error "bar: failed"}
 
153
    test_cd_mongrel mongrel1 ted
 
154
    set test_cd_watch ""
 
155
    list [catch {itcl::delete object mongrel1} msg] $msg \
 
156
        $errorInfo $test_cd_watch [itcl::find objects mongrel*]
 
157
} {1 {bar: failed} {bar: failed
 
158
    while executing
 
159
"error "bar: failed""
 
160
    while deleting object "::mongrel1" in ::test_cd_bar::destructor (body line 1)
 
161
    invoked from within
 
162
"itcl::delete object mongrel1"} {{mongrel destruct} {foobar destruct} {foo destruct}} mongrel1}
 
163
 
 
164
test inherit-1.10 {errors during destruction prevent class delete} {
 
165
    list [catch {itcl::delete class test_cd_foo} msg] $msg
 
166
} {1 {bar: failed}}
 
167
 
 
168
eval namespace delete [itcl::find classes test_cd_*]
 
169
 
 
170
# ----------------------------------------------------------------------
 
171
#  Test data member access and scoping
 
172
# ----------------------------------------------------------------------
 
173
test inherit-2.1 {define classes with data members} {
 
174
    itcl::class test_cd_foo {
 
175
        protected variable x "foo-x"
 
176
        method do {args} {eval $args}
 
177
    }
 
178
    itcl::class test_cd_bar {
 
179
        protected variable x "bar-x"
 
180
        method do {args} {eval $args}
 
181
    }
 
182
    itcl::class test_cd_foobar {
 
183
        inherit test_cd_foo test_cd_bar
 
184
        method do {args} {eval $args}
 
185
    }
 
186
    itcl::class test_cd_geek {
 
187
        method do {args} {eval $args}
 
188
    }
 
189
    itcl::class test_cd_mongrel {
 
190
        inherit test_cd_foobar test_cd_geek
 
191
        protected variable x "mongrel-x"
 
192
        method do {args} {eval $args}
 
193
    }
 
194
} {}
 
195
 
 
196
test inherit-2.2 {"info" provides access to shadowed data members} {
 
197
    test_cd_mongrel #auto
 
198
    list [lsort [test_cd_mongrel0 info variable]] \
 
199
         [test_cd_mongrel0 info variable test_cd_foo::x] \
 
200
         [test_cd_mongrel0 info variable test_cd_bar::x] \
 
201
         [test_cd_mongrel0 info variable test_cd_mongrel::x] \
 
202
         [test_cd_mongrel0 info variable x]
 
203
} {{::test_cd_bar::x ::test_cd_foo::x ::test_cd_mongrel::this ::test_cd_mongrel::x} {protected variable ::test_cd_foo::x foo-x foo-x} {protected variable ::test_cd_bar::x bar-x bar-x} {protected variable ::test_cd_mongrel::x mongrel-x mongrel-x} {protected variable ::test_cd_mongrel::x mongrel-x mongrel-x}}
 
204
 
 
205
test inherit-2.3 {variable resolution works properly in methods} {
 
206
    list [test_cd_mongrel0 test_cd_foo::do set x] \
 
207
         [test_cd_mongrel0 test_cd_bar::do set x] \
 
208
         [test_cd_mongrel0 test_cd_foobar::do set x] \
 
209
         [test_cd_mongrel0 test_cd_mongrel::do set x]
 
210
} {foo-x bar-x foo-x mongrel-x}
 
211
 
 
212
test inherit-2.4 {methods have access to shadowed data members} {
 
213
    list [test_cd_mongrel0 test_cd_foobar::do set x] \
 
214
         [test_cd_mongrel0 test_cd_foobar::do set test_cd_foo::x] \
 
215
         [test_cd_mongrel0 test_cd_foobar::do set test_cd_bar::x] \
 
216
         [test_cd_mongrel0 test_cd_mongrel::do set test_cd_foo::x] \
 
217
         [test_cd_mongrel0 test_cd_mongrel::do set test_cd_bar::x]
 
218
} {foo-x foo-x bar-x foo-x bar-x}
 
219
 
 
220
eval namespace delete [itcl::find classes test_cd_*]
 
221
 
 
222
# ----------------------------------------------------------------------
 
223
#  Test public variables and "configure" method
 
224
# ----------------------------------------------------------------------
 
225
test inherit-3.1 {define classes with public variables} {
 
226
    variable ::test_cd_watch ""
 
227
    itcl::class test_cd_foo {
 
228
        public variable x "foo-x" {
 
229
            global test_cd_watch
 
230
            lappend test_cd_watch "foo: $x in scope [namespace current]"
 
231
        }
 
232
        method do {args} {eval $args}
 
233
    }
 
234
    itcl::class test_cd_bar {
 
235
        public variable x "bar-x" {
 
236
            global test_cd_watch
 
237
            lappend test_cd_watch "bar: $x in scope [namespace current]"
 
238
        }
 
239
        method do {args} {eval $args}
 
240
    }
 
241
    itcl::class test_cd_foobar {
 
242
        inherit test_cd_foo test_cd_bar
 
243
        method do {args} {eval $args}
 
244
    }
 
245
    itcl::class test_cd_geek {
 
246
        method do {args} {eval $args}
 
247
    }
 
248
    itcl::class test_cd_mongrel {
 
249
        inherit test_cd_foobar test_cd_geek
 
250
        public variable x "mongrel-x" {
 
251
            global test_cd_watch
 
252
            lappend test_cd_watch "mongrel: $x in scope [namespace current]"
 
253
        }
 
254
        method do {args} {eval $args}
 
255
    }
 
256
} {}
 
257
 
 
258
test inherit-3.2 {create an object with public variables} {
 
259
    test_cd_mongrel #auto
 
260
} {test_cd_mongrel0}
 
261
 
 
262
test inherit-3.3 {"configure" lists all public variables} {
 
263
    lsort [test_cd_mongrel0 configure]
 
264
} {{-test_cd_bar::x bar-x bar-x} {-test_cd_foo::x foo-x foo-x} {-x mongrel-x mongrel-x}}
 
265
 
 
266
test inherit-3.4 {"configure" treats simple names as "most specific"} {
 
267
    lsort [test_cd_mongrel0 configure -x]
 
268
} {-x mongrel-x mongrel-x}
 
269
 
 
270
test inherit-3.5 {"configure" treats simple names as "most specific"} {
 
271
    set ::test_cd_watch ""
 
272
    list [test_cd_mongrel0 configure -x hello] \
 
273
         [set ::test_cd_watch]
 
274
} {{} {{mongrel: hello in scope ::test_cd_mongrel}}}
 
275
 
 
276
test inherit-3.6 {"configure" allows access to shadowed options} {
 
277
    set ::test_cd_watch ""
 
278
    list [test_cd_mongrel0 configure -test_cd_foo::x hello] \
 
279
         [test_cd_mongrel0 configure -test_cd_bar::x there] \
 
280
         [set ::test_cd_watch]
 
281
} {{} {} {{foo: hello in scope ::test_cd_foo} {bar: there in scope ::test_cd_bar}}}
 
282
 
 
283
test inherit-3.7 {"configure" will change several variables at once} {
 
284
    set ::test_cd_watch ""
 
285
    list [test_cd_mongrel0 configure -x one \
 
286
                                     -test_cd_foo::x two \
 
287
                                     -test_cd_bar::x three] \
 
288
         [set ::test_cd_watch]
 
289
} {{} {{mongrel: one in scope ::test_cd_mongrel} {foo: two in scope ::test_cd_foo} {bar: three in scope ::test_cd_bar}}}
 
290
 
 
291
test inherit-3.8 {"cget" does proper name resolution} {
 
292
    list [test_cd_mongrel0 cget -x] \
 
293
         [test_cd_mongrel0 cget -test_cd_foo::x] \
 
294
         [test_cd_mongrel0 cget -test_cd_bar::x] \
 
295
         [test_cd_mongrel0 cget -test_cd_mongrel::x]
 
296
} {one two three one}
 
297
 
 
298
eval namespace delete [itcl::find classes test_cd_*]
 
299
 
 
300
# ----------------------------------------------------------------------
 
301
#  Test inheritance info
 
302
# ----------------------------------------------------------------------
 
303
test inherit-4.1 {define classes for inheritance info} {
 
304
    itcl::class test_cd_foo {
 
305
        method do {args} {eval $args}
 
306
    }
 
307
    itcl::class test_cd_bar {
 
308
        method do {args} {eval $args}
 
309
    }
 
310
    itcl::class test_cd_foobar {
 
311
        inherit test_cd_foo test_cd_bar
 
312
        method do {args} {eval $args}
 
313
    }
 
314
    itcl::class test_cd_geek {
 
315
        method do {args} {eval $args}
 
316
    }
 
317
    itcl::class test_cd_mongrel {
 
318
        inherit test_cd_foobar test_cd_geek
 
319
        method do {args} {eval $args}
 
320
    }
 
321
} {}
 
322
 
 
323
test inherit-4.2 {create an object for inheritance tests} {
 
324
    test_cd_mongrel #auto
 
325
} {test_cd_mongrel0}
 
326
 
 
327
test inherit-4.3 {"info class" should be virtual} {
 
328
    list [test_cd_mongrel0 info class] \
 
329
         [test_cd_mongrel0 test_cd_foo::do info class] \
 
330
         [test_cd_mongrel0 test_cd_geek::do info class]
 
331
} {::test_cd_mongrel ::test_cd_mongrel ::test_cd_mongrel}
 
332
 
 
333
test inherit-4.4 {"info inherit" depends on class scope} {
 
334
    list [test_cd_mongrel0 info inherit] \
 
335
         [test_cd_mongrel0 test_cd_foo::do info inherit] \
 
336
         [test_cd_mongrel0 test_cd_foobar::do info inherit]
 
337
} {{::test_cd_foobar ::test_cd_geek} {} {::test_cd_foo ::test_cd_bar}}
 
338
 
 
339
test inherit-4.5 {"info heritage" depends on class scope} {
 
340
    list [test_cd_mongrel0 info heritage] \
 
341
         [test_cd_mongrel0 test_cd_foo::do info heritage] \
 
342
         [test_cd_mongrel0 test_cd_foobar::do info heritage]
 
343
} {{::test_cd_mongrel ::test_cd_foobar ::test_cd_foo ::test_cd_bar ::test_cd_geek} ::test_cd_foo {::test_cd_foobar ::test_cd_foo ::test_cd_bar}}
 
344
 
 
345
test inherit-4.6 {built-in "isa" method works} {
 
346
    set status ""
 
347
    foreach c [test_cd_mongrel0 info heritage] {
 
348
        lappend status [test_cd_mongrel0 isa $c]
 
349
    }
 
350
    set status
 
351
} {1 1 1 1 1}
 
352
 
 
353
test inherit-4.7 {built-in "isa" method works within methods} {
 
354
    set status ""
 
355
    foreach c [test_cd_mongrel0 info heritage] {
 
356
        lappend status [test_cd_mongrel0 test_cd_foo::do isa $c]
 
357
    }
 
358
    set status
 
359
} {1 1 1 1 1}
 
360
 
 
361
test inherit-4.8 {built-in "isa" method recognizes bad classes} {
 
362
    itcl::class test_cd_other {}
 
363
    test_cd_mongrel0 isa test_cd_other
 
364
} {0}
 
365
 
 
366
test inherit-4.9 {built-in "isa" method recognizes bad classes} {
 
367
    list [catch {test_cd_mongrel0 isa test_cd_bogus} msg] $msg
 
368
} {1 {class "test_cd_bogus" not found in context "::test_cd_foo"}}
 
369
 
 
370
eval namespace delete [itcl::find classes test_cd_*]
 
371
 
 
372
# ----------------------------------------------------------------------
 
373
#  Test "find objects"
 
374
# ----------------------------------------------------------------------
 
375
test inherit-5.1 {define classes for inheritance info} {
 
376
    itcl::class test_cd_foo {
 
377
    }
 
378
    itcl::class test_cd_bar {
 
379
    }
 
380
    itcl::class test_cd_foobar {
 
381
        inherit test_cd_foo test_cd_bar
 
382
    }
 
383
    itcl::class test_cd_geek {
 
384
    }
 
385
    itcl::class test_cd_mongrel {
 
386
        inherit test_cd_foobar test_cd_geek
 
387
    }
 
388
} {}
 
389
 
 
390
test inherit-5.2 {create objects for info tests} {
 
391
    list [test_cd_foo #auto] [test_cd_foo #auto] \
 
392
         [test_cd_foobar #auto] \
 
393
         [test_cd_geek #auto] \
 
394
         [test_cd_mongrel #auto]
 
395
} {test_cd_foo0 test_cd_foo1 test_cd_foobar0 test_cd_geek0 test_cd_mongrel0}
 
396
 
 
397
test inherit-5.3 {find objects: -class qualifier} {
 
398
    lsort [itcl::find objects -class test_cd_foo]
 
399
} {test_cd_foo0 test_cd_foo1}
 
400
 
 
401
test inherit-5.4 {find objects: -class qualifier} {
 
402
    lsort [itcl::find objects -class test_cd_mongrel]
 
403
} {test_cd_mongrel0}
 
404
 
 
405
test inherit-5.5 {find objects: -isa qualifier} {
 
406
    lsort [itcl::find objects -isa test_cd_foo]
 
407
} {test_cd_foo0 test_cd_foo1 test_cd_foobar0 test_cd_mongrel0}
 
408
 
 
409
test inherit-5.6 {find objects: -isa qualifier} {
 
410
    lsort [itcl::find objects -isa test_cd_mongrel]
 
411
} {test_cd_mongrel0}
 
412
 
 
413
test inherit-5.7 {find objects: name qualifier} {
 
414
    lsort [itcl::find objects test_cd_foo*]
 
415
} {test_cd_foo0 test_cd_foo1 test_cd_foobar0}
 
416
 
 
417
test inherit-5.8 {find objects: -class and -isa qualifiers} {
 
418
    lsort [itcl::find objects -isa test_cd_foo -class test_cd_foobar]
 
419
} {test_cd_foobar0}
 
420
 
 
421
test inherit-5.9 {find objects: -isa and name qualifiers} {
 
422
    lsort [itcl::find objects -isa test_cd_foo *0]
 
423
} {test_cd_foo0 test_cd_foobar0 test_cd_mongrel0}
 
424
 
 
425
test inherit-5.10 {find objects: usage errors} {
 
426
    list [catch {itcl::find objects -xyzzy value} msg] $msg
 
427
} {1 {wrong # args: should be "itcl::find objects ?-class className? ?-isa className? ?pattern?"}}
 
428
 
 
429
eval namespace delete [itcl::find classes test_cd_*]
 
430
 
 
431
# ----------------------------------------------------------------------
 
432
#  Test method scoping and execution
 
433
# ----------------------------------------------------------------------
 
434
test inherit-6.1 {define classes for scope tests} {
 
435
    itcl::class test_cd_foo {
 
436
        method check {} {return "foo"}
 
437
        method do {args} {return "foo says: [eval $args]"}
 
438
    }
 
439
    itcl::class test_cd_bar {
 
440
        method check {} {return "bar"}
 
441
        method do {args} {return "bar says: [eval $args]"}
 
442
    }
 
443
    itcl::class test_cd_foobar {
 
444
        inherit test_cd_foo test_cd_bar
 
445
        method check {} {return "foobar"}
 
446
        method do {args} {return "foobar says: [eval $args]"}
 
447
    }
 
448
    itcl::class test_cd_geek {
 
449
        method check {} {return "geek"}
 
450
        method do {args} {return "geek says: [eval $args]"}
 
451
    }
 
452
    itcl::class test_cd_mongrel {
 
453
        inherit test_cd_foobar test_cd_geek
 
454
        method check {} {return "mongrel"}
 
455
        method do {args} {return "mongrel says: [eval $args]"}
 
456
    }
 
457
} {}
 
458
 
 
459
test inherit-6.2 {create objects for scoping tests} {
 
460
    list [test_cd_mongrel #auto] [test_cd_foobar #auto]
 
461
} {test_cd_mongrel0 test_cd_foobar0}
 
462
 
 
463
test inherit-6.3 {methods are "virtual" outside of the class} {
 
464
    test_cd_mongrel0 check
 
465
} {mongrel}
 
466
 
 
467
test inherit-6.4 {specific methods can be accessed by name} {
 
468
    test_cd_mongrel0 test_cd_foo::check
 
469
} {foo}
 
470
 
 
471
test inherit-6.5 {methods are "virtual" within a class too} {
 
472
    test_cd_mongrel0 test_cd_foobar::do check
 
473
} {foobar says: mongrel}
 
474
 
 
475
test inherit-6.6 {methods are executed where they were defined} {
 
476
    list [test_cd_mongrel0 test_cd_foo::do namespace current] \
 
477
         [test_cd_mongrel0 test_cd_foobar::do namespace current] \
 
478
         [test_cd_mongrel0 do namespace current] \
 
479
} {{foo says: ::test_cd_foo} {foobar says: ::test_cd_foobar} {mongrel says: ::test_cd_mongrel}}
 
480
 
 
481
test inherit-6.7 {"virtual" command no longer exists} {
 
482
    list [catch {
 
483
        test_cd_mongrel0 test_cd_foobar::do virtual namespace current
 
484
    } msg] $msg
 
485
} {1 {invalid command name "virtual"}}
 
486
 
 
487
test inherit-6.8 {"previous" command no longer exists} {
 
488
    list [catch {
 
489
        test_cd_mongrel0 test_cd_foobar::do previous check
 
490
    } msg] $msg
 
491
} {1 {invalid command name "previous"}}
 
492
 
 
493
test inherit-6.9 {errors are detected and reported across class boundaries} {
 
494
    #
 
495
    # NOTE: For tcl8.2.3 and earlier the stack trace will have
 
496
    #       'invoked from within "eval $args"' for the first eval
 
497
    #       statement.  For later versions, it does not.  Use
 
498
    #       string match to reduce the sensitivity to that.
 
499
    #
 
500
    list [catch {
 
501
        test_cd_mongrel0 do test_cd_foobar0 do error "test" "some error"
 
502
    } msg] $msg [string match {some error
 
503
    ("eval" body line 1)*
 
504
    (object "::test_cd_foobar0" method "::test_cd_foobar::do" body line 1)
 
505
    invoked from within
 
506
"test_cd_foobar0 do error test {some error}"
 
507
    ("eval" body line 1)
 
508
    invoked from within
 
509
"eval $args"
 
510
    (object "::test_cd_mongrel0" method "::test_cd_mongrel::do" body line 1)
 
511
    invoked from within
 
512
"test_cd_mongrel0 do test_cd_foobar0 do error "test" "some error""} [set ::errorInfo]]
 
513
} {1 test 1}
 
514
 
 
515
test inherit-6.10 {errors codes are preserved across class boundaries} {
 
516
    list [catch {
 
517
        test_cd_mongrel0 do test_cd_foobar0 do error "test" "problem" CODE-BLUE
 
518
    } msg] $msg [set ::errorCode]
 
519
} {1 test CODE-BLUE}
 
520
 
 
521
test inherit-6.11 {multi-value error codes are preserved across class boundaries} {
 
522
    list [catch {
 
523
        test_cd_mongrel0 do test_cd_foobar0 do error "test" "problem" "CODE BLUE 123"
 
524
    } msg] $msg [set ::errorCode]
 
525
} {1 test {CODE BLUE 123}}
 
526
 
 
527
eval namespace delete [itcl::find classes test_cd_*]
 
528
 
 
529
# ----------------------------------------------------------------------
 
530
#  Test inheritance errors
 
531
# ----------------------------------------------------------------------
 
532
test inherit-7.1 {cannot inherit from non-existant class} {
 
533
    list [catch {
 
534
        itcl::class bogus {
 
535
            inherit non_existant_class_xyzzy
 
536
        }
 
537
    } msg] $msg
 
538
} {1 {cannot inherit from "non_existant_class_xyzzy" (class "non_existant_class_xyzzy" not found in context "::")}}
 
539
 
 
540
test inherit-7.2 {cannot inherit from procs} {
 
541
    proc inherit_test_proc {x y} {
 
542
        error "never call this"
 
543
    }
 
544
    list [catch {
 
545
        itcl::class bogus {
 
546
            inherit inherit_test_proc
 
547
        }
 
548
    } msg] $msg
 
549
} {1 {cannot inherit from "inherit_test_proc" (class "inherit_test_proc" not found in context "::")}}
 
550
 
 
551
test inherit-7.3 {cannot inherit from yourself} {
 
552
    list [catch {
 
553
        itcl::class bogus {
 
554
            inherit bogus
 
555
        }
 
556
    } msg] $msg
 
557
} {1 {class "bogus" cannot inherit from itself}}
 
558
 
 
559
test inherit-7.4 {cannot have more than one inherit statement} {
 
560
    list [catch {
 
561
        itcl::class test_inherit_base1 { }
 
562
        itcl::class test_inherit_base2 { }
 
563
        itcl::class bogus {
 
564
            inherit test_inherit_base1
 
565
            inherit test_inherit_base2
 
566
        }
 
567
    } msg] $msg
 
568
} {1 {inheritance "test_inherit_base1 " already defined for class "::bogus"}}
 
569
 
 
570
::itcl::delete class test_inherit_base1 test_inherit_base2
 
571
 
 
572
# ----------------------------------------------------------------------
 
573
#  Multiple base class error detection
 
574
# ----------------------------------------------------------------------
 
575
test inherit-8.1 {cannot inherit from the same base class more than once} {
 
576
    itcl::class test_mi_base {}
 
577
    itcl::class test_mi_foo {inherit test_mi_base}
 
578
    itcl::class test_mi_bar {inherit test_mi_base}
 
579
    list [catch {
 
580
        itcl::class test_mi_foobar {inherit test_mi_foo test_mi_bar}
 
581
    } msg] $msg
 
582
} {1 {class "::test_mi_foobar" inherits base class "::test_mi_base" more than once:
 
583
  test_mi_foobar->test_mi_foo->test_mi_base
 
584
  test_mi_foobar->test_mi_bar->test_mi_base}}
 
585
 
 
586
itcl::delete class test_mi_base
 
587
 
 
588
::tcltest::cleanupTests
 
589
return