diff options
Diffstat (limited to 'tests/event.test')
-rw-r--r-- | tests/event.test | 125 |
1 files changed, 122 insertions, 3 deletions
diff --git a/tests/event.test b/tests/event.test index d2e77db..a7122f9 100644 --- a/tests/event.test +++ b/tests/event.test @@ -186,6 +186,86 @@ test event-5.2 {Tcl_BackgroundError, HandleBgErrors procedures} { rename bgerror {} set x } {{a simple error}} +test event-5.3 {HandleBgErrors: [Bug 1670155]} -setup { + variable x + proc demo args {variable x done} + variable target [list [namespace which demo] x] + proc trial args {variable target; string length $target} + trace add execution demo enter [namespace code trial] + variable save [interp bgerror {}] + interp bgerror {} $target +} -body { + after 0 {error bar} + vwait [namespace which -variable x] +} -cleanup { + interp bgerror {} $save + unset x target save + rename demo {} + rename trial {} +} -result {} +test event-5.3.1 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror +} -returnCodes error -match glob -result {*msg options*} +test event-5.4 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} +} -returnCodes error -match glob -result {*msg options*} +test event-5.5 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} {} {} +} -returnCodes error -match glob -result {*msg options*} +test event-5.6 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} {} +} -returnCodes error -match glob -result {*-level*} +test event-5.7 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} {-level foo} +} -returnCodes error -match glob -result {*expected integer*} +test event-5.8 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} {-level 0} +} -returnCodes error -match glob -result {*-code*} +test event-5.9 {Default [interp bgerror] handler} -body { + ::tcl::Bgerror {} {-level 0 -code ok} +} -returnCodes error -match glob -result {*expected integer*} +test event-5.10 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror {} {-level 0 -code 0} + rename bgerror {} + set ::res +} {} +test event-5.11 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror msg {-level 0 -code 1} + rename bgerror {} + set ::res +} {msg} +test event-5.12 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror msg {-level 0 -code 2} + rename bgerror {} + set ::res +} {command returned bad code: 2} +test event-5.13 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror msg {-level 0 -code 3} + rename bgerror {} + set ::res +} {invoked "break" outside of a loop} +test event-5.14 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror msg {-level 0 -code 4} + rename bgerror {} + set ::res +} {invoked "continue" outside of a loop} +test event-5.15 {Default [interp bgerror] handler} { + proc bgerror {m} {append ::res $m} + set ::res {} + ::tcl::Bgerror msg {-level 0 -code 5} + rename bgerror {} + set ::res +} {command returned bad code: 5} test event-6.1 {BgErrorDeleteProc procedure} { catch {interp delete foo} @@ -285,6 +365,45 @@ test event-7.5 {correct behaviour when there is no bgerror [Bug 219142]} {exec} "error hello" ("after" script)}} +test event-7.6 {safe hidden bgerror fallback} { + variable result {} + interp create -safe safe + safe alias puts puts + safe alias result ::append [namespace which -variable result] + safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} + safe hide bgerror + safe eval after 0 error foo + update + interp delete safe + set result +} {foo +NONE +foo + while executing +"error foo" + ("after" script) +} + +test event-7.7 {safe hidden bgerror fallback} { + variable result {} + interp create -safe safe + safe alias puts puts + safe alias result ::append [namespace which -variable result] + safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} + safe hide bgerror + safe eval {proc bgerror m {error bar soom baz}} + safe eval after 0 error foo + update + interp delete safe + set result +} {foo +NONE +foo + while executing +"error foo" + ("after" script) +} + # someday : add a test checking that # when there is no bgerror, an error msg goes to stderr @@ -363,8 +482,8 @@ test event-9.4 {Tcl_DeleteExitHandler procedure} {stdio testexithandler} { test event-10.1 {Tcl_Exit procedure} {stdio} { set child [open |[list [interpreter]] r+] puts $child "exit 3" - list [catch {close $child} msg] $msg [lindex $errorCode 0] \ - [lindex $errorCode 2] + list [catch {close $child} msg] $msg [lindex $::errorCode 0] \ + [lindex $::errorCode 2] } {1 {child process exited abnormally} CHILDSTATUS 3} test event-11.1 {Tcl_VwaitCmd procedure} { @@ -405,7 +524,7 @@ test event-11.5 {Tcl_VwaitCmd procedure: round robin scheduling, 2 sources} {soc puts $s foobar close $s } - catch {set s1 [socket -server accept 0]} + catch {set s1 [socket -server accept -myaddr 127.0.0.1 0]} after 1000 catch {set s2 [socket 127.0.0.1 [lindex [fconfigure $s1 -sockname] 2]]} close $s1 |