sl@0: # -*- tcl -*- sl@0: # Functionality covered: operation of all IO commands, and all procedures sl@0: # defined in generic/tclIO.c. sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1994 The Regents of the University of California. sl@0: # Copyright (c) 1994-1997 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: io.test,v 1.40.2.12 2007/02/12 19:25:42 andreas_kupries Exp $ sl@0: sl@0: if {[catch {package require tcltest 2}]} { sl@0: puts stderr "Skipping tests in [info script]. tcltest 2 required." sl@0: return sl@0: } sl@0: namespace eval ::tcl::test::io { sl@0: sl@0: namespace import ::tcltest::cleanupTests sl@0: namespace import ::tcltest::interpreter sl@0: namespace import ::tcltest::makeFile sl@0: namespace import ::tcltest::removeFile sl@0: namespace import ::tcltest::test sl@0: namespace import ::tcltest::testConstraint sl@0: namespace import ::tcltest::viewFile sl@0: sl@0: testConstraint testchannel [llength [info commands testchannel]] sl@0: testConstraint exec [llength [info commands exec]] sl@0: testConstraint openpipe 1 sl@0: testConstraint fileevent [llength [info commands fileevent]] sl@0: testConstraint fcopy [llength [info commands fcopy]] sl@0: sl@0: # You need a *very* special environment to do some tests. In sl@0: # particular, many file systems do not support large-files... sl@0: testConstraint largefileSupport 0 sl@0: sl@0: # set up a long data file for some of the following tests sl@0: sl@0: set path(longfile) [makeFile {} longfile] sl@0: set f [open $path(longfile) w] sl@0: fconfigure $f -eofchar {} -translation lf sl@0: for { set i 0 } { $i < 100 } { incr i} { sl@0: puts $f "#123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef sl@0: \#123456789abcdef01 sl@0: \#" sl@0: } sl@0: close $f sl@0: sl@0: set path(cat) [makeFile { sl@0: set f stdin sl@0: if {$argv != ""} { sl@0: set f [open [lindex $argv 0]] sl@0: } sl@0: fconfigure $f -encoding binary -translation lf -blocking 0 -eofchar \x1a sl@0: fconfigure stdout -encoding binary -translation lf -buffering none sl@0: fileevent $f readable "foo $f" sl@0: proc foo {f} { sl@0: set x [read $f] sl@0: catch {puts -nonewline $x} sl@0: if {[eof $f]} { sl@0: close $f sl@0: exit 0 sl@0: } sl@0: } sl@0: vwait forever sl@0: } cat] sl@0: sl@0: set thisScript [file join [pwd] [info script]] sl@0: sl@0: proc contents {file} { sl@0: set f [open $file] sl@0: fconfigure $f -translation binary sl@0: set a [read $f] sl@0: close $f sl@0: return $a sl@0: } sl@0: sl@0: test io-1.5 {Tcl_WriteChars: CheckChannelErrors} {emptyTest} { sl@0: # no test, need to cause an async error. sl@0: } {} sl@0: sl@0: set path(test1) [makeFile {} test1] sl@0: sl@0: test io-1.6 {Tcl_WriteChars: WriteBytes} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary sl@0: puts -nonewline $f "a\u4e4d\0" sl@0: close $f sl@0: contents $path(test1) sl@0: } "a\x4d\x00" sl@0: test io-1.7 {Tcl_WriteChars: WriteChars} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding shiftjis sl@0: puts -nonewline $f "a\u4e4d\0" sl@0: close $f sl@0: contents $path(test1) sl@0: } "a\x93\xe1\x00" sl@0: sl@0: set path(test2) [makeFile {} test2] sl@0: sl@0: test io-1.8 {Tcl_WriteChars: WriteChars} { sl@0: # This test written for SF bug #506297. sl@0: # sl@0: # Executing this test without the fix for the referenced bug sl@0: # applied to tcl will cause tcl, more specifically WriteChars, to sl@0: # go into an infinite loop. sl@0: sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp sl@0: puts -nonewline $f [format %s%c [string repeat " " 4] 12399] sl@0: close $f sl@0: contents $path(test2) sl@0: } " \x1b\$B\$O\x1b(B" sl@0: sl@0: test io-1.9 {Tcl_WriteChars: WriteChars} { sl@0: # When closing a channel with an encoding that appends sl@0: # escape bytes, check for the case where the escape sl@0: # bytes overflow the current IO buffer. The bytes sl@0: # should be moved into a new buffer. sl@0: sl@0: set data "1234567890 [format %c 12399]" sl@0: sl@0: set sizes [list] sl@0: sl@0: # With default buffer size sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp sl@0: puts -nonewline $f $data sl@0: close $f sl@0: lappend sizes [file size $path(test2)] sl@0: sl@0: # With buffer size equal to the length sl@0: # of the data, the escape bytes would sl@0: # go into the next buffer. sl@0: sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp -buffersize 16 sl@0: puts -nonewline $f $data sl@0: close $f sl@0: lappend sizes [file size $path(test2)] sl@0: sl@0: # With buffer size that is large enough sl@0: # to hold 1 byte of escaped data, but sl@0: # not all 3. This should not write sl@0: # the escape bytes to the first buffer sl@0: # and then again to the second buffer. sl@0: sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp -buffersize 17 sl@0: puts -nonewline $f $data sl@0: close $f sl@0: lappend sizes [file size $path(test2)] sl@0: sl@0: # With buffer size that can hold 2 out of sl@0: # 3 bytes of escaped data. sl@0: sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp -buffersize 18 sl@0: puts -nonewline $f $data sl@0: close $f sl@0: lappend sizes [file size $path(test2)] sl@0: sl@0: # With buffer size that can hold all the sl@0: # data and escape bytes. sl@0: sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -encoding iso2022-jp -buffersize 19 sl@0: puts -nonewline $f $data sl@0: close $f sl@0: lappend sizes [file size $path(test2)] sl@0: sl@0: set sizes sl@0: } {19 19 19 19 19} sl@0: sl@0: test io-2.1 {WriteBytes} { sl@0: # loop until all bytes are written sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary -buffersize 16 -translation crlf sl@0: puts $f "abcdefghijklmnopqrstuvwxyz" sl@0: close $f sl@0: contents $path(test1) sl@0: } "abcdefghijklmnopqrstuvwxyz\r\n" sl@0: test io-2.2 {WriteBytes: savedLF > 0} { sl@0: # After flushing buffer, there was a \n left over from the last sl@0: # \n -> \r\n expansion. It gets stuck at beginning of this buffer. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary -buffersize 16 -translation crlf sl@0: puts -nonewline $f "123456789012345\n12" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "123456789012345\r" "123456789012345\r\n12"] sl@0: test io-2.3 {WriteBytes: flush on line} { sl@0: # Tcl "line" buffering has weird behavior: if current buffer contains sl@0: # a \n, entire buffer gets flushed. Logical behavior would be to flush sl@0: # only up to the \n. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary -buffering line -translation crlf sl@0: puts -nonewline $f "\n12" sl@0: set x [contents $path(test1)] sl@0: close $f sl@0: set x sl@0: } "\r\n12" sl@0: test io-2.4 {WriteBytes: reset sawLF after each buffer} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary -buffering line -translation lf \ sl@0: -buffersize 16 sl@0: puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] sl@0: sl@0: test io-3.1 {WriteChars: compatibility with WriteBytes} { sl@0: # loop until all bytes are written sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding ascii -buffersize 16 -translation crlf sl@0: puts $f "abcdefghijklmnopqrstuvwxyz" sl@0: close $f sl@0: contents $path(test1) sl@0: } "abcdefghijklmnopqrstuvwxyz\r\n" sl@0: test io-3.2 {WriteChars: compatibility with WriteBytes: savedLF > 0} { sl@0: # After flushing buffer, there was a \n left over from the last sl@0: # \n -> \r\n expansion. It gets stuck at beginning of this buffer. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding ascii -buffersize 16 -translation crlf sl@0: puts -nonewline $f "123456789012345\n12" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "123456789012345\r" "123456789012345\r\n12"] sl@0: test io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} { sl@0: # Tcl "line" buffering has weird behavior: if current buffer contains sl@0: # a \n, entire buffer gets flushed. Logical behavior would be to flush sl@0: # only up to the \n. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding ascii -buffering line -translation crlf sl@0: puts -nonewline $f "\n12" sl@0: set x [contents $path(test1)] sl@0: close $f sl@0: set x sl@0: } "\r\n12" sl@0: test io-3.4 {WriteChars: loop over stage buffer} { sl@0: # stage buffer maps to more than can be queued at once. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding jis0208 -buffersize 16 sl@0: puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] sl@0: test io-3.5 {WriteChars: saved != 0} { sl@0: # Bytes produced by UtfToExternal from end of last channel buffer sl@0: # had to be moved to beginning of next channel buffer to preserve sl@0: # requested buffersize. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding jis0208 -buffersize 17 sl@0: puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] sl@0: test io-3.6 {WriteChars: (stageRead + dstWrote == 0)} { sl@0: # One incomplete UTF-8 character at end of staging buffer. Backup sl@0: # in src to the beginning of that UTF-8 character and try again. sl@0: # sl@0: # Translate the first 16 bytes, produce 14 bytes of output, 2 left over sl@0: # (first two bytes of \uff21 in UTF-8). Given those two bytes try sl@0: # translating them again, find that no bytes are read produced, and break sl@0: # to outer loop where those two bytes will have the remaining 4 bytes sl@0: # (the last byte of \uff21 plus the all of \uff22) appended. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding shiftjis -buffersize 16 sl@0: puts -nonewline $f "12345678901234\uff21\uff22" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"] sl@0: test io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} { sl@0: # When translating UTF-8 to external, the produced bytes went past end sl@0: # of the channel buffer. This is done purpose -- we then truncate the sl@0: # bytes at the end of the partial character to preserve the requested sl@0: # blocksize on flush. The truncated bytes are moved to the beginning sl@0: # of the next channel buffer. sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding jis0208 -buffersize 17 sl@0: puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] sl@0: test io-3.8 {WriteChars: reset sawLF after each buffer} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding ascii -buffering line -translation lf \ sl@0: -buffersize 16 sl@0: puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] sl@0: sl@0: test io-4.1 {TranslateOutputEOL: lf} { sl@0: # search for \n sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering line -translation lf sl@0: puts $f "abcde" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "abcde\n" "abcde\n"] sl@0: test io-4.2 {TranslateOutputEOL: cr} { sl@0: # search for \n, replace with \r sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering line -translation cr sl@0: puts $f "abcde" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "abcde\r" "abcde\r"] sl@0: test io-4.3 {TranslateOutputEOL: crlf} { sl@0: # simple case: search for \n, replace with \r sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering line -translation crlf sl@0: puts $f "abcde" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "abcde\r\n" "abcde\r\n"] sl@0: test io-4.4 {TranslateOutputEOL: crlf} { sl@0: # keep storing more bytes in output buffer until output buffer is full. sl@0: # We have 13 bytes initially that would turn into 18 bytes. Fill sl@0: # dest buffer while (dstEnd < dstMax). sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -buffersize 16 sl@0: puts -nonewline $f "1234567\n\n\n\n\nA" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "1234567\r\n\r\n\r\n\r\n\r" "1234567\r\n\r\n\r\n\r\n\r\nA"] sl@0: test io-4.5 {TranslateOutputEOL: crlf} { sl@0: # Check for overflow of the destination buffer sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -buffersize 12 sl@0: puts -nonewline $f "12345678901\n456789012345678901234" sl@0: close $f sl@0: set x [contents $path(test1)] sl@0: } "12345678901\r\n456789012345678901234" sl@0: sl@0: test io-5.1 {CheckFlush: not full} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f sl@0: puts -nonewline $f "12345678901234567890" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "" "12345678901234567890"] sl@0: test io-5.2 {CheckFlush: full} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffersize 16 sl@0: puts -nonewline $f "12345678901234567890" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "1234567890123456" "12345678901234567890"] sl@0: test io-5.3 {CheckFlush: not line} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering line sl@0: puts -nonewline $f "12345678901234567890" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "" "12345678901234567890"] sl@0: test io-5.4 {CheckFlush: line} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering line -translation lf -encoding ascii sl@0: puts -nonewline $f "1234567890\n1234567890" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "1234567890\n1234567890" "1234567890\n1234567890"] sl@0: test io-5.5 {CheckFlush: none} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffering none sl@0: puts -nonewline $f "1234567890" sl@0: set x [list [contents $path(test1)]] sl@0: close $f sl@0: lappend x [contents $path(test1)] sl@0: } [list "1234567890" "1234567890"] sl@0: sl@0: test io-6.1 {Tcl_GetsObj: working} { sl@0: set f [open $path(test1) w] sl@0: puts $f "foo\nboo" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } {foo} sl@0: test io-6.2 {Tcl_GetsObj: CheckChannelErrors() != 0} { sl@0: # no test, need to cause an async error. sl@0: } {} sl@0: test io-6.3 {Tcl_GetsObj: how many have we used?} { sl@0: # if (bufPtr != NULL) {oldRemoved = bufPtr->nextRemoved} sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f "abc\ndefg" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [tell $f] [gets $f line] [tell $f] [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {0 3 5 4 defg} sl@0: test io-6.4 {Tcl_GetsObj: encoding == NULL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation binary sl@0: puts $f "\x81\u1234\0" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation binary sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 3 "\x81\x34\x00"] sl@0: test io-6.5 {Tcl_GetsObj: encoding != NULL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation binary sl@0: puts $f "\x88\xea\x92\x9a" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding shiftjis sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 2 "\u4e00\u4e01"] sl@0: set a "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" sl@0: append a $a sl@0: append a $a sl@0: test io-6.6 {Tcl_GetsObj: loop test} { sl@0: # if (dst >= dstEnd) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts $f $a sl@0: puts $f hi sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 256 $a] sl@0: test io-6.7 {Tcl_GetsObj: error in input} {stdio openpipe} { sl@0: # if (FilterInputBytes(chanPtr, &gs) != 0) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: puts -nonewline $f "hi\nwould" sl@0: flush $f sl@0: gets $f sl@0: fconfigure $f -blocking 0 sl@0: set x [gets $f line] sl@0: close $f sl@0: set x sl@0: } {-1} sl@0: test io-6.8 {Tcl_GetsObj: remember if EOF is seen} { sl@0: set f [open $path(test1) w] sl@0: puts $f "abcdef\x1aghijk\nwombat" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -eofchar \x1a sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {6 abcdef -1 {}} sl@0: test io-6.9 {Tcl_GetsObj: remember if EOF is seen} { sl@0: set f [open $path(test1) w] sl@0: puts $f "abcdefghijk\nwom\u001abat" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -eofchar \x1a sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {11 abcdefghijk 3 wom} sl@0: sl@0: # Comprehensive tests sl@0: sl@0: test io-6.10 {Tcl_GetsObj: lf mode: no chars} { sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {-1 {}} sl@0: test io-6.11 {Tcl_GetsObj: lf mode: lone \n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {0 {} -1 {}} sl@0: test io-6.12 {Tcl_GetsObj: lf mode: lone \r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 1 "\r" -1 ""] sl@0: test io-6.13 {Tcl_GetsObj: lf mode: 1 char} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f a sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.14 {Tcl_GetsObj: lf mode: 1 char followed by EOL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.15 {Tcl_GetsObj: lf mode: several chars} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation lf sl@0: set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 4 "abcd" 10 "efgh\rijkl\r" 4 "mnop" -1 ""] sl@0: test io-6.16 {Tcl_GetsObj: cr mode: no chars} { sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {-1 {}} sl@0: test io-6.17 {Tcl_GetsObj: cr mode: lone \n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 1 "\n" -1 ""] sl@0: test io-6.18 {Tcl_GetsObj: cr mode: lone \r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {0 {} -1 {}} sl@0: test io-6.19 {Tcl_GetsObj: cr mode: 1 char} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f a sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.20 {Tcl_GetsObj: cr mode: 1 char followed by EOL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.21 {Tcl_GetsObj: cr mode: several chars} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 9 "abcd\nefgh" 4 "ijkl" 5 "\nmnop" -1 ""] sl@0: test io-6.22 {Tcl_GetsObj: crlf mode: no chars} { sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {-1 {}} sl@0: test io-6.23 {Tcl_GetsObj: crlf mode: lone \n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 1 "\n" -1 ""] sl@0: test io-6.24 {Tcl_GetsObj: crlf mode: lone \r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 1 "\r" -1 ""] sl@0: test io-6.25 {Tcl_GetsObj: crlf mode: \r\r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 2 "\r\r" -1 ""] sl@0: test io-6.26 {Tcl_GetsObj: crlf mode: \r\n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 0 "" -1 ""] sl@0: test io-6.27 {Tcl_GetsObj: crlf mode: 1 char} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f a sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.28 {Tcl_GetsObj: crlf mode: 1 char followed by EOL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.29 {Tcl_GetsObj: crlf mode: several chars} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 14 "abcd\nefgh\rijkl" 4 "mnop" -1 ""] sl@0: test io-6.30 {Tcl_GetsObj: crlf mode: buffer exhausted} {testchannel} { sl@0: # if (eol >= dstEnd) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\r\nabcdefghijklmnoprstuvwxyz" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf -buffersize 16 sl@0: set x [list [gets $f line] $line [testchannel inputbuffered $f]] sl@0: close $f sl@0: set x sl@0: } [list 15 "123456789012345" 15] sl@0: test io-6.31 {Tcl_GetsObj: crlf mode: buffer exhausted, blocked} {stdio testchannel openpipe fileevent} { sl@0: # (FilterInputBytes() != 0) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {crlf lf} -buffering none sl@0: puts -nonewline $f "bbbbbbbbbbbbbb\r\n123456789012345\r" sl@0: fconfigure $f -buffersize 16 sl@0: set x [gets $f] sl@0: fconfigure $f -blocking 0 sl@0: lappend x [gets $f line] $line [fblocked $f] [testchannel inputbuffered $f] sl@0: close $f sl@0: set x sl@0: } [list "bbbbbbbbbbbbbb" -1 "" 1 16] sl@0: test io-6.32 {Tcl_GetsObj: crlf mode: buffer exhausted, more data} {testchannel} { sl@0: # not (FilterInputBytes() != 0) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\r\n123" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf -buffersize 16 sl@0: set x [list [gets $f line] $line [tell $f] [testchannel inputbuffered $f]] sl@0: close $f sl@0: set x sl@0: } [list 15 "123456789012345" 17 3] sl@0: test io-6.33 {Tcl_GetsObj: crlf mode: buffer exhausted, at eof} { sl@0: # eol still equals dstEnd sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf -buffersize 16 sl@0: set x [list [gets $f line] $line [eof $f]] sl@0: close $f sl@0: set x sl@0: } [list 16 "123456789012345\r" 1] sl@0: test io-6.34 {Tcl_GetsObj: crlf mode: buffer exhausted, not followed by \n} { sl@0: # not (*eol == '\n') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\rabcd\r\nefg" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf -buffersize 16 sl@0: set x [list [gets $f line] $line [tell $f]] sl@0: close $f sl@0: set x sl@0: } [list 20 "123456789012345\rabcd" 22] sl@0: test io-6.35 {Tcl_GetsObj: auto mode: no chars} { sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {-1 {}} sl@0: test io-6.36 {Tcl_GetsObj: auto mode: lone \n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 0 "" -1 ""] sl@0: test io-6.37 {Tcl_GetsObj: auto mode: lone \r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 0 "" -1 ""] sl@0: test io-6.38 {Tcl_GetsObj: auto mode: \r\r} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 0 "" 0 "" -1 ""] sl@0: test io-6.39 {Tcl_GetsObj: auto mode: \r\n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 0 "" -1 ""] sl@0: test io-6.40 {Tcl_GetsObj: auto mode: 1 char} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f a sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.41 {Tcl_GetsObj: auto mode: 1 char followed by EOL} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } {1 a -1 {}} sl@0: test io-6.42 {Tcl_GetsObj: auto mode: several chars} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [gets $f line] $line [gets $f line] $line] sl@0: lappend x [gets $f line] $line [gets $f line] $line [gets $f line] $line sl@0: close $f sl@0: set x sl@0: } [list 4 "abcd" 4 "efgh" 4 "ijkl" 4 "mnop" -1 ""] sl@0: test io-6.43 {Tcl_GetsObj: input saw cr} {stdio testchannel openpipe fileevent} { sl@0: # if (chanPtr->flags & INPUT_SAW_CR) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto lf} -buffering none sl@0: puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" sl@0: fconfigure $f -buffersize 16 sl@0: set x [list [gets $f]] sl@0: fconfigure $f -blocking 0 sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: fconfigure $f -blocking 1 sl@0: puts -nonewline $f "\nabcd\refg\x1a" sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: lappend x [gets $f line] $line sl@0: close $f sl@0: set x sl@0: } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"] sl@0: test io-6.44 {Tcl_GetsObj: input saw cr, not followed by cr} {stdio testchannel openpipe fileevent} { sl@0: # not (*eol == '\n') sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto lf} -buffering none sl@0: puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" sl@0: fconfigure $f -buffersize 16 sl@0: set x [list [gets $f]] sl@0: fconfigure $f -blocking 0 sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: fconfigure $f -blocking 1 sl@0: puts -nonewline $f "abcd\refg\x1a" sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: lappend x [gets $f line] $line sl@0: close $f sl@0: set x sl@0: } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"] sl@0: test io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent} { sl@0: # Tcl_ExternalToUtf() sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto lf} -buffering none sl@0: fconfigure $f -encoding unicode sl@0: puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" sl@0: fconfigure $f -buffersize 16 sl@0: gets $f sl@0: fconfigure $f -blocking 0 sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: fconfigure $f -blocking 1 sl@0: puts -nonewline $f "\nabcd\refg" sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: close $f sl@0: set x sl@0: } [list 15 "123456789abcdef" 1 4 "abcd" 0] sl@0: test io-6.46 {Tcl_GetsObj: input saw cr, followed by just \n should give eof} {stdio testchannel openpipe fileevent} { sl@0: # memmove() sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto lf} -buffering none sl@0: puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" sl@0: fconfigure $f -buffersize 16 sl@0: gets $f sl@0: fconfigure $f -blocking 0 sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: fconfigure $f -blocking 1 sl@0: puts -nonewline $f "\n\x1a" sl@0: lappend x [gets $f line] $line [testchannel queuedcr $f] sl@0: close $f sl@0: set x sl@0: } [list 15 "123456789abcdef" 1 -1 "" 0] sl@0: test io-6.47 {Tcl_GetsObj: auto mode: \r at end of buffer, peek for \n} {testchannel} { sl@0: # (eol == dstEnd) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\r\nabcdefghijklmnopq" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto -buffersize 16 sl@0: set x [list [gets $f] [testchannel inputbuffered $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456789012345" 15] sl@0: test io-6.48 {Tcl_GetsObj: auto mode: \r at end of buffer, no more avail} {testchannel} { sl@0: # PeekAhead() did not get any, so (eol >= dstEnd) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456789012345\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto -buffersize 16 sl@0: set x [list [gets $f] [testchannel queuedcr $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456789012345" 1] sl@0: test io-6.49 {Tcl_GetsObj: auto mode: \r followed by \n} {testchannel} { sl@0: # if (*eol == '\n') {skip++} sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456\r\n78901" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456" 0 8 "78901"] sl@0: test io-6.50 {Tcl_GetsObj: auto mode: \r not followed by \n} {testchannel} { sl@0: # not (*eol == '\n') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456\r78901" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456" 0 7 "78901"] sl@0: test io-6.51 {Tcl_GetsObj: auto mode: \n} { sl@0: # else if (*eol == '\n') {goto gotoeol;} sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456\n78901" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f] [tell $f] [gets $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456" 7 "78901"] sl@0: test io-6.52 {Tcl_GetsObj: saw EOF character} {testchannel} { sl@0: # if (eof != NULL) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "123456\x1ak9012345\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -eofchar \x1a sl@0: set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]] sl@0: close $f sl@0: set x sl@0: } [list "123456" 0 6 ""] sl@0: test io-6.53 {Tcl_GetsObj: device EOF} { sl@0: # didn't produce any bytes sl@0: sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f line] $line [eof $f]] sl@0: close $f sl@0: set x sl@0: } {-1 {} 1} sl@0: test io-6.54 {Tcl_GetsObj: device EOF} { sl@0: # got some bytes before EOF. sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abc sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [gets $f line] $line [eof $f]] sl@0: close $f sl@0: set x sl@0: } {3 abc 1} sl@0: test io-6.55 {Tcl_GetsObj: overconverted} { sl@0: # Tcl_ExternalToUtf(), make sure state updated sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding iso2022-jp sl@0: puts $f "there\u4e00ok\n\u4e01more bytes\nhere" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding iso2022-jp sl@0: set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line] sl@0: close $f sl@0: set x sl@0: } [list 8 "there\u4e00ok" 11 "\u4e01more bytes" 4 "here"] sl@0: test io-6.56 {Tcl_GetsObj: incomplete lines should disable file events} {stdio openpipe fileevent} { sl@0: update sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -buffering none sl@0: puts -nonewline $f "foobar" sl@0: fconfigure $f -blocking 0 sl@0: variable x {} sl@0: after 500 [namespace code { lappend x timeout }] sl@0: fileevent $f readable [namespace code { lappend x [gets $f] }] sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -blocking 1 sl@0: puts -nonewline $f "baz\n" sl@0: after 500 [namespace code { lappend x timeout }] sl@0: fconfigure $f -blocking 0 sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: set x sl@0: } {{} timeout foobarbaz timeout} sl@0: sl@0: test io-7.1 {FilterInputBytes: split up character at end of buffer} { sl@0: # (result == TCL_CONVERT_MULTIBYTE) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding shiftjis sl@0: puts $f "1234567890123\uff10\uff11\uff12\uff13\uff14\nend" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding shiftjis -buffersize 16 sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } "1234567890123\uff10\uff11\uff12\uff13\uff14" sl@0: test io-7.2 {FilterInputBytes: split up character in middle of buffer} { sl@0: # (bufPtr->nextAdded < bufPtr->bufLength) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary sl@0: puts -nonewline $f "1234567890\n123\x82\x4f\x82\x50\x82" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding shiftjis sl@0: set x [list [gets $f line] $line [eof $f]] sl@0: close $f sl@0: set x sl@0: } [list 10 "1234567890" 0] sl@0: test io-7.3 {FilterInputBytes: split up character at EOF} {testchannel} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary sl@0: puts -nonewline $f "1234567890123\x82\x4f\x82\x50\x82" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding shiftjis sl@0: set x [list [gets $f line] $line] sl@0: lappend x [tell $f] [testchannel inputbuffered $f] [eof $f] sl@0: lappend x [gets $f line] $line sl@0: close $f sl@0: set x sl@0: } [list 15 "1234567890123\uff10\uff11" 18 0 1 -1 ""] sl@0: test io-7.4 {FilterInputBytes: recover from split up character} {stdio openpipe fileevent} { sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -encoding binary -buffering none sl@0: puts -nonewline $f "1234567890123\x82\x4f\x82\x50\x82" sl@0: fconfigure $f -encoding shiftjis -blocking 0 sl@0: fileevent $f read [namespace code "ready $f"] sl@0: variable x {} sl@0: proc ready {f} { sl@0: variable x sl@0: lappend x [gets $f line] $line [fblocked $f] sl@0: } sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -encoding binary -blocking 1 sl@0: puts $f "\x51\x82\x52" sl@0: fconfigure $f -encoding shiftjis sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: set x sl@0: } [list -1 "" 1 17 "1234567890123\uff10\uff11\uff12\uff13" 0] sl@0: sl@0: test io-8.1 {PeekAhead: only go to device if no more cached data} {testchannel} { sl@0: # (bufPtr->nextPtr == NULL) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding ascii -translation lf sl@0: puts -nonewline $f "123456789012345\r\n2345678" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding ascii -translation auto -buffersize 16 sl@0: # here sl@0: gets $f sl@0: set x [testchannel inputbuffered $f] sl@0: close $f sl@0: set x sl@0: } "7" sl@0: test io-8.2 {PeekAhead: only go to device if no more cached data} {stdio testchannel openpipe fileevent} { sl@0: # not (bufPtr->nextPtr == NULL) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation lf -encoding ascii -buffering none sl@0: puts -nonewline $f "123456789012345\r\nbcdefghijklmnopqrstuvwxyz" sl@0: variable x {} sl@0: fileevent $f read [namespace code "ready $f"] sl@0: proc ready {f} { sl@0: variable x sl@0: lappend x [gets $f line] $line [testchannel inputbuffered $f] sl@0: } sl@0: fconfigure $f -encoding unicode -buffersize 16 -blocking 0 sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -translation auto -encoding ascii -blocking 1 sl@0: # here sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: set x sl@0: } [list -1 "" 42 15 "123456789012345" 25] sl@0: test io-8.3 {PeekAhead: no cached data available} {stdio testchannel openpipe fileevent} { sl@0: # (bytesLeft == 0) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto binary} sl@0: puts -nonewline $f "abcdefghijklmno\r" sl@0: flush $f sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: close $f sl@0: set x sl@0: } [list 15 "abcdefghijklmno" 1] sl@0: set a "123456789012345678901234567890" sl@0: append a "123456789012345678901234567890" sl@0: append a "1234567890123456789012345678901" sl@0: test io-8.4 {PeekAhead: cached data available in this buffer} { sl@0: # not (bytesLeft == 0) sl@0: sl@0: set f [open $path(test1) w+] sl@0: fconfigure $f -translation binary sl@0: puts $f "${a}\r\nabcdef" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding binary -translation auto sl@0: sl@0: # "${a}\r" was converted in one operation (because ENCODING_LINESIZE sl@0: # is 30). To check if "\n" follows, calls PeekAhead and determines sl@0: # that cached data is available in buffer w/o having to call driver. sl@0: sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } $a sl@0: unset a sl@0: test io-8.5 {PeekAhead: don't peek if last read was short} {stdio testchannel openpipe fileevent} { sl@0: # (bufPtr->nextAdded < bufPtr->length) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto binary} sl@0: puts -nonewline $f "abcdefghijklmno\r" sl@0: flush $f sl@0: # here sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: close $f sl@0: set x sl@0: } {15 abcdefghijklmno 1} sl@0: test io-8.6 {PeekAhead: change to non-blocking mode} {stdio testchannel openpipe fileevent} { sl@0: # ((chanPtr->flags & CHANNEL_NONBLOCKING) == 0) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto binary} -buffersize 16 sl@0: puts -nonewline $f "abcdefghijklmno\r" sl@0: flush $f sl@0: # here sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: close $f sl@0: set x sl@0: } {15 abcdefghijklmno 1} sl@0: test io-8.7 {PeekAhead: cleanup} {stdio testchannel openpipe fileevent} { sl@0: # Make sure bytes are removed from buffer. sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -translation {auto binary} -buffering none sl@0: puts -nonewline $f "abcdefghijklmno\r" sl@0: # here sl@0: set x [list [gets $f line] $line [testchannel queuedcr $f]] sl@0: puts -nonewline $f "\x1a" sl@0: lappend x [gets $f line] $line sl@0: close $f sl@0: set x sl@0: } {15 abcdefghijklmno 1 -1 {}} sl@0: sl@0: sl@0: test io-9.1 {CommonGetsCleanup} { sl@0: } {} sl@0: sl@0: test io-10.1 {Tcl_ReadChars: CheckChannelErrors} { sl@0: # no test, need to cause an async error. sl@0: } {} sl@0: test io-10.2 {Tcl_ReadChars: loop until enough copied} { sl@0: # one time sl@0: # for (copied = 0; (unsigned) toRead > 0; ) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnop sl@0: close $f sl@0: sl@0: set f [open $path(test1)] sl@0: set x [read $f 5] sl@0: close $f sl@0: set x sl@0: } {abcde} sl@0: test io-10.3 {Tcl_ReadChars: loop until enough copied} { sl@0: # multiple times sl@0: # for (copied = 0; (unsigned) toRead > 0; ) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnopqrstuvwxyz sl@0: close $f sl@0: sl@0: set f [open $path(test1)] sl@0: fconfigure $f -buffersize 16 sl@0: # here sl@0: set x [read $f 19] sl@0: close $f sl@0: set x sl@0: } {abcdefghijklmnopqrs} sl@0: test io-10.4 {Tcl_ReadChars: no more in channel buffer} { sl@0: # (copiedNow < 0) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: sl@0: set f [open $path(test1)] sl@0: # here sl@0: set x [read $f 1000] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: test io-10.5 {Tcl_ReadChars: stop on EOF} { sl@0: # (chanPtr->flags & CHANNEL_EOF) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: sl@0: set f [open $path(test1)] sl@0: # here sl@0: set x [read $f 1000] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: sl@0: test io-11.1 {ReadBytes: want to read a lot} { sl@0: # ((unsigned) toRead > (unsigned) srcLen) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding binary sl@0: # here sl@0: set x [read $f 1000] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: test io-11.2 {ReadBytes: want to read all} { sl@0: # ((unsigned) toRead > (unsigned) srcLen) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -encoding binary sl@0: # here sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: test io-11.3 {ReadBytes: allocate more space} { sl@0: # (toRead > length - offset - 1) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijklmnopqrstuvwxyz sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -buffersize 16 -encoding binary sl@0: # here sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } {abcdefghijklmnopqrstuvwxyz} sl@0: test io-11.4 {ReadBytes: EOF char found} { sl@0: # (TranslateInputEOL() != 0) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnopqrstuvwxyz sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -eofchar m -encoding binary sl@0: # here sl@0: set x [list [read $f] [eof $f] [read $f] [eof $f]] sl@0: close $f sl@0: set x sl@0: } [list "abcdefghijkl" 1 "" 1] sl@0: sl@0: test io-12.1 {ReadChars: want to read a lot} { sl@0: # ((unsigned) toRead > (unsigned) srcLen) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: set f [open $path(test1)] sl@0: # here sl@0: set x [read $f 1000] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: test io-12.2 {ReadChars: want to read all} { sl@0: # ((unsigned) toRead > (unsigned) srcLen) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijkl sl@0: close $f sl@0: set f [open $path(test1)] sl@0: # here sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } {abcdefghijkl} sl@0: test io-12.3 {ReadChars: allocate more space} { sl@0: # (toRead > length - offset - 1) sl@0: sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f abcdefghijklmnopqrstuvwxyz sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -buffersize 16 sl@0: # here sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } {abcdefghijklmnopqrstuvwxyz} sl@0: test io-12.4 {ReadChars: split-up char} {stdio testchannel openpipe fileevent} { sl@0: # (srcRead == 0) sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -encoding binary -buffering none -buffersize 16 sl@0: puts -nonewline $f "123456789012345\x96" sl@0: fconfigure $f -encoding shiftjis -blocking 0 sl@0: sl@0: fileevent $f read [namespace code "ready $f"] sl@0: proc ready {f} { sl@0: variable x sl@0: lappend x [read $f] [testchannel inputbuffered $f] sl@0: } sl@0: variable x {} sl@0: sl@0: fconfigure $f -encoding shiftjis sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -encoding binary -blocking 1 sl@0: puts -nonewline $f "\x7b" sl@0: after 500 ;# Give the cat process time to catch up sl@0: fconfigure $f -encoding shiftjis -blocking 0 sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: set x sl@0: } [list "123456789012345" 1 "\u672c" 0] sl@0: test io-12.5 {ReadChars: fileevents on partial characters} {stdio openpipe fileevent} { sl@0: set path(test1) [makeFile { sl@0: fconfigure stdout -encoding binary -buffering none sl@0: gets stdin; puts -nonewline "\xe7" sl@0: gets stdin; puts -nonewline "\x89" sl@0: gets stdin; puts -nonewline "\xa6" sl@0: } test1] sl@0: set f [open "|[list [interpreter] $path(test1)]" r+] sl@0: fileevent $f readable [namespace code { sl@0: lappend x [read $f] sl@0: if {[eof $f]} { sl@0: lappend x eof sl@0: } sl@0: }] sl@0: puts $f "go1" sl@0: flush $f sl@0: fconfigure $f -blocking 0 -encoding utf-8 sl@0: variable x {} sl@0: vwait [namespace which -variable x] sl@0: after 500 [namespace code { lappend x timeout }] sl@0: vwait [namespace which -variable x] sl@0: puts $f "go2" sl@0: flush $f sl@0: vwait [namespace which -variable x] sl@0: after 500 [namespace code { lappend x timeout }] sl@0: vwait [namespace which -variable x] sl@0: puts $f "go3" sl@0: flush $f sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: lappend x [catch {close $f} msg] $msg sl@0: set x sl@0: } "{} timeout {} timeout \u7266 {} eof 0 {}" sl@0: sl@0: test io-13.1 {TranslateInputEOL: cr mode} {} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\rdef\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation cr sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef\n" sl@0: test io-13.2 {TranslateInputEOL: crlf mode} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r\ndef\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef\n" sl@0: test io-13.3 {TranslateInputEOL: crlf mode: naked cr} { sl@0: # (src >= srcMax) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r\ndef\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef\r" sl@0: test io-13.4 {TranslateInputEOL: crlf mode: cr followed by not \n} { sl@0: # (src >= srcMax) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r\ndef\rfgh" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef\rfgh" sl@0: test io-13.5 {TranslateInputEOL: crlf mode: naked lf} { sl@0: # (src >= srcMax) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r\ndef\nfgh" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef\nfgh" sl@0: test io-13.6 {TranslateInputEOL: auto mode: saw cr in last segment} {stdio testchannel openpipe fileevent} { sl@0: # (chanPtr->flags & INPUT_SAW_CR) sl@0: # This test may fail on slower machines. sl@0: sl@0: set f [open "|[list [interpreter] $path(cat)]" w+] sl@0: fconfigure $f -blocking 0 -buffering none -translation {auto lf} sl@0: sl@0: fileevent $f read [namespace code "ready $f"] sl@0: proc ready {f} { sl@0: variable x sl@0: lappend x [read $f] [testchannel queuedcr $f] sl@0: } sl@0: variable x {} sl@0: variable y {} sl@0: sl@0: puts -nonewline $f "abcdefghj\r" sl@0: after 500 [namespace code {set y ok}] sl@0: vwait [namespace which -variable y] sl@0: sl@0: puts -nonewline $f "\n01234" sl@0: after 500 [namespace code {set y ok}] sl@0: vwait [namespace which -variable y] sl@0: sl@0: close $f sl@0: set x sl@0: } [list "abcdefghj\n" 1 "01234" 0] sl@0: test io-13.7 {TranslateInputEOL: auto mode: naked \r} {testchannel openpipe} { sl@0: # (src >= srcMax) sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [list [read $f] [testchannel queuedcr $f]] sl@0: close $f sl@0: set x sl@0: } [list "abcd\n" 1] sl@0: test io-13.8 {TranslateInputEOL: auto mode: \r\n} { sl@0: # (*src == '\n') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\r\ndef" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef" sl@0: test io-13.9 {TranslateInputEOL: auto mode: \r followed by not \n} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\rdef" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef" sl@0: test io-13.10 {TranslateInputEOL: auto mode: \n} { sl@0: # not (*src == '\r') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\ndef" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\ndef" sl@0: test io-13.11 {TranslateInputEOL: EOF char} { sl@0: # (*chanPtr->inEofChar != '\0') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "abcd\ndefgh" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto -eofchar e sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "abcd\nd" sl@0: test io-13.12 {TranslateInputEOL: find EOF char in src} { sl@0: # (*chanPtr->inEofChar != '\0') sl@0: sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "\r\n\r\n\r\nab\r\n\r\ndef\r\n\r\n\r\n" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: fconfigure $f -translation auto -eofchar e sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "\n\n\nab\n\nd" sl@0: sl@0: # Test standard handle management. The functions tested are sl@0: # Tcl_SetStdChannel and Tcl_GetStdChannel. Incidentally we are sl@0: # also testing channel table management. sl@0: sl@0: if {[info commands testchannel] != ""} { sl@0: if {$tcl_platform(platform) == "macintosh"} { sl@0: set consoleFileNames [list console0 console1 console2] sl@0: } else { sl@0: set consoleFileNames [lsort [testchannel open]] sl@0: } sl@0: } else { sl@0: # just to avoid an error sl@0: set consoleFileNames [list] sl@0: } sl@0: sl@0: test io-14.1 {Tcl_SetStdChannel and Tcl_GetStdChannel} {testchannel} { sl@0: set l "" sl@0: lappend l [fconfigure stdin -buffering] sl@0: lappend l [fconfigure stdout -buffering] sl@0: lappend l [fconfigure stderr -buffering] sl@0: lappend l [lsort [testchannel open]] sl@0: set l sl@0: } [list line line none $consoleFileNames] sl@0: test io-14.2 {Tcl_SetStdChannel and Tcl_GetStdChannel} { sl@0: interp create x sl@0: set l "" sl@0: lappend l [x eval {fconfigure stdin -buffering}] sl@0: lappend l [x eval {fconfigure stdout -buffering}] sl@0: lappend l [x eval {fconfigure stderr -buffering}] sl@0: interp delete x sl@0: set l sl@0: } {line line none} sl@0: sl@0: set path(test3) [makeFile {} test3] sl@0: sl@0: test io-14.3 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec openpipe} { sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f { sl@0: close stdin sl@0: close stdout sl@0: close stderr sl@0: set f [} sl@0: puts $f [list open $path(test1) r]] sl@0: puts $f "set f2 \[[list open $path(test2) w]]" sl@0: puts $f "set f3 \[[list open $path(test3) w]]" sl@0: puts $f { puts stdout [gets stdin] sl@0: puts stdout out sl@0: puts stderr err sl@0: close $f sl@0: close $f2 sl@0: close $f3 sl@0: } sl@0: close $f sl@0: set result [exec [interpreter] $path(test1)] sl@0: set f [open $path(test2) r] sl@0: set f2 [open $path(test3) r] sl@0: lappend result [read $f] [read $f2] sl@0: close $f sl@0: close $f2 sl@0: set result sl@0: } {{ sl@0: out sl@0: } {err sl@0: }} sl@0: # This test relies on the fact that the smallest available fd is used first. sl@0: test io-14.4 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec unixOnly} { sl@0: set f [open $path(test1) w] sl@0: puts -nonewline $f { close stdin sl@0: close stdout sl@0: close stderr sl@0: set f [} sl@0: puts $f [list open $path(test1) r]] sl@0: puts $f "set f2 \[[list open $path(test2) w]]" sl@0: puts $f "set f3 \[[list open $path(test3) w]]" sl@0: puts $f { puts stdout [gets stdin] sl@0: puts stdout $f2 sl@0: puts stderr $f3 sl@0: close $f sl@0: close $f2 sl@0: close $f3 sl@0: } sl@0: close $f sl@0: set result [exec [interpreter] $path(test1)] sl@0: set f [open $path(test2) r] sl@0: set f2 [open $path(test3) r] sl@0: lappend result [read $f] [read $f2] sl@0: close $f sl@0: close $f2 sl@0: set result sl@0: } {{ close stdin sl@0: file1 sl@0: } {file2 sl@0: }} sl@0: catch {interp delete z} sl@0: test io-14.5 {Tcl_GetChannel: stdio name translation} { sl@0: interp create z sl@0: eof stdin sl@0: catch {z eval flush stdin} msg1 sl@0: catch {z eval close stdin} msg2 sl@0: catch {z eval flush stdin} msg3 sl@0: set result [list $msg1 $msg2 $msg3] sl@0: interp delete z sl@0: set result sl@0: } {{channel "stdin" wasn't opened for writing} {} {can not find channel named "stdin"}} sl@0: test io-14.6 {Tcl_GetChannel: stdio name translation} { sl@0: interp create z sl@0: eof stdout sl@0: catch {z eval flush stdout} msg1 sl@0: catch {z eval close stdout} msg2 sl@0: catch {z eval flush stdout} msg3 sl@0: set result [list $msg1 $msg2 $msg3] sl@0: interp delete z sl@0: set result sl@0: } {{} {} {can not find channel named "stdout"}} sl@0: test io-14.7 {Tcl_GetChannel: stdio name translation} { sl@0: interp create z sl@0: eof stderr sl@0: catch {z eval flush stderr} msg1 sl@0: catch {z eval close stderr} msg2 sl@0: catch {z eval flush stderr} msg3 sl@0: set result [list $msg1 $msg2 $msg3] sl@0: interp delete z sl@0: set result sl@0: } {{} {} {can not find channel named "stderr"}} sl@0: sl@0: set path(script) [makeFile {} script] sl@0: sl@0: test io-14.8 {reuse of stdio special channels} {stdio openpipe} { sl@0: file delete $path(script) sl@0: file delete $path(test1) sl@0: set f [open $path(script) w] sl@0: puts -nonewline $f { sl@0: close stderr sl@0: set f [} sl@0: puts $f [list open $path(test1) w]] sl@0: puts -nonewline $f { sl@0: puts stderr hello sl@0: close $f sl@0: set f [} sl@0: puts $f [list open $path(test1) r]] sl@0: puts $f { sl@0: puts [gets $f] sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(script)]" r] sl@0: set c [gets $f] sl@0: close $f sl@0: set c sl@0: } hello sl@0: sl@0: test io-14.9 {reuse of stdio special channels} {stdio openpipe fileevent} { sl@0: file delete $path(script) sl@0: file delete $path(test1) sl@0: set f [open $path(script) w] sl@0: puts $f { sl@0: array set path [lindex $argv 0] sl@0: set f [open $path(test1) w] sl@0: puts $f hello sl@0: close $f sl@0: close stderr sl@0: set f [open "|[list [info nameofexecutable] $path(cat) $path(test1)]" r] sl@0: puts [gets $f] sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(script) [array get path]]" r] sl@0: set c [gets $f] sl@0: close $f sl@0: # Added delay to give Windows time to stop the spawned process and clean sl@0: # up its grip on the file test1. Added delete as proper test cleanup. sl@0: # The failing tests were 18.1 and 18.2 as first re-users of file "test1". sl@0: after 10000 sl@0: file delete $path(script) sl@0: file delete $path(test1) sl@0: set c sl@0: } hello sl@0: sl@0: test io-15.1 {Tcl_CreateCloseHandler} { sl@0: } {} sl@0: sl@0: test io-16.1 {Tcl_DeleteCloseHandler} { sl@0: } {} sl@0: sl@0: # Test channel table management. The functions tested are sl@0: # GetChannelTable, DeleteChannelTable, Tcl_RegisterChannel, sl@0: # Tcl_UnregisterChannel, Tcl_GetChannel and Tcl_CreateChannel. sl@0: # sl@0: # These functions use "eof stdin" to ensure that the standard sl@0: # channels are added to the channel table of the interpreter. sl@0: sl@0: test io-17.1 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} { sl@0: set l1 [testchannel refcount stdin] sl@0: eof stdin sl@0: interp create x sl@0: set l "" sl@0: lappend l [expr [testchannel refcount stdin] - $l1] sl@0: x eval {eof stdin} sl@0: lappend l [expr [testchannel refcount stdin] - $l1] sl@0: interp delete x sl@0: lappend l [expr [testchannel refcount stdin] - $l1] sl@0: set l sl@0: } {0 1 0} sl@0: test io-17.2 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} { sl@0: set l1 [testchannel refcount stdout] sl@0: eof stdin sl@0: interp create x sl@0: set l "" sl@0: lappend l [expr [testchannel refcount stdout] - $l1] sl@0: x eval {eof stdout} sl@0: lappend l [expr [testchannel refcount stdout] - $l1] sl@0: interp delete x sl@0: lappend l [expr [testchannel refcount stdout] - $l1] sl@0: set l sl@0: } {0 1 0} sl@0: test io-17.3 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} { sl@0: set l1 [testchannel refcount stderr] sl@0: eof stdin sl@0: interp create x sl@0: set l "" sl@0: lappend l [expr [testchannel refcount stderr] - $l1] sl@0: x eval {eof stderr} sl@0: lappend l [expr [testchannel refcount stderr] - $l1] sl@0: interp delete x sl@0: lappend l [expr [testchannel refcount stderr] - $l1] sl@0: set l sl@0: } {0 1 0} sl@0: sl@0: test io-18.1 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} { sl@0: file delete $path(test1) sl@0: set l "" sl@0: set f [open $path(test1) w] sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: close $f sl@0: if {[catch {lindex [testchannel info $f] 15} msg]} { sl@0: lappend l $msg sl@0: } else { sl@0: lappend l "very broken: $f found after being closed" sl@0: } sl@0: string compare [string tolower $l] \ sl@0: [list 1 [format "can not find channel named \"%s\"" $f]] sl@0: } 0 sl@0: test io-18.2 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} { sl@0: file delete $path(test1) sl@0: set l "" sl@0: set f [open $path(test1) w] sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: interp create x sl@0: interp share "" $f x sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: x eval close $f sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: interp delete x sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: close $f sl@0: if {[catch {lindex [testchannel info $f] 15} msg]} { sl@0: lappend l $msg sl@0: } else { sl@0: lappend l "very broken: $f found after being closed" sl@0: } sl@0: string compare [string tolower $l] \ sl@0: [list 1 2 1 1 [format "can not find channel named \"%s\"" $f]] sl@0: } 0 sl@0: test io-18.3 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} { sl@0: file delete $path(test1) sl@0: set l "" sl@0: set f [open $path(test1) w] sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: interp create x sl@0: interp share "" $f x sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: interp delete x sl@0: lappend l [lindex [testchannel info $f] 15] sl@0: close $f sl@0: if {[catch {lindex [testchannel info $f] 15} msg]} { sl@0: lappend l $msg sl@0: } else { sl@0: lappend l "very broken: $f found after being closed" sl@0: } sl@0: string compare [string tolower $l] \ sl@0: [list 1 2 1 [format "can not find channel named \"%s\"" $f]] sl@0: } 0 sl@0: sl@0: test io-19.1 {Tcl_GetChannel->Tcl_GetStdChannel, standard handles} { sl@0: eof stdin sl@0: } 0 sl@0: test io-19.2 {testing Tcl_GetChannel, user opened handle} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: set x [eof $f] sl@0: close $f sl@0: set x sl@0: } 0 sl@0: test io-19.3 {Tcl_GetChannel, channel not found} { sl@0: list [catch {eof file34} msg] $msg sl@0: } {1 {can not find channel named "file34"}} sl@0: test io-19.4 {Tcl_CreateChannel, insertion into channel table} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: set l "" sl@0: lappend l [eof $f] sl@0: close $f sl@0: if {[catch {lindex [testchannel info $f] 15} msg]} { sl@0: lappend l $msg sl@0: } else { sl@0: lappend l "very broken: $f found after being closed" sl@0: } sl@0: string compare [string tolower $l] \ sl@0: [list 0 [format "can not find channel named \"%s\"" $f]] sl@0: } 0 sl@0: sl@0: test io-20.1 {Tcl_CreateChannel: initial settings} { sl@0: set a [open $path(test2) w] sl@0: set old [encoding system] sl@0: encoding system ascii sl@0: set f [open $path(test1) w] sl@0: set x [fconfigure $f -encoding] sl@0: close $f sl@0: encoding system $old sl@0: close $a sl@0: set x sl@0: } {ascii} sl@0: test io-20.2 {Tcl_CreateChannel: initial settings} {pcOnly} { sl@0: set f [open $path(test1) w+] sl@0: set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]] sl@0: close $f sl@0: set x sl@0: } [list [list \x1a ""] {auto crlf}] sl@0: test io-20.3 {Tcl_CreateChannel: initial settings} {unixOnly} { sl@0: set f [open $path(test1) w+] sl@0: set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]] sl@0: close $f sl@0: set x sl@0: } {{{} {}} {auto lf}} sl@0: test io-20.4 {Tcl_CreateChannel: initial settings} {macOnly} { sl@0: set f [open $path(test1) w+] sl@0: set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]] sl@0: close $f sl@0: set x sl@0: } {{{} {}} {auto cr}} sl@0: sl@0: set path(stdout) [makeFile {} stdout] sl@0: sl@0: test io-20.5 {Tcl_CreateChannel: install channel in empty slot} {stdio openpipe} { sl@0: set f [open $path(script) w] sl@0: puts -nonewline $f { sl@0: close stdout sl@0: set f1 [} sl@0: puts $f [list open $path(stdout) w]] sl@0: puts $f { sl@0: fconfigure $f1 -buffersize 777 sl@0: puts stderr [fconfigure stdout -buffersize] sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(script)]"] sl@0: catch {close $f} msg sl@0: set msg sl@0: } {777} sl@0: sl@0: test io-21.1 {CloseChannelsOnExit} { sl@0: } {} sl@0: sl@0: # Test management of attributes associated with a channel, such as sl@0: # its default translation, its name and type, etc. The functions sl@0: # tested in this group are Tcl_GetChannelName, sl@0: # Tcl_GetChannelType and Tcl_GetChannelFile. Tcl_GetChannelInstanceData sl@0: # not tested because files do not use the instance data. sl@0: sl@0: test io-22.1 {Tcl_GetChannelMode} { sl@0: # Not used anywhere in Tcl. sl@0: } {} sl@0: sl@0: test io-23.1 {Tcl_GetChannelName} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: set n [testchannel name $f] sl@0: close $f sl@0: string compare $n $f sl@0: } 0 sl@0: sl@0: test io-24.1 {Tcl_GetChannelType} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: set t [testchannel type $f] sl@0: close $f sl@0: string compare $t file sl@0: } 0 sl@0: sl@0: test io-25.1 {Tcl_GetChannelHandle, input} {testchannel} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f "1234567890\n098765432" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: gets $f sl@0: set l "" sl@0: lappend l [testchannel inputbuffered $f] sl@0: lappend l [tell $f] sl@0: close $f sl@0: set l sl@0: } {10 11} sl@0: test io-25.2 {Tcl_GetChannelHandle, output} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [tell $f] sl@0: flush $f sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [tell $f] sl@0: close $f sl@0: file delete $path(test1) sl@0: set l sl@0: } {6 6 0 6} sl@0: sl@0: test io-26.1 {Tcl_GetChannelInstanceData} {stdio openpipe} { sl@0: # "pid" command uses Tcl_GetChannelInstanceData sl@0: # Don't care what pid is (but must be a number), just want to exercise it. sl@0: sl@0: set f [open "|[list [interpreter] << exit]"] sl@0: expr [pid $f] sl@0: close $f sl@0: } {} sl@0: sl@0: # Test flushing. The functions tested here are FlushChannel. sl@0: sl@0: test io-27.1 {FlushChannel, no output buffered} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: flush $f sl@0: set s [file size $path(test1)] sl@0: close $f sl@0: set s sl@0: } 0 sl@0: test io-27.2 {FlushChannel, some output buffered} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set l "" sl@0: puts $f hello sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: lappend l [file size $path(test1)] sl@0: set l sl@0: } {0 6 6} sl@0: test io-27.3 {FlushChannel, implicit flush on close} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set l "" sl@0: puts $f hello sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: lappend l [file size $path(test1)] sl@0: set l sl@0: } {0 6} sl@0: test io-27.4 {FlushChannel, implicit flush when buffer fills} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: fconfigure $f -buffersize 60 sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: for {set i 0} {$i < 12} {incr i} { sl@0: puts $f hello sl@0: } sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {0 60 72} sl@0: test io-27.5 {FlushChannel, implicit flush when buffer fills and on close} \ sl@0: {unixOrPc} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffersize 60 -eofchar {} sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: for {set i 0} {$i < 12} {incr i} { sl@0: puts $f hello sl@0: } sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: lappend l [file size $path(test1)] sl@0: set l sl@0: } {0 60 72} sl@0: sl@0: set path(pipe) [makeFile {} pipe] sl@0: set path(output) [makeFile {} output] sl@0: sl@0: test io-27.6 {FlushChannel, async flushing, async close} \ sl@0: {stdio asyncPipeClose openpipe} { sl@0: file delete $path(pipe) sl@0: file delete $path(output) sl@0: set f [open $path(pipe) w] sl@0: puts $f "set f \[[list open $path(output) w]]" sl@0: puts $f { sl@0: fconfigure $f -translation lf -buffering none -eofchar {} sl@0: while {![eof stdin]} { sl@0: after 20 sl@0: puts -nonewline $f [read stdin 1024] sl@0: } sl@0: close $f sl@0: } sl@0: close $f sl@0: set x 01234567890123456789012345678901 sl@0: for {set i 0} {$i < 11} {incr i} { sl@0: set x "$x$x" sl@0: } sl@0: set f [open $path(output) w] sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(pipe)]" w] sl@0: fconfigure $f -blocking off sl@0: puts -nonewline $f $x sl@0: close $f sl@0: set counter 0 sl@0: while {([file size $path(output)] < 65536) && ($counter < 1000)} { sl@0: incr counter sl@0: after 20 sl@0: update sl@0: } sl@0: if {$counter == 1000} { sl@0: set result "file size only [file size $path(output)]" sl@0: } else { sl@0: set result ok sl@0: } sl@0: } ok sl@0: sl@0: # Tests closing a channel. The functions tested are CloseChannel and Tcl_Close. sl@0: sl@0: test io-28.1 {CloseChannel called when all references are dropped} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: interp create x sl@0: interp share "" $f x sl@0: set l "" sl@0: lappend l [testchannel refcount $f] sl@0: x eval close $f sl@0: interp delete x sl@0: lappend l [testchannel refcount $f] sl@0: close $f sl@0: set l sl@0: } {2 1} sl@0: test io-28.2 {CloseChannel called when all references are dropped} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: interp create x sl@0: interp share "" $f x sl@0: puts -nonewline $f abc sl@0: close $f sl@0: x eval puts $f def sl@0: x eval close $f sl@0: interp delete x sl@0: set f [open $path(test1) r] sl@0: set l [gets $f] sl@0: close $f sl@0: set l sl@0: } abcdef sl@0: test io-28.3 {CloseChannel, not called before output queue is empty} \ sl@0: {stdio asyncPipeClose nonPortable openpipe} { sl@0: file delete $path(pipe) sl@0: file delete $path(output) sl@0: set f [open $path(pipe) w] sl@0: puts $f { sl@0: sl@0: # Need to not have eof char appended on close, because the other sl@0: # side of the pipe already closed, so that writing would cause an sl@0: # error "invalid file". sl@0: sl@0: fconfigure stdout -eofchar {} sl@0: fconfigure stderr -eofchar {} sl@0: sl@0: set f [open $path(output) w] sl@0: fconfigure $f -translation lf -buffering none sl@0: for {set x 0} {$x < 20} {incr x} { sl@0: after 20 sl@0: puts -nonewline $f [read stdin 1024] sl@0: } sl@0: close $f sl@0: } sl@0: close $f sl@0: set x 01234567890123456789012345678901 sl@0: for {set i 0} {$i < 11} {incr i} { sl@0: set x "$x$x" sl@0: } sl@0: set f [open $path(output) w] sl@0: close $f sl@0: set f [open "|[list [interpreter] pipe]" r+] sl@0: fconfigure $f -blocking off -eofchar {} sl@0: sl@0: puts -nonewline $f $x sl@0: close $f sl@0: set counter 0 sl@0: while {([file size $path(output)] < 20480) && ($counter < 1000)} { sl@0: incr counter sl@0: after 20 sl@0: update sl@0: } sl@0: if {$counter == 1000} { sl@0: set result probably_broken sl@0: } else { sl@0: set result ok sl@0: } sl@0: } ok sl@0: test io-28.4 {Tcl_Close} {testchannel} { sl@0: file delete $path(test1) sl@0: set l "" sl@0: lappend l [lsort [testchannel open]] sl@0: set f [open $path(test1) w] sl@0: lappend l [lsort [testchannel open]] sl@0: close $f sl@0: lappend l [lsort [testchannel open]] sl@0: set x [list $consoleFileNames \ sl@0: [lsort [eval list $consoleFileNames $f]] \ sl@0: $consoleFileNames] sl@0: string compare $l $x sl@0: } 0 sl@0: test io-28.5 {Tcl_Close vs standard handles} {stdio unixOnly testchannel openpipe} { sl@0: file delete $path(script) sl@0: set f [open $path(script) w] sl@0: puts $f { sl@0: close stdin sl@0: puts [testchannel open] sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(script)]" r] sl@0: set l [gets $f] sl@0: close $f sl@0: set l sl@0: } {file1 file2} sl@0: sl@0: test io-29.1 {Tcl_WriteChars, channel not writable} { sl@0: list [catch {puts stdin hello} msg] $msg sl@0: } {1 {channel "stdin" wasn't opened for writing}} sl@0: test io-29.2 {Tcl_WriteChars, empty string} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f "" sl@0: close $f sl@0: file size $path(test1) sl@0: } 0 sl@0: test io-29.3 {Tcl_WriteChars, nonempty string} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f hello sl@0: close $f sl@0: file size $path(test1) sl@0: } 5 sl@0: test io-29.4 {Tcl_WriteChars, buffering in full buffering mode} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffering full -eofchar {} sl@0: puts $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {6 0 0 6} sl@0: test io-29.5 {Tcl_WriteChars, buffering in line buffering mode} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffering line -eofchar {} sl@0: puts -nonewline $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: puts $f hello sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {5 0 0 11} sl@0: test io-29.6 {Tcl_WriteChars, buffering in no buffering mode} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffering none -eofchar {} sl@0: puts -nonewline $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: puts $f hello sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {0 5 0 11} sl@0: sl@0: test io-29.7 {Tcl_Flush, full buffering} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffering full -eofchar {} sl@0: puts -nonewline $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: puts $f hello sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {5 0 11 0 0 11} sl@0: test io-29.8 {Tcl_Flush, full buffering} {testchannel} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -buffering line sl@0: puts -nonewline $f hello sl@0: set l "" sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: puts $f hello sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: flush $f sl@0: lappend l [testchannel outputbuffered $f] sl@0: lappend l [file size $path(test1)] sl@0: close $f sl@0: set l sl@0: } {5 0 0 5 0 11 0 11} sl@0: test io-29.9 {Tcl_Flush, channel not writable} { sl@0: list [catch {flush stdin} msg] $msg sl@0: } {1 {channel "stdin" wasn't opened for writing}} sl@0: test io-29.10 {Tcl_WriteChars, looping and buffering} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: set f2 [open $path(longfile) r] sl@0: for {set x 0} {$x < 10} {incr x} { sl@0: puts $f1 [gets $f2] sl@0: } sl@0: close $f2 sl@0: close $f1 sl@0: file size $path(test1) sl@0: } 387 sl@0: test io-29.11 {Tcl_WriteChars, no newline, implicit flush} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -eofchar {} sl@0: set f2 [open $path(longfile) r] sl@0: for {set x 0} {$x < 10} {incr x} { sl@0: puts -nonewline $f1 [gets $f2] sl@0: } sl@0: close $f1 sl@0: close $f2 sl@0: file size $path(test1) sl@0: } 377 sl@0: test io-29.12 {Tcl_WriteChars on a pipe} {stdio openpipe} { sl@0: file delete $path(test1) sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 "set f1 \[[list open $path(longfile) r]]" sl@0: puts $f1 { sl@0: for {set x 0} {$x < 10} {incr x} { sl@0: puts [gets $f1] sl@0: } sl@0: } sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r] sl@0: set f2 [open $path(longfile) r] sl@0: set y ok sl@0: for {set x 0} {$x < 10} {incr x} { sl@0: set l1 [gets $f1] sl@0: set l2 [gets $f2] sl@0: if {"$l1" != "$l2"} { sl@0: set y broken sl@0: } sl@0: } sl@0: close $f1 sl@0: close $f2 sl@0: set y sl@0: } ok sl@0: test io-29.13 {Tcl_WriteChars to a pipe, line buffered} {stdio openpipe} { sl@0: file delete $path(test1) sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: puts [gets stdin] sl@0: puts [gets stdin] sl@0: } sl@0: close $f1 sl@0: set y ok sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: fconfigure $f1 -buffering line sl@0: set f2 [open $path(longfile) r] sl@0: set line [gets $f2] sl@0: puts $f1 $line sl@0: set backline [gets $f1] sl@0: if {"$line" != "$backline"} { sl@0: set y broken sl@0: } sl@0: set line [gets $f2] sl@0: puts $f1 $line sl@0: set backline [gets $f1] sl@0: if {"$line" != "$backline"} { sl@0: set y broken sl@0: } sl@0: close $f1 sl@0: close $f2 sl@0: set y sl@0: } ok sl@0: test io-29.14 {Tcl_WriteChars, buffering and implicit flush at close} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts -nonewline $f "Text1" sl@0: puts -nonewline $f " Text 2" sl@0: puts $f " Text 3" sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } {Text1 Text 2 Text 3} sl@0: test io-29.15 {Tcl_Flush, channel not open for writing} { sl@0: file delete $path(test1) sl@0: set fd [open $path(test1) w] sl@0: close $fd sl@0: set fd [open $path(test1) r] sl@0: set x [list [catch {flush $fd} msg] $msg] sl@0: close $fd sl@0: string compare $x \ sl@0: [list 1 "channel \"$fd\" wasn't opened for writing"] sl@0: } 0 sl@0: test io-29.16 {Tcl_Flush on pipe opened only for reading} {stdio openpipe} { sl@0: set fd [open "|[list [interpreter] cat longfile]" r] sl@0: set x [list [catch {flush $fd} msg] $msg] sl@0: catch {close $fd} sl@0: string compare $x \ sl@0: [list 1 "channel \"$fd\" wasn't opened for writing"] sl@0: } 0 sl@0: test io-29.17 {Tcl_WriteChars buffers, then Tcl_Flush flushes} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: flush $f1 sl@0: set x [file size $path(test1)] sl@0: close $f1 sl@0: set x sl@0: } 18 sl@0: test io-29.18 {Tcl_WriteChars and Tcl_Flush intermixed} { sl@0: file delete $path(test1) sl@0: set x "" sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [file size $path(test1)] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [file size $path(test1)] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [file size $path(test1)] sl@0: close $f1 sl@0: set x sl@0: } {18 24 30} sl@0: test io-29.19 {Explicit and implicit flushes} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: set x "" sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [file size $path(test1)] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [file size $path(test1)] sl@0: puts $f1 hello sl@0: close $f1 sl@0: lappend x [file size $path(test1)] sl@0: set x sl@0: } {18 24 30} sl@0: test io-29.20 {Implicit flush when buffer is full} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: set line "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" sl@0: for {set x 0} {$x < 100} {incr x} { sl@0: puts $f1 $line sl@0: } sl@0: set z "" sl@0: lappend z [file size $path(test1)] sl@0: for {set x 0} {$x < 100} {incr x} { sl@0: puts $f1 $line sl@0: } sl@0: lappend z [file size $path(test1)] sl@0: close $f1 sl@0: lappend z [file size $path(test1)] sl@0: set z sl@0: } {4096 12288 12600} sl@0: test io-29.21 {Tcl_Flush to pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {set x [read stdin 6]} sl@0: puts $f1 {set cnt [string length $x]} sl@0: puts $f1 {puts "read $cnt characters"} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: set x [gets $f1] sl@0: catch {close $f1} sl@0: set x sl@0: } "read 6 characters" sl@0: test io-29.22 {Tcl_Flush called at other end of pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: fconfigure stdout -buffering full sl@0: puts hello sl@0: puts hello sl@0: flush stdout sl@0: gets stdin sl@0: puts bye sl@0: flush stdout sl@0: } sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: set x "" sl@0: lappend x [gets $f1] sl@0: lappend x [gets $f1] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [gets $f1] sl@0: close $f1 sl@0: set x sl@0: } {hello hello bye} sl@0: test io-29.23 {Tcl_Flush and line buffering at end of pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: puts hello sl@0: puts hello sl@0: gets stdin sl@0: puts bye sl@0: } sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: set x "" sl@0: lappend x [gets $f1] sl@0: lappend x [gets $f1] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [gets $f1] sl@0: close $f1 sl@0: set x sl@0: } {hello hello bye} sl@0: test io-29.24 {Tcl_WriteChars and Tcl_Flush move end of file} { sl@0: set f [open $path(test3) w] sl@0: puts $f "Line 1" sl@0: puts $f "Line 2" sl@0: set f2 [open $path(test3)] sl@0: set x {} sl@0: lappend x [read -nonewline $f2] sl@0: close $f2 sl@0: flush $f sl@0: set f2 [open $path(test3)] sl@0: lappend x [read -nonewline $f2] sl@0: close $f2 sl@0: close $f sl@0: set x sl@0: } "{} {Line 1\nLine 2}" sl@0: test io-29.25 {Implicit flush with Tcl_Flush to command pipelines} {stdio openpipe fileevent} { sl@0: file delete $path(test3) sl@0: set f [open "|[list [interpreter] $path(cat) | [interpreter] $path(cat) > $path(test3)]" w] sl@0: puts $f "Line 1" sl@0: puts $f "Line 2" sl@0: close $f sl@0: after 100 sl@0: set f [open $path(test3) r] sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "Line 1\nLine 2\n" sl@0: test io-29.26 {Tcl_Flush, Tcl_Write on bidirectional pipelines} {stdio unixExecs openpipe} { sl@0: set f [open "|[list cat -u]" r+] sl@0: puts $f "Line1" sl@0: flush $f sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } {Line1} sl@0: test io-29.27 {Tcl_Flush on closed pipeline} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f [open $path(pipe) w] sl@0: puts $f {exit} sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(pipe)]" r+] sl@0: gets $f sl@0: puts $f output sl@0: after 50 sl@0: # sl@0: # The flush below will get a SIGPIPE. This is an expected part of sl@0: # test and indicates that the test operates correctly. If you run sl@0: # this test under a debugger, the signal will by intercepted unless sl@0: # you disable the debugger's signal interception. sl@0: # sl@0: if {[catch {flush $f} msg]} { sl@0: set x [list 1 $msg $errorCode] sl@0: catch {close $f} sl@0: } else { sl@0: if {[catch {close $f} msg]} { sl@0: set x [list 1 $msg $errorCode] sl@0: } else { sl@0: set x {this was supposed to fail and did not} sl@0: } sl@0: } sl@0: regsub {".*":} $x {"":} x sl@0: string tolower $x sl@0: } {1 {error flushing "": broken pipe} {posix epipe {broken pipe}}} sl@0: test io-29.28 {Tcl_WriteChars, lf mode} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f hello\nthere\nand\nhere sl@0: flush $f sl@0: set s [file size $path(test1)] sl@0: close $f sl@0: set s sl@0: } 21 sl@0: test io-29.29 {Tcl_WriteChars, cr mode} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: file size $path(test1) sl@0: } 21 sl@0: test io-29.30 {Tcl_WriteChars, crlf mode} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: file size $path(test1) sl@0: } 25 sl@0: test io-29.31 {Tcl_WriteChars, background flush} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: file delete $path(output) sl@0: set f [open $path(pipe) w] sl@0: puts $f "set f \[[list open $path(output) w]]" sl@0: puts $f {fconfigure $f -translation lf} sl@0: set x [list while {![eof stdin]}] sl@0: set x "$x {" sl@0: puts $f $x sl@0: puts $f { puts -nonewline $f [read stdin 4096]} sl@0: puts $f { flush $f} sl@0: puts $f "}" sl@0: puts $f {close $f} sl@0: close $f sl@0: set x 01234567890123456789012345678901 sl@0: for {set i 0} {$i < 11} {incr i} { sl@0: set x "$x$x" sl@0: } sl@0: set f [open $path(output) w] sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(pipe)]" r+] sl@0: fconfigure $f -blocking off sl@0: puts -nonewline $f $x sl@0: close $f sl@0: set counter 0 sl@0: while {([file size $path(output)] < 65536) && ($counter < 1000)} { sl@0: incr counter sl@0: after 5 sl@0: update sl@0: } sl@0: if {$counter == 1000} { sl@0: set result "file size only [file size $path(output)]" sl@0: } else { sl@0: set result ok sl@0: } sl@0: } ok sl@0: test io-29.32 {Tcl_WriteChars, background flush to slow reader} \ sl@0: {stdio asyncPipeClose openpipe} { sl@0: file delete $path(pipe) sl@0: file delete $path(output) sl@0: set f [open $path(pipe) w] sl@0: puts $f "set f \[[list open $path(output) w]]" sl@0: puts $f {fconfigure $f -translation lf} sl@0: set x [list while {![eof stdin]}] sl@0: set x "$x \{" sl@0: puts $f $x sl@0: puts $f { after 20} sl@0: puts $f { puts -nonewline $f [read stdin 1024]} sl@0: puts $f { flush $f} sl@0: puts $f "\}" sl@0: puts $f {close $f} sl@0: close $f sl@0: set x 01234567890123456789012345678901 sl@0: for {set i 0} {$i < 11} {incr i} { sl@0: set x "$x$x" sl@0: } sl@0: set f [open $path(output) w] sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(pipe)]" r+] sl@0: fconfigure $f -blocking off sl@0: puts -nonewline $f $x sl@0: close $f sl@0: set counter 0 sl@0: while {([file size $path(output)] < 65536) && ($counter < 1000)} { sl@0: incr counter sl@0: after 20 sl@0: update sl@0: } sl@0: if {$counter == 1000} { sl@0: set result "file size only [file size $path(output)]" sl@0: } else { sl@0: set result ok sl@0: } sl@0: } ok sl@0: test io-29.33 {Tcl_Flush, implicit flush on exit} {exec} { sl@0: set f [open $path(script) w] sl@0: puts $f "set f \[[list open $path(test1) w]]" sl@0: puts $f {fconfigure $f -translation lf sl@0: puts $f hello sl@0: puts $f bye sl@0: puts $f strange sl@0: } sl@0: close $f sl@0: exec [interpreter] $path(script) sl@0: set f [open $path(test1) r] sl@0: set r [read $f] sl@0: close $f sl@0: set r sl@0: } "hello\nbye\nstrange\n" sl@0: test io-29.34 {Tcl_Close, async flush on close, using sockets} {socket tempNotMac fileevent} { sl@0: variable c 0 sl@0: variable x running sl@0: set l abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz sl@0: proc writelots {s l} { sl@0: for {set i 0} {$i < 2000} {incr i} { sl@0: puts $s $l sl@0: } sl@0: } sl@0: proc accept {s a p} { sl@0: variable x sl@0: fileevent $s readable [namespace code [list readit $s]] sl@0: fconfigure $s -blocking off sl@0: set x accepted sl@0: } sl@0: proc readit {s} { sl@0: variable c sl@0: variable x sl@0: set l [gets $s] sl@0: sl@0: if {[eof $s]} { sl@0: close $s sl@0: set x done sl@0: } elseif {([string length $l] > 0) || ![fblocked $s]} { sl@0: incr c sl@0: } sl@0: } sl@0: set ss [socket -server [namespace code accept] 0] sl@0: set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]] sl@0: vwait [namespace which -variable x] sl@0: fconfigure $cs -blocking off sl@0: writelots $cs $l sl@0: close $cs sl@0: close $ss sl@0: vwait [namespace which -variable x] sl@0: set c sl@0: } 2000 sl@0: test io-29.35 {Tcl_Close vs fileevent vs multiple interpreters} {socket tempNotMac fileevent} { sl@0: # On Mac, this test screws up sockets such that subsequent tests using port 2828 sl@0: # either cause errors or panic(). sl@0: sl@0: catch {interp delete x} sl@0: catch {interp delete y} sl@0: interp create x sl@0: interp create y sl@0: set s [socket -server [namespace code accept] 0] sl@0: proc accept {s a p} { sl@0: puts $s hello sl@0: close $s sl@0: } sl@0: set c [socket [info hostname] [lindex [fconfigure $s -sockname] 2]] sl@0: interp share {} $c x sl@0: interp share {} $c y sl@0: close $c sl@0: x eval { sl@0: proc readit {s} { sl@0: gets $s sl@0: if {[eof $s]} { sl@0: close $s sl@0: } sl@0: } sl@0: } sl@0: y eval { sl@0: proc readit {s} { sl@0: gets $s sl@0: if {[eof $s]} { sl@0: close $s sl@0: } sl@0: } sl@0: } sl@0: x eval "fileevent $c readable \{readit $c\}" sl@0: y eval "fileevent $c readable \{readit $c\}" sl@0: y eval [list close $c] sl@0: update sl@0: close $s sl@0: interp delete x sl@0: interp delete y sl@0: } "" sl@0: sl@0: # Test end of line translations. Procedures tested are Tcl_Write, Tcl_Read. sl@0: sl@0: test io-30.1 {Tcl_Write lf, Tcl_Read lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\nthere\nand\nhere\n" sl@0: test io-30.2 {Tcl_Write lf, Tcl_Read cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\nthere\nand\nhere\n" sl@0: test io-30.3 {Tcl_Write lf, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\nthere\nand\nhere\n" sl@0: test io-30.4 {Tcl_Write cr, Tcl_Read cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\nthere\nand\nhere\n" sl@0: test io-30.5 {Tcl_Write cr, Tcl_Read lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\rthere\rand\rhere\r" sl@0: test io-30.6 {Tcl_Write cr, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\rthere\rand\rhere\r" sl@0: test io-30.7 {Tcl_Write crlf, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\nthere\nand\nhere\n" sl@0: test io-30.8 {Tcl_Write crlf, Tcl_Read lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\r\nthere\r\nand\r\nhere\r\n" sl@0: test io-30.9 {Tcl_Write crlf, Tcl_Read cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } "hello\n\nthere\n\nand\n\nhere\n\n" sl@0: test io-30.10 {Tcl_Write lf, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set c [read $f] sl@0: set x [fconfigure $f -translation] sl@0: close $f sl@0: list $c $x sl@0: } {{hello sl@0: there sl@0: and sl@0: here sl@0: } auto} sl@0: test io-30.11 {Tcl_Write cr, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set c [read $f] sl@0: set x [fconfigure $f -translation] sl@0: close $f sl@0: list $c $x sl@0: } {{hello sl@0: there sl@0: and sl@0: here sl@0: } auto} sl@0: test io-30.12 {Tcl_Write crlf, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set c [read $f] sl@0: set x [fconfigure $f -translation] sl@0: close $f sl@0: list $c $x sl@0: } {{hello sl@0: there sl@0: and sl@0: here sl@0: } auto} sl@0: sl@0: test io-30.13 {Tcl_Write crlf on block boundary, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set line "123456789ABCDE" ;# 14 char plus crlf sl@0: puts -nonewline $f x ;# shift crlf across block boundary sl@0: for {set i 0} {$i < 700} {incr i} { sl@0: puts $f $line sl@0: } sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set c [read $f] sl@0: close $f sl@0: string length $c sl@0: } [expr 700*15+1] sl@0: sl@0: test io-30.14 {Tcl_Write crlf on block boundary, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set line "123456789ABCDE" ;# 14 char plus crlf sl@0: puts -nonewline $f x ;# shift crlf across block boundary sl@0: for {set i 0} {$i < 700} {incr i} { sl@0: puts $f $line sl@0: } sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set c [read $f] sl@0: close $f sl@0: string length $c sl@0: } [expr 700*15+1] sl@0: sl@0: test io-30.15 {Tcl_Write mixed, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\rhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set c [read $f] sl@0: close $f sl@0: set c sl@0: } {hello sl@0: there sl@0: and sl@0: here sl@0: } sl@0: test io-30.16 {Tcl_Write ^Z at end, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f hello\nthere\nand\rhere\n\x1a sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set c [read $f] sl@0: close $f sl@0: set c sl@0: } {hello sl@0: there sl@0: and sl@0: here sl@0: } sl@0: test io-30.17 {Tcl_Write, implicit ^Z at end, Tcl_Read auto} {pcOnly} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -eofchar \x1a -translation lf sl@0: puts $f hello\nthere\nand\rhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set c [read $f] sl@0: close $f sl@0: set c sl@0: } {hello sl@0: there sl@0: and sl@0: here sl@0: } sl@0: test io-30.18 {Tcl_Write, ^Z in middle, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cghi\nqrs" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1 {} 1} sl@0: test io-30.19 {Tcl_Write, ^Z no newline in middle, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cghi\nqrs" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1 {} 1} sl@0: test io-30.20 {Tcl_Write, ^Z in middle ignored, Tcl_Read lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set s [format "abc\ndef\n%cghi\nqrs" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "abc def 0 \x1aghi 0 qrs 0 {} 1" sl@0: test io-30.21 {Tcl_Write, ^Z in middle ignored, Tcl_Read cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set s [format "abc\ndef\n%cghi\nqrs" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set l "" sl@0: set x [gets $f] sl@0: lappend l [string compare $x "abc\ndef\n\x1aghi\nqrs\n"] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {0 1 {} 1} sl@0: test io-30.22 {Tcl_Write, ^Z in middle ignored, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set s [format "abc\ndef\n%cghi\nqrs" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set l "" sl@0: set x [gets $f] sl@0: lappend l [string compare $x "abc\ndef\n\x1aghi\nqrs\n"] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {0 1 {} 1} sl@0: test io-30.23 {Tcl_Write lf, ^Z in middle, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: test io-30.24 {Tcl_Write lf, ^Z in middle, Tcl_Read lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: test io-30.25 {Tcl_Write cr, ^Z in middle, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: test io-30.26 {Tcl_Write cr, ^Z in middle, Tcl_Read cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: test io-30.27 {Tcl_Write crlf, ^Z in middle, Tcl_Read auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: test io-30.28 {Tcl_Write crlf, ^Z in middle, Tcl_Read crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format abc\ndef\n%cqrs\ntuv 26] sl@0: puts $f $c sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: set c [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $e sl@0: } {8 1} sl@0: sl@0: # Test end of line translations. Functions tested are Tcl_Write and Tcl_Gets. sl@0: sl@0: test io-31.1 {Tcl_Write lf, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: close $f sl@0: set l sl@0: } {hello 6 auto there 12 auto} sl@0: test io-31.2 {Tcl_Write cr, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: close $f sl@0: set l sl@0: } {hello 6 auto there 12 auto} sl@0: test io-31.3 {Tcl_Write crlf, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: close $f sl@0: set l sl@0: } {hello 7 auto there 14 auto} sl@0: test io-31.4 {Tcl_Write lf, Tcl_Gets lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: close $f sl@0: set l sl@0: } {hello 6 lf there 12 lf} sl@0: test io-31.5 {Tcl_Write lf, Tcl_Gets cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set l "" sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {21 21 cr 1 {} 21 cr 1} sl@0: test io-31.6 {Tcl_Write lf, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set l "" sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {21 21 crlf 1 {} 21 crlf 1} sl@0: test io-31.7 {Tcl_Write cr, Tcl_Gets cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello 6 cr 0 there 12 cr 0} sl@0: test io-31.8 {Tcl_Write cr, Tcl_Gets lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set l "" sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {21 21 lf 1 {} 21 lf 1} sl@0: test io-31.9 {Tcl_Write cr, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set l "" sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {21 21 crlf 1 {} 21 crlf 1} sl@0: test io-31.10 {Tcl_Write crlf, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello 7 crlf 0 there 14 crlf 0} sl@0: test io-31.11 {Tcl_Write crlf, Tcl_Gets cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello 6 cr 0 6 13 cr 0} sl@0: test io-31.12 {Tcl_Write crlf, Tcl_Gets lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: puts $f hello\nthere\nand\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf sl@0: set l "" sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: lappend l [string length [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [fconfigure $f -translation] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {6 7 lf 0 6 14 lf 0} sl@0: test io-31.13 {binary mode is synonym of lf mode} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation binary sl@0: set x [fconfigure $f -translation] sl@0: close $f sl@0: set x sl@0: } lf sl@0: # sl@0: # Test io-9.14 has been removed because "auto" output translation mode is sl@0: # not supoprted. sl@0: # sl@0: test io-31.14 {Tcl_Write mixed, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f hello\nthere\rand\r\nhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.15 {Tcl_Write mixed, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f hello\nthere\rand\r\nhere\r sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.16 {Tcl_Write mixed, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f hello\nthere\rand\r\nhere\n sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.17 {Tcl_Write mixed, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f hello\nthere\rand\r\nhere\r\n sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.18 {Tcl_Write ^Z at end, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "hello\nthere\nand\rhere\n\%c" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.19 {Tcl_Write, implicit ^Z at end, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -eofchar \x1a -translation lf sl@0: puts $f hello\nthere\nand\rhere sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {hello there and here 0 {} 1} sl@0: test io-31.20 {Tcl_Write, ^Z in middle, Tcl_Gets auto, eofChar} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a sl@0: fconfigure $f -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.21 {Tcl_Write, no newline ^Z in middle, Tcl_Gets auto, eofChar} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.22 {Tcl_Write, ^Z in middle ignored, Tcl_Gets lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "abc def 0 \x1aqrs 0 tuv 0 {} 1" sl@0: test io-31.23 {Tcl_Write, ^Z in middle ignored, Tcl_Gets cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "abc def 0 \x1aqrs 0 tuv 0 {} 1" sl@0: test io-31.24 {Tcl_Write, ^Z in middle ignored, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "abc def 0 \x1aqrs 0 tuv 0 {} 1" sl@0: test io-31.25 {Tcl_Write lf, ^Z in middle, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.26 {Tcl_Write lf, ^Z in middle, Tcl_Gets lf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.27 {Tcl_Write cr, ^Z in middle, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.28 {Tcl_Write cr, ^Z in middle, Tcl_Gets cr} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.29 {Tcl_Write crlf, ^Z in middle, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.30 {Tcl_Write crlf, ^Z in middle, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set s [format "abc\ndef\n%cqrs\ntuv" 26] sl@0: puts $f $s sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {abc def 0 {} 1} sl@0: test io-31.31 {Tcl_Write crlf on block boundary, Tcl_Gets crlf} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set line "123456789ABCDE" ;# 14 char plus crlf sl@0: puts -nonewline $f x ;# shift crlf across block boundary sl@0: for {set i 0} {$i < 700} {incr i} { sl@0: puts $f $line sl@0: } sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf sl@0: set c "" sl@0: while {[gets $f line] >= 0} { sl@0: append c $line\n sl@0: } sl@0: close $f sl@0: string length $c sl@0: } [expr 700*15+1] sl@0: test io-31.32 {Tcl_Write crlf on block boundary, Tcl_Gets auto} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set line "123456789ABCDE" ;# 14 char plus crlf sl@0: puts -nonewline $f x ;# shift crlf across block boundary sl@0: for {set i 0} {$i < 700} {incr i} { sl@0: puts $f $line sl@0: } sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto sl@0: set c "" sl@0: while {[gets $f line] >= 0} { sl@0: append c $line\n sl@0: } sl@0: close $f sl@0: string length $c sl@0: } [expr 700*15+1] sl@0: sl@0: sl@0: # Test Tcl_Read and buffering. sl@0: sl@0: test io-32.1 {Tcl_Read, channel not readable} { sl@0: list [catch {read stdout} msg] $msg sl@0: } {1 {channel "stdout" wasn't opened for reading}} sl@0: test io-32.2 {Tcl_Read, zero byte count} { sl@0: read stdin 0 sl@0: } "" sl@0: test io-32.3 {Tcl_Read, negative byte count} { sl@0: set f [open $path(longfile) r] sl@0: set l [list [catch {read $f -1} msg] $msg] sl@0: close $f sl@0: set l sl@0: } {1 {bad argument "-1": should be "nonewline"}} sl@0: test io-32.4 {Tcl_Read, positive byte count} { sl@0: set f [open $path(longfile) r] sl@0: set x [read $f 1024] sl@0: set s [string length $x] sl@0: unset x sl@0: close $f sl@0: set s sl@0: } 1024 sl@0: test io-32.5 {Tcl_Read, multiple buffers} { sl@0: set f [open $path(longfile) r] sl@0: fconfigure $f -buffersize 100 sl@0: set x [read $f 1024] sl@0: set s [string length $x] sl@0: unset x sl@0: close $f sl@0: set s sl@0: } 1024 sl@0: test io-32.6 {Tcl_Read, very large read} { sl@0: set f1 [open $path(longfile) r] sl@0: set z [read $f1 1000000] sl@0: close $f1 sl@0: set l [string length $z] sl@0: set x ok sl@0: set z [file size $path(longfile)] sl@0: if {$z != $l} { sl@0: set x broken sl@0: } sl@0: set x sl@0: } ok sl@0: test io-32.7 {Tcl_Read, nonblocking, file} {nonBlockFiles} { sl@0: set f1 [open $path(longfile) r] sl@0: fconfigure $f1 -blocking off sl@0: set z [read $f1 20] sl@0: close $f1 sl@0: set l [string length $z] sl@0: set x ok sl@0: if {$l != 20} { sl@0: set x broken sl@0: } sl@0: set x sl@0: } ok sl@0: test io-32.8 {Tcl_Read, nonblocking, file} {nonBlockFiles} { sl@0: set f1 [open $path(longfile) r] sl@0: fconfigure $f1 -blocking off sl@0: set z [read $f1 1000000] sl@0: close $f1 sl@0: set x ok sl@0: set l [string length $z] sl@0: set z [file size $path(longfile)] sl@0: if {$z != $l} { sl@0: set x broken sl@0: } sl@0: set x sl@0: } ok sl@0: test io-32.9 {Tcl_Read, read to end of file} { sl@0: set f1 [open $path(longfile) r] sl@0: set z [read $f1] sl@0: close $f1 sl@0: set l [string length $z] sl@0: set x ok sl@0: set z [file size $path(longfile)] sl@0: if {$z != $l} { sl@0: set x broken sl@0: } sl@0: set x sl@0: } ok sl@0: test io-32.10 {Tcl_Read from a pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {puts [gets stdin]} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: set x [read $f1] sl@0: close $f1 sl@0: set x sl@0: } "hello\n" sl@0: test io-32.11 {Tcl_Read from a pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {puts [gets stdin]} sl@0: puts $f1 {puts [gets stdin]} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: set x "" sl@0: lappend x [read $f1 6] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: lappend x [read $f1] sl@0: close $f1 sl@0: set x sl@0: } {{hello sl@0: } {hello sl@0: }} sl@0: test io-32.12 {Tcl_Read, -nonewline} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: puts $f1 hello sl@0: puts $f1 bye sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: set c [read -nonewline $f1] sl@0: close $f1 sl@0: set c sl@0: } {hello sl@0: bye} sl@0: test io-32.13 {Tcl_Read, -nonewline} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: puts $f1 hello sl@0: puts $f1 bye sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: set c [read -nonewline $f1] sl@0: close $f1 sl@0: list [string length $c] $c sl@0: } {9 {hello sl@0: bye}} sl@0: test io-32.14 {Tcl_Read, reading in small chunks} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f "Two lines: this one" sl@0: puts $f "and this one" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [read $f 1] [read $f 2] [read $f]] sl@0: close $f sl@0: set x sl@0: } {T wo { lines: this one sl@0: and this one sl@0: }} sl@0: test io-32.15 {Tcl_Read, asking for more input than available} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f "Two lines: this one" sl@0: puts $f "and this one" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [read $f 100] sl@0: close $f sl@0: set x sl@0: } {Two lines: this one sl@0: and this one sl@0: } sl@0: test io-32.16 {Tcl_Read, read to end of file with -nonewline} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f "Two lines: this one" sl@0: puts $f "and this one" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [read -nonewline $f] sl@0: close $f sl@0: set x sl@0: } {Two lines: this one sl@0: and this one} sl@0: sl@0: # Test Tcl_Gets. sl@0: sl@0: test io-33.1 {Tcl_Gets, reading what was written} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set y "first line" sl@0: puts $f1 $y sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: set x [gets $f1] sl@0: set z ok sl@0: if {"$x" != "$y"} { sl@0: set z broken sl@0: } sl@0: close $f1 sl@0: set z sl@0: } ok sl@0: test io-33.2 {Tcl_Gets into variable} { sl@0: set f1 [open $path(longfile) r] sl@0: set c [gets $f1 x] sl@0: set l [string length x] sl@0: set z ok sl@0: if {$l != $l} { sl@0: set z broken sl@0: } sl@0: close $f1 sl@0: set z sl@0: } ok sl@0: test io-33.3 {Tcl_Gets from pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {puts [gets stdin]} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: flush $f1 sl@0: set x [gets $f1] sl@0: close $f1 sl@0: set z ok sl@0: if {"$x" != "hello"} { sl@0: set z broken sl@0: } sl@0: set z sl@0: } ok sl@0: test io-33.4 {Tcl_Gets with long line} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: close $f sl@0: set f [open $path(test3)] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ} sl@0: test io-33.5 {Tcl_Gets with long line} { sl@0: set f [open $path(test3)] sl@0: set x [gets $f y] sl@0: close $f sl@0: list $x $y sl@0: } {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ} sl@0: test io-33.6 {Tcl_Gets and end of file} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts -nonewline $f "Test1\nTest2" sl@0: close $f sl@0: set f [open $path(test3)] sl@0: set x {} sl@0: set y {} sl@0: lappend x [gets $f y] $y sl@0: set y {} sl@0: lappend x [gets $f y] $y sl@0: set y {} sl@0: lappend x [gets $f y] $y sl@0: close $f sl@0: set x sl@0: } {5 Test1 5 Test2 -1 {}} sl@0: test io-33.7 {Tcl_Gets and bad variable} { sl@0: set f [open $path(test3) w] sl@0: puts $f "Line 1" sl@0: puts $f "Line 2" sl@0: close $f sl@0: catch {unset x} sl@0: set x 24 sl@0: set f [open $path(test3) r] sl@0: set result [list [catch {gets $f x(0)} msg] $msg] sl@0: close $f sl@0: set result sl@0: } {1 {can't set "x(0)": variable isn't array}} sl@0: test io-33.8 {Tcl_Gets, exercising double buffering} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set x "" sl@0: for {set y 0} {$y < 99} {incr y} {set x "a$x"} sl@0: for {set y 0} {$y < 100} {incr y} {puts $f $x} sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: fconfigure $f -translation lf sl@0: for {set y 0} {$y < 100} {incr y} {gets $f} sl@0: close $f sl@0: set y sl@0: } 100 sl@0: test io-33.9 {Tcl_Gets, exercising double buffering} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set x "" sl@0: for {set y 0} {$y < 99} {incr y} {set x "a$x"} sl@0: for {set y 0} {$y < 200} {incr y} {puts $f $x} sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: fconfigure $f -translation lf sl@0: for {set y 0} {$y < 200} {incr y} {gets $f} sl@0: close $f sl@0: set y sl@0: } 200 sl@0: test io-33.10 {Tcl_Gets, exercising double buffering} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set x "" sl@0: for {set y 0} {$y < 99} {incr y} {set x "a$x"} sl@0: for {set y 0} {$y < 300} {incr y} {puts $f $x} sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: fconfigure $f -translation lf sl@0: for {set y 0} {$y < 300} {incr y} {gets $f} sl@0: close $f sl@0: set y sl@0: } 300 sl@0: sl@0: # Test Tcl_Seek and Tcl_Tell. sl@0: sl@0: test io-34.1 {Tcl_Seek to current position at start of file} { sl@0: set f1 [open $path(longfile) r] sl@0: seek $f1 0 current sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } 0 sl@0: test io-34.2 {Tcl_Seek to offset from start} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 10 start sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } 10 sl@0: test io-34.3 {Tcl_Seek to end of file} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 0 end sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } 54 sl@0: test io-34.4 {Tcl_Seek to offset from end of file} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 -10 end sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } 44 sl@0: test io-34.5 {Tcl_Seek to offset from current position} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 10 current sl@0: seek $f1 10 current sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } 20 sl@0: test io-34.6 {Tcl_Seek to offset from end of file} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 -10 end sl@0: set c [tell $f1] sl@0: set r [read $f1] sl@0: close $f1 sl@0: list $c $r sl@0: } {44 {rstuvwxyz sl@0: }} sl@0: test io-34.7 {Tcl_Seek to offset from end of file, then to current position} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 -10 end sl@0: set c1 [tell $f1] sl@0: set r1 [read $f1 5] sl@0: seek $f1 0 current sl@0: set c2 [tell $f1] sl@0: close $f1 sl@0: list $c1 $r1 $c2 sl@0: } {44 rstuv 49} sl@0: test io-34.8 {Tcl_Seek on pipes: not supported} {stdio openpipe} { sl@0: set f1 [open "|[list [interpreter]]" r+] sl@0: set x [list [catch {seek $f1 0 current} msg] $msg] sl@0: close $f1 sl@0: regsub {".*":} $x {"":} x sl@0: string tolower $x sl@0: } {1 {error during seek on "": invalid argument}} sl@0: test io-34.9 {Tcl_Seek, testing buffered input flushing} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" sl@0: close $f sl@0: set f [open $path(test3) RDWR] sl@0: set x [read $f 1] sl@0: seek $f 3 sl@0: lappend x [read $f 1] sl@0: seek $f 0 start sl@0: lappend x [read $f 1] sl@0: seek $f 10 current sl@0: lappend x [read $f 1] sl@0: seek $f -2 end sl@0: lappend x [read $f 1] sl@0: seek $f 50 end sl@0: lappend x [read $f 1] sl@0: seek $f 1 sl@0: lappend x [read $f 1] sl@0: close $f sl@0: set x sl@0: } {a d a l Y {} b} sl@0: sl@0: set path(test3) [makeFile {} test3] sl@0: sl@0: test io-34.10 {Tcl_Seek testing flushing of buffered input} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf sl@0: puts $f xyz\n123 sl@0: close $f sl@0: set f [open $path(test3) r+] sl@0: fconfigure $f -translation lf sl@0: set x [gets $f] sl@0: seek $f 0 current sl@0: puts $f 456 sl@0: close $f sl@0: list $x [viewFile test3] sl@0: } "xyz {xyz sl@0: 456}" sl@0: test io-34.11 {Tcl_Seek testing flushing of buffered output} { sl@0: set f [open $path(test3) w] sl@0: puts $f xyz\n123 sl@0: close $f sl@0: set f [open $path(test3) w+] sl@0: puts $f xyzzy sl@0: seek $f 2 sl@0: set x [gets $f] sl@0: close $f sl@0: list $x [viewFile test3] sl@0: } "zzy xyzzy" sl@0: test io-34.12 {Tcl_Seek testing combination of write, seek back and read} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f xyz\n123 sl@0: close $f sl@0: set f [open $path(test3) a+] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f xyzzy sl@0: flush $f sl@0: set x [tell $f] sl@0: seek $f -4 cur sl@0: set y [gets $f] sl@0: close $f sl@0: list $x [viewFile test3] $y sl@0: } {14 {xyz sl@0: 123 sl@0: xyzzy} zzy} sl@0: test io-34.13 {Tcl_Tell at start of file} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set p [tell $f1] sl@0: close $f1 sl@0: set p sl@0: } 0 sl@0: test io-34.14 {Tcl_Tell after seek to end of file} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 0 end sl@0: set c1 [tell $f1] sl@0: close $f1 sl@0: set c1 sl@0: } 54 sl@0: test io-34.15 {Tcl_Tell combined with seeking} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f1 "abcdefghijklmnopqrstuvwxyz" sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: seek $f1 10 start sl@0: set c1 [tell $f1] sl@0: seek $f1 10 current sl@0: set c2 [tell $f1] sl@0: close $f1 sl@0: list $c1 $c2 sl@0: } {10 20} sl@0: test io-34.16 {Tcl_tell on pipe: always -1} {stdio openpipe} { sl@0: set f1 [open "|[list [interpreter]]" r+] sl@0: set c [tell $f1] sl@0: close $f1 sl@0: set c sl@0: } -1 sl@0: test io-34.17 {Tcl_Tell on pipe: always -1} {stdio openpipe} { sl@0: set f1 [open "|[list [interpreter]]" r+] sl@0: puts $f1 {puts hello} sl@0: flush $f1 sl@0: set c [tell $f1] sl@0: gets $f1 sl@0: close $f1 sl@0: set c sl@0: } -1 sl@0: test io-34.18 {Tcl_Tell combined with seeking and reading} { sl@0: file delete $path(test2) sl@0: set f [open $path(test2) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts -nonewline $f "line1\nline2\nline3\nline4\nline5\n" sl@0: close $f sl@0: set f [open $path(test2)] sl@0: fconfigure $f -translation lf sl@0: set x [tell $f] sl@0: read $f 3 sl@0: lappend x [tell $f] sl@0: seek $f 2 sl@0: lappend x [tell $f] sl@0: seek $f 10 current sl@0: lappend x [tell $f] sl@0: seek $f 0 end sl@0: lappend x [tell $f] sl@0: close $f sl@0: set x sl@0: } {0 3 2 12 30} sl@0: test io-34.19 {Tcl_Tell combined with opening in append mode} { sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f "abcdefghijklmnopqrstuvwxyz" sl@0: puts $f "abcdefghijklmnopqrstuvwxyz" sl@0: close $f sl@0: set f [open $path(test3) a] sl@0: set c [tell $f] sl@0: close $f sl@0: set c sl@0: } 54 sl@0: test io-34.20 {Tcl_Tell combined with writing} { sl@0: set f [open $path(test3) w] sl@0: set l "" sl@0: seek $f 29 start sl@0: lappend l [tell $f] sl@0: puts -nonewline $f a sl@0: seek $f 39 start sl@0: lappend l [tell $f] sl@0: puts -nonewline $f a sl@0: lappend l [tell $f] sl@0: seek $f 407 end sl@0: lappend l [tell $f] sl@0: close $f sl@0: set l sl@0: } {29 39 40 447} sl@0: test io-34.21 {Tcl_Seek and Tcl_Tell on large files} {largefileSupport} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -encoding binary sl@0: set l "" sl@0: lappend l [tell $f] sl@0: puts -nonewline $f abcdef sl@0: lappend l [tell $f] sl@0: flush $f sl@0: lappend l [tell $f] sl@0: # 4GB offset! sl@0: seek $f 0x100000000 sl@0: lappend l [tell $f] sl@0: puts -nonewline $f abcdef sl@0: lappend l [tell $f] sl@0: close $f sl@0: lappend l [file size $f] sl@0: # truncate... sl@0: close [open $path(test3) w] sl@0: lappend l [file size $f] sl@0: set l sl@0: } {0 6 6 4294967296 4294967302 4294967302 0} sl@0: sl@0: # Test Tcl_Eof sl@0: sl@0: test io-35.1 {Tcl_Eof} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f hello sl@0: puts $f hello sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [eof $f] sl@0: lappend x [eof $f] sl@0: gets $f sl@0: lappend x [eof $f] sl@0: gets $f sl@0: lappend x [eof $f] sl@0: gets $f sl@0: lappend x [eof $f] sl@0: lappend x [eof $f] sl@0: close $f sl@0: set x sl@0: } {0 0 0 0 1 1} sl@0: test io-35.2 {Tcl_Eof with pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {gets stdin} sl@0: puts $f1 {puts hello} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: set x [eof $f1] sl@0: flush $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: close $f1 sl@0: set x sl@0: } {0 0 0 1} sl@0: test io-35.3 {Tcl_Eof with pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 {gets stdin} sl@0: puts $f1 {puts hello} sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: puts $f1 hello sl@0: set x [eof $f1] sl@0: flush $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: gets $f1 sl@0: lappend x [eof $f1] sl@0: close $f1 sl@0: set x sl@0: } {0 0 0 1 1 1} sl@0: test io-35.4 {Tcl_Eof, eof detection on nonblocking file} {nonBlockFiles} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -blocking off sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {{} 1} sl@0: test io-35.5 {Tcl_Eof, eof detection on nonblocking pipe} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f [open $path(pipe) w] sl@0: puts $f { sl@0: exit sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter] $path(pipe)]" r] sl@0: set l "" sl@0: lappend l [gets $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {{} 1} sl@0: test io-35.6 {Tcl_Eof, eof char, lf write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {9 8 1} sl@0: test io-35.7 {Tcl_Eof, eof char, lf write, lf read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {9 8 1} sl@0: test io-35.8 {Tcl_Eof, eof char, cr write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {9 8 1} sl@0: test io-35.9 {Tcl_Eof, eof char, cr write, cr read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {9 8 1} sl@0: test io-35.10 {Tcl_Eof, eof char, crlf write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {11 8 1} sl@0: test io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: puts $f abc\ndef sl@0: close $f sl@0: set s [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $s $l $e sl@0: } {11 8 1} sl@0: test io-35.12 {Tcl_Eof, eof char in middle, lf write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {17 8 1} sl@0: test io-35.13 {Tcl_Eof, eof char in middle, lf write, lf read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {17 8 1} sl@0: test io-35.14 {Tcl_Eof, eof char in middle, cr write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {17 8 1} sl@0: test io-35.15 {Tcl_Eof, eof char in middle, cr write, cr read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {17 8 1} sl@0: test io-35.16 {Tcl_Eof, eof char in middle, crlf write, auto read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {21 8 1} sl@0: test io-35.17 {Tcl_Eof, eof char in middle, crlf write, crlf read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf -eofchar {} sl@0: set i [format abc\ndef\n%cqrs\nuvw 26] sl@0: puts $f $i sl@0: close $f sl@0: set c [file size $path(test1)] sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: set l [string length [read $f]] sl@0: set e [eof $f] sl@0: close $f sl@0: list $c $l $e sl@0: } {21 8 1} sl@0: sl@0: # Test Tcl_InputBlocked sl@0: sl@0: test io-36.1 {Tcl_InputBlocked on nonblocking pipe} {stdio openpipe} { sl@0: set f1 [open "|[list [interpreter]]" r+] sl@0: puts $f1 {puts hello_from_pipe} sl@0: flush $f1 sl@0: gets $f1 sl@0: fconfigure $f1 -blocking off -buffering full sl@0: puts $f1 {puts hello} sl@0: set x "" sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: flush $f1 sl@0: after 200 sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: close $f1 sl@0: set x sl@0: } {{} 1 hello 0 {} 1} sl@0: test io-36.2 {Tcl_InputBlocked on blocking pipe} {stdio openpipe} { sl@0: set f1 [open "|[list [interpreter]]" r+] sl@0: fconfigure $f1 -buffering line sl@0: puts $f1 {puts hello_from_pipe} sl@0: set x "" sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: puts $f1 {exit} sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: lappend x [eof $f1] sl@0: close $f1 sl@0: set x sl@0: } {hello_from_pipe 0 {} 0 1} sl@0: test io-36.3 {Tcl_InputBlocked vs files, short read} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnop sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [fblocked $f] sl@0: lappend l [read $f 3] sl@0: lappend l [fblocked $f] sl@0: lappend l [read -nonewline $f] sl@0: lappend l [fblocked $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {0 abc 0 defghijklmnop 0 1} sl@0: test io-36.4 {Tcl_InputBlocked vs files, event driven read} {fileevent} { sl@0: proc in {f} { sl@0: variable l sl@0: variable x sl@0: lappend l [read $f 3] sl@0: if {[eof $f]} {lappend l eof; close $f; set x done} sl@0: } sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnop sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: fileevent $f readable [namespace code [list in $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: set l sl@0: } {abc def ghi jkl mno {p sl@0: } eof} sl@0: test io-36.5 {Tcl_InputBlocked vs files, short read, nonblocking} {nonBlockFiles} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnop sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -blocking off sl@0: set l "" sl@0: lappend l [fblocked $f] sl@0: lappend l [read $f 3] sl@0: lappend l [fblocked $f] sl@0: lappend l [read -nonewline $f] sl@0: lappend l [fblocked $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } {0 abc 0 defghijklmnop 0 1} sl@0: test io-36.6 {Tcl_InputBlocked vs files, event driven read} {nonBlockFiles fileevent} { sl@0: proc in {f} { sl@0: variable l sl@0: variable x sl@0: lappend l [read $f 3] sl@0: if {[eof $f]} {lappend l eof; close $f; set x done} sl@0: } sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f abcdefghijklmnop sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -blocking off sl@0: set l "" sl@0: fileevent $f readable [namespace code [list in $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: set l sl@0: } {abc def ghi jkl mno {p sl@0: } eof} sl@0: sl@0: # Test Tcl_InputBuffered sl@0: sl@0: test io-37.1 {Tcl_InputBuffered} {testchannel} { sl@0: set f [open $path(longfile) r] sl@0: fconfigure $f -buffersize 4096 sl@0: read $f 3 sl@0: set l "" sl@0: lappend l [testchannel inputbuffered $f] sl@0: lappend l [tell $f] sl@0: close $f sl@0: set l sl@0: } {4093 3} sl@0: test io-37.2 {Tcl_InputBuffered, test input flushing on seek} {testchannel} { sl@0: set f [open $path(longfile) r] sl@0: fconfigure $f -buffersize 4096 sl@0: read $f 3 sl@0: set l "" sl@0: lappend l [testchannel inputbuffered $f] sl@0: lappend l [tell $f] sl@0: seek $f 0 current sl@0: lappend l [testchannel inputbuffered $f] sl@0: lappend l [tell $f] sl@0: close $f sl@0: set l sl@0: } {4093 3 0 3} sl@0: sl@0: # Test Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize sl@0: sl@0: test io-38.1 {Tcl_GetChannelBufferSize, default buffer size} { sl@0: set f [open $path(longfile) r] sl@0: set s [fconfigure $f -buffersize] sl@0: close $f sl@0: set s sl@0: } 4096 sl@0: test io-38.2 {Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize} { sl@0: set f [open $path(longfile) r] sl@0: set l "" sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize 10000 sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize 1 sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize -1 sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize 0 sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize 100000 sl@0: lappend l [fconfigure $f -buffersize] sl@0: fconfigure $f -buffersize 10000000 sl@0: lappend l [fconfigure $f -buffersize] sl@0: close $f sl@0: set l sl@0: } {4096 10000 1 1 1 100000 100000} sl@0: sl@0: test io-38.3 {Tcl_SetChannelBufferSize, changing buffersize between reads} { sl@0: # This test crashes the interp if Bug #427196 is not fixed sl@0: sl@0: set chan [open [info script] r] sl@0: fconfigure $chan -buffersize 10 sl@0: set var [read $chan 2] sl@0: fconfigure $chan -buffersize 32 sl@0: append var [read $chan] sl@0: close $chan sl@0: } {} sl@0: sl@0: # Test Tcl_SetChannelOption, Tcl_GetChannelOption sl@0: sl@0: test io-39.1 {Tcl_GetChannelOption} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set x [fconfigure $f1 -blocking] sl@0: close $f1 sl@0: set x sl@0: } 1 sl@0: # sl@0: # Test 17.2 was removed. sl@0: # sl@0: test io-39.2 {Tcl_GetChannelOption} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set x [fconfigure $f1 -buffering] sl@0: close $f1 sl@0: set x sl@0: } full sl@0: test io-39.3 {Tcl_GetChannelOption} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -buffering line sl@0: set x [fconfigure $f1 -buffering] sl@0: close $f1 sl@0: set x sl@0: } line sl@0: test io-39.4 {Tcl_GetChannelOption, Tcl_SetChannelOption} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set l "" sl@0: lappend l [fconfigure $f1 -buffering] sl@0: fconfigure $f1 -buffering line sl@0: lappend l [fconfigure $f1 -buffering] sl@0: fconfigure $f1 -buffering none sl@0: lappend l [fconfigure $f1 -buffering] sl@0: fconfigure $f1 -buffering line sl@0: lappend l [fconfigure $f1 -buffering] sl@0: fconfigure $f1 -buffering full sl@0: lappend l [fconfigure $f1 -buffering] sl@0: close $f1 sl@0: set l sl@0: } {full line none line full} sl@0: test io-39.5 {Tcl_GetChannelOption, invariance} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set l "" sl@0: lappend l [fconfigure $f1 -buffering] sl@0: lappend l [list [catch {fconfigure $f1 -buffering green} msg] $msg] sl@0: lappend l [fconfigure $f1 -buffering] sl@0: close $f1 sl@0: set l sl@0: } {full {1 {bad value for -buffering: must be one of full, line, or none}} full} sl@0: test io-39.6 {Tcl_SetChannelOption, multiple options} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -buffering line sl@0: puts $f1 hello sl@0: puts $f1 bye sl@0: set x [file size $path(test1)] sl@0: close $f1 sl@0: set x sl@0: } 10 sl@0: test io-39.7 {Tcl_SetChannelOption, buffering, translation} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf sl@0: puts $f1 hello sl@0: puts $f1 bye sl@0: set x "" sl@0: fconfigure $f1 -buffering line sl@0: lappend x [file size $path(test1)] sl@0: puts $f1 really_bye sl@0: lappend x [file size $path(test1)] sl@0: close $f1 sl@0: set x sl@0: } {0 21} sl@0: test io-39.8 {Tcl_SetChannelOption, different buffering options} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set l "" sl@0: fconfigure $f1 -translation lf -buffering none -eofchar {} sl@0: puts -nonewline $f1 hello sl@0: lappend l [file size $path(test1)] sl@0: puts -nonewline $f1 hello sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f1 -buffering full sl@0: puts -nonewline $f1 hello sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f1 -buffering none sl@0: lappend l [file size $path(test1)] sl@0: puts -nonewline $f1 hello sl@0: lappend l [file size $path(test1)] sl@0: close $f1 sl@0: lappend l [file size $path(test1)] sl@0: set l sl@0: } {5 10 10 10 20 20} sl@0: test io-39.9 {Tcl_SetChannelOption, blocking mode} {nonBlockFiles} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: close $f1 sl@0: set f1 [open $path(test1) r] sl@0: set x "" sl@0: lappend x [fconfigure $f1 -blocking] sl@0: fconfigure $f1 -blocking off sl@0: lappend x [fconfigure $f1 -blocking] sl@0: lappend x [gets $f1] sl@0: lappend x [read $f1 1000] sl@0: lappend x [fblocked $f1] sl@0: lappend x [eof $f1] sl@0: close $f1 sl@0: set x sl@0: } {1 0 {} {} 0 1} sl@0: test io-39.10 {Tcl_SetChannelOption, blocking mode} {stdio openpipe} { sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: gets stdin sl@0: after 100 sl@0: puts hi sl@0: gets stdin sl@0: } sl@0: close $f1 sl@0: set x "" sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: fconfigure $f1 -blocking off -buffering line sl@0: lappend x [fconfigure $f1 -blocking] sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: fconfigure $f1 -blocking on sl@0: puts $f1 hello sl@0: fconfigure $f1 -blocking off sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: fconfigure $f1 -blocking on sl@0: puts $f1 bye sl@0: fconfigure $f1 -blocking off sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: fconfigure $f1 -blocking on sl@0: lappend x [fconfigure $f1 -blocking] sl@0: lappend x [gets $f1] sl@0: lappend x [fblocked $f1] sl@0: lappend x [eof $f1] sl@0: lappend x [gets $f1] sl@0: lappend x [eof $f1] sl@0: close $f1 sl@0: set x sl@0: } {0 {} 1 {} 1 {} 1 1 hi 0 0 {} 1} sl@0: test io-39.11 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffersize -10 sl@0: set x [fconfigure $f -buffersize] sl@0: close $f sl@0: set x sl@0: } 4096 sl@0: test io-39.12 {Tcl_SetChannelOption, Tcl_GetChannelOption buffer size} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffersize 10000000 sl@0: set x [fconfigure $f -buffersize] sl@0: close $f sl@0: set x sl@0: } 4096 sl@0: test io-39.13 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -buffersize 40000 sl@0: set x [fconfigure $f -buffersize] sl@0: close $f sl@0: set x sl@0: } 40000 sl@0: test io-39.14 {Tcl_SetChannelOption: -encoding, binary & utf-8} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding {} sl@0: puts -nonewline $f \xe7\x89\xa6 sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -encoding utf-8 sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } \u7266 sl@0: test io-39.15 {Tcl_SetChannelOption: -encoding, binary & utf-8} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -encoding binary sl@0: puts -nonewline $f \xe7\x89\xa6 sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -encoding utf-8 sl@0: set x [read $f] sl@0: close $f sl@0: set x sl@0: } \u7266 sl@0: test io-39.16 {Tcl_SetChannelOption: -encoding, errors} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: set result [list [catch {fconfigure $f -encoding foobar} msg] $msg] sl@0: close $f sl@0: set result sl@0: } {1 {unknown encoding "foobar"}} sl@0: test io-39.17 {Tcl_SetChannelOption: -encoding, clearing CHANNEL_NEED_MORE_DATA} {stdio openpipe fileevent} { sl@0: set f [open "|[list [interpreter] $path(cat)]" r+] sl@0: fconfigure $f -encoding binary sl@0: puts -nonewline $f "\xe7" sl@0: flush $f sl@0: fconfigure $f -encoding utf-8 -blocking 0 sl@0: variable x {} sl@0: fileevent $f readable [namespace code { lappend x [read $f] }] sl@0: vwait [namespace which -variable x] sl@0: after 300 [namespace code { lappend x timeout }] sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -encoding utf-8 sl@0: vwait [namespace which -variable x] sl@0: after 300 [namespace code { lappend x timeout }] sl@0: vwait [namespace which -variable x] sl@0: fconfigure $f -encoding binary sl@0: vwait [namespace which -variable x] sl@0: after 300 [namespace code { lappend x timeout }] sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: set x sl@0: } "{} timeout {} timeout \xe7 timeout" sl@0: sl@0: test io-39.18 {Tcl_SetChannelOption, setting read mode independently} \ sl@0: {socket} { sl@0: proc accept {s a p} {close $s} sl@0: set s1 [socket -server [namespace code accept] 0] sl@0: set port [lindex [fconfigure $s1 -sockname] 2] sl@0: set s2 [socket 127.0.0.1 $port] sl@0: update sl@0: fconfigure $s2 -translation {auto lf} sl@0: set modes [fconfigure $s2 -translation] sl@0: close $s1 sl@0: close $s2 sl@0: set modes sl@0: } {auto lf} sl@0: test io-39.19 {Tcl_SetChannelOption, setting read mode independently} \ sl@0: {socket} { sl@0: proc accept {s a p} {close $s} sl@0: set s1 [socket -server [namespace code accept] 0] sl@0: set port [lindex [fconfigure $s1 -sockname] 2] sl@0: set s2 [socket 127.0.0.1 $port] sl@0: update sl@0: fconfigure $s2 -translation {auto crlf} sl@0: set modes [fconfigure $s2 -translation] sl@0: close $s1 sl@0: close $s2 sl@0: set modes sl@0: } {auto crlf} sl@0: test io-39.20 {Tcl_SetChannelOption, setting read mode independently} \ sl@0: {socket} { sl@0: proc accept {s a p} {close $s} sl@0: set s1 [socket -server [namespace code accept] 0] sl@0: set port [lindex [fconfigure $s1 -sockname] 2] sl@0: set s2 [socket 127.0.0.1 $port] sl@0: update sl@0: fconfigure $s2 -translation {auto cr} sl@0: set modes [fconfigure $s2 -translation] sl@0: close $s1 sl@0: close $s2 sl@0: set modes sl@0: } {auto cr} sl@0: test io-39.21 {Tcl_SetChannelOption, setting read mode independently} \ sl@0: {socket} { sl@0: proc accept {s a p} {close $s} sl@0: set s1 [socket -server [namespace code accept] 0] sl@0: set port [lindex [fconfigure $s1 -sockname] 2] sl@0: set s2 [socket 127.0.0.1 $port] sl@0: update sl@0: fconfigure $s2 -translation {auto auto} sl@0: set modes [fconfigure $s2 -translation] sl@0: close $s1 sl@0: close $s2 sl@0: set modes sl@0: } {auto crlf} sl@0: sl@0: test io-39.22 {Tcl_SetChannelOption, invariance} {unixOnly} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w+] sl@0: set l "" sl@0: lappend l [fconfigure $f1 -eofchar] sl@0: fconfigure $f1 -eofchar {ON GO} sl@0: lappend l [fconfigure $f1 -eofchar] sl@0: fconfigure $f1 -eofchar D sl@0: lappend l [fconfigure $f1 -eofchar] sl@0: close $f1 sl@0: set l sl@0: } {{{} {}} {O G} {D D}} sl@0: sl@0: test io-39.22a {Tcl_SetChannelOption, invariance} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w+] sl@0: set l [list] sl@0: fconfigure $f1 -eofchar {ON GO} sl@0: lappend l [fconfigure $f1 -eofchar] sl@0: fconfigure $f1 -eofchar D sl@0: lappend l [fconfigure $f1 -eofchar] sl@0: lappend l [list [catch {fconfigure $f1 -eofchar {1 2 3}} msg] $msg] sl@0: close $f1 sl@0: set l sl@0: } {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}} sl@0: sl@0: sl@0: test io-39.23 {Tcl_GetChannelOption, server socket is not readable or sl@0: writeable, it should still have valid -eofchar and -translation options } { sl@0: set l [list] sl@0: set sock [socket -server [namespace code accept] 0] sl@0: lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation] sl@0: close $sock sl@0: set l sl@0: } {{{}} auto} sl@0: test io-39.24 {Tcl_SetChannelOption, server socket is not readable or sl@0: writable so we can't change -eofchar or -translation } { sl@0: set l [list] sl@0: set sock [socket -server [namespace code accept] 0] sl@0: fconfigure $sock -eofchar D -translation lf sl@0: lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation] sl@0: close $sock sl@0: set l sl@0: } {{{}} auto} sl@0: sl@0: test io-40.1 {POSIX open access modes: RDWR} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts $f xyzzy sl@0: close $f sl@0: set f [open $path(test3) RDWR] sl@0: puts -nonewline $f "ab" sl@0: seek $f 0 current sl@0: set x [gets $f] sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: lappend x [gets $f] sl@0: close $f sl@0: set x sl@0: } {zzy abzzy} sl@0: test io-40.2 {POSIX open access modes: CREAT} {unixOnly} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) {WRONLY CREAT} 0600] sl@0: file stat $path(test3) stats sl@0: set x [format "0%o" [expr $stats(mode)&0777]] sl@0: puts $f "line 1" sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: lappend x [gets $f] sl@0: close $f sl@0: set x sl@0: } {0600 {line 1}} sl@0: sl@0: # some tests can only be run is umask is 2 sl@0: # if "umask" cannot be run, the tests will be skipped. sl@0: catch {testConstraint umask2 [expr {[exec umask] == 2}]} sl@0: sl@0: test io-40.3 {POSIX open access modes: CREAT} {unixOnly umask2} { sl@0: # This test only works if your umask is 2, like ouster's. sl@0: file delete $path(test3) sl@0: set f [open $path(test3) {WRONLY CREAT}] sl@0: close $f sl@0: file stat test3 stats sl@0: format "0%o" [expr $stats(mode)&0777] sl@0: } 0664 sl@0: test io-40.4 {POSIX open access modes: CREAT} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -eofchar {} sl@0: puts $f xyzzy sl@0: close $f sl@0: set f [open $path(test3) {WRONLY CREAT}] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f "ab" sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } abzzy sl@0: test io-40.5 {POSIX open access modes: APPEND} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f xyzzy sl@0: close $f sl@0: set f [open $path(test3) {WRONLY APPEND}] sl@0: fconfigure $f -translation lf sl@0: puts $f "new line" sl@0: seek $f 0 sl@0: puts $f "abc" sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: fconfigure $f -translation lf sl@0: set x "" sl@0: seek $f 6 current sl@0: lappend x [gets $f] sl@0: lappend x [gets $f] sl@0: close $f sl@0: set x sl@0: } {{new line} abc} sl@0: test io-40.6 {POSIX open access modes: EXCL} -match regexp -body { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts $f xyzzy sl@0: close $f sl@0: open $path(test3) {WRONLY CREAT EXCL} sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": file (already )?exists} sl@0: test io-40.7 {POSIX open access modes: EXCL} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) {WRONLY CREAT EXCL}] sl@0: fconfigure $f -eofchar {} sl@0: puts $f "A test line" sl@0: close $f sl@0: viewFile test3 sl@0: } {A test line} sl@0: test io-40.8 {POSIX open access modes: TRUNC} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: puts $f xyzzy sl@0: close $f sl@0: set f [open $path(test3) {WRONLY TRUNC}] sl@0: puts $f abc sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } abc sl@0: test io-40.9 {POSIX open access modes: NONBLOCK} {nonPortable macOrUnix} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) {WRONLY NONBLOCK CREAT}] sl@0: puts $f "NONBLOCK test" sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: set x [gets $f] sl@0: close $f sl@0: set x sl@0: } {NONBLOCK test} sl@0: test io-40.10 {POSIX open access modes: RDONLY} { sl@0: set f [open $path(test1) w] sl@0: puts $f "two lines: this one" sl@0: puts $f "and this" sl@0: close $f sl@0: set f [open $path(test1) RDONLY] sl@0: set x [list [gets $f] [catch {puts $f Test} msg] $msg] sl@0: close $f sl@0: string compare [string tolower $x] \ sl@0: [list {two lines: this one} 1 \ sl@0: [format "channel \"%s\" wasn't opened for writing" $f]] sl@0: } 0 sl@0: test io-40.11 {POSIX open access modes: RDONLY} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) RDONLY sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: test io-40.12 {POSIX open access modes: WRONLY} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) WRONLY sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: test io-40.13 {POSIX open access modes: WRONLY} { sl@0: makeFile xyzzy test3 sl@0: set f [open $path(test3) WRONLY] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f "ab" sl@0: seek $f 0 current sl@0: set x [list [catch {gets $f} msg] $msg] sl@0: close $f sl@0: lappend x [viewFile test3] sl@0: string compare [string tolower $x] \ sl@0: [list 1 "channel \"$f\" wasn't opened for reading" abzzy] sl@0: } 0 sl@0: test io-40.14 {POSIX open access modes: RDWR} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) RDWR sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: test io-40.15 {POSIX open access modes: RDWR} { sl@0: makeFile xyzzy test3 sl@0: set f [open $path(test3) RDWR] sl@0: puts -nonewline $f "ab" sl@0: seek $f 0 current sl@0: set x [gets $f] sl@0: close $f sl@0: lappend x [viewFile test3] sl@0: } {zzy abzzy} sl@0: if {![file exists ~/_test_] && [file writable ~]} { sl@0: test io-40.16 {tilde substitution in open} -setup { sl@0: makeFile {Some text} _test_ ~ sl@0: } -body { sl@0: file exists [file join $env(HOME) _test_] sl@0: } -cleanup { sl@0: removeFile _test_ ~ sl@0: } -result 1 sl@0: } sl@0: test io-40.17 {tilde substitution in open} { sl@0: set home $env(HOME) sl@0: unset env(HOME) sl@0: set x [list [catch {open ~/foo} msg] $msg] sl@0: set env(HOME) $home sl@0: set x sl@0: } {1 {couldn't find HOME environment variable to expand path}} sl@0: sl@0: test io-41.1 {Tcl_FileeventCmd: errors} {fileevent} { sl@0: list [catch {fileevent foo} msg] $msg sl@0: } {1 {wrong # args: should be "fileevent channelId event ?script?"}} sl@0: test io-41.2 {Tcl_FileeventCmd: errors} {fileevent} { sl@0: list [catch {fileevent foo bar baz q} msg] $msg sl@0: } {1 {wrong # args: should be "fileevent channelId event ?script?"}} sl@0: test io-41.3 {Tcl_FileeventCmd: errors} {fileevent} { sl@0: list [catch {fileevent gorp readable} msg] $msg sl@0: } {1 {can not find channel named "gorp"}} sl@0: test io-41.4 {Tcl_FileeventCmd: errors} {fileevent} { sl@0: list [catch {fileevent gorp writable} msg] $msg sl@0: } {1 {can not find channel named "gorp"}} sl@0: test io-41.5 {Tcl_FileeventCmd: errors} {fileevent} { sl@0: list [catch {fileevent gorp who-knows} msg] $msg sl@0: } {1 {bad event name "who-knows": must be readable or writable}} sl@0: sl@0: # sl@0: # Test fileevent on a file sl@0: # sl@0: sl@0: set path(foo) [makeFile {} foo] sl@0: set f [open $path(foo) w+] sl@0: sl@0: test io-42.1 {Tcl_FileeventCmd: creating, deleting, querying} {fileevent} { sl@0: list [fileevent $f readable] [fileevent $f writable] sl@0: } {{} {}} sl@0: test io-42.2 {Tcl_FileeventCmd: replacing} {fileevent} { sl@0: set result {} sl@0: fileevent $f r "first script" sl@0: lappend result [fileevent $f readable] sl@0: fileevent $f r "new script" sl@0: lappend result [fileevent $f readable] sl@0: fileevent $f r "yet another" sl@0: lappend result [fileevent $f readable] sl@0: fileevent $f r "" sl@0: lappend result [fileevent $f readable] sl@0: } {{first script} {new script} {yet another} {}} sl@0: test io-42.3 {Tcl_FileeventCmd: replacing, with NULL chars in script} {fileevent} { sl@0: set result {} sl@0: fileevent $f r "first scr\0ipt" sl@0: lappend result [string length [fileevent $f readable]] sl@0: fileevent $f r "new scr\0ipt" sl@0: lappend result [string length [fileevent $f readable]] sl@0: fileevent $f r "yet ano\0ther" sl@0: lappend result [string length [fileevent $f readable]] sl@0: fileevent $f r "" sl@0: lappend result [fileevent $f readable] sl@0: } {13 11 12 {}} sl@0: sl@0: test io-43.1 {Tcl_FileeventCmd: creating, deleting, querying} {stdio unixExecs fileevent} { sl@0: set result {} sl@0: fileevent $f readable "script 1" sl@0: lappend result [fileevent $f readable] [fileevent $f writable] sl@0: fileevent $f writable "write script" sl@0: lappend result [fileevent $f readable] [fileevent $f writable] sl@0: fileevent $f readable {} sl@0: lappend result [fileevent $f readable] [fileevent $f writable] sl@0: fileevent $f writable {} sl@0: lappend result [fileevent $f readable] [fileevent $f writable] sl@0: } {{script 1} {} {script 1} {write script} {} {write script} {} {}} sl@0: test io-43.2 {Tcl_FileeventCmd: deleting when many present} -setup { sl@0: set f2 [open "|[list cat -u]" r+] sl@0: set f3 [open "|[list cat -u]" r+] sl@0: } -constraints {stdio unixExecs fileevent openpipe} -body { sl@0: set result {} sl@0: lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r] sl@0: fileevent $f r "read f" sl@0: fileevent $f2 r "read f2" sl@0: fileevent $f3 r "read f3" sl@0: lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r] sl@0: fileevent $f2 r {} sl@0: lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r] sl@0: fileevent $f3 r {} sl@0: lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r] sl@0: fileevent $f r {} sl@0: lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r] sl@0: } -cleanup { sl@0: catch {close $f2} sl@0: catch {close $f3} sl@0: } -result {{} {} {} {read f} {read f2} {read f3} {read f} {} {read f3} {read f} {} {} {} {} {}} sl@0: sl@0: test io-44.1 {FileEventProc procedure: normal read event} -setup { sl@0: set f2 [open "|[list cat -u]" r+] sl@0: set f3 [open "|[list cat -u]" r+] sl@0: } -constraints {stdio unixExecs fileevent openpipe} -body { sl@0: fileevent $f2 readable [namespace code { sl@0: set x [gets $f2]; fileevent $f2 readable {} sl@0: }] sl@0: puts $f2 text; flush $f2 sl@0: variable x initial sl@0: vwait [namespace which -variable x] sl@0: set x sl@0: } -cleanup { sl@0: catch {close $f2} sl@0: catch {close $f3} sl@0: } -result {text} sl@0: test io-44.2 {FileEventProc procedure: error in read event} -setup { sl@0: set f2 [open "|[list cat -u]" r+] sl@0: set f3 [open "|[list cat -u]" r+] sl@0: } -constraints {stdio unixExecs fileevent openpipe} -body { sl@0: proc ::bgerror args "set [namespace which -variable x] \$args" sl@0: fileevent $f2 readable {error bogus} sl@0: puts $f2 text; flush $f2 sl@0: variable x initial sl@0: vwait [namespace which -variable x] sl@0: rename ::bgerror {} sl@0: list $x [fileevent $f2 readable] sl@0: } -cleanup { sl@0: catch {close $f2} sl@0: catch {close $f3} sl@0: } -result {bogus {}} sl@0: test io-44.3 {FileEventProc procedure: normal write event} -setup { sl@0: set f2 [open "|[list cat -u]" r+] sl@0: set f3 [open "|[list cat -u]" r+] sl@0: } -constraints {stdio unixExecs fileevent openpipe} -body { sl@0: fileevent $f2 writable [namespace code { sl@0: lappend x "triggered" sl@0: incr count -1 sl@0: if {$count <= 0} { sl@0: fileevent $f2 writable {} sl@0: } sl@0: }] sl@0: variable x initial sl@0: set count 3 sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: set x sl@0: } -cleanup { sl@0: catch {close $f2} sl@0: catch {close $f3} sl@0: } -result {initial triggered triggered triggered} sl@0: test io-44.4 {FileEventProc procedure: eror in write event} -setup { sl@0: set f2 [open "|[list cat -u]" r+] sl@0: set f3 [open "|[list cat -u]" r+] sl@0: } -constraints {stdio unixExecs fileevent openpipe} -body { sl@0: proc ::bgerror args "set [namespace which -variable x] \$args" sl@0: fileevent $f2 writable {error bad-write} sl@0: variable x initial sl@0: vwait [namespace which -variable x] sl@0: rename ::bgerror {} sl@0: list $x [fileevent $f2 writable] sl@0: } -cleanup { sl@0: catch {close $f2} sl@0: catch {close $f3} sl@0: } -result {bad-write {}} sl@0: test io-44.5 {FileEventProc procedure: end of file} {stdio unixExecs openpipe fileevent} { sl@0: set f4 [open "|[list [interpreter] $path(cat) << foo]" r] sl@0: fileevent $f4 readable [namespace code { sl@0: if {[gets $f4 line] < 0} { sl@0: lappend x eof sl@0: fileevent $f4 readable {} sl@0: } else { sl@0: lappend x $line sl@0: } sl@0: }] sl@0: variable x initial sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: close $f4 sl@0: set x sl@0: } {initial foo eof} sl@0: sl@0: sl@0: close $f sl@0: makeFile "foo bar" foo sl@0: test io-45.1 {DeleteFileEvent, cleanup on close} {fileevent} { sl@0: set f [open $path(foo) r] sl@0: fileevent $f readable [namespace code { sl@0: lappend x "binding triggered: \"[gets $f]\"" sl@0: fileevent $f readable {} sl@0: }] sl@0: close $f sl@0: set x initial sl@0: after 100 [namespace code { set y done }] sl@0: variable y sl@0: vwait [namespace which -variable y] sl@0: set x sl@0: } {initial} sl@0: test io-45.2 {DeleteFileEvent, cleanup on close} {fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: fileevent $f readable [namespace code { sl@0: lappend x "f triggered: \"[gets $f]\"" sl@0: fileevent $f readable {} sl@0: }] sl@0: fileevent $f2 readable [namespace code { sl@0: lappend x "f2 triggered: \"[gets $f2]\"" sl@0: fileevent $f2 readable {} sl@0: }] sl@0: close $f sl@0: variable x initial sl@0: vwait [namespace which -variable x] sl@0: close $f2 sl@0: set x sl@0: } {initial {f2 triggered: "foo bar"}} sl@0: test io-45.3 {DeleteFileEvent, cleanup on close} {fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: set f3 [open $path(foo) r] sl@0: fileevent $f readable {f script} sl@0: fileevent $f2 readable {f2 script} sl@0: fileevent $f3 readable {f3 script} sl@0: set x {} sl@0: close $f2 sl@0: lappend x [catch {fileevent $f readable} msg] $msg \ sl@0: [catch {fileevent $f2 readable}] \ sl@0: [catch {fileevent $f3 readable} msg] $msg sl@0: close $f3 sl@0: lappend x [catch {fileevent $f readable} msg] $msg \ sl@0: [catch {fileevent $f2 readable}] \ sl@0: [catch {fileevent $f3 readable}] sl@0: close $f sl@0: lappend x [catch {fileevent $f readable}] \ sl@0: [catch {fileevent $f2 readable}] \ sl@0: [catch {fileevent $f3 readable}] sl@0: } {0 {f script} 1 0 {f3 script} 0 {f script} 1 1 1 1 1} sl@0: sl@0: # Execute these tests only if the "testfevent" command is present. sl@0: testConstraint testfevent [llength [info commands testfevent]] sl@0: sl@0: test io-46.1 {Tcl event loop vs multiple interpreters} {testfevent fileevent} { sl@0: testfevent create sl@0: set script "set f \[[list open $path(foo) r]]\n" sl@0: append script { sl@0: set x "no event" sl@0: fileevent $f readable [namespace code { sl@0: set x "f triggered: [gets $f]" sl@0: fileevent $f readable {} sl@0: }] sl@0: } sl@0: testfevent cmd $script sl@0: after 1 ;# We must delay because Windows takes a little time to notice sl@0: update sl@0: testfevent cmd {close $f} sl@0: list [testfevent cmd {set x}] [testfevent cmd {info commands after}] sl@0: } {{f triggered: foo bar} after} sl@0: test io-46.2 {Tcl event loop vs multiple interpreters} testfevent { sl@0: testfevent create sl@0: testfevent cmd { sl@0: variable x 0 sl@0: after 100 {set x triggered} sl@0: vwait [namespace which -variable x] sl@0: set x sl@0: } sl@0: } {triggered} sl@0: test io-46.3 {Tcl event loop vs multiple interpreters} testfevent { sl@0: testfevent create sl@0: testfevent cmd { sl@0: set x 0 sl@0: after 10 {lappend x timer} sl@0: after 30 sl@0: set result $x sl@0: update idletasks sl@0: lappend result $x sl@0: update sl@0: lappend result $x sl@0: } sl@0: } {0 0 {0 timer}} sl@0: sl@0: test io-47.1 {fileevent vs multiple interpreters} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: set f3 [open $path(foo) r] sl@0: fileevent $f readable {script 1} sl@0: testfevent create sl@0: testfevent share $f2 sl@0: testfevent cmd "fileevent $f2 readable {script 2}" sl@0: fileevent $f3 readable {sript 3} sl@0: set x {} sl@0: lappend x [fileevent $f2 readable] sl@0: testfevent delete sl@0: lappend x [fileevent $f readable] [fileevent $f2 readable] \ sl@0: [fileevent $f3 readable] sl@0: close $f sl@0: close $f2 sl@0: close $f3 sl@0: set x sl@0: } {{} {script 1} {} {sript 3}} sl@0: test io-47.2 {deleting fileevent on interpreter delete} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: set f3 [open $path(foo) r] sl@0: set f4 [open $path(foo) r] sl@0: fileevent $f readable {script 1} sl@0: testfevent create sl@0: testfevent share $f2 sl@0: testfevent share $f3 sl@0: testfevent cmd "fileevent $f2 readable {script 2} sl@0: fileevent $f3 readable {script 3}" sl@0: fileevent $f4 readable {script 4} sl@0: testfevent delete sl@0: set x [list [fileevent $f readable] [fileevent $f2 readable] \ sl@0: [fileevent $f3 readable] [fileevent $f4 readable]] sl@0: close $f sl@0: close $f2 sl@0: close $f3 sl@0: close $f4 sl@0: set x sl@0: } {{script 1} {} {} {script 4}} sl@0: test io-47.3 {deleting fileevent on interpreter delete} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: set f3 [open $path(foo) r] sl@0: set f4 [open $path(foo) r] sl@0: testfevent create sl@0: testfevent share $f3 sl@0: testfevent share $f4 sl@0: fileevent $f readable {script 1} sl@0: fileevent $f2 readable {script 2} sl@0: testfevent cmd "fileevent $f3 readable {script 3} sl@0: fileevent $f4 readable {script 4}" sl@0: testfevent delete sl@0: set x [list [fileevent $f readable] [fileevent $f2 readable] \ sl@0: [fileevent $f3 readable] [fileevent $f4 readable]] sl@0: close $f sl@0: close $f2 sl@0: close $f3 sl@0: close $f4 sl@0: set x sl@0: } {{script 1} {script 2} {} {}} sl@0: test io-47.4 {file events on shared files and multiple interpreters} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: set f2 [open $path(foo) r] sl@0: testfevent create sl@0: testfevent share $f sl@0: testfevent cmd "fileevent $f readable {script 1}" sl@0: fileevent $f readable {script 2} sl@0: fileevent $f2 readable {script 3} sl@0: set x [list [fileevent $f2 readable] \ sl@0: [testfevent cmd "fileevent $f readable"] \ sl@0: [fileevent $f readable]] sl@0: testfevent delete sl@0: close $f sl@0: close $f2 sl@0: set x sl@0: } {{script 3} {script 1} {script 2}} sl@0: test io-47.5 {file events on shared files, deleting file events} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: testfevent create sl@0: testfevent share $f sl@0: testfevent cmd "fileevent $f readable {script 1}" sl@0: fileevent $f readable {script 2} sl@0: testfevent cmd "fileevent $f readable {}" sl@0: set x [list [testfevent cmd "fileevent $f readable"] \ sl@0: [fileevent $f readable]] sl@0: testfevent delete sl@0: close $f sl@0: set x sl@0: } {{} {script 2}} sl@0: test io-47.6 {file events on shared files, deleting file events} {testfevent fileevent} { sl@0: set f [open $path(foo) r] sl@0: testfevent create sl@0: testfevent share $f sl@0: testfevent cmd "fileevent $f readable {script 1}" sl@0: fileevent $f readable {script 2} sl@0: fileevent $f readable {} sl@0: set x [list [testfevent cmd "fileevent $f readable"] \ sl@0: [fileevent $f readable]] sl@0: testfevent delete sl@0: close $f sl@0: set x sl@0: } {{script 1} {}} sl@0: sl@0: set path(bar) [makeFile {} bar] sl@0: sl@0: test io-48.1 {testing readability conditions} {fileevent} { sl@0: set f [open $path(bar) w] sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: close $f sl@0: set f [open $path(bar) r] sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: lappend l called sl@0: if {[eof $f]} { sl@0: close $f sl@0: set x done sl@0: } else { sl@0: gets $f sl@0: } sl@0: } sl@0: set l "" sl@0: variable x not_done sl@0: vwait [namespace which -variable x] sl@0: list $x $l sl@0: } {done {called called called called called called called}} sl@0: test io-48.2 {testing readability conditions} {nonBlockFiles fileevent} { sl@0: set f [open $path(bar) w] sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: close $f sl@0: set f [open $path(bar) r] sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: fconfigure $f -blocking off sl@0: proc consume {f} { sl@0: variable x sl@0: variable l sl@0: lappend l called sl@0: if {[eof $f]} { sl@0: close $f sl@0: set x done sl@0: } else { sl@0: gets $f sl@0: } sl@0: } sl@0: set l "" sl@0: variable x not_done sl@0: vwait [namespace which -variable x] sl@0: list $x $l sl@0: } {done {called called called called called called called}} sl@0: sl@0: set path(my_script) [makeFile {} my_script] sl@0: sl@0: test io-48.3 {testing readability conditions} {stdio unixOnly nonBlockFiles openpipe fileevent} { sl@0: set f [open $path(bar) w] sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: puts $f abcdefg sl@0: close $f sl@0: set f [open $path(my_script) w] sl@0: puts $f { sl@0: proc copy_slowly {f} { sl@0: while {![eof $f]} { sl@0: puts [gets $f] sl@0: after 200 sl@0: } sl@0: close $f sl@0: } sl@0: } sl@0: close $f sl@0: set f [open "|[list [interpreter]]" r+] sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: fconfigure $f -buffering line sl@0: fconfigure $f -blocking off sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: if {[eof $f]} { sl@0: set x done sl@0: } else { sl@0: gets $f sl@0: lappend l [fblocked $f] sl@0: gets $f sl@0: lappend l [fblocked $f] sl@0: } sl@0: } sl@0: set l "" sl@0: variable x not_done sl@0: puts $f [list source $path(my_script)] sl@0: puts $f "set f \[[list open $path(bar) r]]" sl@0: puts $f {copy_slowly $f} sl@0: puts $f {exit} sl@0: vwait [namespace which -variable x] sl@0: close $f sl@0: list $x $l sl@0: } {done {0 1 0 1 0 1 0 1 0 1 0 1 0 0}} sl@0: test io-48.4 {lf write, testing readability, ^Z termination, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: variable c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable c sl@0: variable x sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.5 {lf write, testing readability, ^Z in middle, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: variable c sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.6 {cr write, testing readability, ^Z termination, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: variable c sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.7 {cr write, testing readability, ^Z in middle, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable c sl@0: variable x sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.8 {crlf write, testing readability, ^Z termination, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: variable c sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation auto -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.9 {crlf write, testing readability, ^Z in middle, auto read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable c sl@0: variable x sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation auto sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.10 {lf write, testing readability, ^Z in middle, lf read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable c sl@0: variable x sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation lf sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.11 {lf write, testing readability, ^Z termination, lf read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: set c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: variable c sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation lf -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.12 {cr write, testing readability, ^Z in middle, cr read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable l sl@0: variable x sl@0: variable c sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation cr sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.13 {cr write, testing readability, ^Z termination, cr read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation cr sl@0: set c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable c sl@0: variable x sl@0: variable l sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation cr -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.14 {crlf write, testing readability, ^Z in middle, crlf read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format "abc\ndef\n%cfoo\nbar\n" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable c sl@0: variable x sl@0: variable l sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -eofchar \x1a -translation crlf sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: test io-48.15 {crlf write, testing readability, ^Z termi, crlf read mode} {fileevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation crlf sl@0: set c [format "abc\ndef\n%c" 26] sl@0: puts -nonewline $f $c sl@0: close $f sl@0: proc consume {f} { sl@0: variable c sl@0: variable x sl@0: variable l sl@0: if {[eof $f]} { sl@0: set x done sl@0: close $f sl@0: } else { sl@0: lappend l [gets $f] sl@0: incr c sl@0: } sl@0: } sl@0: set c 0 sl@0: set l "" sl@0: set f [open $path(test1) r] sl@0: fconfigure $f -translation crlf -eofchar \x1a sl@0: fileevent $f readable [namespace code [list consume $f]] sl@0: variable x sl@0: vwait [namespace which -variable x] sl@0: list $c $l sl@0: } {3 {abc def {}}} sl@0: sl@0: test io-49.1 {testing crlf reading, leftover cr disgorgment} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\rb\rc\r\n" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 1] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: lappend l [read $f 1] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "7 a 1 [list \r] 2 b 3 [list \r] 4 c 5 { sl@0: } 7 0 {} 1" sl@0: test io-49.2 {testing crlf reading, leftover cr disgorgment} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\rb\rc\r\n" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: lappend l [read $f 2] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 2] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 2] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: lappend l [read $f 2] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "7 [list a\r] 2 [list b\r] 4 [list c\n] 7 0 {} 7 1" sl@0: test io-49.3 {testing crlf reading, leftover cr disgorgment} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\rb\rc\r\n" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: lappend l [read $f 3] sl@0: lappend l [tell $f] sl@0: lappend l [read $f 3] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: lappend l [read $f 3] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "7 [list a\rb] 3 [list \rc\n] 7 0 {} 7 1" sl@0: test io-49.4 {testing crlf reading, leftover cr disgorgment} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\rb\rc\r\n" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: lappend l [read $f 3] sl@0: lappend l [tell $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } "7 [list a\rb] 3 [list \rc] 7 0 {} 7 1" sl@0: test io-49.5 {testing crlf reading, leftover cr disgorgment} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts -nonewline $f "a\rb\rc\r\n" sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set l "" sl@0: lappend l [file size $path(test1)] sl@0: fconfigure $f -translation crlf sl@0: lappend l [set x [gets $f]] sl@0: lappend l [tell $f] sl@0: lappend l [gets $f] sl@0: lappend l [tell $f] sl@0: lappend l [eof $f] sl@0: close $f sl@0: set l sl@0: } [list 7 a\rb\rc 7 {} 7 1] sl@0: sl@0: testConstraint testchannelevent [llength [info commands testchannelevent]] sl@0: test io-50.1 {testing handler deletion} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list delhandler $f]] sl@0: proc delhandler {f} { sl@0: variable z sl@0: set z called sl@0: testchannelevent $f delete 0 sl@0: } sl@0: set z not_called sl@0: update sl@0: close $f sl@0: set z sl@0: } called sl@0: test io-50.2 {testing handler deletion with multiple handlers} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list delhandler $f 1]] sl@0: testchannelevent $f add readable [namespace code [list delhandler $f 0]] sl@0: proc delhandler {f i} { sl@0: variable z sl@0: lappend z "called delhandler $f $i" sl@0: testchannelevent $f delete 0 sl@0: } sl@0: set z "" sl@0: update sl@0: close $f sl@0: string compare [string tolower $z] \ sl@0: [list [list called delhandler $f 0] [list called delhandler $f 1]] sl@0: } 0 sl@0: test io-50.3 {testing handler deletion with multiple handlers} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list notcalled $f 1]] sl@0: testchannelevent $f add readable [namespace code [list delhandler $f 0]] sl@0: set z "" sl@0: proc notcalled {f i} { sl@0: variable z sl@0: lappend z "notcalled was called!! $f $i" sl@0: } sl@0: proc delhandler {f i} { sl@0: variable z sl@0: testchannelevent $f delete 1 sl@0: lappend z "delhandler $f $i called" sl@0: testchannelevent $f delete 0 sl@0: lappend z "delhandler $f $i deleted myself" sl@0: } sl@0: set z "" sl@0: update sl@0: close $f sl@0: string compare [string tolower $z] \ sl@0: [list [list delhandler $f 0 called] \ sl@0: [list delhandler $f 0 deleted myself]] sl@0: } 0 sl@0: test io-50.4 {testing handler deletion vs reentrant calls} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list delrecursive $f]] sl@0: proc delrecursive {f} { sl@0: variable z sl@0: variable u sl@0: if {"$u" == "recursive"} { sl@0: testchannelevent $f delete 0 sl@0: lappend z "delrecursive deleting recursive" sl@0: } else { sl@0: lappend z "delrecursive calling recursive" sl@0: set u recursive sl@0: update sl@0: } sl@0: } sl@0: set u toplevel sl@0: set z "" sl@0: update sl@0: close $f sl@0: string compare [string tolower $z] \ sl@0: {{delrecursive calling recursive} {delrecursive deleting recursive}} sl@0: } 0 sl@0: test io-50.5 {testing handler deletion vs reentrant calls} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list notcalled $f]] sl@0: testchannelevent $f add readable [namespace code [list del $f]] sl@0: proc notcalled {f} { sl@0: variable z sl@0: lappend z "notcalled was called!! $f" sl@0: } sl@0: proc del {f} { sl@0: variable u sl@0: variable z sl@0: if {"$u" == "recursive"} { sl@0: testchannelevent $f delete 1 sl@0: testchannelevent $f delete 0 sl@0: lappend z "del deleted notcalled" sl@0: lappend z "del deleted myself" sl@0: } else { sl@0: set u recursive sl@0: lappend z "del calling recursive" sl@0: update sl@0: lappend z "del after update" sl@0: } sl@0: } sl@0: set z "" sl@0: set u toplevel sl@0: update sl@0: close $f sl@0: string compare [string tolower $z] \ sl@0: [list {del calling recursive} {del deleted notcalled} \ sl@0: {del deleted myself} {del after update}] sl@0: } 0 sl@0: test io-50.6 {testing handler deletion vs reentrant calls} {testchannelevent} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: testchannelevent $f add readable [namespace code [list second $f]] sl@0: testchannelevent $f add readable [namespace code [list first $f]] sl@0: proc first {f} { sl@0: variable u sl@0: variable z sl@0: if {"$u" == "toplevel"} { sl@0: lappend z "first called" sl@0: set u first sl@0: update sl@0: lappend z "first after update" sl@0: } else { sl@0: lappend z "first called not toplevel" sl@0: } sl@0: } sl@0: proc second {f} { sl@0: variable u sl@0: variable z sl@0: if {"$u" == "first"} { sl@0: lappend z "second called, first time" sl@0: set u second sl@0: testchannelevent $f delete 0 sl@0: } elseif {"$u" == "second"} { sl@0: lappend z "second called, second time" sl@0: testchannelevent $f delete 0 sl@0: } else { sl@0: lappend z "second called, cannot happen!" sl@0: testchannelevent $f removeall sl@0: } sl@0: } sl@0: set z "" sl@0: set u toplevel sl@0: update sl@0: close $f sl@0: string compare [string tolower $z] \ sl@0: [list {first called} {first called not toplevel} \ sl@0: {second called, first time} {second called, second time} \ sl@0: {first after update}] sl@0: } 0 sl@0: sl@0: test io-51.1 {Test old socket deletion on Macintosh} {socket} { sl@0: set x 0 sl@0: set result "" sl@0: proc accept {s a p} { sl@0: variable x sl@0: variable wait sl@0: fconfigure $s -blocking off sl@0: puts $s "sock[incr x]" sl@0: close $s sl@0: set wait done sl@0: } sl@0: set ss [socket -server [namespace code accept] 0] sl@0: variable wait "" sl@0: set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]] sl@0: vwait [namespace which -variable wait] sl@0: lappend result [gets $cs] sl@0: close $cs sl@0: sl@0: set wait "" sl@0: set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]] sl@0: vwait [namespace which -variable wait] sl@0: lappend result [gets $cs] sl@0: close $cs sl@0: sl@0: set wait "" sl@0: set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]] sl@0: vwait [namespace which -variable wait] sl@0: lappend result [gets $cs] sl@0: close $cs sl@0: sl@0: set wait "" sl@0: set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]] sl@0: vwait [namespace which -variable wait] sl@0: lappend result [gets $cs] sl@0: close $cs sl@0: close $ss sl@0: set result sl@0: } {sock1 sock2 sock3 sock4} sl@0: sl@0: test io-52.1 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fcopy $f1 $f2 -command { # } sl@0: catch { fcopy $f1 $f2 } msg sl@0: close $f1 sl@0: close $f2 sl@0: string compare $msg "channel \"$f1\" is busy" sl@0: } {0} sl@0: test io-52.2 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: set f3 [open $thisScript] sl@0: fcopy $f1 $f2 -command { # } sl@0: catch { fcopy $f3 $f2 } msg sl@0: close $f1 sl@0: close $f2 sl@0: close $f3 sl@0: string compare $msg "channel \"$f2\" is busy" sl@0: } {0} sl@0: test io-52.3 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation cr -blocking 0 sl@0: set s0 [fcopy $f1 $f2] sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: close $f1 sl@0: close $f2 sl@0: set s1 [file size $thisScript] sl@0: set s2 [file size $path(test1)] sl@0: if {("$s1" == "$s2") && ($s0 == $s1)} { sl@0: lappend result ok sl@0: } sl@0: set result sl@0: } {0 0 ok} sl@0: test io-52.4 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation cr -blocking 0 sl@0: fcopy $f1 $f2 -size 40 sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: close $f1 sl@0: close $f2 sl@0: lappend result [file size $path(test1)] sl@0: } {0 0 40} sl@0: test io-52.5 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation lf -blocking 0 sl@0: fcopy $f1 $f2 -size -1 sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: close $f1 sl@0: close $f2 sl@0: set s1 [file size $thisScript] sl@0: set s2 [file size $path(test1)] sl@0: if {"$s1" == "$s2"} { sl@0: lappend result ok sl@0: } sl@0: set result sl@0: } {0 0 ok} sl@0: test io-52.6 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation lf -blocking 0 sl@0: set s0 [fcopy $f1 $f2 -size [expr [file size $thisScript] + 5]] sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: close $f1 sl@0: close $f2 sl@0: set s1 [file size $thisScript] sl@0: set s2 [file size $path(test1)] sl@0: if {("$s1" == "$s2") && ($s0 == $s1)} { sl@0: lappend result ok sl@0: } sl@0: set result sl@0: } {0 0 ok} sl@0: test io-52.7 {TclCopyChannel} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation lf -blocking 0 sl@0: fcopy $f1 $f2 sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: set s1 [file size $thisScript] sl@0: set s2 [file size $path(test1)] sl@0: close $f1 sl@0: close $f2 sl@0: if {"$s1" == "$s2"} { sl@0: lappend result ok sl@0: } sl@0: set result sl@0: } {0 0 ok} sl@0: test io-52.8 {TclCopyChannel} {stdio openpipe fcopy} { sl@0: file delete $path(test1) sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: fconfigure $f1 -translation lf sl@0: puts $f1 " sl@0: puts ready sl@0: gets stdin sl@0: set f1 \[open [list $thisScript] r\] sl@0: fconfigure \$f1 -translation lf sl@0: puts \[read \$f1 100\] sl@0: close \$f1 sl@0: " sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: fconfigure $f1 -translation lf sl@0: gets $f1 sl@0: puts $f1 ready sl@0: flush $f1 sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f2 -translation lf sl@0: set s0 [fcopy $f1 $f2 -size 40] sl@0: catch {close $f1} sl@0: close $f2 sl@0: list $s0 [file size $path(test1)] sl@0: } {40 40} sl@0: sl@0: # Empty files, to register them with the test facility sl@0: set path(kyrillic.txt) [makeFile {} kyrillic.txt] sl@0: set path(utf8-fcopy.txt) [makeFile {} utf8-fcopy.txt] sl@0: set path(utf8-rp.txt) [makeFile {} utf8-rp.txt] sl@0: sl@0: # Create kyrillic file, use lf translation to avoid os eol issues sl@0: set out [open $path(kyrillic.txt) w] sl@0: fconfigure $out -encoding koi8-r -translation lf sl@0: puts $out "\u0410\u0410" sl@0: close $out sl@0: sl@0: test io-52.9 {TclCopyChannel & encodings} {fcopy} { sl@0: # Copy kyrillic to UTF-8, using fcopy. sl@0: sl@0: set in [open $path(kyrillic.txt) r] sl@0: set out [open $path(utf8-fcopy.txt) w] sl@0: sl@0: fconfigure $in -encoding koi8-r -translation lf sl@0: fconfigure $out -encoding utf-8 -translation lf sl@0: sl@0: fcopy $in $out sl@0: close $in sl@0: close $out sl@0: sl@0: # Do the same again, but differently (read/puts). sl@0: sl@0: set in [open $path(kyrillic.txt) r] sl@0: set out [open $path(utf8-rp.txt) w] sl@0: sl@0: fconfigure $in -encoding koi8-r -translation lf sl@0: fconfigure $out -encoding utf-8 -translation lf sl@0: sl@0: puts -nonewline $out [read $in] sl@0: sl@0: close $in sl@0: close $out sl@0: sl@0: list [file size $path(kyrillic.txt)] \ sl@0: [file size $path(utf8-fcopy.txt)] \ sl@0: [file size $path(utf8-rp.txt)] sl@0: } {3 5 5} sl@0: sl@0: test io-52.10 {TclCopyChannel & encodings} {fcopy} { sl@0: # encoding to binary (=> implies that the sl@0: # internal utf-8 is written) sl@0: sl@0: set in [open $path(kyrillic.txt) r] sl@0: set out [open $path(utf8-fcopy.txt) w] sl@0: sl@0: fconfigure $in -encoding koi8-r -translation lf sl@0: # -translation binary is also -encoding binary sl@0: fconfigure $out -translation binary sl@0: sl@0: fcopy $in $out sl@0: close $in sl@0: close $out sl@0: sl@0: file size $path(utf8-fcopy.txt) sl@0: } 5 sl@0: sl@0: test io-52.11 {TclCopyChannel & encodings} {fcopy} { sl@0: # binary to encoding => the input has to be sl@0: # in utf-8 to make sense to the encoder sl@0: sl@0: set in [open $path(utf8-fcopy.txt) r] sl@0: set out [open $path(kyrillic.txt) w] sl@0: sl@0: # -translation binary is also -encoding binary sl@0: fconfigure $in -translation binary sl@0: fconfigure $out -encoding koi8-r -translation lf sl@0: sl@0: fcopy $in $out sl@0: close $in sl@0: close $out sl@0: sl@0: file size $path(kyrillic.txt) sl@0: } 3 sl@0: sl@0: test io-53.1 {CopyData} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation cr -blocking 0 sl@0: fcopy $f1 $f2 -size 0 sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: close $f1 sl@0: close $f2 sl@0: lappend result [file size $path(test1)] sl@0: } {0 0 0} sl@0: test io-53.2 {CopyData} {fcopy} { sl@0: file delete $path(test1) sl@0: set f1 [open $thisScript] sl@0: set f2 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -blocking 0 sl@0: fconfigure $f2 -translation cr -blocking 0 sl@0: fcopy $f1 $f2 -command [namespace code {set s0}] sl@0: set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]] sl@0: variable s0 sl@0: vwait [namespace which -variable s0] sl@0: close $f1 sl@0: close $f2 sl@0: set s1 [file size $thisScript] sl@0: set s2 [file size $path(test1)] sl@0: if {("$s1" == "$s2") && ($s0 == $s1)} { sl@0: lappend result ok sl@0: } sl@0: set result sl@0: } {0 0 ok} sl@0: test io-53.3 {CopyData: background read underflow} {stdio unixOnly openpipe fcopy} { sl@0: file delete $path(test1) sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts -nonewline $f1 { sl@0: puts ready sl@0: flush stdout ;# Don't assume line buffered! sl@0: fcopy stdin stdout -command { set x } sl@0: vwait x sl@0: set f [} sl@0: puts $f1 [list open $path(test1) w]] sl@0: puts $f1 { sl@0: fconfigure $f -translation lf sl@0: puts $f "done" sl@0: close $f sl@0: } sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: set result [gets $f1] sl@0: puts $f1 line1 sl@0: flush $f1 sl@0: lappend result [gets $f1] sl@0: puts $f1 line2 sl@0: flush $f1 sl@0: lappend result [gets $f1] sl@0: close $f1 sl@0: after 500 sl@0: set f [open $path(test1)] sl@0: lappend result [read $f] sl@0: close $f sl@0: set result sl@0: } "ready line1 line2 {done\n}" sl@0: test io-53.4 {CopyData: background write overflow} {stdio unixOnly openpipe fileevent fcopy} { sl@0: set big bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n sl@0: variable x sl@0: for {set x 0} {$x < 12} {incr x} { sl@0: append big $big sl@0: } sl@0: file delete $path(test1) sl@0: file delete $path(pipe) sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: puts ready sl@0: fcopy stdin stdout -command { set x } sl@0: vwait x sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf sl@0: puts $f "done" sl@0: close $f sl@0: } sl@0: close $f1 sl@0: set f1 [open "|[list [interpreter] $path(pipe)]" r+] sl@0: set result [gets $f1] sl@0: fconfigure $f1 -blocking 0 sl@0: puts $f1 $big sl@0: flush $f1 sl@0: after 500 sl@0: set result "" sl@0: fileevent $f1 read [namespace code { sl@0: append result [read $f1 1024] sl@0: if {[string length $result] >= [string length $big]} { sl@0: set x done sl@0: } sl@0: }] sl@0: vwait [namespace which -variable x] sl@0: close $f1 sl@0: set big {} sl@0: set x sl@0: } done sl@0: set result {} sl@0: sl@0: proc FcopyTestAccept {sock args} { sl@0: after 1000 "close $sock" sl@0: } sl@0: proc FcopyTestDone {bytes {error {}}} { sl@0: variable fcopyTestDone sl@0: if {[string length $error]} { sl@0: set fcopyTestDone 1 sl@0: } else { sl@0: set fcopyTestDone 0 sl@0: } sl@0: } sl@0: sl@0: test io-53.5 {CopyData: error during fcopy} {socket fcopy} { sl@0: variable fcopyTestDone sl@0: set listen [socket -server [namespace code FcopyTestAccept] 0] sl@0: set in [open $thisScript] ;# 126 K sl@0: set out [socket 127.0.0.1 [lindex [fconfigure $listen -sockname] 2]] sl@0: catch {unset fcopyTestDone} sl@0: close $listen ;# This means the socket open never really succeeds sl@0: fcopy $in $out -command [namespace code FcopyTestDone] sl@0: variable fcopyTestDone sl@0: if ![info exists fcopyTestDone] { sl@0: vwait [namespace which -variable fcopyTestDone] ;# The error occurs here in the b.g. sl@0: } sl@0: close $in sl@0: close $out sl@0: set fcopyTestDone ;# 1 for error condition sl@0: } 1 sl@0: test io-53.6 {CopyData: error during fcopy} {stdio openpipe fcopy} { sl@0: variable fcopyTestDone sl@0: file delete $path(pipe) sl@0: file delete $path(test1) sl@0: catch {unset fcopyTestDone} sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 "exit 1" sl@0: close $f1 sl@0: set in [open "|[list [interpreter] $path(pipe)]" r+] sl@0: set out [open $path(test1) w] sl@0: fcopy $in $out -command [namespace code FcopyTestDone] sl@0: variable fcopyTestDone sl@0: if ![info exists fcopyTestDone] { sl@0: vwait [namespace which -variable fcopyTestDone] sl@0: } sl@0: catch {close $in} sl@0: close $out sl@0: set fcopyTestDone ;# 0 for plain end of file sl@0: } {0} sl@0: sl@0: proc doFcopy {in out {bytes 0} {error {}}} { sl@0: variable fcopyTestDone sl@0: variable fcopyTestCount sl@0: incr fcopyTestCount $bytes sl@0: if {[string length $error]} { sl@0: set fcopyTestDone 1 sl@0: } elseif {[eof $in]} { sl@0: set fcopyTestDone 0 sl@0: } else { sl@0: # Delay next fcopy to wait for size>0 input bytes sl@0: after 100 [list sl@0: fcopy $in $out -size 1000 \ sl@0: -command [namespace code [list doFcopy $in $out]] sl@0: ] sl@0: } sl@0: } sl@0: sl@0: test io-53.7 {CopyData: Flooding fcopy from pipe} {stdio openpipe fcopy} { sl@0: variable fcopyTestDone sl@0: file delete $path(pipe) sl@0: catch {unset fcopyTestDone} sl@0: set fcopyTestCount 0 sl@0: set f1 [open $path(pipe) w] sl@0: puts $f1 { sl@0: # Write 10 bytes / 10 msec sl@0: proc Write {count} { sl@0: puts -nonewline "1234567890" sl@0: if {[incr count -1]} { sl@0: after 10 [list Write $count] sl@0: } else { sl@0: set ::ready 1 sl@0: } sl@0: } sl@0: fconfigure stdout -buffering none sl@0: Write 345 ;# 3450 bytes ~3.45 sec sl@0: vwait ready sl@0: exit 0 sl@0: } sl@0: close $f1 sl@0: set in [open "|[list [interpreter] $path(pipe) &]" r+] sl@0: set out [open $path(test1) w] sl@0: doFcopy $in $out sl@0: variable fcopyTestDone sl@0: if ![info exists fcopyTestDone] { sl@0: vwait [namespace which -variable fcopyTestDone] sl@0: } sl@0: catch {close $in} sl@0: close $out sl@0: # -1=error 0=script error N=number of bytes sl@0: expr ($fcopyTestDone == 0) ? $fcopyTestCount : -1 sl@0: } {3450} sl@0: sl@0: test io-54.1 {Recursive channel events} {socket fileevent} { sl@0: # This test checks to see if file events are delivered during recursive sl@0: # event loops when there is buffered data on the channel. sl@0: sl@0: proc accept {s a p} { sl@0: variable as sl@0: fconfigure $s -translation lf sl@0: puts $s "line 1\nline2\nline3" sl@0: flush $s sl@0: set as $s sl@0: } sl@0: proc readit {s next} { sl@0: variable x sl@0: variable result sl@0: lappend result $next sl@0: if {$next == 1} { sl@0: fileevent $s readable [namespace code [list readit $s 2]] sl@0: vwait [namespace which -variable x] sl@0: } sl@0: incr x sl@0: } sl@0: set ss [socket -server [namespace code accept] 0] sl@0: sl@0: # We need to delay on some systems until the creation of the sl@0: # server socket completes. sl@0: sl@0: set done 0 sl@0: for {set i 0} {$i < 10} {incr i} { sl@0: if {![catch {set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]}]} { sl@0: set done 1 sl@0: break sl@0: } sl@0: after 100 sl@0: } sl@0: if {$done == 0} { sl@0: close $ss sl@0: error "failed to connect to server" sl@0: } sl@0: variable result {} sl@0: variable x 0 sl@0: variable as sl@0: vwait [namespace which -variable as] sl@0: fconfigure $cs -translation lf sl@0: lappend result [gets $cs] sl@0: fconfigure $cs -blocking off sl@0: fileevent $cs readable [namespace code [list readit $cs 1]] sl@0: set a [after 2000 [namespace code { set x failure }]] sl@0: vwait [namespace which -variable x] sl@0: after cancel $a sl@0: close $as sl@0: close $ss sl@0: close $cs sl@0: list $result $x sl@0: } {{{line 1} 1 2} 2} sl@0: test io-54.2 {Testing for busy-wait in recursive channel events} {socket fileevent} { sl@0: set accept {} sl@0: set after {} sl@0: variable s [socket -server [namespace code accept] 0] sl@0: proc accept {s a p} { sl@0: variable counter sl@0: variable accept sl@0: sl@0: set accept $s sl@0: set counter 0 sl@0: fconfigure $s -blocking off -buffering line -translation lf sl@0: fileevent $s readable [namespace code "doit $s"] sl@0: } sl@0: proc doit {s} { sl@0: variable counter sl@0: variable after sl@0: sl@0: incr counter sl@0: set l [gets $s] sl@0: if {"$l" == ""} { sl@0: fileevent $s readable [namespace code "doit1 $s"] sl@0: set after [after 1000 [namespace code newline]] sl@0: } sl@0: } sl@0: proc doit1 {s} { sl@0: variable counter sl@0: variable accept sl@0: sl@0: incr counter sl@0: set l [gets $s] sl@0: close $s sl@0: set accept {} sl@0: } sl@0: proc producer {} { sl@0: variable s sl@0: variable writer sl@0: sl@0: set writer [socket 127.0.0.1 [lindex [fconfigure $s -sockname] 2]] sl@0: fconfigure $writer -buffering line sl@0: puts -nonewline $writer hello sl@0: flush $writer sl@0: } sl@0: proc newline {} { sl@0: variable done sl@0: variable writer sl@0: sl@0: puts $writer hello sl@0: flush $writer sl@0: set done 1 sl@0: } sl@0: producer sl@0: variable done sl@0: vwait [namespace which -variable done] sl@0: close $writer sl@0: close $s sl@0: after cancel $after sl@0: if {$accept != {}} {close $accept} sl@0: set counter sl@0: } 1 sl@0: sl@0: set path(fooBar) [makeFile {} fooBar] sl@0: sl@0: test io-55.1 {ChannelEventScriptInvoker: deletion} {fileevent} { sl@0: variable x sl@0: proc eventScript {fd} { sl@0: variable x sl@0: close $fd sl@0: error "planned error" sl@0: set x whoops sl@0: } sl@0: proc ::bgerror {args} "set [namespace which -variable x] got_error" sl@0: set f [open $path(fooBar) w] sl@0: fileevent $f writable [namespace code [list eventScript $f]] sl@0: variable x not_done sl@0: vwait [namespace which -variable x] sl@0: set x sl@0: } {got_error} sl@0: sl@0: test io-56.1 {ChannelTimerProc} {testchannelevent} { sl@0: set f [open $path(fooBar) w] sl@0: puts $f "this is a test" sl@0: close $f sl@0: set f [open $path(fooBar) r] sl@0: testchannelevent $f add readable [namespace code { sl@0: read $f 1 sl@0: incr x sl@0: }] sl@0: variable x 0 sl@0: vwait [namespace which -variable x] sl@0: vwait [namespace which -variable x] sl@0: set result $x sl@0: testchannelevent $f set 0 none sl@0: after idle [namespace code {set y done}] sl@0: variable y sl@0: vwait [namespace which -variable y] sl@0: close $f sl@0: lappend result $y sl@0: } {2 done} sl@0: sl@0: test io-57.1 {buffered data and file events, gets} {fileevent} { sl@0: proc accept {sock args} { sl@0: variable s2 sl@0: set s2 $sock sl@0: } sl@0: set server [socket -server [namespace code accept] 0] sl@0: set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]] sl@0: variable s2 sl@0: vwait [namespace which -variable s2] sl@0: update sl@0: fileevent $s2 readable [namespace code {lappend result readable}] sl@0: puts $s "12\n34567890" sl@0: flush $s sl@0: variable result [gets $s2] sl@0: after 1000 [namespace code {lappend result timer}] sl@0: vwait [namespace which -variable result] sl@0: lappend result [gets $s2] sl@0: vwait [namespace which -variable result] sl@0: close $s sl@0: close $s2 sl@0: close $server sl@0: set result sl@0: } {12 readable 34567890 timer} sl@0: test io-57.2 {buffered data and file events, read} {fileevent} { sl@0: proc accept {sock args} { sl@0: variable s2 sl@0: set s2 $sock sl@0: } sl@0: set server [socket -server [namespace code accept] 0] sl@0: set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]] sl@0: variable s2 sl@0: vwait [namespace which -variable s2] sl@0: update sl@0: fileevent $s2 readable [namespace code {lappend result readable}] sl@0: puts -nonewline $s "1234567890" sl@0: flush $s sl@0: variable result [read $s2 1] sl@0: after 1000 [namespace code {lappend result timer}] sl@0: vwait [namespace which -variable result] sl@0: lappend result [read $s2 9] sl@0: vwait [namespace which -variable result] sl@0: close $s sl@0: close $s2 sl@0: close $server sl@0: set result sl@0: } {1 readable 234567890 timer} sl@0: sl@0: test io-58.1 {Tcl_NotifyChannel and error when closing} {stdio unixOrPc openpipe fileevent} { sl@0: set out [open $path(script) w] sl@0: puts $out { sl@0: puts "normal message from pipe" sl@0: puts stderr "error message from pipe" sl@0: exit 1 sl@0: } sl@0: proc readit {pipe} { sl@0: variable x sl@0: variable result sl@0: if {[eof $pipe]} { sl@0: set x [catch {close $pipe} line] sl@0: lappend result catch $line sl@0: } else { sl@0: gets $pipe line sl@0: lappend result gets $line sl@0: } sl@0: } sl@0: close $out sl@0: set pipe [open "|[list [interpreter] $path(script)]" r] sl@0: fileevent $pipe readable [namespace code [list readit $pipe]] sl@0: variable x "" sl@0: set result "" sl@0: vwait [namespace which -variable x] sl@0: list $x $result sl@0: } {1 {gets {normal message from pipe} gets {} catch {error message from pipe}}} sl@0: sl@0: sl@0: testConstraint testmainthread [llength [info commands testmainthread]] sl@0: test io-59.1 {Thread reference of channels} {testmainthread testchannel} { sl@0: # TIP #10 sl@0: # More complicated tests (like that the reference changes as a sl@0: # channel is moved from thread to thread) can be done only in the sl@0: # extension which fully implements the moving of channels between sl@0: # threads, i.e. 'Threads'. Or we have to extend [testthread] as well. sl@0: sl@0: set f [open $path(longfile) r] sl@0: set result [testchannel mthread $f] sl@0: close $f sl@0: string equal $result [testmainthread] sl@0: } {1} sl@0: sl@0: sl@0: test io-60.1 {writing illegal utf sequences} {openpipe fileevent} { sl@0: # This test will hang in older revisions of the core. sl@0: sl@0: set out [open $path(script) w] sl@0: puts $out { sl@0: puts [encoding convertfrom identity \xe2] sl@0: exit 1 sl@0: } sl@0: proc readit {pipe} { sl@0: variable x sl@0: variable result sl@0: if {[eof $pipe]} { sl@0: set x [catch {close $pipe} line] sl@0: lappend result catch $line sl@0: } else { sl@0: gets $pipe line sl@0: lappend result gets $line sl@0: } sl@0: } sl@0: close $out sl@0: set pipe [open "|[list [interpreter] $path(script)]" r] sl@0: fileevent $pipe readable [namespace code [list readit $pipe]] sl@0: variable x "" sl@0: set result "" sl@0: vwait [namespace which -variable x] sl@0: sl@0: # cut of the remainder of the error stack, especially the filename sl@0: set result [lreplace $result 3 3 [lindex [split [lindex $result 3] \n] 0]] sl@0: list $x $result sl@0: } {1 {gets {} catch {error writing "stdout": invalid argument}}} sl@0: sl@0: test io-61.1 {Reset eof state after changing the eof char} -setup { sl@0: set datafile [makeFile {} eofchar] sl@0: set f [open $datafile w] sl@0: fconfigure $f -translation binary sl@0: puts -nonewline $f [string repeat "Ho hum\n" 11] sl@0: puts $f = sl@0: set line [string repeat "Ge gla " 4] sl@0: puts -nonewline $f [string repeat [string trimright $line]\n 834] sl@0: close $f sl@0: } -body { sl@0: set f [open $datafile r] sl@0: fconfigure $f -eofchar = sl@0: set res {} sl@0: lappend res [read $f; tell $f] sl@0: fconfigure $f -eofchar {} sl@0: lappend res [read $f 1] sl@0: lappend res [read $f; tell $f] sl@0: # Any seek zaps the internals into a good state. sl@0: #seek $f 0 start sl@0: #seek $f 0 current sl@0: #lappend res [read $f; tell $f] sl@0: close $f sl@0: set res sl@0: } -cleanup { sl@0: removeFile eofchar sl@0: } -result {77 = 23431} sl@0: sl@0: # cleanup sl@0: foreach file [list fooBar longfile script output test1 pipe my_script foo \ sl@0: bar test2 test3 cat stdout kyrillic.txt utf8-fcopy.txt utf8-rp.txt] { sl@0: removeFile $file sl@0: } sl@0: cleanupTests sl@0: } sl@0: namespace delete ::tcl::test::io sl@0: return