1 source [file dirname [info script]]/testing.tcl
4 needs cmd gets tclcompat
8 test regr-1.1 "Double dereference arrays" {
9 array set a {one ONE two TWO three THREE}
10 array set b {ONE 1 TWO 2 THREE 3}
15 # Will assert on exit if the bug exists
16 test regr-1.2 "Reference count shared literals" {
25 test regr-1.3 "Invalid for expression" jim {
26 # Crashes with invalid expression
28 for {set i 0} {$i < n} {incr i} {
36 test regr-1.4 "format double percent" {
40 test regr-1.5 "lassign with empty list" {
41 unset -nocomplain a b c
46 test io-1.1 "Read last line with no newline" {
48 set f [open [file dirname [info script]]/testio.in]
49 while {[gets $f buf] >= 0} {
58 array set g3 {4 5 6 7}
61 test unset-1.1 "Simple var" {
63 list [catch {unset g4; info exists g4} msg] $msg
66 test unset-1.2 "Simple var" {
67 list [catch {unset g4; info exists g4} msg] $msg
68 } {1 {can't unset "g4": no such variable}}
70 test unset-1.3 "Simple var" {
71 list [catch {unset g2; info exists g2} msg] $msg
72 } {1 {can't unset "g2": no such variable}}
74 test unset-1.4 "Global via global" {
76 list [catch {unset g1; info exists g1} msg] $msg
79 test unset-1.5 "Global error" {
80 list [catch {unset ::g2; info exists ::g2} msg] $msg
83 test unset-1.6 "Global array" {
84 list [catch {unset ::g3; info exists ::g3} msg] $msg
87 test unset-1.7 "Simple var -nocomplain" {
88 list [catch {unset -nocomplain g2; info exists g2} msg] $msg
91 test unset-1.8 "Simple var --" {
92 list [catch {unset -- g2; info exists g2} msg] $msg
93 } {1 {can't unset "g2": no such variable}}
95 test unset-1.9 "Simple var -nocomplain --" {
97 list [catch {unset -nocomplain -- g2; info exists g2} msg] $msg
100 test unset-1.10 "Var named -nocomplain with --" {
102 list [catch {unset -- -nocomplain; info exists -nocomplain} msg] $msg
105 test unset-1.11 "Unset no args" {
106 list [catch {unset} msg] $msg
112 test lrepeat-1.1 "Basic tests" {
116 test lrepeat-1.2 "Basic tests" {
120 test lrepeat-1.3 "Basic tests" {
124 test lrepeat-1.4 "Basic tests" {
128 test lrepeat-1.5 "Errors" {
132 test lrepeat-1.6 "Errors" {
136 test lrepeat-1.7 "Errors" {
140 test lrepeat-1.8 "Errors" {
141 catch {lrepeat -10 a}
144 test lindex-1.1 "Integer" {
148 test lindex-1.2 "Integer" {
152 test lindex-1.3 "Integer" {
156 test lindex-1.4 "Integer" {
160 test lindex-1.5 "end" {
164 test lindex-1.6 "end" {
168 test lindex-1.7 "end" {
172 test lindex-1.8 "end + " {
176 test lindex-1.9 "end + " {
177 lindex {a b c} end+-1
180 test lindex-1.10 "end - errors" {
181 catch {lindex {a b c} end-}
184 test lindex-1.11 "end - errors" {
185 catch {lindex {a b c} end-blah}
188 test lindex-1.12 "int+int, int-int" {
192 test lindex-1.13 "int+int, int-int" {
196 test lindex-1.14 "int+int, int-int" {
200 test lindex-1.15 "int+int, int-int" {
202 lindex $l [lsearch $l b]-1
205 test lindex-1.16 "int+int, int-int" {
209 test lindex-1.17 "int+int - errors" {
210 catch {lindex {a b c} 5-blah}
213 test lindex-1.18 "int+int - errors" {
214 catch {lindex {a b c} blah-2}
217 test lindex-1.19 "int+int - errors" {
218 catch {lindex {a b c} 5+blah}
221 test lindex-1.20 "unary plus" {
225 test incr-1.1 "incr unset" {
231 test incr-1.2 "incr, incr unset" {
235 test incr-1.3 "incr unset array element" {
241 test incr-1.4 "incr array element - shimmering" {
246 test catch-1.1 "catch ok" {
247 list [catch {set abc 2} result] $result
250 test catch-1.2 "catch error" {
251 list [catch {error 3} result] $result
254 test catch-1.3 "catch break" {
255 list [catch {break} result] $result
258 test catch-1.4 "catch -nobreak" {
262 # This acts just like break since it won't be caught by catch
263 catch -nobreak {break} tmp
268 test catch-1.5 "catch -no3" {
272 # Same as above, but specify as an integer
273 catch -no3 {break} tmp
278 test catch-1.6 "catch break" {
282 # This does nothing since the break is caught
289 test catch-1.7 "catch exit" {
290 # Normally exit would not be caught
291 dict get [info returncodes] [catch -exit {exit 5} result]
294 test catch-1.8 "catch error has -errorinfo" {
295 set rc [catch {set undefined} msg opts]
296 list $rc [info exists opts(-errorinfo)]
299 test catch-1.9 "catch no error has no -errorinfo" {
300 set rc [catch {set x 1} msg opts]
301 list $rc [info exists opts(-errorinfo)]
304 test return-1.1 "return can rethrow an error" {
305 proc a {} { error "from a" }
306 proc b {} { catch {a} msg opts; return {*}$opts $msg }
307 set rc [catch {b} msg opts]
308 list $rc $msg [llength $opts(-errorinfo)]
311 test return-1.2 "error can rethrow an error" {
312 proc a {} { error "from a" }
313 proc b {} { catch {a} msg; error $msg [info stacktrace] }
314 set rc [catch {b} msg opts]
315 list $rc $msg [llength $opts(-errorinfo)]
318 test return-1.3 "return can rethrow no error" {
319 proc a {} { return "from a" }
320 proc b {} { catch {a} msg opts; return {*}$opts $msg }
321 set rc [catch {b} msg opts]
322 #list $rc $msg [llength $opts(-errorinfo)]
323 list $rc $msg [info exists opts(-errorinfo)]
326 test stringreverse-1.1 "Containing nulls" {
327 string reverse abc\0def
330 test split-1.1 "Split with leading null" {
331 split "\0abc\0def\0" \0
334 test parsevar-1.1 "Variables should include double colons" {
341 test sharing-1.1 "Problems with ref sharing in arrays: lappend" {
348 test sharing-1.2 "Problems with ref sharing in arrays: append" {
355 test sharing-1.3 "Problems with ref sharing in arrays: incr" {
362 test sharing-1.4 "Problems with ref sharing in arrays: lset" {
369 test jimexpr-1.1 "integer ** operator" {
373 test jimexpr-1.2 "integer ** operator" {
377 test jimexpr-1.3 "integer ** operator" {
381 test jimexpr-1.4 "integer ** operator" {
385 test jimexpr-1.5 "integer ** operator" {
389 test jimexpr-1.6 "+ command" {
393 test jimexpr-1.7 "+ command" {
397 test jimexpr-1.8 "+ command" {
401 test jimexpr-1.9 "* command" {
405 test jimexpr-1.10 "* command" {
409 test jimexpr-1.11 "* command" {
413 test jimexpr-1.12 "/ command" {
417 test jimexpr-1.12 "/ command" {
421 test jimexpr-1.13 "/ command" {
425 test jimexpr-1.14 "/ command" {
429 test jimexpr-1.15 "- command" {
433 test jimexpr-1.15 "- command" {
437 test jimexpr-1.16 "- command" {
441 test jimexpr-1.17 "- command" {
445 test jimexpr-1.17 "- command" {
449 test jimexpr-2.1 "errors in math commands" {
450 list [catch /] [catch {/ x}] [catch -] [catch {- blah blah}] [catch {- 2.0 blah}] [catch {+ x y}] [catch {* x}]
453 test jimexpr-2.2 "not var optimisation" {
457 list [expr {!$x}] [expr {!$y}] [expr {!$z}]
460 test jimexpr-2.3 "expr access unset var" {
462 catch {expr {3 * $a}}
465 test jimexpr-2.4 "expr double as bool" {
472 # May be supported if support compiled in
473 test jimexpr-2.5 "double ** operator" {
474 catch {expr {2.0 ** 3}} result
475 expr {$result in {unsupported 8.0}}
478 test jimexpr-2.6 "exit in expression" {
479 # The inner 'exit 0' should propagate through the if to
483 if {[catch {exit 0}] == 1} {
491 # This one is for test coverage of an unusual case
492 test jimobj-1.1 "duplicate obj with no dupIntRepProc" {
493 proc "x x" {} { return 2 }
495 # force it to be a command object
499 # Now force it to be duplicated
501 # force the duplicate object it to be a command object again
503 # And get the string rep
507 test jimobj-1.2 "cooerced double to int" {
509 # cooerce to a double
511 # Now get the int rep
515 test jimobj-1.3 "cooerced double to double" {
517 # cooerce to a double
519 # Now use as a double
523 test jimobj-1.4 "incr dict sugar" {
530 test jim-badvar-1.1 "invalid variable name" {
535 test jim-badvar-1.2 "incr invalid variable name" {
540 test lset-1.1 "lset with bad var" {
541 catch {lset badvar 1 x}
544 test dict-1.1 "dict to string" {
545 set a [dict create abc \\ def \"]
547 # The order of keys in the dictionary is random
548 if {$x eq "xabc \\\\ def {\"}" || $x eq "xdef {\"} abc \\\\"} {
551 return "failed: \"$x\""
555 test channels-1.1 {info channels} {
556 lsort [info channels]
557 } {stderr stdin stdout}
559 test lmap-1.1 {lmap} {
560 lmap p {1 2 3} {incr p}
563 test exprerr-1.1 {Error message with bad expr} {
564 catch {expr {5 ||}} msg
566 } {syntax error in expression "5 ||": premature end of expression}
568 test eval-list-1.1 {Lost string rep with list} {
569 set x {set y 1; incr y}
570 # Convert to list rep internally
572 # But make sure we don't lost the original string rep
576 test info-statics-1.1 {info statics commands} {
578 proc a {} {x {y 2}} {}
579 lsort [info statics a]