os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/proc-old.test
Update contrib.
1 # Commands covered: proc, return, global
3 # This file, proc-old.test, includes the original set of tests for Tcl's
4 # proc, return, and global commands. There is now a new file proc.test
5 # that contains tests for the tclProc.c source file.
7 # Sourcing this file into Tcl runs the tests and generates output for
8 # errors. No output means no errors were found.
10 # Copyright (c) 1991-1993 The Regents of the University of California.
11 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
12 # Copyright (c) 1998-1999 by Scriptics Corporation.
14 # See the file "license.terms" for information on usage and redistribution
15 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
17 # RCS: @(#) $Id: proc-old.test,v 1.9.2.1 2003/03/27 21:46:32 msofer Exp $
19 if {[lsearch [namespace children] ::tcltest] == -1} {
20 package require tcltest
21 namespace import -force ::tcltest::*
27 proc tproc {} {return a; return b}
28 test proc-old-1.1 {simple procedure call and return} {tproc} a
33 test proc-old-1.2 {simple procedure call and return} {tproc 2} 3
34 test proc-old-1.3 {simple procedure call and return} {
35 proc tproc {} {return foo}
37 test proc-old-1.4 {simple procedure call and return} {
38 proc tproc {} {return}
41 proc tproc1 {a} {incr a; return $a}
42 proc tproc2 {a b} {incr a; return $a}
43 test proc-old-1.5 {simple procedure call and return (2 procs with same body but different parameters)} {
44 list [tproc1 123] [tproc2 456 789]
46 test proc-old-1.6 {simple procedure call and return (shared proc body string)} {
48 proc tproc {} {} ;# body is shared with x
49 list [tproc] [append x foo]
52 test proc-old-2.1 {local and global variables} {
60 test proc-old-2.2 {local and global variables} {
68 test proc-old-2.3 {local and global variables} {
77 test proc-old-2.4 {local and global variables} {
85 catch {unset _undefined_}
86 test proc-old-2.5 {local and global variables} {
91 list [catch {tproc xxx} msg] $msg
92 } {1 {can't read "_undefined_": no such variable}}
93 test proc-old-2.6 {local and global variables} {
100 proc do {cmd} {eval $cmd}
101 test proc-old-3.1 {local and global arrays} {
104 list [catch {do {global a; set a(0)}} msg] $msg
106 test proc-old-3.2 {local and global arrays} {
109 list [catch {do {global a; set a(x) newValue}} msg] $msg $a(x)
110 } {0 newValue newValue}
111 test proc-old-3.3 {local and global arrays} {
115 list [catch {do {global a; unset a(y)}; array names a} msg] $msg
117 test proc-old-3.4 {local and global arrays} {
121 list [catch {do {global a; unset a; info exists a}} msg] $msg \
124 test proc-old-3.5 {local and global arrays} {
128 list [catch {do {global a; unset a(y); array names a}} msg] $msg
131 test proc-old-3.6 {local and global arrays} {
135 do {global a; do {global a; unset a}; set a(z) 22}
136 list [catch {array names a} msg] $msg
138 test proc-old-3.7 {local and global arrays} {
139 proc t1 {args} {global info; set info 1}
142 do {global a; trace var a(1) w t1}
146 test proc-old-3.8 {local and global arrays} {
147 proc t1 {args} {global info; set info 1}
151 do {global a; trace vdelete a(1) w t1}
155 test proc-old-3.9 {local and global arrays} {
156 proc t1 {args} {global info; set info 1}
159 do {global a; trace vinfo a(1)}
163 test proc-old-30.1 {arguments and defaults} {
165 return [list $x $y $z]
169 test proc-old-30.2 {arguments and defaults} {
171 return [list $x $y $z]
173 list [catch {tproc 11 12} msg] $msg
174 } {1 {wrong # args: should be "tproc x y z"}}
175 test proc-old-30.3 {arguments and defaults} {
177 return [list $x $y $z]
179 list [catch {tproc 11 12 13 14} msg] $msg
180 } {1 {wrong # args: should be "tproc x y z"}}
181 test proc-old-30.4 {arguments and defaults} {
182 proc tproc {x {y y-default} {z z-default}} {
183 return [list $x $y $z]
187 test proc-old-30.5 {arguments and defaults} {
188 proc tproc {x {y y-default} {z z-default}} {
189 return [list $x $y $z]
193 test proc-old-30.6 {arguments and defaults} {
194 proc tproc {x {y y-default} {z z-default}} {
195 return [list $x $y $z]
198 } {11 y-default z-default}
199 test proc-old-30.7 {arguments and defaults} {
200 proc tproc {x {y y-default} {z z-default}} {
201 return [list $x $y $z]
203 list [catch {tproc} msg] $msg
204 } {1 {wrong # args: should be "tproc x ?y? ?z?"}}
205 test proc-old-30.8 {arguments and defaults} {
207 proc tproc {x {y y-default} z} {
208 return [list $x $y $z]
212 } {1 {wrong # args: should be "tproc x ?y? z"}}
213 test proc-old-30.9 {arguments and defaults} {
214 proc tproc {x {y y-default} args} {
215 return [list $x $y $args]
219 test proc-old-30.10 {arguments and defaults} {
220 proc tproc {x {y y-default} args} {
221 return [list $x $y $args]
225 test proc-old-30.11 {arguments and defaults} {
226 proc tproc {x {y y-default} args} {
227 return [list $x $y $args]
231 test proc-old-30.12 {arguments and defaults} {
232 proc tproc {x {y y-default} args} {
233 return [list $x $y $args]
235 list [catch {tproc} msg] $msg
236 } {1 {wrong # args: should be "tproc x ?y? args"}}
238 test proc-old-4.1 {variable numbers of arguments} {
239 proc tproc args {return $args}
242 test proc-old-4.2 {variable numbers of arguments} {
243 proc tproc args {return $args}
244 tproc 1 2 3 4 5 6 7 8
246 test proc-old-4.3 {variable numbers of arguments} {
247 proc tproc args {return $args}
248 tproc 1 {2 3} {4 {5 6} {{{7}}}} 8
249 } {1 {2 3} {4 {5 6} {{{7}}}} 8}
250 test proc-old-4.4 {variable numbers of arguments} {
251 proc tproc {x y args} {return $args}
254 test proc-old-4.5 {variable numbers of arguments} {
255 proc tproc {x y args} {return $args}
258 test proc-old-4.6 {variable numbers of arguments} {
259 proc tproc {x missing args} {return $args}
260 list [catch {tproc 1} msg] $msg
261 } {1 {wrong # args: should be "tproc x missing args"}}
263 test proc-old-5.1 {error conditions} {
264 list [catch {proc} msg] $msg
265 } {1 {wrong # args: should be "proc name args body"}}
266 test proc-old-5.2 {error conditions} {
267 list [catch {proc tproc b} msg] $msg
268 } {1 {wrong # args: should be "proc name args body"}}
269 test proc-old-5.3 {error conditions} {
270 list [catch {proc tproc b c d e} msg] $msg
271 } {1 {wrong # args: should be "proc name args body"}}
272 test proc-old-5.4 {error conditions} {
273 list [catch {proc tproc \{xyz {return foo}} msg] $msg
274 } {1 {unmatched open brace in list}}
275 test proc-old-5.5 {error conditions} {
276 list [catch {proc tproc {{} y} {return foo}} msg] $msg
277 } {1 {procedure "tproc" has argument with no name}}
278 test proc-old-5.6 {error conditions} {
279 list [catch {proc tproc {{} y} {return foo}} msg] $msg
280 } {1 {procedure "tproc" has argument with no name}}
281 test proc-old-5.7 {error conditions} {
282 list [catch {proc tproc {{x 1 2} y} {return foo}} msg] $msg
283 } {1 {too many fields in argument specifier "x 1 2"}}
284 test proc-old-5.8 {error conditions} {
287 test proc-old-5.9 {error conditions} {
288 list [catch {global} msg] $msg
289 } {1 {wrong # args: should be "global varName ?varName ...?"}}
294 test proc-old-5.10 {error conditions} {
295 list [catch {tproc} msg] $msg
296 } {1 {variable "a" already exists}}
297 test proc-old-5.11 {error conditions} {
298 catch {rename tproc {}}
300 proc tproc {x {} z} {return foo}
302 list [catch {tproc 1} msg] $msg
303 } {1 {invalid command name "tproc"}}
304 test proc-old-5.12 {error conditions} {
307 error "error in procedure"
310 list [catch tproc msg] $msg
311 } {1 {error in procedure}}
312 test proc-old-5.13 {error conditions} {
315 error "error in procedure"
320 } {error in procedure
322 "error "error in procedure""
323 (procedure "tproc" line 3)
326 test proc-old-5.14 {error conditions} {
334 } {invoked "break" outside of a loop
335 (procedure "tproc" line 1)
338 test proc-old-5.15 {error conditions} {
346 } {invoked "continue" outside of a loop
347 (procedure "tproc" line 1)
350 test proc-old-5.16 {error conditions} {
353 set fooMsg "foo was called: $args"
362 set fooMsg "foo not called"
363 list [catch tproc msg] $msg $errorInfo $fooMsg
364 } {1 {Nested error} {Nested error
366 "error "Nested error""
367 (procedure "tproc" line 5)
369 "tproc"} {foo was called: x {} u}}
371 # The tests below will really only be useful when run under Purify or
372 # some other system that can detect accesses to freed memory...
374 test proc-old-6.1 {procedure that redefines itself} {
383 test proc-old-6.2 {procedure that deletes itself} {
392 return -code $code abc
394 test proc-old-7.1 {return with special completion code} {
395 list [catch {tproc ok} msg] $msg
397 test proc-old-7.2 {return with special completion code} {
398 list [catch {tproc error} msg] $msg $errorInfo $errorCode
402 test proc-old-7.3 {return with special completion code} {
403 list [catch {tproc return} msg] $msg
405 test proc-old-7.4 {return with special completion code} {
406 list [catch {tproc break} msg] $msg
408 test proc-old-7.5 {return with special completion code} {
409 list [catch {tproc continue} msg] $msg
411 test proc-old-7.6 {return with special completion code} {
412 list [catch {tproc -14} msg] $msg
414 test proc-old-7.7 {return with special completion code} {
415 list [catch {tproc gorp} msg] $msg
416 } {1 {bad completion code "gorp": must be ok, error, return, break, continue, or an integer}}
417 test proc-old-7.8 {return with special completion code} {
418 list [catch {tproc 10b} msg] $msg
419 } {1 {bad completion code "10b": must be ok, error, return, break, continue, or an integer}}
420 test proc-old-7.9 {return with special completion code} {
424 list [catch tproc2 msg] $msg
426 test proc-old-7.10 {return with special completion code} {
430 list [catch tproc2 msg] $msg
432 test proc-old-7.11 {return with special completion code} {
434 global errorCode errorInfo
435 catch {open _bad_file_name r} msg
436 return -code error -errorinfo $errorInfo -errorcode $errorCode $msg
438 set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
439 regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
441 } {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
443 "open _bad_file_name r"
445 "tproc2"} {posix enoent {no such file or directory}}}
446 test proc-old-7.12 {return with special completion code} {
448 global errorCode errorInfo
449 catch {open _bad_file_name r} msg
450 return -code error -errorcode $errorCode $msg
452 set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
453 regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
455 } {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
457 "tproc2"} {posix enoent {no such file or directory}}}
458 test proc-old-7.13 {return with special completion code} {
460 global errorCode errorInfo
461 catch {open _bad_file_name r} msg
462 return -code error -errorinfo $errorInfo $msg
464 set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
465 regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
467 } {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
469 "open _bad_file_name r"
472 test proc-old-7.14 {return with special completion code} {
474 global errorCode errorInfo
475 catch {open _bad_file_name r} msg
476 return -code error $msg
478 set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
479 regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
481 } {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
484 test proc-old-7.15 {return with special completion code} {
485 list [catch {return -badOption foo message} msg] $msg
486 } {1 {bad option "-badOption": must be -code, -errorcode, or -errorinfo}}
488 test proc-old-8.1 {unset and undefined local arrays} {
490 foreach v {xxx, yyy} {
498 test proc-old-9.1 {empty command name} {
507 test proc-old-10.1 {ByteCode epoch change during recursive proc execution} {
512 if $x then {t1 0} ;# recursive call after foo's code is invalidated
520 catch {rename foo ""}
521 ::tcltest::cleanupTests