Diff
Not logged in

Differences From Artifact [e26dbfaf7a]:

To Artifact [44873c091b]:


1
2
3
4
5
6
7
8

9
10
11
12
13
14



15











16
17
18
19
20
21
22
# Commands covered:  info
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1991-1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.

#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: info.test,v 1.5 1998/11/11 02:39:56 welch Exp $




if {[string compare test [info procs test]] == 1} then {source defs}












test info-1.1 {info args option} {
    proc t1 {a bbb c} {return foo}
    info args t1
} {a bbb c}
test info-1.2 {info args option} {
    proc t1 {{a default1} {bbb default2} {c default3} args} {return foo}







|
>




|

>
>
>
|
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Commands covered:  info
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1991-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: info.test,v 1.6 1999/04/16 00:47:29 stanton Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

# Set up namespaces needed to test operation of "info args", "info body",
# "info default", and "info procs" with imported procedures.

catch {namespace delete test_ns_info1 test_ns_info2}

namespace eval test_ns_info1 {
    namespace export *
    proc p {x} {return "x=$x"}
    proc q {{y 27} z} {return "y=$y"}
}


test info-1.1 {info args option} {
    proc t1 {a bbb c} {return foo}
    info args t1
} {a bbb c}
test info-1.2 {info args option} {
    proc t1 {{a default1} {bbb default2} {c default3} args} {return foo}
34
35
36
37
38
39
40







41
42
43
44
45
46
47
48
49
50
51







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    list [catch {info args set} msg] $msg
} {1 {"set" isn't a procedure}}
test info-1.6 {info args option} {
    proc t1 {a b} {set c 123; set d $c}
    t1 1 2
    info args t1
} {a b}








test info-2.1 {info body option} {
    proc t1 {} {body of t1}
    info body t1
} {body of t1}
test info-2.2 {info body option} {
    list [catch {info body set} msg] $msg
} {1 {"set" isn't a procedure}}
test info-2.3 {info body option} {
    list [catch {info args set 1} msg] $msg
} {1 {wrong # args: should be "info args procname"}}








# "info cmdcount" is no longer accurate for compiled commands! The expected
# result for info-3.1 used to be "3" and is now "1" since the "set"s have
# been compiled away.
test info-3.1 {info cmdcount option} {
    set x [info cmdcount]
    set y 12345
    set z [info cm]
    expr $z-$x
} 1
test info-3.2 {info body option} {
    list [catch {info cmdcount 1} msg] $msg
} {1 {wrong # args: should be "info cmdcount"}}

test info-4.1 {info commands option} {
    proc t1 {} {}
    proc t2 {} {}
    set x " [info commands] "







>
>
>
>
>
>
>











>
>
>
>
>
>
>










|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    list [catch {info args set} msg] $msg
} {1 {"set" isn't a procedure}}
test info-1.6 {info args option} {
    proc t1 {a b} {set c 123; set d $c}
    t1 1 2
    info args t1
} {a b}
test info-1.7 {info args option} {
    catch {namespace delete test_ns_info2}
    namespace eval test_ns_info2 {
        namespace import ::test_ns_info1::*
        list [info args p] [info args q]
    }
} {x {y z}}

test info-2.1 {info body option} {
    proc t1 {} {body of t1}
    info body t1
} {body of t1}
test info-2.2 {info body option} {
    list [catch {info body set} msg] $msg
} {1 {"set" isn't a procedure}}
test info-2.3 {info body option} {
    list [catch {info args set 1} msg] $msg
} {1 {wrong # args: should be "info args procname"}}
test info-2.4 {info body option} {
    catch {namespace delete test_ns_info2}
    namespace eval test_ns_info2 {
        namespace import ::test_ns_info1::*
        list [info body p] [info body q]
    }
} {{return "x=$x"} {return "y=$y"}}

# "info cmdcount" is no longer accurate for compiled commands! The expected
# result for info-3.1 used to be "3" and is now "1" since the "set"s have
# been compiled away.
test info-3.1 {info cmdcount option} {
    set x [info cmdcount]
    set y 12345
    set z [info cm]
    expr $z-$x
} 1
test info-3.2 {info cmdcount option} {
    list [catch {info cmdcount 1} msg] $msg
} {1 {wrong # args: should be "info cmdcount"}}

test info-4.1 {info commands option} {
    proc t1 {} {}
    proc t2 {} {}
    set x " [info commands] "
89
90
91
92
93
94
95



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
catch {rename _t1_ {}}
catch {rename _t2_ {}}
test info-4.5 {info commands option} {
    list [catch {info commands a b} msg] $msg
} {1 {wrong # args: should be "info commands ?pattern?"}}

test info-5.1 {info complete option} {



    info complete ""
} 1
test info-5.2 {info complete option} {
    info complete "  \n"
} 1
test info-5.3 {info complete option} {
    info complete "abc def"
} 1
test info-5.4 {info complete option} {
    info complete "a b c d e f \t\n"
} 1
test info-5.5 {info complete option} {
    info complete {a b c"d}
} 1
test info-5.6 {info complete option} {
    info complete {a b "c d" e}
} 1
test info-5.7 {info complete option} {
    info complete {a b "c d"}
} 1
test info-5.8 {info complete option} {
    info complete {a b "c d"}
} 1
test info-5.9 {info complete option} {
    info complete {a b "c d}
} 0
test info-5.10 {info complete option} {
    info complete {a b "}
} 0
test info-5.11 {info complete option} {
    info complete {a b "cd"xyz}
} 1
test info-5.12 {info complete option} {
    info complete {a b "c $d() d"}
} 1
test info-5.13 {info complete option} {
    info complete {a b "c $dd("}
} 0
test info-5.14 {info complete option} {
    info complete {a b "c \"}
} 0
test info-5.15 {info complete option} {
    info complete {a b "c [d e f]"}
} 1
test info-5.16 {info complete option} {
    info complete {a b "c [d e f] g"}
} 1
test info-5.17 {info complete option} {
    info complete {a b "c [d e f"}
} 0
test info-5.18 {info complete option} {
    info complete {a {b c d} e}
} 1
test info-5.19 {info complete option} {
    info complete {a {b c d}}
} 1
test info-5.20 {info complete option} {
    info complete "a b\{c d"
} 1
test info-5.21 {info complete option} {
    info complete "a b \{c"
} 0
test info-5.22 {info complete option} {
    info complete "a b \{c{ }"
} 0
test info-5.23 {info complete option} {
    info complete "a b {c d e}xxx"
} 1
test info-5.24 {info complete option} {
    info complete "a b {c \\\{d e}xxx"
} 1
test info-5.25 {info complete option} {
    info complete {a b [ab cd ef]}
} 1
test info-5.26 {info complete option} {
    info complete {a b x[ab][cd][ef] gh}
} 1
test info-5.27 {info complete option} {
    info complete {a b x[ab][cd[ef] gh}
} 0
test info-5.28 {info complete option} {
    info complete {a b x[ gh}
} 0
test info-5.29 {info complete option} {
    info complete {[]]]}
} 1
test info-5.30 {info complete option} {
    info complete {abc x$yyy}
} 1
test info-5.31 {info complete option} {
    info complete "abc x\${abc\[\\d} xyz"
} 1
test info-5.32 {info complete option} {
    info complete "abc x\$\{ xyz"
} 0
test info-5.33 {info complete option} {
    info complete {word $a(xyz)}
} 1
test info-5.34 {info complete option} {
    info complete {word $a(}
} 0
test info-5.35 {info complete option} {
    info complete "set a \\\n"
} 0
test info-5.36 {info complete option} {
    info complete "set a \\n "
} 1
test info-5.37 {info complete option} {
    info complete "set a \\"
} 1
test info-5.38 {info complete option} {
    info complete "foo \\\n\{"
} 0
test info-5.39 {info complete option} {
    info complete " # \{"
} 1
test info-5.40 {info complete option} {
    info complete "foo bar;# \{"
} 1
test info-5.41 {info complete option} {
    info complete "a\nb\n# \{\n# \{\nc\n"
} 1
test info-5.42 {info complete option} {
    info complete "#Incomplete comment\\\n"
} 0
test info-5.43 {info complete option} {
    info complete "#Incomplete comment\\\nBut now it's complete.\n"
} 1
test info-5.44 {info complete option} {
    info complete "# Complete comment\\\\\n"
} 1
test info-5.45 {info complete option} {
    info complete "abc\\\n def"
} 1
test info-5.46 {info complete option} {
    info complete "abc\\\n "
} 1
test info-5.47 {info complete option} {
    info complete "abc\\\n"
} 0
test info-5.48 {info complete option} {
    info complete "set x [binary format H 00]; puts hi"
} 1
test info-5.49 {info complete option} {
    info complete "set x [binary format H 00]; \{"
} 0

test info-6.1 {info default option} {
    proc t1 {a b {c d} {e "long default value"}} {}
    info default t1 a value
} 0
test info-6.2 {info default option} {
    proc t1 {a b {c d} {e "long default value"}} {}







>
>
>
|


|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133





















134



135


















































































































136
137
138
139
140
141
142
catch {rename _t1_ {}}
catch {rename _t2_ {}}
test info-4.5 {info commands option} {
    list [catch {info commands a b} msg] $msg
} {1 {wrong # args: should be "info commands ?pattern?"}}

test info-5.1 {info complete option} {
    list [catch {info complete} msg] $msg
} {1 {wrong # args: should be "info complete command"}}
test info-5.2 {info complete option} {
    info complete abc
} 1
test info-5.2 {info complete option} {
    info complete "\{abcd "
} 0
test info-5.3 {info complete option} {





















    info complete {# Comment should be complete command}



} 1



















































































































test info-6.1 {info default option} {
    proc t1 {a b {c d} {e "long default value"}} {}
    info default t1 a value
} 0
test info-6.2 {info default option} {
    proc t1 {a b {c d} {e "long default value"}} {}
284
285
286
287
288
289
290







291
292
293
294
295
296
297
} {1 {couldn't store default value in variable "a"}}
test info-6.10 {info default option} {
    catch {unset a}
    set a(0) 88
    proc t1 {{a 18} b} {}
    list [catch {info default t1 a a} msg] $msg
} {1 {couldn't store default value in variable "a"}}







catch {unset a}

test info-7.1 {info exists option} {
    set value foo
    info exists value
} 1
catch {unset _nonexistent_}







>
>
>
>
>
>
>







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
} {1 {couldn't store default value in variable "a"}}
test info-6.10 {info default option} {
    catch {unset a}
    set a(0) 88
    proc t1 {{a 18} b} {}
    list [catch {info default t1 a a} msg] $msg
} {1 {couldn't store default value in variable "a"}}
test info-6.11 {info default option} {
    catch {namespace delete test_ns_info2}
    namespace eval test_ns_info2 {
        namespace import ::test_ns_info1::*
        list [info default p x foo] $foo [info default q y bar] $bar
    }
} {0 {} 1 27}
catch {unset a}

test info-7.1 {info exists option} {
    set value foo
    info exists value
} 1
catch {unset _nonexistent_}
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
set tcl_library $savedLibrary

test info-11.1 {info loaded option} {
    list [catch {info loaded a b} msg] $msg
} {1 {wrong # args: should be "info loaded ?interp?"}}
test info-11.2 {info loaded option} {
    list [catch {info loaded {}}] [catch {info loaded gorp} msg] $msg
} {0 1 {couldn't find slave interpreter named "gorp"}}

test info-12.1 {info locals option} {
    set a 22
    proc t1 {x y} {
        set b 13
        set c testing
        global a







|







313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
set tcl_library $savedLibrary

test info-11.1 {info loaded option} {
    list [catch {info loaded a b} msg] $msg
} {1 {wrong # args: should be "info loaded ?interp?"}}
test info-11.2 {info loaded option} {
    list [catch {info loaded {}}] [catch {info loaded gorp} msg] $msg
} {0 1 {could not find interpreter "gorp"}}

test info-12.1 {info locals option} {
    set a 22
    proc t1 {x y} {
        set b 13
        set c testing
        global a
495
496
497
498
499
500
501
502

503

504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    lsort [info pr _tt*]
} {_tt1 _tt2}
catch {rename _tt1 {}}
catch {rename _tt2 {}}
test info-15.3 {info procs option} {
    list [catch {info procs 2 3} msg] $msg
} {1 {wrong # args: should be "info procs ?pattern?"}}


set self info.test

if {$tcl_platform(os) == "Win32s"} {
    set self info~1.tes
}


test info-16.1 {info script option} {
    list [catch {info script x} msg] $msg
} {1 {wrong # args: should be "info script"}}
test info-16.2 {info script option} {
    file tail [info sc]
} $self
removeFile gorp.info
makeFile "info script\n" gorp.info
test info-16.3 {info script option} {
    list [source gorp.info] [file tail [info script]]
} [list gorp.info $self]
test info-16.4 {resetting "info script" after errors} {
    catch {source ~_nobody_/foo}
    file tail [info script]
} $self
test info-16.5 {resetting "info script" after errors} {
    catch {source _nonexistent_}
    file tail [info script]
} $self
removeFile gorp.info

test info-17.1 {info sharedlibextension option} {
    list [catch {info sharedlibextension foo} msg] $msg
} {1 {wrong # args: should be "info sharedlibextension"}}

test info-18.1 {info tclversion option} {







|
>
|
>
|
|
|
>






|




|



|



|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
    lsort [info pr _tt*]
} {_tt1 _tt2}
catch {rename _tt1 {}}
catch {rename _tt2 {}}
test info-15.3 {info procs option} {
    list [catch {info procs 2 3} msg] $msg
} {1 {wrong # args: should be "info procs ?pattern?"}}
test info-15.4 {info procs option} {
    catch {namespace delete test_ns_info2}
    namespace eval test_ns_info2 {
        namespace import ::test_ns_info1::*
        proc r {} {}
        list [info procs] [info procs p*]
    }
} {{p q r} p}

test info-16.1 {info script option} {
    list [catch {info script x} msg] $msg
} {1 {wrong # args: should be "info script"}}
test info-16.2 {info script option} {
    file tail [info sc]
} "info.test"
removeFile gorp.info
makeFile "info script\n" gorp.info
test info-16.3 {info script option} {
    list [source gorp.info] [file tail [info script]]
} [list gorp.info info.test]
test info-16.4 {resetting "info script" after errors} {
    catch {source ~_nobody_/foo}
    file tail [info script]
} "info.test"
test info-16.5 {resetting "info script" after errors} {
    catch {source _nonexistent_}
    file tail [info script]
} "info.test"
removeFile gorp.info

test info-17.1 {info sharedlibextension option} {
    list [catch {info sharedlibextension foo} msg] $msg
} {1 {wrong # args: should be "info sharedlibextension"}}

test info-18.1 {info tclversion option} {
590
591
592
593
594
595
596

















} {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}}
test info-20.4 {miscellaneous error conditions} {
    list [catch {info l} msg] $msg
} {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}}
test info-20.5 {miscellaneous error conditions} {
    list [catch {info s} msg] $msg
} {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}}
























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
} {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}}
test info-20.4 {miscellaneous error conditions} {
    list [catch {info l} msg] $msg
} {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}}
test info-20.5 {miscellaneous error conditions} {
    list [catch {info s} msg] $msg
} {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}}

# cleanup
catch {namespace delete test_ns_info1 test_ns_info2}
::tcltest::cleanupTests
return