| 1 |
# Commands covered: for, continue, break |
| 2 |
# |
| 3 |
# This file contains the original set of tests for Tcl's for command. |
| 4 |
# Since the for command is now compiled, a new set of tests covering |
| 5 |
# the new implementation is in the file "for.test". Sourcing this file |
| 6 |
# into Tcl runs the tests and generates output for errors. |
| 7 |
# No output means no errors were found. |
| 8 |
# |
| 9 |
# Copyright (c) 1991-1993 The Regents of the University of California. |
| 10 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 11 |
# |
| 12 |
# See the file "license.terms" for information on usage and redistribution |
| 13 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 14 |
|
| 15 |
if {"::tcltest" ni [namespace children]} { |
| 16 |
package require tcltest 2.5 |
| 17 |
namespace import -force ::tcltest::* |
| 18 |
} |
| 19 |
|
| 20 |
# Check "for" and its use of continue and break. |
| 21 |
|
| 22 |
catch {unset a i} |
| 23 |
test for-old-1.1 {for tests} { |
| 24 |
set a {} |
| 25 |
for {set i 1} {$i<6} {incr i} { |
| 26 |
set a [concat $a $i] |
| 27 |
} |
| 28 |
set a |
| 29 |
} {1 2 3 4 5} |
| 30 |
test for-old-1.2 {for tests} { |
| 31 |
set a {} |
| 32 |
for {set i 1} {$i<6} {incr i} { |
| 33 |
if {$i==4} continue |
| 34 |
set a [concat $a $i] |
| 35 |
} |
| 36 |
set a |
| 37 |
} {1 2 3 5} |
| 38 |
test for-old-1.3 {for tests} { |
| 39 |
set a {} |
| 40 |
for {set i 1} {$i<6} {incr i} { |
| 41 |
if {$i==4} break |
| 42 |
set a [concat $a $i] |
| 43 |
} |
| 44 |
set a |
| 45 |
} {1 2 3} |
| 46 |
test for-old-1.4 {for tests} {catch {for 1 2 3} msg} 1 |
| 47 |
test for-old-1.5 {for tests} { |
| 48 |
catch {for 1 2 3} msg |
| 49 |
set msg |
| 50 |
} {wrong # args: should be "for start test next command"} |
| 51 |
test for-old-1.6 {for tests} {catch {for 1 2 3 4 5} msg} 1 |
| 52 |
test for-old-1.7 {for tests} { |
| 53 |
catch {for 1 2 3 4 5} msg |
| 54 |
set msg |
| 55 |
} {wrong # args: should be "for start test next command"} |
| 56 |
test for-old-1.8 {for tests} { |
| 57 |
set a {xyz} |
| 58 |
for {set i 1} {$i<6} {incr i} {} |
| 59 |
set a |
| 60 |
} xyz |
| 61 |
test for-old-1.9 {for tests} { |
| 62 |
set a {} |
| 63 |
for {set i 1} {$i<6} {incr i; if {$i==4} break} { |
| 64 |
set a [concat $a $i] |
| 65 |
} |
| 66 |
set a |
| 67 |
} {1 2 3} |
| 68 |
|
| 69 |
# cleanup |
| 70 |
::tcltest::cleanupTests |
| 71 |
return |