1 # Commands covered: for, continue, break
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1996 Sun Microsystems, Inc.
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 if {[string compare test [info procs test]] == 1} then {source defs}
16 # Basic "for" operation.
18 test for-1.1 {TclCompileForCmd: missing initial command} {
19 list [catch {for} msg] $msg
20 } {1 {wrong # args: should be "for start test next command"}}
21 test for-1.2 {TclCompileForCmd: error in initial command} {
22 list [catch {for {set}} msg] $msg $errorInfo
23 } {1 {wrong # args: should be "for start test next command"} {wrong # args: should be "for start test next command"
27 test for-1.3 {TclCompileForCmd: missing test expression} {
28 catch {for {set i 0}} msg
30 } {wrong # args: should be "for start test next command"}
31 test for-1.4 {TclCompileForCmd: error in test expression} {
32 catch {for {set i 0} {$i<}} msg
34 } {wrong # args: should be "for start test next command"
36 "for {set i 0} {$i<}"}
37 test for-1.5 {TclCompileForCmd: test expression is enclosed in quotes} {
39 for {} "$i > 5" {incr i} {}
41 test for-1.6 {TclCompileForCmd: missing "next" command} {
42 catch {for {set i 0} {$i < 5}} msg
44 } {wrong # args: should be "for start test next command"}
45 test for-1.7 {TclCompileForCmd: missing command body} {
46 catch {for {set i 0} {$i < 5} {incr i}} msg
48 } {wrong # args: should be "for start test next command"}
49 test for-1.8 {TclCompileForCmd: error compiling command body} {
50 catch {for {set i 0} {$i < 5} {incr i} {set}} msg
52 } {wrong # args: should be "set varName ?newValue?"
57 "for {set i 0} {$i < 5} {incr i} {set}"}
59 test for-1.9 {TclCompileForCmd: simple command body} {
61 for {set i 1} {$i<6} {set i [expr $i+1]} {
67 test for-1.10 {TclCompileForCmd: command body in quotes} {
69 for {set i 1} {$i<6} {set i [expr $i+1]} "append a x"
72 test for-1.11 {TclCompileForCmd: computed command body} {
76 set x1 {append a x1; }
78 set x2 {; append a x2}
80 for {set i 1} {$i<6} {set i [expr $i+1]} $x1$bb$x2
83 test for-1.12 {TclCompileForCmd: error in "next" command} {
84 catch {for {set i 0} {$i < 5} {set} {puts $i}} msg
86 } {wrong # args: should be "set varName ?newValue?"
89 ("for" loop-end command)
91 "for {set i 0} {$i < 5} {set} {puts $i}"}
92 test for-1.13 {TclCompileForCmd: long command body} {
94 for {set i 1} {$i<6} {set i [expr $i+1]} {
97 if {$i>6 && $tcl_platform(machine)=="xxx"} {
100 catch {incr i -5} msg
102 if {$i>6 && $tcl_platform(machine)=="xxx"} {
105 catch {incr i -5} msg
107 if {$i>6 && $tcl_platform(machine)=="xxx"} {
110 catch {incr i -5} msg
112 if {$i>6 && $tcl_platform(machine)=="xxx"} {
115 catch {incr i -5} msg
117 if {$i>6 && $tcl_platform(machine)=="xxx"} {
120 catch {incr i -5} msg
126 test for-1.14 {TclCompileForCmd: for command result} {
127 set a [for {set i 0} {$i < 5} {incr i} {}]
130 test for-1.15 {TclCompileForCmd: for command result} {
131 set a [for {set i 0} {$i < 5} {incr i} {if $i==3 break}]
135 # Check "for" and "continue".
137 test for-2.1 {TclCompileContinueCmd: arguments after "continue"} {
138 catch {continue foo} msg
140 } {wrong # args: should be "continue"}
141 test for-2.2 {TclCompileContinueCmd: continue result} {
144 test for-2.3 {continue tests} {
146 for {set i 1} {$i <= 4} {set i [expr $i+1]} {
147 if {$i == 2} continue
152 test for-2.4 {continue tests} {
154 for {set i 1} {$i <= 4} {set i [expr $i+1]} {
155 if {$i != 2} continue
160 test for-2.5 {continue tests, nested loops} {
162 for {set i 1} {$i <= 4} {incr i} {
163 for {set a 1} {$a <= 2} {incr a} {
164 if {$i>=2 && $a>=2} continue
165 set msg [concat $msg "$i.$a"]
169 } {1.1 1.2 2.1 3.1 4.1}
170 test for-2.6 {continue tests, long command body} {
172 for {set i 1} {$i<6} {set i [expr $i+1]} {
176 if {$i>6 && $tcl_platform(machine)=="xxx"} {
179 catch {incr i -5} msg
181 if {$i>6 && $tcl_platform(machine)=="xxx"} {
184 catch {incr i -5} msg
186 if {$i>6 && $tcl_platform(machine)=="xxx"} {
189 catch {incr i -5} msg
191 if {$i>6 && $tcl_platform(machine)=="xxx"} {
194 catch {incr i -5} msg
196 if {$i>6 && $tcl_platform(machine)=="xxx"} {
199 catch {incr i -5} msg
206 # Check "for" and "break".
208 test for-3.1 {TclCompileBreakCmd: arguments after "break"} {
209 catch {break foo} msg
211 } {wrong # args: should be "break"}
212 test for-3.2 {TclCompileBreakCmd: break result} {
215 test for-3.3 {break tests} {
217 for {set i 1} {$i <= 4} {incr i} {
223 test for-3.4 {break tests, nested loops} {
225 for {set i 1} {$i <= 4} {incr i} {
226 for {set a 1} {$a <= 2} {incr a} {
227 if {$i>=2 && $a>=2} break
228 set msg [concat $msg "$i.$a"]
232 } {1.1 1.2 2.1 3.1 4.1}
233 test for-3.5 {break tests, long command body} {
235 for {set i 1} {$i<6} {set i [expr $i+1]} {
239 if {$i>6 && $tcl_platform(machine)=="xxx"} {
242 catch {incr i -5} msg
244 if {$i>6 && $tcl_platform(machine)=="xxx"} {
247 catch {incr i -5} msg
249 if {$i>6 && $tcl_platform(machine)=="xxx"} {
252 catch {incr i -5} msg
255 if {$i>6 && $tcl_platform(machine)=="xxx"} {
258 catch {incr i -5} msg
260 if {$i>6 && $tcl_platform(machine)=="xxx"} {
263 catch {incr i -5} msg
269 # A simplified version of exmh's mail formatting routine to stress "for",
270 # "break", "while", and "if".
273 0 {Return-path: george@tcl} \
274 1 {Return-path: <george@tcl>} \
275 2 {Received: from tcl by tcl.Somewhere.COM (SMI-8.6/SMI-SVR4)} \
276 3 { id LAA10027; Wed, 11 Sep 1996 11:14:53 -0700} \
277 4 {Message-id: <199609111814.LAA10027@tcl.Somewhere.COM>} \
278 5 {X-mailer: exmh version 1.6.9 8/22/96} \
279 6 {Mime-version: 1.0} \
280 7 {Content-type: text/plain; charset=iso-8859-1} \
281 8 {Content-transfer-encoding: quoted-printable} \
282 9 {Content-length: 2162} \
284 11 {Subject: tcl7.6} \
285 12 {Date: Wed, 11 Sep 1996 11:14:53 -0700} \
286 13 {From: George <george@tcl>} \
287 14 {The Tcl 7.6 and Tk 4.2 releases} \
289 16 {This page contains information about Tcl 7.6 and Tk4.2, which are the most recent} \
290 17 {releases of the Tcl scripting language and the Tk toolkit. The first beta versions of these} \
291 18 {releases were released on August 30, 1996. These releases contain only minor changes,} \
292 19 {so we hope to have only a single beta release and to go final in early October, 1996. } \
297 24 {The most important changes in the releases are summarized below. See the README} \
298 25 {and changes files in the distributions for more complete information on what has} \
299 26 {changed, including both feature changes and bug fixes. } \
301 28 { There are new options to the file command for copying files (file copy),} \
302 29 { deleting files and directories (file delete), creating directories (file} \
303 30 { mkdir), and renaming files (file rename). } \
304 31 { The implementation of exec has been improved greatly for Windows 95 and} \
306 33 { There is a new memory allocator for the Macintosh version, which should be} \
307 34 { more efficient than the old one. } \
308 35 { Tk's grid geometry manager has been completely rewritten. The layout} \
309 36 { algorithm produces much better layouts than before, especially where rows or} \
310 37 { columns were stretchable. } \
311 38 { There are new commands for creating common dialog boxes:} \
312 39 { tk_chooseColor, tk_getOpenFile, tk_getSaveFile and} \
313 40 { tk_messageBox. These use native dialog boxes if they are available. } \
314 41 { There is a new virtual event mechanism for handling events in a more portable} \
315 42 { way. See the new command event. It also allows events (both physical and} \
316 43 { virtual) to be generated dynamically. } \
318 45 {Tcl 7.6 and Tk 4.2 are backwards-compatible with Tcl 7.5 and Tk 4.1 except for} \
319 46 {changes in the C APIs for custom channel drivers. Scripts written for earlier releases} \
320 47 {should work on these new releases as well. } \
322 49 {Obtaining The Releases} \
324 51 {Binary Releases} \
326 53 {Pre-compiled releases are available for the following platforms: } \
328 55 { Windows 3.1, Windows 95, and Windows NT: Fetch} \
329 56 { ftp://ftp.sunlabs.com/pub/tcl/win42b1.exe, then execute it. The file is a} \
330 57 { self-extracting executable. It will install the Tcl and Tk libraries, the wish and} \
331 58 { tclsh programs, and documentation. } \
332 59 { Macintosh (both 68K and PowerPC): Fetch} \
333 60 { ftp://ftp.sunlabs.com/pub/tcl/mactk4.2b1.sea.hqx. The file is in binhex format,} \
334 61 { which is understood by Fetch, StuffIt, and many other Mac utilities. The} \
335 62 { unpacked file is a self-installing executable: double-click on it and it will create a} \
336 63 { folder containing all that you need to run Tcl and Tk. } \
337 64 { UNIX (Solaris 2.* and SunOS, other systems soon to follow). Easy to install} \
338 65 { binary packages are now for sale at the Sun Labs Tcl/Tk Shop. Check it out!} \
344 set tag {level= type=text/plain part=0 sel Charset}
345 set ix [lsearch -regexp $tag text/enriched]
350 set breakrange {6.42 78.0}
351 set F1 [lindex $breakrange 0]
352 set F2 [lindex $breakrange 1]
353 set breakrange [lrange $breakrange 2 end]
354 if {[string length $F1] == 0} {
363 set last [array size lines]
365 for {set L 1} {$L < $last} {incr L} {
368 # Blank or empty line terminates headers
369 # Leading --- terminates headers
370 if {[regexp {^[ ]*$} $line] || [regexp {^--+} $line]} {
373 if {[regexp -nocase {^x-mailer:} $line]} {
382 # Decide whether or not to break the body line
385 if {[string first {> } $line] == 0} {
386 # This is quoted text from previous message, don't reformat
387 append result $line $NL
388 if {$quote && !$inheaders} {
389 # Fix from <sarr@umich.edu> to handle text/enriched
390 if {$L > $L1 && $L < $L2 && $line != {}} {
391 # enriched requires two newlines for each one.
393 } elseif {$L > $L2} {
394 set L1 [lindex $ranges 0]
395 set L2 [lindex $ranges 1]
396 set ranges [lrange $ranges 2 end]
397 set quote [llength $L1]
404 # Nothing left to format
405 append result $line $NL
407 } elseif {$L < $F1} {
408 # Not yet to formatted block
409 append result $line $NL
411 } elseif {$L > $F2} {
412 # Past formatted block
413 set F1 [lindex $breakrange 0]
414 set F2 [lindex $breakrange 1]
415 set breakrange [lrange $breakrange 2 end]
416 append result $line $NL
417 if {[string length $F1] == 0} {
423 set climit [expr $limit-1]
427 while {[string length $line] > $limit} {
428 for {set c [expr $limit-1]} {$c >= $cutoff} {incr c -1} {
429 set char [string index $line $c]
430 if {$char == " " || $char == "\t"} {
433 if {$char == ">"} { ;# Hack for enriched formatting
439 set c [expr $limit-1]
441 set c [string length $line]
444 set newline [string range $line 0 $c]
445 if {! $continuation} {
446 append result $newline $NL
448 append result \ $newline $NL
451 set line [string trimright [string range $line $c end]]
458 if {[string length $line] != 0} {
459 append result \ $line $NL
462 append result $line $NL
463 if {$quote && !$inheaders} {
464 if {$L > $L1 && $L < $L2 && $line != {}} {
465 # enriched requires two newlines for each one.
467 } elseif {$L > $L2} {
468 set L1 [lindex $ranges 0]
469 set L2 [lindex $ranges 1]
470 set ranges [lrange $ranges 2 end]
471 set quote [llength $L1]
478 test for-3.6 {break tests} {
480 } {Return-path: <george@tcl>
481 Received: from tcl by tcl.Somewhere.COM (SMI-8.6/SMI-SVR4)
482 id LAA10027; Wed, 11 Sep 1996 11:14:53 -0700
483 Message-id: <199609111814.LAA10027@tcl.Somewhere.COM>
485 Content-type: text/plain; charset=iso-8859-1
486 Content-transfer-encoding: quoted-printable
490 Date: Wed, 11 Sep 1996 11:14:53 -0700
491 From: George <george@tcl>
492 The Tcl 7.6 and Tk 4.2 releases
494 This page contains information about Tcl 7.6 and Tk4.2,
495 which are the most recent
496 releases of the Tcl scripting language and the Tk toolk
497 it. The first beta versions of these
498 releases were released on August 30, 1996. These releas
499 es contain only minor changes,
500 so we hope to have only a single beta release and to
501 go final in early October, 1996.
506 The most important changes in the releases are summariz
507 ed below. See the README
508 and changes files in the distributions for more complet
509 e information on what has
510 changed, including both feature changes and bug fixes.
512 There are new options to the file command for
513 copying files (file copy),
514 deleting files and directories (file delete),
515 creating directories (file
516 mkdir), and renaming files (file rename).
517 The implementation of exec has been improved great
518 ly for Windows 95 and
520 There is a new memory allocator for the Macintosh
521 version, which should be
522 more efficient than the old one.
523 Tk's grid geometry manager has been completely
524 rewritten. The layout
525 algorithm produces much better layouts than before
526 , especially where rows or
527 columns were stretchable.
528 There are new commands for creating common dialog
530 tk_chooseColor, tk_getOpenFile, tk_getSaveFile and
531 tk_messageBox. These use native dialog boxes if
533 There is a new virtual event mechanism for handlin
534 g events in a more portable
535 way. See the new command event. It also allows
536 events (both physical and
537 virtual) to be generated dynamically.
539 Tcl 7.6 and Tk 4.2 are backwards-compatible with Tcl
540 7.5 and Tk 4.1 except for
541 changes in the C APIs for custom channel drivers. Scrip
542 ts written for earlier releases
543 should work on these new releases as well.
545 Obtaining The Releases
549 Pre-compiled releases are available for the following
552 Windows 3.1, Windows 95, and Windows NT: Fetch
553 ftp://ftp.sunlabs.com/pub/tcl/win42b1.exe, then
554 execute it. The file is a
555 self-extracting executable. It will install the
556 Tcl and Tk libraries, the wish and
557 tclsh programs, and documentation.
558 Macintosh (both 68K and PowerPC): Fetch
559 ftp://ftp.sunlabs.com/pub/tcl/mactk4.2b1.sea.hqx.
560 The file is in binhex format,
561 which is understood by Fetch, StuffIt, and many
562 other Mac utilities. The
563 unpacked file is a self-installing executable:
564 double-click on it and it will create a
565 folder containing all that you need to run Tcl
567 UNIX (Solaris 2.* and SunOS, other systems
568 soon to follow). Easy to install
569 binary packages are now for sale at the Sun Labs
570 Tcl/Tk Shop. Check it out!
573 # Check that "break" resets the interpreter's result
575 test for-4.1 {break must reset the interp result} {
577 set z GLOBTESTDIR/dir2/file2.c
578 if [string match GLOBTESTDIR/dir2/* $z] {
585 # Check "for" and computed command names.
587 test for-5.1 {for and computed command names} {
590 $z {set i 0} {$i<10} {incr i} {set j $i}