diff options
Diffstat (limited to 'tests/if.test')
-rw-r--r-- | tests/if.test | 84 |
1 files changed, 34 insertions, 50 deletions
diff --git a/tests/if.test b/tests/if.test index 1c79ef2..4f46354 100644 --- a/tests/if.test +++ b/tests/if.test @@ -10,10 +10,10 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: if.test,v 1.7 2001/12/04 15:36:29 dkf Exp $ +# RCS: @(#) $Id: if.test,v 1.12 2006/10/09 19:15:44 msofer Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { - package require tcltest + package require tcltest 2 namespace import -force ::tcltest::* } @@ -26,12 +26,9 @@ test if-1.1 {TclCompileIfCmd: missing if/elseif test} { test if-1.2 {TclCompileIfCmd: error in if/elseif test} { list [catch {if {[error "error in condition"]} foo} msg] $msg } {1 {error in condition}} -test if-1.3 {TclCompileIfCmd: error in if/elseif test} { - list [catch {if {1+}} msg] $msg $errorInfo -} {1 {syntax error in expression "1+": premature end of expression} {syntax error in expression "1+": premature end of expression - ("if" test expression) - while compiling -"if {1+}"}} +test if-1.3 {TclCompileIfCmd: error in if/elseif test} -body { + list [catch {if {1+}} msg] $msg $::errorInfo +} -match glob -result {1 * {*"if {1+}"}} test if-1.4 {TclCompileIfCmd: if/elseif test in braces} { set a {} if {1<2} {set a 1} @@ -63,15 +60,12 @@ test if-1.9 {TclCompileIfCmd: missing "then" body} { catch {if 1<2 then} msg set msg } {wrong # args: no script following "then" argument} -test if-1.10 {TclCompileIfCmd: error in "then" body} { +test if-1.10 {TclCompileIfCmd: error in "then" body} -body { set a {} - list [catch {if {$a!="xxx"} then {set}} msg] $msg $errorInfo -} {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" - while compiling -"set" - ("if" then script line 1) - while compiling -"if {$a!="xxx"} then {set}"}} + list [catch {if {$a!="xxx"} then {set}} msg] $msg $::errorInfo +} -match glob -result {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" + while *ing +"set"*}} test if-1.11 {TclCompileIfCmd: error in "then" body} { list [catch {if 2 then {[error "error in then clause"]}} msg] $msg } {1 {error in then clause}} @@ -177,13 +171,10 @@ test if-2.3 {TclCompileIfCmd: missing expression after "elseif"} { catch {if 1<2 {set a 1} elseif} msg set msg } {wrong # args: no expression after "elseif" argument} -test if-2.4 {TclCompileIfCmd: error in expression after "elseif"} { +test if-2.4 {TclCompileIfCmd: error in expression after "elseif"} -body { set a {} - list [catch {if 3>4 {set a 1} elseif {1>}} msg] $msg $errorInfo -} {1 {syntax error in expression "1>": premature end of expression} {syntax error in expression "1>": premature end of expression - ("if" test expression) - while compiling -"if 3>4 {set a 1} elseif {1>}"}} + list [catch {if 3>4 {set a 1} elseif {1>}} msg] $msg $::errorInfo +} -match glob -result {1 * {*"if 3>4 {set a 1} elseif {1>}"}} test if-2.5 {TclCompileIfCmd: test jumpFalse instruction replacement after long "elseif" body} { catch {unset i} set a {} @@ -304,16 +295,13 @@ test if-3.3 {TclCompileIfCmd: missing body after "else"} { catch {if 2<1 {set a 1} else} msg set msg } {wrong # args: no script following "else" argument} -test if-3.4 {TclCompileIfCmd: error compiling body after "else"} { +test if-3.4 {TclCompileIfCmd: error compiling body after "else"} -body { set a {} catch {if 2<1 {set a 1} else {set}} msg - set errorInfo -} {wrong # args: should be "set varName ?newValue?" - while compiling -"set" - ("if" else script line 1) - while compiling -"if 2<1 {set a 1} else {set}"} + set ::errorInfo +} -match glob -result {wrong # args: should be "set varName ?newValue?" + while *ing +"set"*} test if-3.5 {TclCompileIfCmd: extra arguments after "else" argument} { set a {} catch {if 2<1 {set a 1} else {set a 2} or something} msg @@ -509,12 +497,10 @@ test if-5.2 {if cmd with computed command names: error in if/elseif test} { set z if list [catch {$z {[error "error in condition"]} foo} msg] $msg } {1 {error in condition}} -test if-5.3 {if cmd with computed command names: error in if/elseif test} { +test if-5.3 {if cmd with computed command names: error in if/elseif test} -body { set z if - list [catch {$z {1+}} msg] $msg $errorInfo -} {1 {syntax error in expression "1+": premature end of expression} {syntax error in expression "1+": premature end of expression - while executing -"$z {1+}"}} + list [catch {$z {1+}} msg] $msg $::errorInfo +} -match glob -result {1 * {*"$z {1+}"}} test if-5.4 {if cmd with computed command names: if/elseif test in braces} { set z if set a {} @@ -552,12 +538,12 @@ test if-5.9 {if cmd with computed command names: missing "then" body} { catch {$z 1<2 then} msg set msg } {wrong # args: no script following "then" argument} -test if-5.10 {if cmd with computed command names: error in "then" body} { +test if-5.10 {if cmd with computed command names: error in "then" body} -body { set z if set a {} - list [catch {$z {$a!="xxx"} then {set}} msg] $msg $errorInfo -} {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" - while compiling + list [catch {$z {$a!="xxx"} then {set}} msg] $msg $::errorInfo +} -match glob -result {1 {wrong # args: should be "set varName ?newValue?"} {wrong # args: should be "set varName ?newValue?" + while *ing "set" invoked from within "$z {$a!="xxx"} then {set}"}} @@ -676,13 +662,11 @@ test if-6.3 {if cmd with computed command names: missing expression after "elsei catch {$z 1<2 {set a 1} elseif} msg set msg } {wrong # args: no expression after "elseif" argument} -test if-6.4 {if cmd with computed command names: error in expression after "elseif"} { +test if-6.4 {if cmd with computed command names: error in expression after "elseif"} -body { set z if set a {} - list [catch {$z 3>4 {set a 1} elseif {1>}} msg] $msg $errorInfo -} {1 {syntax error in expression "1>": premature end of expression} {syntax error in expression "1>": premature end of expression - while executing -"$z 3>4 {set a 1} elseif {1>}"}} + list [catch {$z 3>4 {set a 1} elseif {1>}} msg] $msg $::errorInfo +} -match glob -result {1 * {*"$z 3>4 {set a 1} elseif {1>}"}} test if-6.5 {if cmd with computed command names: test jumpFalse instruction replacement after long "elseif" body} { set z if catch {unset i} @@ -807,13 +791,13 @@ test if-7.3 {if cmd with computed command names: missing body after "else"} { catch {$z 2<1 {set a 1} else} msg set msg } {wrong # args: no script following "else" argument} -test if-7.4 {if cmd with computed command names: error compiling body after "else"} { +test if-7.4 {if cmd with computed command names: error compiling body after "else"} -body { set z if set a {} catch {$z 2<1 {set a 1} else {set}} msg - set errorInfo -} {wrong # args: should be "set varName ?newValue?" - while compiling + set ::errorInfo +} -match glob -result {wrong # args: should be "set varName ?newValue?" + while *ing "set" invoked from within "$z 2<1 {set a 1} else {set}"} @@ -1090,7 +1074,7 @@ test if-10.5 {substituted control words} { set elseif elseif; proc elseif {} {return badelseif} list [catch {if 1 $then {if 0 {} $elseif 1 {if 0 {} $else {list ok}}}} a] $a } {0 ok} -test if-10.6 {double invocation of variable traces} { +test if-10.6 {double invocation of variable traces} -body { set iftracecounter 0 proc iftraceproc {args} { upvar #0 iftracecounter counter @@ -1108,7 +1092,7 @@ test if-10.6 {double invocation of variable traces} { list [catch {if "$iftracevar + 20" {}} a] $a \ [catch {if "$iftracevar + 20" {}} b] $b \ [unset iftracevar iftracecounter] -} {1 {syntax error in expression "1 oops 10 + 20": extra tokens at end of expression} 0 {} {}} +} -match glob -result {1 {*} 0 {} {}} # cleanup ::tcltest::cleanupTests |