📄 io.test
字号:
set f [open $path(test1) w] puts -nonewline $f abcdefghijkl close $f set f [open $path(test1)] # here set x [read $f] close $f set x} {abcdefghijkl}test io-12.3 {ReadChars: allocate more space} { # (toRead > length - offset - 1) set f [open $path(test1) w] puts -nonewline $f abcdefghijklmnopqrstuvwxyz close $f set f [open $path(test1)] fconfigure $f -buffersize 16 # here set x [read $f] close $f set x} {abcdefghijklmnopqrstuvwxyz}test io-12.4 {ReadChars: split-up char} {stdio testchannel} { # (srcRead == 0) set f [open "|[list [interpreter] $path(cat)]" w+] fconfigure $f -encoding binary -buffering none -buffersize 16 puts -nonewline $f "123456789012345\x96" fconfigure $f -encoding shiftjis -blocking 0 fileevent $f read [namespace code "ready $f"] proc ready {f} { variable x lappend x [read $f] [testchannel inputbuffered $f] } variable x {} fconfigure $f -encoding shiftjis vwait [namespace which -variable x] fconfigure $f -encoding binary -blocking 1 puts -nonewline $f "\x7b" after 500 ;# Give the cat process time to catch up fconfigure $f -encoding shiftjis -blocking 0 vwait [namespace which -variable x] close $f set x} [list "123456789012345" 1 "\u672c" 0]test io-12.5 {ReadChars: fileevents on partial characters} {stdio} { set path(test1) [makeFile { fconfigure stdout -encoding binary -buffering none gets stdin; puts -nonewline "\xe7" gets stdin; puts -nonewline "\x89" gets stdin; puts -nonewline "\xa6" } test1] set f [open "|[list [interpreter] $path(test1)]" r+] fileevent $f readable [namespace code { lappend x [read $f] if {[eof $f]} { lappend x eof } }] puts $f "go1" flush $f fconfigure $f -blocking 0 -encoding utf-8 variable x {} vwait [namespace which -variable x] after 500 [namespace code { lappend x timeout }] vwait [namespace which -variable x] puts $f "go2" flush $f vwait [namespace which -variable x] after 500 [namespace code { lappend x timeout }] vwait [namespace which -variable x] puts $f "go3" flush $f vwait [namespace which -variable x] vwait [namespace which -variable x] lappend x [catch {close $f} msg] $msg set x} "{} timeout {} timeout \u7266 {} eof 0 {}"test io-13.1 {TranslateInputEOL: cr mode} {} { set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\rdef\r" close $f set f [open $path(test1)] fconfigure $f -translation cr set x [read $f] close $f set x} "abcd\ndef\n"test io-13.2 {TranslateInputEOL: crlf mode} { set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r\ndef\r\n" close $f set f [open $path(test1)] fconfigure $f -translation crlf set x [read $f] close $f set x} "abcd\ndef\n"test io-13.3 {TranslateInputEOL: crlf mode: naked cr} { # (src >= srcMax) set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r\ndef\r" close $f set f [open $path(test1)] fconfigure $f -translation crlf set x [read $f] close $f set x} "abcd\ndef\r"test io-13.4 {TranslateInputEOL: crlf mode: cr followed by not \n} { # (src >= srcMax) set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r\ndef\rfgh" close $f set f [open $path(test1)] fconfigure $f -translation crlf set x [read $f] close $f set x} "abcd\ndef\rfgh"test io-13.5 {TranslateInputEOL: crlf mode: naked lf} { # (src >= srcMax) set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r\ndef\nfgh" close $f set f [open $path(test1)] fconfigure $f -translation crlf set x [read $f] close $f set x} "abcd\ndef\nfgh"test io-13.6 {TranslateInputEOL: auto mode: saw cr in last segment} {stdio testchannel} { # (chanPtr->flags & INPUT_SAW_CR) # This test may fail on slower machines. set f [open "|[list [interpreter] $path(cat)]" w+] fconfigure $f -blocking 0 -buffering none -translation {auto lf} fileevent $f read [namespace code "ready $f"] proc ready {f} { variable x lappend x [read $f] [testchannel queuedcr $f] } variable x {} variable y {} puts -nonewline $f "abcdefghj\r" after 500 [namespace code {set y ok}] vwait [namespace which -variable y] puts -nonewline $f "\n01234" after 500 [namespace code {set y ok}] vwait [namespace which -variable y] close $f set x} [list "abcdefghj\n" 1 "01234" 0]test io-13.7 {TranslateInputEOL: auto mode: naked \r} {testchannel} { # (src >= srcMax) set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r" close $f set f [open $path(test1)] fconfigure $f -translation auto set x [list [read $f] [testchannel queuedcr $f]] close $f set x} [list "abcd\n" 1]test io-13.8 {TranslateInputEOL: auto mode: \r\n} { # (*src == '\n') set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\r\ndef" close $f set f [open $path(test1)] fconfigure $f -translation auto set x [read $f] close $f set x} "abcd\ndef"test io-13.9 {TranslateInputEOL: auto mode: \r followed by not \n} { set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\rdef" close $f set f [open $path(test1)] fconfigure $f -translation auto set x [read $f] close $f set x} "abcd\ndef"test io-13.10 {TranslateInputEOL: auto mode: \n} { # not (*src == '\r') set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\ndef" close $f set f [open $path(test1)] fconfigure $f -translation auto set x [read $f] close $f set x} "abcd\ndef"test io-13.11 {TranslateInputEOL: EOF char} { # (*chanPtr->inEofChar != '\0') set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "abcd\ndefgh" close $f set f [open $path(test1)] fconfigure $f -translation auto -eofchar e set x [read $f] close $f set x} "abcd\nd"test io-13.12 {TranslateInputEOL: find EOF char in src} { # (*chanPtr->inEofChar != '\0') set f [open $path(test1) w] fconfigure $f -translation lf puts -nonewline $f "\r\n\r\n\r\nab\r\n\r\ndef\r\n\r\n\r\n" close $f set f [open $path(test1)] fconfigure $f -translation auto -eofchar e set x [read $f] close $f set x} "\n\n\nab\n\nd" # Test standard handle management. The functions tested are# Tcl_SetStdChannel and Tcl_GetStdChannel. Incidentally we are# also testing channel table management.if {[info commands testchannel] != ""} { if {$tcl_platform(platform) == "macintosh"} { set consoleFileNames [list console0 console1 console2] } else { set consoleFileNames [lsort [testchannel open]] }} else { # just to avoid an error set consoleFileNames [list]}test io-14.1 {Tcl_SetStdChannel and Tcl_GetStdChannel} {testchannel} { set l "" lappend l [fconfigure stdin -buffering] lappend l [fconfigure stdout -buffering] lappend l [fconfigure stderr -buffering] lappend l [lsort [testchannel open]] set l} [list line line none $consoleFileNames]test io-14.2 {Tcl_SetStdChannel and Tcl_GetStdChannel} { interp create x set l "" lappend l [x eval {fconfigure stdin -buffering}] lappend l [x eval {fconfigure stdout -buffering}] lappend l [x eval {fconfigure stderr -buffering}] interp delete x set l} {line line none}set path(test3) [makeFile {} test3]test io-14.3 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec} { set f [open $path(test1) w] puts $f [format { close stdin close stdout close stderr set f [open "%s" r] set f2 [open "%s" w] set f3 [open "%s" w] puts stdout [gets stdin] puts stdout out puts stderr err close $f close $f2 close $f3 } $path(test1) $path(test2) $path(test3)] close $f set result [exec [interpreter] $path(test1)] set f [open $path(test2) r] set f2 [open $path(test3) r] lappend result [read $f] [read $f2] close $f close $f2 set result} {{out} {err}}# This test relies on the fact that the smallest available fd is used first.test io-14.4 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec unixOnly} { set f [open $path(test1) w] puts $f [format { close stdin close stdout close stderr set f [open "%s" r] set f2 [open "%s" w] set f3 [open "%s" w] puts stdout [gets stdin] puts stdout $f2 puts stderr $f3 close $f close $f2 close $f3 } $path(test1) $path(test2) $path(test3)] close $f set result [exec [interpreter] $path(test1)] set f [open $path(test2) r] set f2 [open $path(test3) r] lappend result [read $f] [read $f2] close $f close $f2 set result} {{ close stdinfile1} {file2}}catch {interp delete z}test io-14.5 {Tcl_GetChannel: stdio name translation} { interp create z eof stdin catch {z eval flush stdin} msg1 catch {z eval close stdin} msg2 catch {z eval flush stdin} msg3 set result [list $msg1 $msg2 $msg3] interp delete z set result} {{channel "stdin" wasn't opened for writing} {} {can not find channel named "stdin"}}test io-14.6 {Tcl_GetChannel: stdio name translation} { interp create z eof stdout catch {z eval flush stdout} msg1 catch {z eval close stdout} msg2 catch {z eval flush stdout} msg3 set result [list $msg1 $msg2 $msg3] interp delete z set result} {{} {} {can not find channel named "stdout"}}test io-14.7 {Tcl_GetChannel: stdio name translation} { interp create z eof stderr catch {z eval flush stderr} msg1 catch {z eval close stderr} msg2 catch {z eval flush stderr} msg3 set result [list $msg1 $msg2 $msg3] interp delete z set result} {{} {} {can not find channel named "stderr"}}set path(script) [makeFile {} script]test io-14.8 {reuse of stdio special channels} {stdio} { removeFile script removeFile test1 set f [open $path(script) w] puts $f [format { close stderr set f [open "%s" w] puts stderr hello close $f set f [open "%s" r] puts [gets $f] } $path(test1) $path(test1)] close $f set f [open "|[list [interpreter] $path(script)]" r] set c [gets $f] close $f set c} hellotest io-14.9 {reuse of stdio special channels} {stdio} { removeFile script removeFile test1 set f [open $path(script) w] puts $f { array set path [lindex $argv 0] set f [open $path(test1) w] puts $f hello close $f close stderr set f [open "|[list [info nameofexecutable] $path(cat) $path(test1)]" r] puts [gets $f] } close $f set f [open "|[list [interpreter] $path(script) [array get path]]" r] set c [gets $f] close $f set c} hellotest io-15.1 {Tcl_CreateCloseHandler} {} {}test io-16.1 {Tcl_DeleteCloseHandler} {} {}# Test channel table management. The functions tested are# GetChannelTable, DeleteChannelTable, Tcl_RegisterChannel,# Tcl_UnregisterChannel, Tcl_GetChannel and Tcl_CreateChannel.## These functions use "eof stdin" to ensure that the standard# channels are added to the channel table of the interpreter.test io-17.1 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} { set l1 [testchannel refcount stdin] eof stdin interp create x set l "" lappend l [expr [testchannel refcount stdin] - $l1] x eval {eof stdin} lappend l [expr [testchannel refcount stdin] - $l1] interp delete x lappend l [expr [testchannel refcount stdin] - $l1] set l} {0 1 0}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -