1 # Commands covered: set (plus basic command syntax). Also tests the
2 # procedures in the file tclOldParse.c. This set of tests is an old
3 # one that predates the new parser in Tcl 8.1.
5 # This file contains a collection of tests for one or more of the Tcl
6 # built-in commands. Sourcing this file into Tcl runs the tests and
7 # generates output for errors. No output means no errors were found.
9 # Copyright (c) 1991-1993 The Regents of the University of California.
10 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 if {"::tcltest" ni [namespace children]} {
17 package require tcltest 2.5
18 namespace import -force ::tcltest::*
21 ::tcltest::loadTestedCommands
22 catch [list package require -exact Tcltest [info patchlevel]]
24 testConstraint testwordend [llength [info commands testwordend]]
25 testConstraint testbytestring [llength [info commands testbytestring]]
27 # Save the argv value for restoration later
30 proc fourArgs {a b c d} {
31 global arg1 arg2 arg3 arg4
43 # Basic argument parsing.
45 test parseOld-1.1 {basic argument parsing} {
48 list $arg1 $arg2 $arg3 $arg4
50 test parseOld-1.2 {basic argument parsing} {
52 eval "fourArgs 123\v4\f56\r7890"
53 list $arg1 $arg2 $arg3 $arg4
58 test parseOld-2.1 {quotes and variable-substitution} {
62 test parseOld-2.2 {quotes and variable-substitution} {
67 test parseOld-2.3 {quotes and variable-substitution} {
68 set argv "xy[format xabc]"
71 test parseOld-2.4 {quotes and variable-substitution} {
75 test parseOld-2.5 {quotes and variable-substitution} {
80 test parseOld-2.6 {quotes and variable-substitution} {
87 test parseOld-3.1 {braces} {
91 test parseOld-3.2 {braces} {
94 set b [string index $argv 1]
97 test parseOld-3.3 {braces} {
98 set argv {a[format xyz] b}
101 test parseOld-3.4 {braces} {
105 test parseOld-3.5 {braces} {
109 test parseOld-3.6 {braces} {
113 test parseOld-3.7 {braces} {
114 set a [format "last]"]
118 # Command substitution.
120 test parseOld-4.1 {command substitution} {
124 test parseOld-4.2 {command substitution} {
125 set a a[format xyz]b[format q]
128 test parseOld-4.3 {command substitution} {
136 test parseOld-4.4 {command substitution} {
138 if {[catch {expr {int($a)}}]} {set a foo}
142 # Variable substitution.
144 test parseOld-5.1 {variable substitution} {
149 test parseOld-5.2 {variable substitution} {
154 test parseOld-5.3 {variable substitution} {
159 test parseOld-5.4 {variable substitution} {
164 test parseOld-5.5 {variable substitution} {catch {$_non_existent_} msg} 1
165 test parseOld-5.6 {variable substitution} {
166 catch {$_non_existent_} msg
168 } {can't read "_non_existent_": no such variable}
169 test parseOld-5.7 {array variable substitution} {
175 test parseOld-5.8 {array variable substitution} {
181 test parseOld-5.9 {array variable substitution} {
182 unset -nocomplain a qqq
184 set $a([format x]\ y [format z]) foo
187 test parseOld-5.10 {array variable substitution} {
189 list [catch {set b $a(22)} msg] $msg
190 } {1 {can't read "a(22)": no such variable}}
191 test parseOld-5.11 {array variable substitution} {
195 test parseOld-5.12 {empty array name support} {
196 list [catch {set b a$()} msg] $msg
197 } {1 {can't read "()": no such variable}}
199 test parseOld-5.13 {array variable substitution} {
201 set long {This is a very long variable, long enough to cause storage \
202 allocation to occur in Tcl_ParseVar. If that storage isn't getting \
203 freed up correctly, then a core leak will occur when this test is \
204 run. This text is probably beginning to sound like drivel, but I've \
205 run out of things to say and I need more characters still.}
208 list $b [array names a]
209 } {777 {{This is a very long variable, long enough to cause storage \
210 allocation to occur in Tcl_ParseVar. If that storage isn't getting \
211 freed up correctly, then a core leak will occur when this test is \
212 run. This text is probably beginning to sound like drivel, but I've \
213 run out of things to say and I need more characters still.}}}
214 test parseOld-5.14 {array variable substitution} {
215 unset -nocomplain a b a1
221 unset -nocomplain a a1
223 test parseOld-7.1 {backslash substitution} {
227 test parseOld-7.2 {backslash substitution} {
231 test parseOld-7.3 {backslash substitution} {
236 test parseOld-7.4 {backslash substitution} {
241 test parseOld-7.5 {backslash substitution} {
244 set error [catch {if {24 < \
245 35} {set a 22} {set \
249 test parseOld-7.6 {backslash substitution} {
252 test parseOld-7.7 {backslash substitution} {
255 test parseOld-7.8 {backslash substitution} {
256 eval "concat x\\\n a"
258 test parseOld-7.9 {backslash substitution} {
261 test parseOld-7.10 {backslash substitution} {
262 eval "list a b\\\nc d"
264 test parseOld-7.11 {backslash substitution} {
265 eval "list a \"b c\"\\\nd e"
267 test parseOld-7.12 {backslash substitution} testbytestring {
268 expr {[list \ua2] eq [testbytestring "\xc2\xa2"]}
270 test parseOld-7.13 {backslash substitution} testbytestring {
271 expr {[list \u4e21] eq [testbytestring "\xe4\xb8\xa1"]}
273 test parseOld-7.14 {backslash substitution} testbytestring {
274 expr {[list \u4e2k] eq [testbytestring "\xd3\xa2k"]}
279 test parseOld-8.1 {semi-colons} {
284 test parseOld-8.2 {semi-colons} {
289 test parseOld-8.3 {semi-colons} {
290 getArgs a b ; set b 1
293 test parseOld-8.4 {semi-colons} {
294 getArgs a b ; set b 1
298 # The following checks are to ensure that the interpreter's result
299 # gets re-initialized by Tcl_Eval in all the right places.
302 test parseOld-9.1 {result initialization} {concat abc} abc
303 test parseOld-9.2 {result initialization} {concat abc; proc foo {} {}} {}
304 test parseOld-9.3 {result initialization} {concat abc; proc foo {} $a} {}
305 test parseOld-9.4 {result initialization} {proc foo {} [concat abc]} {}
306 test parseOld-9.5 {result initialization} {concat abc; } abc
307 test parseOld-9.6 {result initialization} {
311 test parseOld-9.7 {result initialization} {} {}
312 test parseOld-9.8 {result initialization} {concat abc; ; ;} abc
316 test parseOld-10.1 {syntax errors} {catch "set a \{bcd" msg} 1
317 test parseOld-10.2 {syntax errors} {
318 catch "set a \{bcd" msg
320 } {missing close-brace}
321 test parseOld-10.3 {syntax errors} {catch {set a "bcd} msg} 1
322 test parseOld-10.4 {syntax errors} {
323 catch {set a "bcd} msg
326 #" Emacs formatting >:^(
327 test parseOld-10.5 {syntax errors} {catch {set a "bcd"xy} msg} 1
328 test parseOld-10.6 {syntax errors} {
329 catch {set a "bcd"xy} msg
331 } {extra characters after close-quote}
332 test parseOld-10.7 {syntax errors} {catch "set a {bcd}xy" msg} 1
333 test parseOld-10.8 {syntax errors} {
334 catch "set a {bcd}xy" msg
336 } {extra characters after close-brace}
337 test parseOld-10.9 {syntax errors} {catch {set a [format abc} msg} 1
338 test parseOld-10.10 {syntax errors} {
339 catch {set a [format abc} msg
341 } {missing close-bracket}
342 test parseOld-10.11 {syntax errors} {catch gorp-a-lot msg} 1
343 test parseOld-10.12 {syntax errors} {
346 } {invalid command name "gorp-a-lot"}
347 test parseOld-10.13 {syntax errors} {
353 # The next test will fail on the Mac, 'cause the MSL uses a fixed sized
354 # buffer for %d conversions (LAME!). I won't leave the test out, however,
355 # since MetroWerks may some day fix this.
357 test parseOld-10.14 {syntax errors} {
358 list [catch {eval \$x[format "%01000d" 0](} msg] $msg $::errorInfo
359 } {1 {missing )} {missing )
361 "$x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
364 "eval \$x[format "%01000d" 0]("}}
365 test parseOld-10.15 {syntax errors, missplaced braces} {
367 proc misplaced_end_brace {} {
369 set when [expr ${what}size - [set off$what]}]
372 } {extra characters after close-brace}
373 test parseOld-10.16 {syntax errors, missplaced braces} {
377 set when [expr ${what}size - [set off$what]}]
380 } {extra characters after close-brace}
381 test parseOld-10.17 {syntax errors, unusual spacing} {
382 list [catch {return [ [1]]} msg] $msg
383 } {1 {invalid command name "1"}}
384 # Long values (stressing storage management)
386 set a {1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH}
388 test parseOld-11.1 {long values} {
391 test parseOld-11.2 {long values} {
394 test parseOld-11.3 {long values} {
395 set b "1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH"
398 test parseOld-11.4 {long values} {
402 test parseOld-11.5 {long values} {
406 test parseOld-11.6 {long values} {
407 set b [concat 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH]
410 test parseOld-11.7 {long values} {
411 set b [concat 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH]
414 # Duplicate action of previous test
415 llength [set b [concat 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH]]
416 test parseOld-11.8 {long values} {
419 test parseOld-11.9 {long values} {
420 set a [concat 0000 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ]
424 foreach j [concat 0000 1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ] {
425 set test [string index 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ $i]
426 set test $test$test$test$test
427 test parseOld-11.10-[incr i] {long values} {
431 test parseOld-11.11 {test buffer overflow in backslashes in braces} {
432 expr {"a" == {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101\101}}
435 test parseOld-12.1 {comments} {
440 test parseOld-12.2 {comments} {
442 eval " # set a new\nset a new"
445 test parseOld-12.3 {comments} {
447 eval " # set a new\\\nset a new"
450 test parseOld-12.4 {comments} {
452 eval " # set a new\\\\\nset a new"
456 test parseOld-13.1 {comments at the end of a bracketed script} {
463 test parseOld-15.1 {TclScriptEnd procedure} {
464 info complete {puts [
466 #this is a comment ]}
468 test parseOld-15.2 {TclScriptEnd procedure} {
469 info complete "abc\\\n"
471 test parseOld-15.3 {TclScriptEnd procedure} {
472 info complete "abc\\\\\n"
474 test parseOld-15.4 {TclScriptEnd procedure} {
475 info complete "xyz \[abc \{abc\]"
477 test parseOld-15.5 {TclScriptEnd procedure} {
478 info complete "xyz \[abc"
483 ::tcltest::cleanupTests