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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [info.test] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
# Commands covered:  info
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-1994 The Regents of the University of California.
8
# Copyright (c) 1994-1995 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: info.test,v 1.1.1.1 2002-01-16 10:25:36 markom Exp $
14
 
15
if {[string compare test [info procs test]] == 1} then {source defs}
16
 
17
test info-1.1 {info args option} {
18
    proc t1 {a bbb c} {return foo}
19
    info args t1
20
} {a bbb c}
21
test info-1.2 {info args option} {
22
    proc t1 {{a default1} {bbb default2} {c default3} args} {return foo}
23
    info a t1
24
} {a bbb c args}
25
test info-1.3 {info args option} {
26
    proc t1 "" {return foo}
27
    info args t1
28
} {}
29
test info-1.4 {info args option} {
30
    catch {rename t1 {}}
31
    list [catch {info args t1} msg] $msg
32
} {1 {"t1" isn't a procedure}}
33
test info-1.5 {info args option} {
34
    list [catch {info args set} msg] $msg
35
} {1 {"set" isn't a procedure}}
36
test info-1.6 {info args option} {
37
    proc t1 {a b} {set c 123; set d $c}
38
    t1 1 2
39
    info args t1
40
} {a b}
41
 
42
test info-2.1 {info body option} {
43
    proc t1 {} {body of t1}
44
    info body t1
45
} {body of t1}
46
test info-2.2 {info body option} {
47
    list [catch {info body set} msg] $msg
48
} {1 {"set" isn't a procedure}}
49
test info-2.3 {info body option} {
50
    list [catch {info args set 1} msg] $msg
51
} {1 {wrong # args: should be "info args procname"}}
52
 
53
# "info cmdcount" is no longer accurate for compiled commands! The expected
54
# result for info-3.1 used to be "3" and is now "1" since the "set"s have
55
# been compiled away.
56
test info-3.1 {info cmdcount option} {
57
    set x [info cmdcount]
58
    set y 12345
59
    set z [info cm]
60
    expr $z-$x
61
} 1
62
test info-3.2 {info body option} {
63
    list [catch {info cmdcount 1} msg] $msg
64
} {1 {wrong # args: should be "info cmdcount"}}
65
 
66
test info-4.1 {info commands option} {
67
    proc t1 {} {}
68
    proc t2 {} {}
69
    set x " [info commands] "
70
    list [string match {* t1 *} $x] [string match {* t2 *} $x] \
71
            [string match {* set *} $x] [string match {* list *} $x]
72
} {1 1 1 1}
73
test info-4.2 {info commands option} {
74
    proc t1 {} {}
75
    rename t1 {}
76
    set x [info comm]
77
    string match {* t1 *} $x
78
} 0
79
test info-4.3 {info commands option} {
80
    proc _t1_ {} {}
81
    proc _t2_ {} {}
82
    info commands _t1_
83
} _t1_
84
test info-4.4 {info commands option} {
85
    proc _t1_ {} {}
86
    proc _t2_ {} {}
87
    lsort [info commands _t*]
88
} {_t1_ _t2_}
89
catch {rename _t1_ {}}
90
catch {rename _t2_ {}}
91
test info-4.5 {info commands option} {
92
    list [catch {info commands a b} msg] $msg
93
} {1 {wrong # args: should be "info commands ?pattern?"}}
94
 
95
test info-5.1 {info complete option} {
96
    info complete ""
97
} 1
98
test info-5.2 {info complete option} {
99
    info complete "  \n"
100
} 1
101
test info-5.3 {info complete option} {
102
    info complete "abc def"
103
} 1
104
test info-5.4 {info complete option} {
105
    info complete "a b c d e f \t\n"
106
} 1
107
test info-5.5 {info complete option} {
108
    info complete {a b c"d}
109
} 1
110
test info-5.6 {info complete option} {
111
    info complete {a b "c d" e}
112
} 1
113
test info-5.7 {info complete option} {
114
    info complete {a b "c d"}
115
} 1
116
test info-5.8 {info complete option} {
117
    info complete {a b "c d"}
118
} 1
119
test info-5.9 {info complete option} {
120
    info complete {a b "c d}
121
} 0
122
test info-5.10 {info complete option} {
123
    info complete {a b "}
124
} 0
125
test info-5.11 {info complete option} {
126
    info complete {a b "cd"xyz}
127
} 1
128
test info-5.12 {info complete option} {
129
    info complete {a b "c $d() d"}
130
} 1
131
test info-5.13 {info complete option} {
132
    info complete {a b "c $dd("}
133
} 0
134
test info-5.14 {info complete option} {
135
    info complete {a b "c \"}
136
} 0
137
test info-5.15 {info complete option} {
138
    info complete {a b "c [d e f]"}
139
} 1
140
test info-5.16 {info complete option} {
141
    info complete {a b "c [d e f] g"}
142
} 1
143
test info-5.17 {info complete option} {
144
    info complete {a b "c [d e f"}
145
} 0
146
test info-5.18 {info complete option} {
147
    info complete {a {b c d} e}
148
} 1
149
test info-5.19 {info complete option} {
150
    info complete {a {b c d}}
151
} 1
152
test info-5.20 {info complete option} {
153
    info complete "a b\{c d"
154
} 1
155
test info-5.21 {info complete option} {
156
    info complete "a b \{c"
157
} 0
158
test info-5.22 {info complete option} {
159
    info complete "a b \{c{ }"
160
} 0
161
test info-5.23 {info complete option} {
162
    info complete "a b {c d e}xxx"
163
} 1
164
test info-5.24 {info complete option} {
165
    info complete "a b {c \\\{d e}xxx"
166
} 1
167
test info-5.25 {info complete option} {
168
    info complete {a b [ab cd ef]}
169
} 1
170
test info-5.26 {info complete option} {
171
    info complete {a b x[ab][cd][ef] gh}
172
} 1
173
test info-5.27 {info complete option} {
174
    info complete {a b x[ab][cd[ef] gh}
175
} 0
176
test info-5.28 {info complete option} {
177
    info complete {a b x[ gh}
178
} 0
179
test info-5.29 {info complete option} {
180
    info complete {[]]]}
181
} 1
182
test info-5.30 {info complete option} {
183
    info complete {abc x$yyy}
184
} 1
185
test info-5.31 {info complete option} {
186
    info complete "abc x\${abc\[\\d} xyz"
187
} 1
188
test info-5.32 {info complete option} {
189
    info complete "abc x\$\{ xyz"
190
} 0
191
test info-5.33 {info complete option} {
192
    info complete {word $a(xyz)}
193
} 1
194
test info-5.34 {info complete option} {
195
    info complete {word $a(}
196
} 0
197
test info-5.35 {info complete option} {
198
    info complete "set a \\\n"
199
} 0
200
test info-5.36 {info complete option} {
201
    info complete "set a \\n "
202
} 1
203
test info-5.37 {info complete option} {
204
    info complete "set a \\"
205
} 1
206
test info-5.38 {info complete option} {
207
    info complete "foo \\\n\{"
208
} 0
209
test info-5.39 {info complete option} {
210
    info complete " # \{"
211
} 1
212
test info-5.40 {info complete option} {
213
    info complete "foo bar;# \{"
214
} 1
215
test info-5.41 {info complete option} {
216
    info complete "a\nb\n# \{\n# \{\nc\n"
217
} 1
218
test info-5.42 {info complete option} {
219
    info complete "#Incomplete comment\\\n"
220
} 0
221
test info-5.43 {info complete option} {
222
    info complete "#Incomplete comment\\\nBut now it's complete.\n"
223
} 1
224
test info-5.44 {info complete option} {
225
    info complete "# Complete comment\\\\\n"
226
} 1
227
test info-5.45 {info complete option} {
228
    info complete "abc\\\n def"
229
} 1
230
test info-5.46 {info complete option} {
231
    info complete "abc\\\n "
232
} 1
233
test info-5.47 {info complete option} {
234
    info complete "abc\\\n"
235
} 0
236
test info-5.48 {info complete option} {
237
    info complete "set x [binary format H 00]; puts hi"
238
} 1
239
test info-5.49 {info complete option} {
240
    info complete "set x [binary format H 00]; \{"
241
} 0
242
 
243
test info-6.1 {info default option} {
244
    proc t1 {a b {c d} {e "long default value"}} {}
245
    info default t1 a value
246
} 0
247
test info-6.2 {info default option} {
248
    proc t1 {a b {c d} {e "long default value"}} {}
249
    set value 12345
250
    info d t1 a value
251
    set value
252
} {}
253
test info-6.3 {info default option} {
254
    proc t1 {a b {c d} {e "long default value"}} {}
255
    info default t1 c value
256
} 1
257
test info-6.4 {info default option} {
258
    proc t1 {a b {c d} {e "long default value"}} {}
259
    set value 12345
260
    info default t1 c value
261
    set value
262
} d
263
test info-6.5 {info default option} {
264
    proc t1 {a b {c d} {e "long default value"}} {}
265
    set value 12345
266
    set x [info default t1 e value]
267
    list $x $value
268
} {1 {long default value}}
269
test info-6.6 {info default option} {
270
    list [catch {info default a b} msg] $msg
271
} {1 {wrong # args: should be "info default procname arg varname"}}
272
test info-6.7 {info default option} {
273
    list [catch {info default _nonexistent_ a b} msg] $msg
274
} {1 {"_nonexistent_" isn't a procedure}}
275
test info-6.8 {info default option} {
276
    proc t1 {a b} {}
277
    list [catch {info default t1 x value} msg] $msg
278
} {1 {procedure "t1" doesn't have an argument "x"}}
279
test info-6.9 {info default option} {
280
    catch {unset a}
281
    set a(0) 88
282
    proc t1 {a b} {}
283
    list [catch {info default t1 a a} msg] $msg
284
} {1 {couldn't store default value in variable "a"}}
285
test info-6.10 {info default option} {
286
    catch {unset a}
287
    set a(0) 88
288
    proc t1 {{a 18} b} {}
289
    list [catch {info default t1 a a} msg] $msg
290
} {1 {couldn't store default value in variable "a"}}
291
catch {unset a}
292
 
293
test info-7.1 {info exists option} {
294
    set value foo
295
    info exists value
296
} 1
297
catch {unset _nonexistent_}
298
test info-7.2 {info exists option} {
299
    info exists _nonexistent_
300
} 0
301
test info-7.3 {info exists option} {
302
    proc t1 {x} {return [info exists x]}
303
    t1 2
304
} 1
305
test info-7.4 {info exists option} {
306
    proc t1 {x} {
307
        global _nonexistent_
308
        return [info exists _nonexistent_]
309
    }
310
    t1 2
311
} 0
312
test info-7.5 {info exists option} {
313
    proc t1 {x} {
314
        set y 47
315
        return [info exists y]
316
    }
317
    t1 2
318
} 1
319
test info-7.6 {info exists option} {
320
    proc t1 {x} {return [info exists value]}
321
    t1 2
322
} 0
323
test info-7.7 {info exists option} {
324
    catch {unset x}
325
    set x(2) 44
326
    list [info exists x] [info exists x(1)] [info exists x(2)]
327
} {1 0 1}
328
catch {unset x}
329
test info-7.8 {info exists option} {
330
    list [catch {info exists} msg] $msg
331
} {1 {wrong # args: should be "info exists varName"}}
332
test info-7.9 {info exists option} {
333
    list [catch {info exists 1 2} msg] $msg
334
} {1 {wrong # args: should be "info exists varName"}}
335
 
336
test info-8.1 {info globals option} {
337
    set x 1
338
    set y 2
339
    set value 23
340
    set a " [info globals] "
341
    list [string match {* x *} $a] [string match {* y *} $a] \
342
            [string match {* value *} $a] [string match {* _foobar_ *} $a]
343
} {1 1 1 0}
344
test info-8.2 {info globals option} {
345
    set _xxx1 1
346
    set _xxx2 2
347
    lsort [info g _xxx*]
348
} {_xxx1 _xxx2}
349
test info-8.3 {info globals option} {
350
    list [catch {info globals 1 2} msg] $msg
351
} {1 {wrong # args: should be "info globals ?pattern?"}}
352
 
353
test info-9.1 {info level option} {
354
    info level
355
} 0
356
test info-9.2 {info level option} {
357
    proc t1 {a b} {
358
        set x [info le]
359
        set y [info level 1]
360
        list $x $y
361
    }
362
    t1 146 testString
363
} {1 {t1 146 testString}}
364
test info-9.3 {info level option} {
365
    proc t1 {a b} {
366
        t2 [expr $a*2] $b
367
    }
368
    proc t2 {x y} {
369
        list [info level] [info level 1] [info level 2] [info level -1] \
370
                [info level 0]
371
    }
372
    t1 146 {a {b c} {{{c}}}}
373
} {2 {t1 146 {a {b c} {{{c}}}}} {t2 292 {a {b c} {{{c}}}}} {t1 146 {a {b c} {{{c}}}}} {t2 292 {a {b c} {{{c}}}}}}
374
test info-9.4 {info level option} {
375
    proc t1 {} {
376
        set x [info level]
377
        set y [info level 1]
378
        list $x $y
379
    }
380
    t1
381
} {1 t1}
382
test info-9.5 {info level option} {
383
    list [catch {info level 1 2} msg] $msg
384
} {1 {wrong # args: should be "info level ?number?"}}
385
test info-9.6 {info level option} {
386
    list [catch {info level 123a} msg] $msg
387
} {1 {expected integer but got "123a"}}
388
test info-9.7 {info level option} {
389
    list [catch {info level 0} msg] $msg
390
} {1 {bad level "0"}}
391
test info-9.8 {info level option} {
392
    proc t1 {} {info level -1}
393
    list [catch {t1} msg] $msg
394
} {1 {bad level "-1"}}
395
test info-9.9 {info level option} {
396
    proc t1 {x} {info level $x}
397
    list [catch {t1 -3} msg] $msg
398
} {1 {bad level "-3"}}
399
 
400
set savedLibrary $tcl_library
401
test info-10.1 {info library option} {
402
    list [catch {info library x} msg] $msg
403
} {1 {wrong # args: should be "info library"}}
404
test info-10.2 {info library option} {
405
    set tcl_library 12345
406
    info library
407
} {12345}
408
test info-10.3 {info library option} {
409
    unset tcl_library
410
    list [catch {info library} msg] $msg
411
} {1 {no library has been specified for Tcl}}
412
set tcl_library $savedLibrary
413
 
414
test info-11.1 {info loaded option} {
415
    list [catch {info loaded a b} msg] $msg
416
} {1 {wrong # args: should be "info loaded ?interp?"}}
417
test info-11.2 {info loaded option} {
418
    list [catch {info loaded {}}] [catch {info loaded gorp} msg] $msg
419
} {0 1 {couldn't find slave interpreter named "gorp"}}
420
 
421
test info-12.1 {info locals option} {
422
    set a 22
423
    proc t1 {x y} {
424
        set b 13
425
        set c testing
426
        global a
427
        return [info locals]
428
    }
429
    lsort [t1 23 24]
430
} {b c x y}
431
test info-12.2 {info locals option} {
432
    proc t1 {x y} {
433
        set xx1 2
434
        set xx2 3
435
        set y 4
436
        return [info loc x*]
437
    }
438
    lsort [t1 2 3]
439
} {x xx1 xx2}
440
test info-12.3 {info locals option} {
441
    list [catch {info locals 1 2} msg] $msg
442
} {1 {wrong # args: should be "info locals ?pattern?"}}
443
test info-12.4 {info locals option} {
444
    info locals
445
} {}
446
test info-12.5 {info locals option} {
447
    proc t1 {} {return [info locals]}
448
    t1
449
} {}
450
test info-12.6 {info locals vs unset compiled locals} {
451
    proc t1 {lst} {
452
        foreach $lst $lst {}
453
        unset lst
454
        return [info locals]
455
    }
456
    lsort [t1 {a b c c d e f}]
457
} {a b c d e f}
458
test info-12.7 {info locals with temporary variables} {
459
    proc t1 {} {
460
        foreach a {b c} {}
461
        info locals
462
    }
463
    t1
464
} {a}
465
 
466
test info-13.1 {info nameofexecutable option} {
467
    list [catch {info nameofexecutable foo} msg] $msg
468
} {1 {wrong # args: should be "info nameofexecutable"}}
469
 
470
test info-14.1 {info patchlevel option} {
471
    set a [info patchlevel]
472
    regexp {[0-9]+\.[0-9]+([p[0-9]+)?} $a
473
} 1
474
test info-14.2 {info patchlevel option} {
475
    list [catch {info patchlevel a} msg] $msg
476
} {1 {wrong # args: should be "info patchlevel"}}
477
test info-14.3 {info patchlevel option} {
478
    set t $tcl_patchLevel
479
    unset tcl_patchLevel
480
    set result [list [catch {info patchlevel} msg] $msg]
481
    set tcl_patchLevel $t
482
    set result
483
} {1 {can't read "tcl_patchLevel": no such variable}}
484
 
485
test info-15.1 {info procs option} {
486
    proc t1 {} {}
487
    proc t2 {} {}
488
    set x " [info procs] "
489
    list [string match {* t1 *} $x] [string match {* t2 *} $x] \
490
            [string match {* _undefined_ *} $x]
491
} {1 1 0}
492
test info-15.2 {info procs option} {
493
    proc _tt1 {} {}
494
    proc _tt2 {} {}
495
    lsort [info pr _tt*]
496
} {_tt1 _tt2}
497
catch {rename _tt1 {}}
498
catch {rename _tt2 {}}
499
test info-15.3 {info procs option} {
500
    list [catch {info procs 2 3} msg] $msg
501
} {1 {wrong # args: should be "info procs ?pattern?"}}
502
 
503
set self info.test
504
if {$tcl_platform(os) == "Win32s"} {
505
    set self info~1.tes
506
}
507
 
508
test info-16.1 {info script option} {
509
    list [catch {info script x} msg] $msg
510
} {1 {wrong # args: should be "info script"}}
511
test info-16.2 {info script option} {
512
    file tail [info sc]
513
} $self
514
removeFile gorp.info
515
makeFile "info script\n" gorp.info
516
test info-16.3 {info script option} {
517
    list [source gorp.info] [file tail [info script]]
518
} [list gorp.info $self]
519
test info-16.4 {resetting "info script" after errors} {
520
    catch {source ~_nobody_/foo}
521
    file tail [info script]
522
} $self
523
test info-16.5 {resetting "info script" after errors} {
524
    catch {source _nonexistent_}
525
    file tail [info script]
526
} $self
527
removeFile gorp.info
528
 
529
test info-17.1 {info sharedlibextension option} {
530
    list [catch {info sharedlibextension foo} msg] $msg
531
} {1 {wrong # args: should be "info sharedlibextension"}}
532
 
533
test info-18.1 {info tclversion option} {
534
    set x [info tclversion]
535
    scan $x "%d.%d%c" a b c
536
} 2
537
test info-18.2 {info tclversion option} {
538
    list [catch {info t 2} msg] $msg
539
} {1 {wrong # args: should be "info tclversion"}}
540
test info-18.3 {info tclversion option} {
541
    set t $tcl_version
542
    unset tcl_version
543
    set result [list [catch {info tclversion} msg] $msg]
544
    set tcl_version $t
545
    set result
546
} {1 {can't read "tcl_version": no such variable}}
547
 
548
test info-19.1 {info vars option} {
549
    set a 1
550
    set b 2
551
    proc t1 {x y} {
552
        global a b
553
        set c 33
554
        return [info vars]
555
    }
556
    lsort [t1 18 19]
557
} {a b c x y}
558
test info-19.2 {info vars option} {
559
    set xxx1 1
560
    set xxx2 2
561
    proc t1 {xxa y} {
562
        global xxx1 xxx2
563
        set c 33
564
        return [info vars x*]
565
    }
566
    lsort [t1 18 19]
567
} {xxa xxx1 xxx2}
568
test info-19.3 {info vars option} {
569
    lsort [info vars]
570
} [lsort [info globals]]
571
test info-19.4 {info vars option} {
572
    list [catch {info vars a b} msg] $msg
573
} {1 {wrong # args: should be "info vars ?pattern?"}}
574
test info-19.5 {info vars with temporary variables} {
575
    proc t1 {} {
576
        foreach a {b c} {}
577
        info vars
578
    }
579
    t1
580
} {a}
581
 
582
test info-20.1 {miscellaneous error conditions} {
583
    list [catch {info} msg] $msg
584
} {1 {wrong # args: should be "info option ?arg arg ...?"}}
585
test info-20.2 {miscellaneous error conditions} {
586
    list [catch {info gorp} msg] $msg
587
} {1 {bad option "gorp": must be args, body, cmdcount, commands, complete, default, exists, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}}
588
test info-20.3 {miscellaneous error conditions} {
589
    list [catch {info c} msg] $msg
590
} {1 {ambiguous option "c": must be args, body, cmdcount, commands, complete, default, exists, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}}
591
test info-20.4 {miscellaneous error conditions} {
592
    list [catch {info l} msg] $msg
593
} {1 {ambiguous option "l": must be args, body, cmdcount, commands, complete, default, exists, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}}
594
test info-20.5 {miscellaneous error conditions} {
595
    list [catch {info s} msg] $msg
596
} {1 {ambiguous option "s": must be args, body, cmdcount, commands, complete, default, exists, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars}}

powered by: WebSVN 2.1.0

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