3 # This file contains the original set of tests for Tcl's if command.
4 # Since the if command is now compiled, a new set of tests covering
5 # the new implementation is in the file "if.test". Sourcing this file
6 # into Tcl runs the tests and generates output for errors.
7 # 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 test if-old-1.1 {taking proper branch} {
23 if 0 {set a 1} else {set a 2}
26 test if-old-1.2 {taking proper branch} {
28 if 1 {set a 1} else {set a 2}
31 test if-old-1.3 {taking proper branch} {
36 test if-old-1.4 {taking proper branch} {
41 test if-old-1.5 {taking proper branch} {
43 if 0 {set a 1} else {}
46 test if-old-1.6 {taking proper branch} {
48 if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
51 test if-old-1.7 {taking proper branch} {
53 if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
56 test if-old-1.8 {taking proper branch} {
58 if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
61 test if-old-1.9 {taking proper branch, multiline test expr} {
63 if {($tcl_platform(platform) != "foobar1") && \
64 ($tcl_platform(platform) != "foobar2")} {set a 3} else {set a 4}
69 test if-old-2.1 {optional then-else args} {
71 if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
74 test if-old-2.2 {optional then-else args} {
76 if 1 then {set a 1} else {set a 2}
79 test if-old-2.3 {optional then-else args} {
81 if 0 {set a 1} else {set a 2}
84 test if-old-2.4 {optional then-else args} {
86 if 1 {set a 1} else {set a 2}
89 test if-old-2.5 {optional then-else args} {
91 if 0 then {set a 1} {set a 2}
94 test if-old-2.6 {optional then-else args} {
96 if 1 then {set a 1} {set a 2}
99 test if-old-2.7 {optional then-else args} {
101 if 0 then {set a 1} else {set a 2}
104 test if-old-2.8 {optional then-else args} {
106 if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
110 test if-old-3.1 {return value} {
111 if 1 then {set a 22; concat abc}
113 test if-old-3.2 {return value} {
114 if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
116 test if-old-3.3 {return value} {
117 if 0 then {set a 22; concat abc} else {concat def}
119 test if-old-3.4 {return value} {
120 if 0 then {set a 22; concat abc}
122 test if-old-3.5 {return value} {
123 if 0 then {set a 22; concat abc} elseif 0 {concat def}
126 test if-old-4.1 {error conditions} {
127 list [catch {if} msg] $msg
128 } {1 {wrong # args: no expression after "if" argument}}
129 test if-old-4.2 {error conditions} {
130 list [catch {if {[error "error in condition"]} foo} msg] $msg
131 } {1 {error in condition}}
132 test if-old-4.3 {error conditions} {
133 list [catch {if 2} msg] $msg
134 } {1 {wrong # args: no script following "2" argument}}
135 test if-old-4.4 {error conditions} {
136 list [catch {if 2 then} msg] $msg
137 } {1 {wrong # args: no script following "then" argument}}
138 test if-old-4.5 {error conditions} {
139 list [catch {if 2 the} msg] $msg
140 } {1 {invalid command name "the"}}
141 test if-old-4.6 {error conditions} {
142 list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
143 } {1 {error in then clause}}
144 test if-old-4.7 {error conditions} {
145 list [catch {if 0 then foo elseif} msg] $msg
146 } {1 {wrong # args: no expression after "elseif" argument}}
147 test if-old-4.8 {error conditions} {
148 list [catch {if 0 then foo elsei} msg] $msg
149 } {1 {invalid command name "elsei"}}
150 test if-old-4.9 {error conditions} {
151 list [catch {if 0 then foo elseif 0 bar else} msg] $msg
152 } {1 {wrong # args: no script following "else" argument}}
153 test if-old-4.10 {error conditions} {
154 list [catch {if 0 then foo elseif 0 bar els} msg] $msg
155 } {1 {invalid command name "els"}}
156 test if-old-4.11 {error conditions} {
157 list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
158 } {1 {error in else clause}}
161 ::tcltest::cleanupTests