diff options
Diffstat (limited to 'tests/if.test')
-rw-r--r-- | tests/if.test | 82 |
1 files changed, 33 insertions, 49 deletions
diff --git a/tests/if.test b/tests/if.test index e9da6d5..f941d54 100644 --- a/tests/if.test +++ b/tests/if.test @@ -11,7 +11,7 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. if {[lsearch [namespace children] ::tcltest] == -1} { - package require tcltest + package require tcltest 2 namespace import -force ::tcltest::* } @@ -24,12 +24,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} @@ -61,15 +58,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}} @@ -175,13 +169,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 {} @@ -302,16 +293,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 @@ -507,12 +495,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 {} @@ -550,12 +536,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}"}} @@ -674,13 +660,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} @@ -805,13 +789,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}"} @@ -1088,7 +1072,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 @@ -1106,7 +1090,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 |