os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/proc-old.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/proc-old.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,534 @@
1.4 +# Commands covered: proc, return, global
1.5 +#
1.6 +# This file, proc-old.test, includes the original set of tests for Tcl's
1.7 +# proc, return, and global commands. There is now a new file proc.test
1.8 +# that contains tests for the tclProc.c source file.
1.9 +#
1.10 +# Sourcing this file into Tcl runs the tests and generates output for
1.11 +# errors. No output means no errors were found.
1.12 +#
1.13 +# Copyright (c) 1991-1993 The Regents of the University of California.
1.14 +# Copyright (c) 1994-1997 Sun Microsystems, Inc.
1.15 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.16 +#
1.17 +# See the file "license.terms" for information on usage and redistribution
1.18 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.19 +#
1.20 +# RCS: @(#) $Id: proc-old.test,v 1.9.2.1 2003/03/27 21:46:32 msofer Exp $
1.21 +
1.22 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.23 + package require tcltest
1.24 + namespace import -force ::tcltest::*
1.25 +}
1.26 +
1.27 +catch {rename t1 ""}
1.28 +catch {rename foo ""}
1.29 +
1.30 +proc tproc {} {return a; return b}
1.31 +test proc-old-1.1 {simple procedure call and return} {tproc} a
1.32 +proc tproc x {
1.33 + set x [expr $x+1]
1.34 + return $x
1.35 +}
1.36 +test proc-old-1.2 {simple procedure call and return} {tproc 2} 3
1.37 +test proc-old-1.3 {simple procedure call and return} {
1.38 + proc tproc {} {return foo}
1.39 +} {}
1.40 +test proc-old-1.4 {simple procedure call and return} {
1.41 + proc tproc {} {return}
1.42 + tproc
1.43 +} {}
1.44 +proc tproc1 {a} {incr a; return $a}
1.45 +proc tproc2 {a b} {incr a; return $a}
1.46 +test proc-old-1.5 {simple procedure call and return (2 procs with same body but different parameters)} {
1.47 + list [tproc1 123] [tproc2 456 789]
1.48 +} {124 457}
1.49 +test proc-old-1.6 {simple procedure call and return (shared proc body string)} {
1.50 + set x {}
1.51 + proc tproc {} {} ;# body is shared with x
1.52 + list [tproc] [append x foo]
1.53 +} {{} foo}
1.54 +
1.55 +test proc-old-2.1 {local and global variables} {
1.56 + proc tproc x {
1.57 + set x [expr $x+1]
1.58 + return $x
1.59 + }
1.60 + set x 42
1.61 + list [tproc 6] $x
1.62 +} {7 42}
1.63 +test proc-old-2.2 {local and global variables} {
1.64 + proc tproc x {
1.65 + set y [expr $x+1]
1.66 + return $y
1.67 + }
1.68 + set y 18
1.69 + list [tproc 6] $y
1.70 +} {7 18}
1.71 +test proc-old-2.3 {local and global variables} {
1.72 + proc tproc x {
1.73 + global y
1.74 + set y [expr $x+1]
1.75 + return $y
1.76 + }
1.77 + set y 189
1.78 + list [tproc 6] $y
1.79 +} {7 7}
1.80 +test proc-old-2.4 {local and global variables} {
1.81 + proc tproc x {
1.82 + global y
1.83 + return [expr $x+$y]
1.84 + }
1.85 + set y 189
1.86 + list [tproc 6] $y
1.87 +} {195 189}
1.88 +catch {unset _undefined_}
1.89 +test proc-old-2.5 {local and global variables} {
1.90 + proc tproc x {
1.91 + global _undefined_
1.92 + return $_undefined_
1.93 + }
1.94 + list [catch {tproc xxx} msg] $msg
1.95 +} {1 {can't read "_undefined_": no such variable}}
1.96 +test proc-old-2.6 {local and global variables} {
1.97 + set a 114
1.98 + set b 115
1.99 + global a b
1.100 + list $a $b
1.101 +} {114 115}
1.102 +
1.103 +proc do {cmd} {eval $cmd}
1.104 +test proc-old-3.1 {local and global arrays} {
1.105 + catch {unset a}
1.106 + set a(0) 22
1.107 + list [catch {do {global a; set a(0)}} msg] $msg
1.108 +} {0 22}
1.109 +test proc-old-3.2 {local and global arrays} {
1.110 + catch {unset a}
1.111 + set a(x) 22
1.112 + list [catch {do {global a; set a(x) newValue}} msg] $msg $a(x)
1.113 +} {0 newValue newValue}
1.114 +test proc-old-3.3 {local and global arrays} {
1.115 + catch {unset a}
1.116 + set a(x) 22
1.117 + set a(y) 33
1.118 + list [catch {do {global a; unset a(y)}; array names a} msg] $msg
1.119 +} {0 x}
1.120 +test proc-old-3.4 {local and global arrays} {
1.121 + catch {unset a}
1.122 + set a(x) 22
1.123 + set a(y) 33
1.124 + list [catch {do {global a; unset a; info exists a}} msg] $msg \
1.125 + [info exists a]
1.126 +} {0 0 0}
1.127 +test proc-old-3.5 {local and global arrays} {
1.128 + catch {unset a}
1.129 + set a(x) 22
1.130 + set a(y) 33
1.131 + list [catch {do {global a; unset a(y); array names a}} msg] $msg
1.132 +} {0 x}
1.133 +catch {unset a}
1.134 +test proc-old-3.6 {local and global arrays} {
1.135 + catch {unset a}
1.136 + set a(x) 22
1.137 + set a(y) 33
1.138 + do {global a; do {global a; unset a}; set a(z) 22}
1.139 + list [catch {array names a} msg] $msg
1.140 +} {0 z}
1.141 +test proc-old-3.7 {local and global arrays} {
1.142 + proc t1 {args} {global info; set info 1}
1.143 + catch {unset a}
1.144 + set info {}
1.145 + do {global a; trace var a(1) w t1}
1.146 + set a(1) 44
1.147 + set info
1.148 +} 1
1.149 +test proc-old-3.8 {local and global arrays} {
1.150 + proc t1 {args} {global info; set info 1}
1.151 + catch {unset a}
1.152 + trace var a(1) w t1
1.153 + set info {}
1.154 + do {global a; trace vdelete a(1) w t1}
1.155 + set a(1) 44
1.156 + set info
1.157 +} {}
1.158 +test proc-old-3.9 {local and global arrays} {
1.159 + proc t1 {args} {global info; set info 1}
1.160 + catch {unset a}
1.161 + trace var a(1) w t1
1.162 + do {global a; trace vinfo a(1)}
1.163 +} {{w t1}}
1.164 +catch {unset a}
1.165 +
1.166 +test proc-old-30.1 {arguments and defaults} {
1.167 + proc tproc {x y z} {
1.168 + return [list $x $y $z]
1.169 + }
1.170 + tproc 11 12 13
1.171 +} {11 12 13}
1.172 +test proc-old-30.2 {arguments and defaults} {
1.173 + proc tproc {x y z} {
1.174 + return [list $x $y $z]
1.175 + }
1.176 + list [catch {tproc 11 12} msg] $msg
1.177 +} {1 {wrong # args: should be "tproc x y z"}}
1.178 +test proc-old-30.3 {arguments and defaults} {
1.179 + proc tproc {x y z} {
1.180 + return [list $x $y $z]
1.181 + }
1.182 + list [catch {tproc 11 12 13 14} msg] $msg
1.183 +} {1 {wrong # args: should be "tproc x y z"}}
1.184 +test proc-old-30.4 {arguments and defaults} {
1.185 + proc tproc {x {y y-default} {z z-default}} {
1.186 + return [list $x $y $z]
1.187 + }
1.188 + tproc 11 12 13
1.189 +} {11 12 13}
1.190 +test proc-old-30.5 {arguments and defaults} {
1.191 + proc tproc {x {y y-default} {z z-default}} {
1.192 + return [list $x $y $z]
1.193 + }
1.194 + tproc 11 12
1.195 +} {11 12 z-default}
1.196 +test proc-old-30.6 {arguments and defaults} {
1.197 + proc tproc {x {y y-default} {z z-default}} {
1.198 + return [list $x $y $z]
1.199 + }
1.200 + tproc 11
1.201 +} {11 y-default z-default}
1.202 +test proc-old-30.7 {arguments and defaults} {
1.203 + proc tproc {x {y y-default} {z z-default}} {
1.204 + return [list $x $y $z]
1.205 + }
1.206 + list [catch {tproc} msg] $msg
1.207 +} {1 {wrong # args: should be "tproc x ?y? ?z?"}}
1.208 +test proc-old-30.8 {arguments and defaults} {
1.209 + list [catch {
1.210 + proc tproc {x {y y-default} z} {
1.211 + return [list $x $y $z]
1.212 + }
1.213 + tproc 2 3
1.214 + } msg] $msg
1.215 +} {1 {wrong # args: should be "tproc x ?y? z"}}
1.216 +test proc-old-30.9 {arguments and defaults} {
1.217 + proc tproc {x {y y-default} args} {
1.218 + return [list $x $y $args]
1.219 + }
1.220 + tproc 2 3 4 5
1.221 +} {2 3 {4 5}}
1.222 +test proc-old-30.10 {arguments and defaults} {
1.223 + proc tproc {x {y y-default} args} {
1.224 + return [list $x $y $args]
1.225 + }
1.226 + tproc 2 3
1.227 +} {2 3 {}}
1.228 +test proc-old-30.11 {arguments and defaults} {
1.229 + proc tproc {x {y y-default} args} {
1.230 + return [list $x $y $args]
1.231 + }
1.232 + tproc 2
1.233 +} {2 y-default {}}
1.234 +test proc-old-30.12 {arguments and defaults} {
1.235 + proc tproc {x {y y-default} args} {
1.236 + return [list $x $y $args]
1.237 + }
1.238 + list [catch {tproc} msg] $msg
1.239 +} {1 {wrong # args: should be "tproc x ?y? args"}}
1.240 +
1.241 +test proc-old-4.1 {variable numbers of arguments} {
1.242 + proc tproc args {return $args}
1.243 + tproc
1.244 +} {}
1.245 +test proc-old-4.2 {variable numbers of arguments} {
1.246 + proc tproc args {return $args}
1.247 + tproc 1 2 3 4 5 6 7 8
1.248 +} {1 2 3 4 5 6 7 8}
1.249 +test proc-old-4.3 {variable numbers of arguments} {
1.250 + proc tproc args {return $args}
1.251 + tproc 1 {2 3} {4 {5 6} {{{7}}}} 8
1.252 +} {1 {2 3} {4 {5 6} {{{7}}}} 8}
1.253 +test proc-old-4.4 {variable numbers of arguments} {
1.254 + proc tproc {x y args} {return $args}
1.255 + tproc 1 2 3 4 5 6 7
1.256 +} {3 4 5 6 7}
1.257 +test proc-old-4.5 {variable numbers of arguments} {
1.258 + proc tproc {x y args} {return $args}
1.259 + tproc 1 2
1.260 +} {}
1.261 +test proc-old-4.6 {variable numbers of arguments} {
1.262 + proc tproc {x missing args} {return $args}
1.263 + list [catch {tproc 1} msg] $msg
1.264 +} {1 {wrong # args: should be "tproc x missing args"}}
1.265 +
1.266 +test proc-old-5.1 {error conditions} {
1.267 + list [catch {proc} msg] $msg
1.268 +} {1 {wrong # args: should be "proc name args body"}}
1.269 +test proc-old-5.2 {error conditions} {
1.270 + list [catch {proc tproc b} msg] $msg
1.271 +} {1 {wrong # args: should be "proc name args body"}}
1.272 +test proc-old-5.3 {error conditions} {
1.273 + list [catch {proc tproc b c d e} msg] $msg
1.274 +} {1 {wrong # args: should be "proc name args body"}}
1.275 +test proc-old-5.4 {error conditions} {
1.276 + list [catch {proc tproc \{xyz {return foo}} msg] $msg
1.277 +} {1 {unmatched open brace in list}}
1.278 +test proc-old-5.5 {error conditions} {
1.279 + list [catch {proc tproc {{} y} {return foo}} msg] $msg
1.280 +} {1 {procedure "tproc" has argument with no name}}
1.281 +test proc-old-5.6 {error conditions} {
1.282 + list [catch {proc tproc {{} y} {return foo}} msg] $msg
1.283 +} {1 {procedure "tproc" has argument with no name}}
1.284 +test proc-old-5.7 {error conditions} {
1.285 + list [catch {proc tproc {{x 1 2} y} {return foo}} msg] $msg
1.286 +} {1 {too many fields in argument specifier "x 1 2"}}
1.287 +test proc-old-5.8 {error conditions} {
1.288 + catch {return}
1.289 +} 2
1.290 +test proc-old-5.9 {error conditions} {
1.291 + list [catch {global} msg] $msg
1.292 +} {1 {wrong # args: should be "global varName ?varName ...?"}}
1.293 +proc tproc {} {
1.294 + set a 22
1.295 + global a
1.296 +}
1.297 +test proc-old-5.10 {error conditions} {
1.298 + list [catch {tproc} msg] $msg
1.299 +} {1 {variable "a" already exists}}
1.300 +test proc-old-5.11 {error conditions} {
1.301 + catch {rename tproc {}}
1.302 + catch {
1.303 + proc tproc {x {} z} {return foo}
1.304 + }
1.305 + list [catch {tproc 1} msg] $msg
1.306 +} {1 {invalid command name "tproc"}}
1.307 +test proc-old-5.12 {error conditions} {
1.308 + proc tproc {} {
1.309 + set a 22
1.310 + error "error in procedure"
1.311 + return
1.312 + }
1.313 + list [catch tproc msg] $msg
1.314 +} {1 {error in procedure}}
1.315 +test proc-old-5.13 {error conditions} {
1.316 + proc tproc {} {
1.317 + set a 22
1.318 + error "error in procedure"
1.319 + return
1.320 + }
1.321 + catch tproc msg
1.322 + set errorInfo
1.323 +} {error in procedure
1.324 + while executing
1.325 +"error "error in procedure""
1.326 + (procedure "tproc" line 3)
1.327 + invoked from within
1.328 +"tproc"}
1.329 +test proc-old-5.14 {error conditions} {
1.330 + proc tproc {} {
1.331 + set a 22
1.332 + break
1.333 + return
1.334 + }
1.335 + catch tproc msg
1.336 + set errorInfo
1.337 +} {invoked "break" outside of a loop
1.338 + (procedure "tproc" line 1)
1.339 + invoked from within
1.340 +"tproc"}
1.341 +test proc-old-5.15 {error conditions} {
1.342 + proc tproc {} {
1.343 + set a 22
1.344 + continue
1.345 + return
1.346 + }
1.347 + catch tproc msg
1.348 + set errorInfo
1.349 +} {invoked "continue" outside of a loop
1.350 + (procedure "tproc" line 1)
1.351 + invoked from within
1.352 +"tproc"}
1.353 +test proc-old-5.16 {error conditions} {
1.354 + proc foo args {
1.355 + global fooMsg
1.356 + set fooMsg "foo was called: $args"
1.357 + }
1.358 + proc tproc {} {
1.359 + set x 44
1.360 + trace var x u foo
1.361 + while {$x < 100} {
1.362 + error "Nested error"
1.363 + }
1.364 + }
1.365 + set fooMsg "foo not called"
1.366 + list [catch tproc msg] $msg $errorInfo $fooMsg
1.367 +} {1 {Nested error} {Nested error
1.368 + while executing
1.369 +"error "Nested error""
1.370 + (procedure "tproc" line 5)
1.371 + invoked from within
1.372 +"tproc"} {foo was called: x {} u}}
1.373 +
1.374 +# The tests below will really only be useful when run under Purify or
1.375 +# some other system that can detect accesses to freed memory...
1.376 +
1.377 +test proc-old-6.1 {procedure that redefines itself} {
1.378 + proc tproc {} {
1.379 + proc tproc {} {
1.380 + return 44
1.381 + }
1.382 + return 45
1.383 + }
1.384 + tproc
1.385 +} 45
1.386 +test proc-old-6.2 {procedure that deletes itself} {
1.387 + proc tproc {} {
1.388 + rename tproc {}
1.389 + return 45
1.390 + }
1.391 + tproc
1.392 +} 45
1.393 +
1.394 +proc tproc code {
1.395 + return -code $code abc
1.396 +}
1.397 +test proc-old-7.1 {return with special completion code} {
1.398 + list [catch {tproc ok} msg] $msg
1.399 +} {0 abc}
1.400 +test proc-old-7.2 {return with special completion code} {
1.401 + list [catch {tproc error} msg] $msg $errorInfo $errorCode
1.402 +} {1 abc {abc
1.403 + while executing
1.404 +"tproc error"} NONE}
1.405 +test proc-old-7.3 {return with special completion code} {
1.406 + list [catch {tproc return} msg] $msg
1.407 +} {2 abc}
1.408 +test proc-old-7.4 {return with special completion code} {
1.409 + list [catch {tproc break} msg] $msg
1.410 +} {3 abc}
1.411 +test proc-old-7.5 {return with special completion code} {
1.412 + list [catch {tproc continue} msg] $msg
1.413 +} {4 abc}
1.414 +test proc-old-7.6 {return with special completion code} {
1.415 + list [catch {tproc -14} msg] $msg
1.416 +} {-14 abc}
1.417 +test proc-old-7.7 {return with special completion code} {
1.418 + list [catch {tproc gorp} msg] $msg
1.419 +} {1 {bad completion code "gorp": must be ok, error, return, break, continue, or an integer}}
1.420 +test proc-old-7.8 {return with special completion code} {
1.421 + list [catch {tproc 10b} msg] $msg
1.422 +} {1 {bad completion code "10b": must be ok, error, return, break, continue, or an integer}}
1.423 +test proc-old-7.9 {return with special completion code} {
1.424 + proc tproc2 {} {
1.425 + tproc return
1.426 + }
1.427 + list [catch tproc2 msg] $msg
1.428 +} {0 abc}
1.429 +test proc-old-7.10 {return with special completion code} {
1.430 + proc tproc2 {} {
1.431 + return -code error
1.432 + }
1.433 + list [catch tproc2 msg] $msg
1.434 +} {1 {}}
1.435 +test proc-old-7.11 {return with special completion code} {
1.436 + proc tproc2 {} {
1.437 + global errorCode errorInfo
1.438 + catch {open _bad_file_name r} msg
1.439 + return -code error -errorinfo $errorInfo -errorcode $errorCode $msg
1.440 + }
1.441 + set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
1.442 + regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
1.443 + normalizeMsg $msg
1.444 +} {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
1.445 + while executing
1.446 +"open _bad_file_name r"
1.447 + invoked from within
1.448 +"tproc2"} {posix enoent {no such file or directory}}}
1.449 +test proc-old-7.12 {return with special completion code} {
1.450 + proc tproc2 {} {
1.451 + global errorCode errorInfo
1.452 + catch {open _bad_file_name r} msg
1.453 + return -code error -errorcode $errorCode $msg
1.454 + }
1.455 + set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
1.456 + regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
1.457 + normalizeMsg $msg
1.458 +} {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
1.459 + while executing
1.460 +"tproc2"} {posix enoent {no such file or directory}}}
1.461 +test proc-old-7.13 {return with special completion code} {
1.462 + proc tproc2 {} {
1.463 + global errorCode errorInfo
1.464 + catch {open _bad_file_name r} msg
1.465 + return -code error -errorinfo $errorInfo $msg
1.466 + }
1.467 + set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
1.468 + regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
1.469 + normalizeMsg $msg
1.470 +} {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
1.471 + while executing
1.472 +"open _bad_file_name r"
1.473 + invoked from within
1.474 +"tproc2"} none}
1.475 +test proc-old-7.14 {return with special completion code} {
1.476 + proc tproc2 {} {
1.477 + global errorCode errorInfo
1.478 + catch {open _bad_file_name r} msg
1.479 + return -code error $msg
1.480 + }
1.481 + set msg [list [catch tproc2 msg] $msg $errorInfo $errorCode]
1.482 + regsub -all [file join {} _bad_file_name] $msg "_bad_file_name" msg
1.483 + normalizeMsg $msg
1.484 +} {1 {couldn't open "_bad_file_name": no such file or directory} {couldn't open "_bad_file_name": no such file or directory
1.485 + while executing
1.486 +"tproc2"} none}
1.487 +test proc-old-7.15 {return with special completion code} {
1.488 + list [catch {return -badOption foo message} msg] $msg
1.489 +} {1 {bad option "-badOption": must be -code, -errorcode, or -errorinfo}}
1.490 +
1.491 +test proc-old-8.1 {unset and undefined local arrays} {
1.492 + proc t1 {} {
1.493 + foreach v {xxx, yyy} {
1.494 + catch {unset $v}
1.495 + }
1.496 + set yyy(foo) bar
1.497 + }
1.498 + t1
1.499 +} bar
1.500 +
1.501 +test proc-old-9.1 {empty command name} {
1.502 + catch {rename {} ""}
1.503 + proc t1 {args} {
1.504 + return
1.505 + }
1.506 + set v [t1]
1.507 + catch {$v}
1.508 +} 1
1.509 +
1.510 +test proc-old-10.1 {ByteCode epoch change during recursive proc execution} {
1.511 + proc t1 x {
1.512 + set y 20
1.513 + rename expr expr.old
1.514 + rename expr.old expr
1.515 + if $x then {t1 0} ;# recursive call after foo's code is invalidated
1.516 + return 20
1.517 + }
1.518 + t1 1
1.519 +} 20
1.520 +
1.521 +# cleanup
1.522 +catch {rename t1 ""}
1.523 +catch {rename foo ""}
1.524 +::tcltest::cleanupTests
1.525 +return
1.526 +
1.527 +
1.528 +
1.529 +
1.530 +
1.531 +
1.532 +
1.533 +
1.534 +
1.535 +
1.536 +
1.537 +