From 15fd9ef834884fbc1b67a491dead6fa004a3fd45 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 17 May 2024 13:21:47 +0000 Subject: split iocmd-32.3 in two tests (move cycle outside of the test) --- tests/ioCmd.test | 97 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/tests/ioCmd.test b/tests/ioCmd.test index a2061fa..74fabe7 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -2117,13 +2117,15 @@ test iocmd-32.2 {delete interp of reflected chan} { interp delete child } {} -test iocmd-32.3 {prevent copy-state against segfault by finalize, bug [79474c58800cdf94]} -setup { - proc test_chan {writeErr args} { +# 1st attempt without error in write, another with error in write: +foreach ::writeErr {0 1} { +test iocmd-32.3.$::writeErr {prevent copy-state against segfault by finalize, bug [79474c58800cdf94]} -setup { + proc test_chan {args} { set rest [lassign $args mode chan] lappend ::ret $mode switch -exact $mode { read {puts $chan "Test" ; close $chan} - write {if {$writeErr} {return}; set data [lindex $rest 0]; string length $data} + write {if {$::writeErr} {return "boom"}; set data [lindex $rest 0]; string length $data} finalize {after 20 {set ::done done}} initialize {return "initialize watch finalize read write"} } @@ -2132,59 +2134,56 @@ test iocmd-32.3 {prevent copy-state against segfault by finalize, bug [79474c588 set toev [after 5000 {set ::done tout}] } -body { set ::ret {} - # 1st attempt without error in write, another with error in write: - foreach i {0 1} { - set ch [chan create "read write" [list test_chan $i]] - lappend clchlst $ch - - lassign [chan pipe] in1 out1 - lappend clchlst $in1 $out1 - lassign [chan pipe] in2 out2 - lappend clchlst $in2 $out2 - lassign [chan pipe] in3 out3 - lappend clchlst $in3 $out3 - - # simulate exec: echo test >@ $out2 2>@ $out3 <@ $in1 &: - fileevent $out2 writable [list apply {{cho che} { - puts $cho test; close $cho; close $che - }} $out2 $out3] - # recopy to given chans in handler - fileevent $in2 readable [list apply {{in out} { - if {[catch { - chan copy $in $out - } msg]} { - #puts err:$msg - fileevent $in readable {} - } - }} $in2 $ch] - fileevent $in3 readable [list apply {{in out} { - if {[catch { - chan copy $in $out - } msg]} { - #puts err:$msg - fileevent $in readable {} - } - }} $in3 $ch] - fileevent $out1 writable [list apply {{in out} { - if {[catch { - chan copy $in $out - } msg]} { - #puts err:$msg - fileevent $out writable {} - } - }} $ch $out1] + set ch [chan create "read write" test_chan] + lappend clchlst $ch + + lassign [chan pipe] in1 out1 + lappend clchlst $in1 $out1 + lassign [chan pipe] in2 out2 + lappend clchlst $in2 $out2 + lassign [chan pipe] in3 out3 + lappend clchlst $in3 $out3 + + # simulate exec: echo test >@ $out2 2>@ $out3 <@ $in1 &: + fileevent $out2 writable [list apply {{cho che} { + puts $cho test; close $cho; close $che + }} $out2 $out3] + # recopy to given chans in handler + fileevent $in2 readable [list apply {{in out} { + if {[catch { + chan copy $in $out + } msg]} { + #puts err:$msg + fileevent $in readable {} + } + }} $in2 $ch] + fileevent $in3 readable [list apply {{in out} { + if {[catch { + chan copy $in $out + } msg]} { + #puts err:$msg + fileevent $in readable {} + } + }} $in3 $ch] + fileevent $out1 writable [list apply {{in out} { + if {[catch { + chan copy $in $out + } msg]} { + #puts err:$msg + fileevent $out writable {} + } + }} $ch $out1] - vwait ::done - lappend ::ret $::done - } - set ::ret + vwait ::done + lappend ::ret $::done } -cleanup { foreach ch $clchlst { catch {close $ch} } after cancel $toev unset -nocomplain ::done ::ret ch in1 in2 in3 out1 out2 out3 toev clchlst -} -result [lrepeat 2 initialize read write finalize done] +} -result {initialize read write finalize done} +}; unset ::writeErr # ### ### ### ######### ######### ######### ## Same tests as above, but exercising the code forwarding and -- cgit v0.12