sl@0: # Commands covered: if sl@0: # sl@0: # This file contains the original set of tests for Tcl's if command. sl@0: # Since the if command is now compiled, a new set of tests covering sl@0: # the new implementation is in the file "if.test". Sourcing this file sl@0: # into Tcl runs the tests and generates output for errors. sl@0: # No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1993 The Regents of the University of California. sl@0: # Copyright (c) 1994-1996 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: if-old.test,v 1.5.24.1 2003/03/27 13:11:12 dkf Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: test if-old-1.1 {taking proper branch} { sl@0: set a {} sl@0: if 0 {set a 1} else {set a 2} sl@0: set a sl@0: } 2 sl@0: test if-old-1.2 {taking proper branch} { sl@0: set a {} sl@0: if 1 {set a 1} else {set a 2} sl@0: set a sl@0: } 1 sl@0: test if-old-1.3 {taking proper branch} { sl@0: set a {} sl@0: if 1<2 {set a 1} sl@0: set a sl@0: } 1 sl@0: test if-old-1.4 {taking proper branch} { sl@0: set a {} sl@0: if 1>2 {set a 1} sl@0: set a sl@0: } {} sl@0: test if-old-1.5 {taking proper branch} { sl@0: set a {} sl@0: if 0 {set a 1} else {} sl@0: set a sl@0: } {} sl@0: test if-old-1.6 {taking proper branch} { sl@0: set a {} sl@0: if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4} sl@0: set a sl@0: } {2} sl@0: test if-old-1.7 {taking proper branch} { sl@0: set a {} sl@0: if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4} sl@0: set a sl@0: } {3} sl@0: test if-old-1.8 {taking proper branch} { sl@0: set a {} sl@0: if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4} sl@0: set a sl@0: } {4} sl@0: test if-old-1.9 {taking proper branch, multiline test expr} { sl@0: set a {} sl@0: if {($tcl_platform(platform) != "foobar1") && \ sl@0: ($tcl_platform(platform) != "foobar2")} {set a 3} else {set a 4} sl@0: set a sl@0: } {3} sl@0: sl@0: sl@0: test if-old-2.1 {optional then-else args} { sl@0: set a 44 sl@0: if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2} sl@0: set a sl@0: } 2 sl@0: test if-old-2.2 {optional then-else args} { sl@0: set a 44 sl@0: if 1 then {set a 1} else {set a 2} sl@0: set a sl@0: } 1 sl@0: test if-old-2.3 {optional then-else args} { sl@0: set a 44 sl@0: if 0 {set a 1} else {set a 2} sl@0: set a sl@0: } 2 sl@0: test if-old-2.4 {optional then-else args} { sl@0: set a 44 sl@0: if 1 {set a 1} else {set a 2} sl@0: set a sl@0: } 1 sl@0: test if-old-2.5 {optional then-else args} { sl@0: set a 44 sl@0: if 0 then {set a 1} {set a 2} sl@0: set a sl@0: } 2 sl@0: test if-old-2.6 {optional then-else args} { sl@0: set a 44 sl@0: if 1 then {set a 1} {set a 2} sl@0: set a sl@0: } 1 sl@0: test if-old-2.7 {optional then-else args} { sl@0: set a 44 sl@0: if 0 then {set a 1} else {set a 2} sl@0: set a sl@0: } 2 sl@0: test if-old-2.8 {optional then-else args} { sl@0: set a 44 sl@0: if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4} sl@0: set a sl@0: } 4 sl@0: sl@0: test if-old-3.1 {return value} { sl@0: if 1 then {set a 22; concat abc} sl@0: } abc sl@0: test if-old-3.2 {return value} { sl@0: if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi} sl@0: } def sl@0: test if-old-3.3 {return value} { sl@0: if 0 then {set a 22; concat abc} else {concat def} sl@0: } def sl@0: test if-old-3.4 {return value} { sl@0: if 0 then {set a 22; concat abc} sl@0: } {} sl@0: test if-old-3.5 {return value} { sl@0: if 0 then {set a 22; concat abc} elseif 0 {concat def} sl@0: } {} sl@0: sl@0: test if-old-4.1 {error conditions} { sl@0: list [catch {if} msg] $msg sl@0: } {1 {wrong # args: no expression after "if" argument}} sl@0: test if-old-4.2 {error conditions} { sl@0: list [catch {if {[error "error in condition"]} foo} msg] $msg sl@0: } {1 {error in condition}} sl@0: test if-old-4.3 {error conditions} { sl@0: list [catch {if 2} msg] $msg sl@0: } {1 {wrong # args: no script following "2" argument}} sl@0: test if-old-4.4 {error conditions} { sl@0: list [catch {if 2 then} msg] $msg sl@0: } {1 {wrong # args: no script following "then" argument}} sl@0: test if-old-4.5 {error conditions} { sl@0: list [catch {if 2 the} msg] $msg sl@0: } {1 {invalid command name "the"}} sl@0: test if-old-4.6 {error conditions} { sl@0: list [catch {if 2 then {[error "error in then clause"]}} msg] $msg sl@0: } {1 {error in then clause}} sl@0: test if-old-4.7 {error conditions} { sl@0: list [catch {if 0 then foo elseif} msg] $msg sl@0: } {1 {wrong # args: no expression after "elseif" argument}} sl@0: test if-old-4.8 {error conditions} { sl@0: list [catch {if 0 then foo elsei} msg] $msg sl@0: } {1 {invalid command name "elsei"}} sl@0: test if-old-4.9 {error conditions} { sl@0: list [catch {if 0 then foo elseif 0 bar else} msg] $msg sl@0: } {1 {wrong # args: no script following "else" argument}} sl@0: test if-old-4.10 {error conditions} { sl@0: list [catch {if 0 then foo elseif 0 bar els} msg] $msg sl@0: } {1 {invalid command name "els"}} sl@0: test if-old-4.11 {error conditions} { sl@0: list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg sl@0: } {1 {error in else clause}} sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return