os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/io.test
Update contrib.
2 # Functionality covered: operation of all IO commands, and all procedures
3 # defined in generic/tclIO.c.
5 # This file contains a collection of tests for one or more of the Tcl
6 # built-in commands. Sourcing this file into Tcl runs the tests and
7 # generates output for errors. No output means no errors were found.
9 # Copyright (c) 1991-1994 The Regents of the University of California.
10 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # RCS: @(#) $Id: io.test,v 1.40.2.12 2007/02/12 19:25:42 andreas_kupries Exp $
18 if {[catch {package require tcltest 2}]} {
19 puts stderr "Skipping tests in [info script]. tcltest 2 required."
22 namespace eval ::tcl::test::io {
24 namespace import ::tcltest::cleanupTests
25 namespace import ::tcltest::interpreter
26 namespace import ::tcltest::makeFile
27 namespace import ::tcltest::removeFile
28 namespace import ::tcltest::test
29 namespace import ::tcltest::testConstraint
30 namespace import ::tcltest::viewFile
32 testConstraint testchannel [llength [info commands testchannel]]
33 testConstraint exec [llength [info commands exec]]
34 testConstraint openpipe 1
35 testConstraint fileevent [llength [info commands fileevent]]
36 testConstraint fcopy [llength [info commands fcopy]]
38 # You need a *very* special environment to do some tests. In
39 # particular, many file systems do not support large-files...
40 testConstraint largefileSupport 0
42 # set up a long data file for some of the following tests
44 set path(longfile) [makeFile {} longfile]
45 set f [open $path(longfile) w]
46 fconfigure $f -eofchar {} -translation lf
47 for { set i 0 } { $i < 100 } { incr i} {
48 puts $f "#123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
54 set path(cat) [makeFile {
57 set f [open [lindex $argv 0]]
59 fconfigure $f -encoding binary -translation lf -blocking 0 -eofchar \x1a
60 fconfigure stdout -encoding binary -translation lf -buffering none
61 fileevent $f readable "foo $f"
64 catch {puts -nonewline $x}
73 set thisScript [file join [pwd] [info script]]
75 proc contents {file} {
77 fconfigure $f -translation binary
83 test io-1.5 {Tcl_WriteChars: CheckChannelErrors} {emptyTest} {
84 # no test, need to cause an async error.
87 set path(test1) [makeFile {} test1]
89 test io-1.6 {Tcl_WriteChars: WriteBytes} {
90 set f [open $path(test1) w]
91 fconfigure $f -encoding binary
92 puts -nonewline $f "a\u4e4d\0"
96 test io-1.7 {Tcl_WriteChars: WriteChars} {
97 set f [open $path(test1) w]
98 fconfigure $f -encoding shiftjis
99 puts -nonewline $f "a\u4e4d\0"
101 contents $path(test1)
104 set path(test2) [makeFile {} test2]
106 test io-1.8 {Tcl_WriteChars: WriteChars} {
107 # This test written for SF bug #506297.
109 # Executing this test without the fix for the referenced bug
110 # applied to tcl will cause tcl, more specifically WriteChars, to
111 # go into an infinite loop.
113 set f [open $path(test2) w]
114 fconfigure $f -encoding iso2022-jp
115 puts -nonewline $f [format %s%c [string repeat " " 4] 12399]
117 contents $path(test2)
118 } " \x1b\$B\$O\x1b(B"
120 test io-1.9 {Tcl_WriteChars: WriteChars} {
121 # When closing a channel with an encoding that appends
122 # escape bytes, check for the case where the escape
123 # bytes overflow the current IO buffer. The bytes
124 # should be moved into a new buffer.
126 set data "1234567890 [format %c 12399]"
130 # With default buffer size
131 set f [open $path(test2) w]
132 fconfigure $f -encoding iso2022-jp
133 puts -nonewline $f $data
135 lappend sizes [file size $path(test2)]
137 # With buffer size equal to the length
138 # of the data, the escape bytes would
139 # go into the next buffer.
141 set f [open $path(test2) w]
142 fconfigure $f -encoding iso2022-jp -buffersize 16
143 puts -nonewline $f $data
145 lappend sizes [file size $path(test2)]
147 # With buffer size that is large enough
148 # to hold 1 byte of escaped data, but
149 # not all 3. This should not write
150 # the escape bytes to the first buffer
151 # and then again to the second buffer.
153 set f [open $path(test2) w]
154 fconfigure $f -encoding iso2022-jp -buffersize 17
155 puts -nonewline $f $data
157 lappend sizes [file size $path(test2)]
159 # With buffer size that can hold 2 out of
160 # 3 bytes of escaped data.
162 set f [open $path(test2) w]
163 fconfigure $f -encoding iso2022-jp -buffersize 18
164 puts -nonewline $f $data
166 lappend sizes [file size $path(test2)]
168 # With buffer size that can hold all the
169 # data and escape bytes.
171 set f [open $path(test2) w]
172 fconfigure $f -encoding iso2022-jp -buffersize 19
173 puts -nonewline $f $data
175 lappend sizes [file size $path(test2)]
180 test io-2.1 {WriteBytes} {
181 # loop until all bytes are written
183 set f [open $path(test1) w]
184 fconfigure $f -encoding binary -buffersize 16 -translation crlf
185 puts $f "abcdefghijklmnopqrstuvwxyz"
187 contents $path(test1)
188 } "abcdefghijklmnopqrstuvwxyz\r\n"
189 test io-2.2 {WriteBytes: savedLF > 0} {
190 # After flushing buffer, there was a \n left over from the last
191 # \n -> \r\n expansion. It gets stuck at beginning of this buffer.
193 set f [open $path(test1) w]
194 fconfigure $f -encoding binary -buffersize 16 -translation crlf
195 puts -nonewline $f "123456789012345\n12"
196 set x [list [contents $path(test1)]]
198 lappend x [contents $path(test1)]
199 } [list "123456789012345\r" "123456789012345\r\n12"]
200 test io-2.3 {WriteBytes: flush on line} {
201 # Tcl "line" buffering has weird behavior: if current buffer contains
202 # a \n, entire buffer gets flushed. Logical behavior would be to flush
205 set f [open $path(test1) w]
206 fconfigure $f -encoding binary -buffering line -translation crlf
207 puts -nonewline $f "\n12"
208 set x [contents $path(test1)]
212 test io-2.4 {WriteBytes: reset sawLF after each buffer} {
213 set f [open $path(test1) w]
214 fconfigure $f -encoding binary -buffering line -translation lf \
216 puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz"
217 set x [list [contents $path(test1)]]
219 lappend x [contents $path(test1)]
220 } [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"]
222 test io-3.1 {WriteChars: compatibility with WriteBytes} {
223 # loop until all bytes are written
225 set f [open $path(test1) w]
226 fconfigure $f -encoding ascii -buffersize 16 -translation crlf
227 puts $f "abcdefghijklmnopqrstuvwxyz"
229 contents $path(test1)
230 } "abcdefghijklmnopqrstuvwxyz\r\n"
231 test io-3.2 {WriteChars: compatibility with WriteBytes: savedLF > 0} {
232 # After flushing buffer, there was a \n left over from the last
233 # \n -> \r\n expansion. It gets stuck at beginning of this buffer.
235 set f [open $path(test1) w]
236 fconfigure $f -encoding ascii -buffersize 16 -translation crlf
237 puts -nonewline $f "123456789012345\n12"
238 set x [list [contents $path(test1)]]
240 lappend x [contents $path(test1)]
241 } [list "123456789012345\r" "123456789012345\r\n12"]
242 test io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} {
243 # Tcl "line" buffering has weird behavior: if current buffer contains
244 # a \n, entire buffer gets flushed. Logical behavior would be to flush
247 set f [open $path(test1) w]
248 fconfigure $f -encoding ascii -buffering line -translation crlf
249 puts -nonewline $f "\n12"
250 set x [contents $path(test1)]
254 test io-3.4 {WriteChars: loop over stage buffer} {
255 # stage buffer maps to more than can be queued at once.
257 set f [open $path(test1) w]
258 fconfigure $f -encoding jis0208 -buffersize 16
259 puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
260 set x [list [contents $path(test1)]]
262 lappend x [contents $path(test1)]
263 } [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"]
264 test io-3.5 {WriteChars: saved != 0} {
265 # Bytes produced by UtfToExternal from end of last channel buffer
266 # had to be moved to beginning of next channel buffer to preserve
267 # requested buffersize.
269 set f [open $path(test1) w]
270 fconfigure $f -encoding jis0208 -buffersize 17
271 puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
272 set x [list [contents $path(test1)]]
274 lappend x [contents $path(test1)]
275 } [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"]
276 test io-3.6 {WriteChars: (stageRead + dstWrote == 0)} {
277 # One incomplete UTF-8 character at end of staging buffer. Backup
278 # in src to the beginning of that UTF-8 character and try again.
280 # Translate the first 16 bytes, produce 14 bytes of output, 2 left over
281 # (first two bytes of \uff21 in UTF-8). Given those two bytes try
282 # translating them again, find that no bytes are read produced, and break
283 # to outer loop where those two bytes will have the remaining 4 bytes
284 # (the last byte of \uff21 plus the all of \uff22) appended.
286 set f [open $path(test1) w]
287 fconfigure $f -encoding shiftjis -buffersize 16
288 puts -nonewline $f "12345678901234\uff21\uff22"
289 set x [list [contents $path(test1)]]
291 lappend x [contents $path(test1)]
292 } [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"]
293 test io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} {
294 # When translating UTF-8 to external, the produced bytes went past end
295 # of the channel buffer. This is done purpose -- we then truncate the
296 # bytes at the end of the partial character to preserve the requested
297 # blocksize on flush. The truncated bytes are moved to the beginning
298 # of the next channel buffer.
300 set f [open $path(test1) w]
301 fconfigure $f -encoding jis0208 -buffersize 17
302 puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
303 set x [list [contents $path(test1)]]
305 lappend x [contents $path(test1)]
306 } [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"]
307 test io-3.8 {WriteChars: reset sawLF after each buffer} {
308 set f [open $path(test1) w]
309 fconfigure $f -encoding ascii -buffering line -translation lf \
311 puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz"
312 set x [list [contents $path(test1)]]
314 lappend x [contents $path(test1)]
315 } [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"]
317 test io-4.1 {TranslateOutputEOL: lf} {
320 set f [open $path(test1) w]
321 fconfigure $f -buffering line -translation lf
323 set x [list [contents $path(test1)]]
325 lappend x [contents $path(test1)]
326 } [list "abcde\n" "abcde\n"]
327 test io-4.2 {TranslateOutputEOL: cr} {
328 # search for \n, replace with \r
330 set f [open $path(test1) w]
331 fconfigure $f -buffering line -translation cr
333 set x [list [contents $path(test1)]]
335 lappend x [contents $path(test1)]
336 } [list "abcde\r" "abcde\r"]
337 test io-4.3 {TranslateOutputEOL: crlf} {
338 # simple case: search for \n, replace with \r
340 set f [open $path(test1) w]
341 fconfigure $f -buffering line -translation crlf
343 set x [list [contents $path(test1)]]
345 lappend x [contents $path(test1)]
346 } [list "abcde\r\n" "abcde\r\n"]
347 test io-4.4 {TranslateOutputEOL: crlf} {
348 # keep storing more bytes in output buffer until output buffer is full.
349 # We have 13 bytes initially that would turn into 18 bytes. Fill
350 # dest buffer while (dstEnd < dstMax).
352 set f [open $path(test1) w]
353 fconfigure $f -translation crlf -buffersize 16
354 puts -nonewline $f "1234567\n\n\n\n\nA"
355 set x [list [contents $path(test1)]]
357 lappend x [contents $path(test1)]
358 } [list "1234567\r\n\r\n\r\n\r\n\r" "1234567\r\n\r\n\r\n\r\n\r\nA"]
359 test io-4.5 {TranslateOutputEOL: crlf} {
360 # Check for overflow of the destination buffer
362 set f [open $path(test1) w]
363 fconfigure $f -translation crlf -buffersize 12
364 puts -nonewline $f "12345678901\n456789012345678901234"
366 set x [contents $path(test1)]
367 } "12345678901\r\n456789012345678901234"
369 test io-5.1 {CheckFlush: not full} {
370 set f [open $path(test1) w]
372 puts -nonewline $f "12345678901234567890"
373 set x [list [contents $path(test1)]]
375 lappend x [contents $path(test1)]
376 } [list "" "12345678901234567890"]
377 test io-5.2 {CheckFlush: full} {
378 set f [open $path(test1) w]
379 fconfigure $f -buffersize 16
380 puts -nonewline $f "12345678901234567890"
381 set x [list [contents $path(test1)]]
383 lappend x [contents $path(test1)]
384 } [list "1234567890123456" "12345678901234567890"]
385 test io-5.3 {CheckFlush: not line} {
386 set f [open $path(test1) w]
387 fconfigure $f -buffering line
388 puts -nonewline $f "12345678901234567890"
389 set x [list [contents $path(test1)]]
391 lappend x [contents $path(test1)]
392 } [list "" "12345678901234567890"]
393 test io-5.4 {CheckFlush: line} {
394 set f [open $path(test1) w]
395 fconfigure $f -buffering line -translation lf -encoding ascii
396 puts -nonewline $f "1234567890\n1234567890"
397 set x [list [contents $path(test1)]]
399 lappend x [contents $path(test1)]
400 } [list "1234567890\n1234567890" "1234567890\n1234567890"]
401 test io-5.5 {CheckFlush: none} {
402 set f [open $path(test1) w]
403 fconfigure $f -buffering none
404 puts -nonewline $f "1234567890"
405 set x [list [contents $path(test1)]]
407 lappend x [contents $path(test1)]
408 } [list "1234567890" "1234567890"]
410 test io-6.1 {Tcl_GetsObj: working} {
411 set f [open $path(test1) w]
414 set f [open $path(test1)]
419 test io-6.2 {Tcl_GetsObj: CheckChannelErrors() != 0} {
420 # no test, need to cause an async error.
422 test io-6.3 {Tcl_GetsObj: how many have we used?} {
423 # if (bufPtr != NULL) {oldRemoved = bufPtr->nextRemoved}
425 set f [open $path(test1) w]
426 fconfigure $f -translation crlf
429 set f [open $path(test1)]
430 set x [list [tell $f] [gets $f line] [tell $f] [gets $f line] $line]
434 test io-6.4 {Tcl_GetsObj: encoding == NULL} {
435 set f [open $path(test1) w]
436 fconfigure $f -translation binary
437 puts $f "\x81\u1234\0"
439 set f [open $path(test1)]
440 fconfigure $f -translation binary
441 set x [list [gets $f line] $line]
444 } [list 3 "\x81\x34\x00"]
445 test io-6.5 {Tcl_GetsObj: encoding != NULL} {
446 set f [open $path(test1) w]
447 fconfigure $f -translation binary
448 puts $f "\x88\xea\x92\x9a"
450 set f [open $path(test1)]
451 fconfigure $f -encoding shiftjis
452 set x [list [gets $f line] $line]
455 } [list 2 "\u4e00\u4e01"]
456 set a "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
459 test io-6.6 {Tcl_GetsObj: loop test} {
462 set f [open $path(test1) w]
466 set f [open $path(test1)]
467 set x [list [gets $f line] $line]
471 test io-6.7 {Tcl_GetsObj: error in input} {stdio openpipe} {
472 # if (FilterInputBytes(chanPtr, &gs) != 0)
474 set f [open "|[list [interpreter] $path(cat)]" w+]
475 puts -nonewline $f "hi\nwould"
478 fconfigure $f -blocking 0
483 test io-6.8 {Tcl_GetsObj: remember if EOF is seen} {
484 set f [open $path(test1) w]
485 puts $f "abcdef\x1aghijk\nwombat"
487 set f [open $path(test1)]
488 fconfigure $f -eofchar \x1a
489 set x [list [gets $f line] $line [gets $f line] $line]
493 test io-6.9 {Tcl_GetsObj: remember if EOF is seen} {
494 set f [open $path(test1) w]
495 puts $f "abcdefghijk\nwom\u001abat"
497 set f [open $path(test1)]
498 fconfigure $f -eofchar \x1a
499 set x [list [gets $f line] $line [gets $f line] $line]
502 } {11 abcdefghijk 3 wom}
504 # Comprehensive tests
506 test io-6.10 {Tcl_GetsObj: lf mode: no chars} {
507 set f [open $path(test1) w]
509 set f [open $path(test1)]
510 fconfigure $f -translation lf
511 set x [list [gets $f line] $line]
515 test io-6.11 {Tcl_GetsObj: lf mode: lone \n} {
516 set f [open $path(test1) w]
517 fconfigure $f -translation lf
518 puts -nonewline $f "\n"
520 set f [open $path(test1)]
521 fconfigure $f -translation lf
522 set x [list [gets $f line] $line [gets $f line] $line]
526 test io-6.12 {Tcl_GetsObj: lf mode: lone \r} {
527 set f [open $path(test1) w]
528 fconfigure $f -translation lf
529 puts -nonewline $f "\r"
531 set f [open $path(test1)]
532 fconfigure $f -translation lf
533 set x [list [gets $f line] $line [gets $f line] $line]
536 } [list 1 "\r" -1 ""]
537 test io-6.13 {Tcl_GetsObj: lf mode: 1 char} {
538 set f [open $path(test1) w]
539 fconfigure $f -translation lf
542 set f [open $path(test1)]
543 fconfigure $f -translation lf
544 set x [list [gets $f line] $line [gets $f line] $line]
548 test io-6.14 {Tcl_GetsObj: lf mode: 1 char followed by EOL} {
549 set f [open $path(test1) w]
550 fconfigure $f -translation lf
551 puts -nonewline $f "a\n"
553 set f [open $path(test1)]
554 fconfigure $f -translation lf
555 set x [list [gets $f line] $line [gets $f line] $line]
559 test io-6.15 {Tcl_GetsObj: lf mode: several chars} {
560 set f [open $path(test1) w]
561 fconfigure $f -translation lf
562 puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop"
564 set f [open $path(test1)]
565 fconfigure $f -translation lf
566 set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line [gets $f line] $line]
569 } [list 4 "abcd" 10 "efgh\rijkl\r" 4 "mnop" -1 ""]
570 test io-6.16 {Tcl_GetsObj: cr mode: no chars} {
571 set f [open $path(test1) w]
573 set f [open $path(test1)]
574 fconfigure $f -translation cr
575 set x [list [gets $f line] $line]
579 test io-6.17 {Tcl_GetsObj: cr mode: lone \n} {
580 set f [open $path(test1) w]
581 fconfigure $f -translation lf
582 puts -nonewline $f "\n"
584 set f [open $path(test1)]
585 fconfigure $f -translation cr
586 set x [list [gets $f line] $line [gets $f line] $line]
589 } [list 1 "\n" -1 ""]
590 test io-6.18 {Tcl_GetsObj: cr mode: lone \r} {
591 set f [open $path(test1) w]
592 fconfigure $f -translation lf
593 puts -nonewline $f "\r"
595 set f [open $path(test1)]
596 fconfigure $f -translation cr
597 set x [list [gets $f line] $line [gets $f line] $line]
601 test io-6.19 {Tcl_GetsObj: cr mode: 1 char} {
602 set f [open $path(test1) w]
603 fconfigure $f -translation lf
606 set f [open $path(test1)]
607 fconfigure $f -translation cr
608 set x [list [gets $f line] $line [gets $f line] $line]
612 test io-6.20 {Tcl_GetsObj: cr mode: 1 char followed by EOL} {
613 set f [open $path(test1) w]
614 fconfigure $f -translation lf
615 puts -nonewline $f "a\r"
617 set f [open $path(test1)]
618 fconfigure $f -translation cr
619 set x [list [gets $f line] $line [gets $f line] $line]
623 test io-6.21 {Tcl_GetsObj: cr mode: several chars} {
624 set f [open $path(test1) w]
625 fconfigure $f -translation lf
626 puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop"
628 set f [open $path(test1)]
629 fconfigure $f -translation cr
630 set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line [gets $f line] $line]
633 } [list 9 "abcd\nefgh" 4 "ijkl" 5 "\nmnop" -1 ""]
634 test io-6.22 {Tcl_GetsObj: crlf mode: no chars} {
635 set f [open $path(test1) w]
637 set f [open $path(test1)]
638 fconfigure $f -translation crlf
639 set x [list [gets $f line] $line]
643 test io-6.23 {Tcl_GetsObj: crlf mode: lone \n} {
644 set f [open $path(test1) w]
645 fconfigure $f -translation lf
646 puts -nonewline $f "\n"
648 set f [open $path(test1)]
649 fconfigure $f -translation crlf
650 set x [list [gets $f line] $line [gets $f line] $line]
653 } [list 1 "\n" -1 ""]
654 test io-6.24 {Tcl_GetsObj: crlf mode: lone \r} {
655 set f [open $path(test1) w]
656 fconfigure $f -translation lf
657 puts -nonewline $f "\r"
659 set f [open $path(test1)]
660 fconfigure $f -translation crlf
661 set x [list [gets $f line] $line [gets $f line] $line]
664 } [list 1 "\r" -1 ""]
665 test io-6.25 {Tcl_GetsObj: crlf mode: \r\r} {
666 set f [open $path(test1) w]
667 fconfigure $f -translation lf
668 puts -nonewline $f "\r\r"
670 set f [open $path(test1)]
671 fconfigure $f -translation crlf
672 set x [list [gets $f line] $line [gets $f line] $line]
675 } [list 2 "\r\r" -1 ""]
676 test io-6.26 {Tcl_GetsObj: crlf mode: \r\n} {
677 set f [open $path(test1) w]
678 fconfigure $f -translation lf
679 puts -nonewline $f "\r\n"
681 set f [open $path(test1)]
682 fconfigure $f -translation crlf
683 set x [list [gets $f line] $line [gets $f line] $line]
687 test io-6.27 {Tcl_GetsObj: crlf mode: 1 char} {
688 set f [open $path(test1) w]
689 fconfigure $f -translation lf
692 set f [open $path(test1)]
693 fconfigure $f -translation crlf
694 set x [list [gets $f line] $line [gets $f line] $line]
698 test io-6.28 {Tcl_GetsObj: crlf mode: 1 char followed by EOL} {
699 set f [open $path(test1) w]
700 fconfigure $f -translation lf
701 puts -nonewline $f "a\r\n"
703 set f [open $path(test1)]
704 fconfigure $f -translation crlf
705 set x [list [gets $f line] $line [gets $f line] $line]
709 test io-6.29 {Tcl_GetsObj: crlf mode: several chars} {
710 set f [open $path(test1) w]
711 fconfigure $f -translation lf
712 puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop"
714 set f [open $path(test1)]
715 fconfigure $f -translation crlf
716 set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line]
719 } [list 14 "abcd\nefgh\rijkl" 4 "mnop" -1 ""]
720 test io-6.30 {Tcl_GetsObj: crlf mode: buffer exhausted} {testchannel} {
723 set f [open $path(test1) w]
724 fconfigure $f -translation lf
725 puts -nonewline $f "123456789012345\r\nabcdefghijklmnoprstuvwxyz"
727 set f [open $path(test1)]
728 fconfigure $f -translation crlf -buffersize 16
729 set x [list [gets $f line] $line [testchannel inputbuffered $f]]
732 } [list 15 "123456789012345" 15]
733 test io-6.31 {Tcl_GetsObj: crlf mode: buffer exhausted, blocked} {stdio testchannel openpipe fileevent} {
734 # (FilterInputBytes() != 0)
736 set f [open "|[list [interpreter] $path(cat)]" w+]
737 fconfigure $f -translation {crlf lf} -buffering none
738 puts -nonewline $f "bbbbbbbbbbbbbb\r\n123456789012345\r"
739 fconfigure $f -buffersize 16
741 fconfigure $f -blocking 0
742 lappend x [gets $f line] $line [fblocked $f] [testchannel inputbuffered $f]
745 } [list "bbbbbbbbbbbbbb" -1 "" 1 16]
746 test io-6.32 {Tcl_GetsObj: crlf mode: buffer exhausted, more data} {testchannel} {
747 # not (FilterInputBytes() != 0)
749 set f [open $path(test1) w]
750 fconfigure $f -translation lf
751 puts -nonewline $f "123456789012345\r\n123"
753 set f [open $path(test1)]
754 fconfigure $f -translation crlf -buffersize 16
755 set x [list [gets $f line] $line [tell $f] [testchannel inputbuffered $f]]
758 } [list 15 "123456789012345" 17 3]
759 test io-6.33 {Tcl_GetsObj: crlf mode: buffer exhausted, at eof} {
760 # eol still equals dstEnd
762 set f [open $path(test1) w]
763 fconfigure $f -translation lf
764 puts -nonewline $f "123456789012345\r"
766 set f [open $path(test1)]
767 fconfigure $f -translation crlf -buffersize 16
768 set x [list [gets $f line] $line [eof $f]]
771 } [list 16 "123456789012345\r" 1]
772 test io-6.34 {Tcl_GetsObj: crlf mode: buffer exhausted, not followed by \n} {
775 set f [open $path(test1) w]
776 fconfigure $f -translation lf
777 puts -nonewline $f "123456789012345\rabcd\r\nefg"
779 set f [open $path(test1)]
780 fconfigure $f -translation crlf -buffersize 16
781 set x [list [gets $f line] $line [tell $f]]
784 } [list 20 "123456789012345\rabcd" 22]
785 test io-6.35 {Tcl_GetsObj: auto mode: no chars} {
786 set f [open $path(test1) w]
788 set f [open $path(test1)]
789 fconfigure $f -translation auto
790 set x [list [gets $f line] $line]
794 test io-6.36 {Tcl_GetsObj: auto mode: lone \n} {
795 set f [open $path(test1) w]
796 fconfigure $f -translation lf
797 puts -nonewline $f "\n"
799 set f [open $path(test1)]
800 fconfigure $f -translation auto
801 set x [list [gets $f line] $line [gets $f line] $line]
805 test io-6.37 {Tcl_GetsObj: auto mode: lone \r} {
806 set f [open $path(test1) w]
807 fconfigure $f -translation lf
808 puts -nonewline $f "\r"
810 set f [open $path(test1)]
811 fconfigure $f -translation auto
812 set x [list [gets $f line] $line [gets $f line] $line]
816 test io-6.38 {Tcl_GetsObj: auto mode: \r\r} {
817 set f [open $path(test1) w]
818 fconfigure $f -translation lf
819 puts -nonewline $f "\r\r"
821 set f [open $path(test1)]
822 fconfigure $f -translation auto
823 set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line]
826 } [list 0 "" 0 "" -1 ""]
827 test io-6.39 {Tcl_GetsObj: auto mode: \r\n} {
828 set f [open $path(test1) w]
829 fconfigure $f -translation lf
830 puts -nonewline $f "\r\n"
832 set f [open $path(test1)]
833 fconfigure $f -translation auto
834 set x [list [gets $f line] $line [gets $f line] $line]
838 test io-6.40 {Tcl_GetsObj: auto mode: 1 char} {
839 set f [open $path(test1) w]
840 fconfigure $f -translation lf
843 set f [open $path(test1)]
844 fconfigure $f -translation auto
845 set x [list [gets $f line] $line [gets $f line] $line]
849 test io-6.41 {Tcl_GetsObj: auto mode: 1 char followed by EOL} {
850 set f [open $path(test1) w]
851 fconfigure $f -translation lf
852 puts -nonewline $f "a\r\n"
854 set f [open $path(test1)]
855 fconfigure $f -translation auto
856 set x [list [gets $f line] $line [gets $f line] $line]
860 test io-6.42 {Tcl_GetsObj: auto mode: several chars} {
861 set f [open $path(test1) w]
862 fconfigure $f -translation lf
863 puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop"
865 set f [open $path(test1)]
866 fconfigure $f -translation auto
867 set x [list [gets $f line] $line [gets $f line] $line]
868 lappend x [gets $f line] $line [gets $f line] $line [gets $f line] $line
871 } [list 4 "abcd" 4 "efgh" 4 "ijkl" 4 "mnop" -1 ""]
872 test io-6.43 {Tcl_GetsObj: input saw cr} {stdio testchannel openpipe fileevent} {
873 # if (chanPtr->flags & INPUT_SAW_CR)
875 set f [open "|[list [interpreter] $path(cat)]" w+]
876 fconfigure $f -translation {auto lf} -buffering none
877 puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r"
878 fconfigure $f -buffersize 16
879 set x [list [gets $f]]
880 fconfigure $f -blocking 0
881 lappend x [gets $f line] $line [testchannel queuedcr $f]
882 fconfigure $f -blocking 1
883 puts -nonewline $f "\nabcd\refg\x1a"
884 lappend x [gets $f line] $line [testchannel queuedcr $f]
885 lappend x [gets $f line] $line
888 } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"]
889 test io-6.44 {Tcl_GetsObj: input saw cr, not followed by cr} {stdio testchannel openpipe fileevent} {
892 set f [open "|[list [interpreter] $path(cat)]" w+]
893 fconfigure $f -translation {auto lf} -buffering none
894 puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r"
895 fconfigure $f -buffersize 16
896 set x [list [gets $f]]
897 fconfigure $f -blocking 0
898 lappend x [gets $f line] $line [testchannel queuedcr $f]
899 fconfigure $f -blocking 1
900 puts -nonewline $f "abcd\refg\x1a"
901 lappend x [gets $f line] $line [testchannel queuedcr $f]
902 lappend x [gets $f line] $line
905 } [list "bbbbbbbbbbbbbbb" 15 "123456789abcdef" 1 4 "abcd" 0 3 "efg"]
906 test io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} {stdio testchannel openpipe fileevent} {
907 # Tcl_ExternalToUtf()
909 set f [open "|[list [interpreter] $path(cat)]" w+]
910 fconfigure $f -translation {auto lf} -buffering none
911 fconfigure $f -encoding unicode
912 puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r"
913 fconfigure $f -buffersize 16
915 fconfigure $f -blocking 0
916 set x [list [gets $f line] $line [testchannel queuedcr $f]]
917 fconfigure $f -blocking 1
918 puts -nonewline $f "\nabcd\refg"
919 lappend x [gets $f line] $line [testchannel queuedcr $f]
922 } [list 15 "123456789abcdef" 1 4 "abcd" 0]
923 test io-6.46 {Tcl_GetsObj: input saw cr, followed by just \n should give eof} {stdio testchannel openpipe fileevent} {
926 set f [open "|[list [interpreter] $path(cat)]" w+]
927 fconfigure $f -translation {auto lf} -buffering none
928 puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r"
929 fconfigure $f -buffersize 16
931 fconfigure $f -blocking 0
932 set x [list [gets $f line] $line [testchannel queuedcr $f]]
933 fconfigure $f -blocking 1
934 puts -nonewline $f "\n\x1a"
935 lappend x [gets $f line] $line [testchannel queuedcr $f]
938 } [list 15 "123456789abcdef" 1 -1 "" 0]
939 test io-6.47 {Tcl_GetsObj: auto mode: \r at end of buffer, peek for \n} {testchannel} {
942 set f [open $path(test1) w]
943 fconfigure $f -translation lf
944 puts -nonewline $f "123456789012345\r\nabcdefghijklmnopq"
946 set f [open $path(test1)]
947 fconfigure $f -translation auto -buffersize 16
948 set x [list [gets $f] [testchannel inputbuffered $f]]
951 } [list "123456789012345" 15]
952 test io-6.48 {Tcl_GetsObj: auto mode: \r at end of buffer, no more avail} {testchannel} {
953 # PeekAhead() did not get any, so (eol >= dstEnd)
955 set f [open $path(test1) w]
956 fconfigure $f -translation lf
957 puts -nonewline $f "123456789012345\r"
959 set f [open $path(test1)]
960 fconfigure $f -translation auto -buffersize 16
961 set x [list [gets $f] [testchannel queuedcr $f]]
964 } [list "123456789012345" 1]
965 test io-6.49 {Tcl_GetsObj: auto mode: \r followed by \n} {testchannel} {
966 # if (*eol == '\n') {skip++}
968 set f [open $path(test1) w]
969 fconfigure $f -translation lf
970 puts -nonewline $f "123456\r\n78901"
972 set f [open $path(test1)]
973 set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]]
976 } [list "123456" 0 8 "78901"]
977 test io-6.50 {Tcl_GetsObj: auto mode: \r not followed by \n} {testchannel} {
980 set f [open $path(test1) w]
981 fconfigure $f -translation lf
982 puts -nonewline $f "123456\r78901"
984 set f [open $path(test1)]
985 set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]]
988 } [list "123456" 0 7 "78901"]
989 test io-6.51 {Tcl_GetsObj: auto mode: \n} {
990 # else if (*eol == '\n') {goto gotoeol;}
992 set f [open $path(test1) w]
993 fconfigure $f -translation lf
994 puts -nonewline $f "123456\n78901"
996 set f [open $path(test1)]
997 set x [list [gets $f] [tell $f] [gets $f]]
1000 } [list "123456" 7 "78901"]
1001 test io-6.52 {Tcl_GetsObj: saw EOF character} {testchannel} {
1004 set f [open $path(test1) w]
1005 fconfigure $f -translation lf
1006 puts -nonewline $f "123456\x1ak9012345\r"
1008 set f [open $path(test1)]
1009 fconfigure $f -eofchar \x1a
1010 set x [list [gets $f] [testchannel queuedcr $f] [tell $f] [gets $f]]
1013 } [list "123456" 0 6 ""]
1014 test io-6.53 {Tcl_GetsObj: device EOF} {
1015 # didn't produce any bytes
1017 set f [open $path(test1) w]
1019 set f [open $path(test1)]
1020 set x [list [gets $f line] $line [eof $f]]
1024 test io-6.54 {Tcl_GetsObj: device EOF} {
1025 # got some bytes before EOF.
1027 set f [open $path(test1) w]
1028 puts -nonewline $f abc
1030 set f [open $path(test1)]
1031 set x [list [gets $f line] $line [eof $f]]
1035 test io-6.55 {Tcl_GetsObj: overconverted} {
1036 # Tcl_ExternalToUtf(), make sure state updated
1038 set f [open $path(test1) w]
1039 fconfigure $f -encoding iso2022-jp
1040 puts $f "there\u4e00ok\n\u4e01more bytes\nhere"
1042 set f [open $path(test1)]
1043 fconfigure $f -encoding iso2022-jp
1044 set x [list [gets $f line] $line [gets $f line] $line [gets $f line] $line]
1047 } [list 8 "there\u4e00ok" 11 "\u4e01more bytes" 4 "here"]
1048 test io-6.56 {Tcl_GetsObj: incomplete lines should disable file events} {stdio openpipe fileevent} {
1050 set f [open "|[list [interpreter] $path(cat)]" w+]
1051 fconfigure $f -buffering none
1052 puts -nonewline $f "foobar"
1053 fconfigure $f -blocking 0
1055 after 500 [namespace code { lappend x timeout }]
1056 fileevent $f readable [namespace code { lappend x [gets $f] }]
1057 vwait [namespace which -variable x]
1058 vwait [namespace which -variable x]
1059 fconfigure $f -blocking 1
1060 puts -nonewline $f "baz\n"
1061 after 500 [namespace code { lappend x timeout }]
1062 fconfigure $f -blocking 0
1063 vwait [namespace which -variable x]
1064 vwait [namespace which -variable x]
1067 } {{} timeout foobarbaz timeout}
1069 test io-7.1 {FilterInputBytes: split up character at end of buffer} {
1070 # (result == TCL_CONVERT_MULTIBYTE)
1072 set f [open $path(test1) w]
1073 fconfigure $f -encoding shiftjis
1074 puts $f "1234567890123\uff10\uff11\uff12\uff13\uff14\nend"
1076 set f [open $path(test1)]
1077 fconfigure $f -encoding shiftjis -buffersize 16
1081 } "1234567890123\uff10\uff11\uff12\uff13\uff14"
1082 test io-7.2 {FilterInputBytes: split up character in middle of buffer} {
1083 # (bufPtr->nextAdded < bufPtr->bufLength)
1085 set f [open $path(test1) w]
1086 fconfigure $f -encoding binary
1087 puts -nonewline $f "1234567890\n123\x82\x4f\x82\x50\x82"
1089 set f [open $path(test1)]
1090 fconfigure $f -encoding shiftjis
1091 set x [list [gets $f line] $line [eof $f]]
1094 } [list 10 "1234567890" 0]
1095 test io-7.3 {FilterInputBytes: split up character at EOF} {testchannel} {
1096 set f [open $path(test1) w]
1097 fconfigure $f -encoding binary
1098 puts -nonewline $f "1234567890123\x82\x4f\x82\x50\x82"
1100 set f [open $path(test1)]
1101 fconfigure $f -encoding shiftjis
1102 set x [list [gets $f line] $line]
1103 lappend x [tell $f] [testchannel inputbuffered $f] [eof $f]
1104 lappend x [gets $f line] $line
1107 } [list 15 "1234567890123\uff10\uff11" 18 0 1 -1 ""]
1108 test io-7.4 {FilterInputBytes: recover from split up character} {stdio openpipe fileevent} {
1109 set f [open "|[list [interpreter] $path(cat)]" w+]
1110 fconfigure $f -encoding binary -buffering none
1111 puts -nonewline $f "1234567890123\x82\x4f\x82\x50\x82"
1112 fconfigure $f -encoding shiftjis -blocking 0
1113 fileevent $f read [namespace code "ready $f"]
1117 lappend x [gets $f line] $line [fblocked $f]
1119 vwait [namespace which -variable x]
1120 fconfigure $f -encoding binary -blocking 1
1121 puts $f "\x51\x82\x52"
1122 fconfigure $f -encoding shiftjis
1123 vwait [namespace which -variable x]
1126 } [list -1 "" 1 17 "1234567890123\uff10\uff11\uff12\uff13" 0]
1128 test io-8.1 {PeekAhead: only go to device if no more cached data} {testchannel} {
1129 # (bufPtr->nextPtr == NULL)
1131 set f [open $path(test1) w]
1132 fconfigure $f -encoding ascii -translation lf
1133 puts -nonewline $f "123456789012345\r\n2345678"
1135 set f [open $path(test1)]
1136 fconfigure $f -encoding ascii -translation auto -buffersize 16
1139 set x [testchannel inputbuffered $f]
1143 test io-8.2 {PeekAhead: only go to device if no more cached data} {stdio testchannel openpipe fileevent} {
1144 # not (bufPtr->nextPtr == NULL)
1146 set f [open "|[list [interpreter] $path(cat)]" w+]
1147 fconfigure $f -translation lf -encoding ascii -buffering none
1148 puts -nonewline $f "123456789012345\r\nbcdefghijklmnopqrstuvwxyz"
1150 fileevent $f read [namespace code "ready $f"]
1153 lappend x [gets $f line] $line [testchannel inputbuffered $f]
1155 fconfigure $f -encoding unicode -buffersize 16 -blocking 0
1156 vwait [namespace which -variable x]
1157 fconfigure $f -translation auto -encoding ascii -blocking 1
1159 vwait [namespace which -variable x]
1162 } [list -1 "" 42 15 "123456789012345" 25]
1163 test io-8.3 {PeekAhead: no cached data available} {stdio testchannel openpipe fileevent} {
1166 set f [open "|[list [interpreter] $path(cat)]" w+]
1167 fconfigure $f -translation {auto binary}
1168 puts -nonewline $f "abcdefghijklmno\r"
1170 set x [list [gets $f line] $line [testchannel queuedcr $f]]
1173 } [list 15 "abcdefghijklmno" 1]
1174 set a "123456789012345678901234567890"
1175 append a "123456789012345678901234567890"
1176 append a "1234567890123456789012345678901"
1177 test io-8.4 {PeekAhead: cached data available in this buffer} {
1178 # not (bytesLeft == 0)
1180 set f [open $path(test1) w+]
1181 fconfigure $f -translation binary
1182 puts $f "${a}\r\nabcdef"
1184 set f [open $path(test1)]
1185 fconfigure $f -encoding binary -translation auto
1187 # "${a}\r" was converted in one operation (because ENCODING_LINESIZE
1188 # is 30). To check if "\n" follows, calls PeekAhead and determines
1189 # that cached data is available in buffer w/o having to call driver.
1196 test io-8.5 {PeekAhead: don't peek if last read was short} {stdio testchannel openpipe fileevent} {
1197 # (bufPtr->nextAdded < bufPtr->length)
1199 set f [open "|[list [interpreter] $path(cat)]" w+]
1200 fconfigure $f -translation {auto binary}
1201 puts -nonewline $f "abcdefghijklmno\r"
1204 set x [list [gets $f line] $line [testchannel queuedcr $f]]
1207 } {15 abcdefghijklmno 1}
1208 test io-8.6 {PeekAhead: change to non-blocking mode} {stdio testchannel openpipe fileevent} {
1209 # ((chanPtr->flags & CHANNEL_NONBLOCKING) == 0)
1211 set f [open "|[list [interpreter] $path(cat)]" w+]
1212 fconfigure $f -translation {auto binary} -buffersize 16
1213 puts -nonewline $f "abcdefghijklmno\r"
1216 set x [list [gets $f line] $line [testchannel queuedcr $f]]
1219 } {15 abcdefghijklmno 1}
1220 test io-8.7 {PeekAhead: cleanup} {stdio testchannel openpipe fileevent} {
1221 # Make sure bytes are removed from buffer.
1223 set f [open "|[list [interpreter] $path(cat)]" w+]
1224 fconfigure $f -translation {auto binary} -buffering none
1225 puts -nonewline $f "abcdefghijklmno\r"
1227 set x [list [gets $f line] $line [testchannel queuedcr $f]]
1228 puts -nonewline $f "\x1a"
1229 lappend x [gets $f line] $line
1232 } {15 abcdefghijklmno 1 -1 {}}
1235 test io-9.1 {CommonGetsCleanup} {
1238 test io-10.1 {Tcl_ReadChars: CheckChannelErrors} {
1239 # no test, need to cause an async error.
1241 test io-10.2 {Tcl_ReadChars: loop until enough copied} {
1243 # for (copied = 0; (unsigned) toRead > 0; )
1245 set f [open $path(test1) w]
1246 puts $f abcdefghijklmnop
1249 set f [open $path(test1)]
1254 test io-10.3 {Tcl_ReadChars: loop until enough copied} {
1256 # for (copied = 0; (unsigned) toRead > 0; )
1258 set f [open $path(test1) w]
1259 puts $f abcdefghijklmnopqrstuvwxyz
1262 set f [open $path(test1)]
1263 fconfigure $f -buffersize 16
1268 } {abcdefghijklmnopqrs}
1269 test io-10.4 {Tcl_ReadChars: no more in channel buffer} {
1272 set f [open $path(test1) w]
1273 puts -nonewline $f abcdefghijkl
1276 set f [open $path(test1)]
1278 set x [read $f 1000]
1282 test io-10.5 {Tcl_ReadChars: stop on EOF} {
1283 # (chanPtr->flags & CHANNEL_EOF)
1285 set f [open $path(test1) w]
1286 puts -nonewline $f abcdefghijkl
1289 set f [open $path(test1)]
1291 set x [read $f 1000]
1296 test io-11.1 {ReadBytes: want to read a lot} {
1297 # ((unsigned) toRead > (unsigned) srcLen)
1299 set f [open $path(test1) w]
1300 puts -nonewline $f abcdefghijkl
1302 set f [open $path(test1)]
1303 fconfigure $f -encoding binary
1305 set x [read $f 1000]
1309 test io-11.2 {ReadBytes: want to read all} {
1310 # ((unsigned) toRead > (unsigned) srcLen)
1312 set f [open $path(test1) w]
1313 puts -nonewline $f abcdefghijkl
1315 set f [open $path(test1)]
1316 fconfigure $f -encoding binary
1322 test io-11.3 {ReadBytes: allocate more space} {
1323 # (toRead > length - offset - 1)
1325 set f [open $path(test1) w]
1326 puts -nonewline $f abcdefghijklmnopqrstuvwxyz
1328 set f [open $path(test1)]
1329 fconfigure $f -buffersize 16 -encoding binary
1334 } {abcdefghijklmnopqrstuvwxyz}
1335 test io-11.4 {ReadBytes: EOF char found} {
1336 # (TranslateInputEOL() != 0)
1338 set f [open $path(test1) w]
1339 puts $f abcdefghijklmnopqrstuvwxyz
1341 set f [open $path(test1)]
1342 fconfigure $f -eofchar m -encoding binary
1344 set x [list [read $f] [eof $f] [read $f] [eof $f]]
1347 } [list "abcdefghijkl" 1 "" 1]
1349 test io-12.1 {ReadChars: want to read a lot} {
1350 # ((unsigned) toRead > (unsigned) srcLen)
1352 set f [open $path(test1) w]
1353 puts -nonewline $f abcdefghijkl
1355 set f [open $path(test1)]
1357 set x [read $f 1000]
1361 test io-12.2 {ReadChars: want to read all} {
1362 # ((unsigned) toRead > (unsigned) srcLen)
1364 set f [open $path(test1) w]
1365 puts -nonewline $f abcdefghijkl
1367 set f [open $path(test1)]
1373 test io-12.3 {ReadChars: allocate more space} {
1374 # (toRead > length - offset - 1)
1376 set f [open $path(test1) w]
1377 puts -nonewline $f abcdefghijklmnopqrstuvwxyz
1379 set f [open $path(test1)]
1380 fconfigure $f -buffersize 16
1385 } {abcdefghijklmnopqrstuvwxyz}
1386 test io-12.4 {ReadChars: split-up char} {stdio testchannel openpipe fileevent} {
1389 set f [open "|[list [interpreter] $path(cat)]" w+]
1390 fconfigure $f -encoding binary -buffering none -buffersize 16
1391 puts -nonewline $f "123456789012345\x96"
1392 fconfigure $f -encoding shiftjis -blocking 0
1394 fileevent $f read [namespace code "ready $f"]
1397 lappend x [read $f] [testchannel inputbuffered $f]
1401 fconfigure $f -encoding shiftjis
1402 vwait [namespace which -variable x]
1403 fconfigure $f -encoding binary -blocking 1
1404 puts -nonewline $f "\x7b"
1405 after 500 ;# Give the cat process time to catch up
1406 fconfigure $f -encoding shiftjis -blocking 0
1407 vwait [namespace which -variable x]
1410 } [list "123456789012345" 1 "\u672c" 0]
1411 test io-12.5 {ReadChars: fileevents on partial characters} {stdio openpipe fileevent} {
1412 set path(test1) [makeFile {
1413 fconfigure stdout -encoding binary -buffering none
1414 gets stdin; puts -nonewline "\xe7"
1415 gets stdin; puts -nonewline "\x89"
1416 gets stdin; puts -nonewline "\xa6"
1418 set f [open "|[list [interpreter] $path(test1)]" r+]
1419 fileevent $f readable [namespace code {
1427 fconfigure $f -blocking 0 -encoding utf-8
1429 vwait [namespace which -variable x]
1430 after 500 [namespace code { lappend x timeout }]
1431 vwait [namespace which -variable x]
1434 vwait [namespace which -variable x]
1435 after 500 [namespace code { lappend x timeout }]
1436 vwait [namespace which -variable x]
1439 vwait [namespace which -variable x]
1440 vwait [namespace which -variable x]
1441 lappend x [catch {close $f} msg] $msg
1443 } "{} timeout {} timeout \u7266 {} eof 0 {}"
1445 test io-13.1 {TranslateInputEOL: cr mode} {} {
1446 set f [open $path(test1) w]
1447 fconfigure $f -translation lf
1448 puts -nonewline $f "abcd\rdef\r"
1450 set f [open $path(test1)]
1451 fconfigure $f -translation cr
1456 test io-13.2 {TranslateInputEOL: crlf mode} {
1457 set f [open $path(test1) w]
1458 fconfigure $f -translation lf
1459 puts -nonewline $f "abcd\r\ndef\r\n"
1461 set f [open $path(test1)]
1462 fconfigure $f -translation crlf
1467 test io-13.3 {TranslateInputEOL: crlf mode: naked cr} {
1470 set f [open $path(test1) w]
1471 fconfigure $f -translation lf
1472 puts -nonewline $f "abcd\r\ndef\r"
1474 set f [open $path(test1)]
1475 fconfigure $f -translation crlf
1480 test io-13.4 {TranslateInputEOL: crlf mode: cr followed by not \n} {
1483 set f [open $path(test1) w]
1484 fconfigure $f -translation lf
1485 puts -nonewline $f "abcd\r\ndef\rfgh"
1487 set f [open $path(test1)]
1488 fconfigure $f -translation crlf
1493 test io-13.5 {TranslateInputEOL: crlf mode: naked lf} {
1496 set f [open $path(test1) w]
1497 fconfigure $f -translation lf
1498 puts -nonewline $f "abcd\r\ndef\nfgh"
1500 set f [open $path(test1)]
1501 fconfigure $f -translation crlf
1506 test io-13.6 {TranslateInputEOL: auto mode: saw cr in last segment} {stdio testchannel openpipe fileevent} {
1507 # (chanPtr->flags & INPUT_SAW_CR)
1508 # This test may fail on slower machines.
1510 set f [open "|[list [interpreter] $path(cat)]" w+]
1511 fconfigure $f -blocking 0 -buffering none -translation {auto lf}
1513 fileevent $f read [namespace code "ready $f"]
1516 lappend x [read $f] [testchannel queuedcr $f]
1521 puts -nonewline $f "abcdefghj\r"
1522 after 500 [namespace code {set y ok}]
1523 vwait [namespace which -variable y]
1525 puts -nonewline $f "\n01234"
1526 after 500 [namespace code {set y ok}]
1527 vwait [namespace which -variable y]
1531 } [list "abcdefghj\n" 1 "01234" 0]
1532 test io-13.7 {TranslateInputEOL: auto mode: naked \r} {testchannel openpipe} {
1535 set f [open $path(test1) w]
1536 fconfigure $f -translation lf
1537 puts -nonewline $f "abcd\r"
1539 set f [open $path(test1)]
1540 fconfigure $f -translation auto
1541 set x [list [read $f] [testchannel queuedcr $f]]
1545 test io-13.8 {TranslateInputEOL: auto mode: \r\n} {
1548 set f [open $path(test1) w]
1549 fconfigure $f -translation lf
1550 puts -nonewline $f "abcd\r\ndef"
1552 set f [open $path(test1)]
1553 fconfigure $f -translation auto
1558 test io-13.9 {TranslateInputEOL: auto mode: \r followed by not \n} {
1559 set f [open $path(test1) w]
1560 fconfigure $f -translation lf
1561 puts -nonewline $f "abcd\rdef"
1563 set f [open $path(test1)]
1564 fconfigure $f -translation auto
1569 test io-13.10 {TranslateInputEOL: auto mode: \n} {
1570 # not (*src == '\r')
1572 set f [open $path(test1) w]
1573 fconfigure $f -translation lf
1574 puts -nonewline $f "abcd\ndef"
1576 set f [open $path(test1)]
1577 fconfigure $f -translation auto
1582 test io-13.11 {TranslateInputEOL: EOF char} {
1583 # (*chanPtr->inEofChar != '\0')
1585 set f [open $path(test1) w]
1586 fconfigure $f -translation lf
1587 puts -nonewline $f "abcd\ndefgh"
1589 set f [open $path(test1)]
1590 fconfigure $f -translation auto -eofchar e
1595 test io-13.12 {TranslateInputEOL: find EOF char in src} {
1596 # (*chanPtr->inEofChar != '\0')
1598 set f [open $path(test1) w]
1599 fconfigure $f -translation lf
1600 puts -nonewline $f "\r\n\r\n\r\nab\r\n\r\ndef\r\n\r\n\r\n"
1602 set f [open $path(test1)]
1603 fconfigure $f -translation auto -eofchar e
1609 # Test standard handle management. The functions tested are
1610 # Tcl_SetStdChannel and Tcl_GetStdChannel. Incidentally we are
1611 # also testing channel table management.
1613 if {[info commands testchannel] != ""} {
1614 if {$tcl_platform(platform) == "macintosh"} {
1615 set consoleFileNames [list console0 console1 console2]
1617 set consoleFileNames [lsort [testchannel open]]
1620 # just to avoid an error
1621 set consoleFileNames [list]
1624 test io-14.1 {Tcl_SetStdChannel and Tcl_GetStdChannel} {testchannel} {
1626 lappend l [fconfigure stdin -buffering]
1627 lappend l [fconfigure stdout -buffering]
1628 lappend l [fconfigure stderr -buffering]
1629 lappend l [lsort [testchannel open]]
1631 } [list line line none $consoleFileNames]
1632 test io-14.2 {Tcl_SetStdChannel and Tcl_GetStdChannel} {
1635 lappend l [x eval {fconfigure stdin -buffering}]
1636 lappend l [x eval {fconfigure stdout -buffering}]
1637 lappend l [x eval {fconfigure stderr -buffering}]
1642 set path(test3) [makeFile {} test3]
1644 test io-14.3 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec openpipe} {
1645 set f [open $path(test1) w]
1646 puts -nonewline $f {
1651 puts $f [list open $path(test1) r]]
1652 puts $f "set f2 \[[list open $path(test2) w]]"
1653 puts $f "set f3 \[[list open $path(test3) w]]"
1654 puts $f { puts stdout [gets stdin]
1662 set result [exec [interpreter] $path(test1)]
1663 set f [open $path(test2) r]
1664 set f2 [open $path(test3) r]
1665 lappend result [read $f] [read $f2]
1673 # This test relies on the fact that the smallest available fd is used first.
1674 test io-14.4 {Tcl_SetStdChannel & Tcl_GetStdChannel} {exec unixOnly} {
1675 set f [open $path(test1) w]
1676 puts -nonewline $f { close stdin
1680 puts $f [list open $path(test1) r]]
1681 puts $f "set f2 \[[list open $path(test2) w]]"
1682 puts $f "set f3 \[[list open $path(test3) w]]"
1683 puts $f { puts stdout [gets stdin]
1691 set result [exec [interpreter] $path(test1)]
1692 set f [open $path(test2) r]
1693 set f2 [open $path(test3) r]
1694 lappend result [read $f] [read $f2]
1702 catch {interp delete z}
1703 test io-14.5 {Tcl_GetChannel: stdio name translation} {
1706 catch {z eval flush stdin} msg1
1707 catch {z eval close stdin} msg2
1708 catch {z eval flush stdin} msg3
1709 set result [list $msg1 $msg2 $msg3]
1712 } {{channel "stdin" wasn't opened for writing} {} {can not find channel named "stdin"}}
1713 test io-14.6 {Tcl_GetChannel: stdio name translation} {
1716 catch {z eval flush stdout} msg1
1717 catch {z eval close stdout} msg2
1718 catch {z eval flush stdout} msg3
1719 set result [list $msg1 $msg2 $msg3]
1722 } {{} {} {can not find channel named "stdout"}}
1723 test io-14.7 {Tcl_GetChannel: stdio name translation} {
1726 catch {z eval flush stderr} msg1
1727 catch {z eval close stderr} msg2
1728 catch {z eval flush stderr} msg3
1729 set result [list $msg1 $msg2 $msg3]
1732 } {{} {} {can not find channel named "stderr"}}
1734 set path(script) [makeFile {} script]
1736 test io-14.8 {reuse of stdio special channels} {stdio openpipe} {
1737 file delete $path(script)
1738 file delete $path(test1)
1739 set f [open $path(script) w]
1740 puts -nonewline $f {
1743 puts $f [list open $path(test1) w]]
1744 puts -nonewline $f {
1748 puts $f [list open $path(test1) r]]
1753 set f [open "|[list [interpreter] $path(script)]" r]
1759 test io-14.9 {reuse of stdio special channels} {stdio openpipe fileevent} {
1760 file delete $path(script)
1761 file delete $path(test1)
1762 set f [open $path(script) w]
1764 array set path [lindex $argv 0]
1765 set f [open $path(test1) w]
1769 set f [open "|[list [info nameofexecutable] $path(cat) $path(test1)]" r]
1773 set f [open "|[list [interpreter] $path(script) [array get path]]" r]
1776 # Added delay to give Windows time to stop the spawned process and clean
1777 # up its grip on the file test1. Added delete as proper test cleanup.
1778 # The failing tests were 18.1 and 18.2 as first re-users of file "test1".
1780 file delete $path(script)
1781 file delete $path(test1)
1785 test io-15.1 {Tcl_CreateCloseHandler} {
1788 test io-16.1 {Tcl_DeleteCloseHandler} {
1791 # Test channel table management. The functions tested are
1792 # GetChannelTable, DeleteChannelTable, Tcl_RegisterChannel,
1793 # Tcl_UnregisterChannel, Tcl_GetChannel and Tcl_CreateChannel.
1795 # These functions use "eof stdin" to ensure that the standard
1796 # channels are added to the channel table of the interpreter.
1798 test io-17.1 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} {
1799 set l1 [testchannel refcount stdin]
1803 lappend l [expr [testchannel refcount stdin] - $l1]
1805 lappend l [expr [testchannel refcount stdin] - $l1]
1807 lappend l [expr [testchannel refcount stdin] - $l1]
1810 test io-17.2 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} {
1811 set l1 [testchannel refcount stdout]
1815 lappend l [expr [testchannel refcount stdout] - $l1]
1817 lappend l [expr [testchannel refcount stdout] - $l1]
1819 lappend l [expr [testchannel refcount stdout] - $l1]
1822 test io-17.3 {GetChannelTable, DeleteChannelTable on std handles} {testchannel} {
1823 set l1 [testchannel refcount stderr]
1827 lappend l [expr [testchannel refcount stderr] - $l1]
1829 lappend l [expr [testchannel refcount stderr] - $l1]
1831 lappend l [expr [testchannel refcount stderr] - $l1]
1835 test io-18.1 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} {
1836 file delete $path(test1)
1838 set f [open $path(test1) w]
1839 lappend l [lindex [testchannel info $f] 15]
1841 if {[catch {lindex [testchannel info $f] 15} msg]} {
1844 lappend l "very broken: $f found after being closed"
1846 string compare [string tolower $l] \
1847 [list 1 [format "can not find channel named \"%s\"" $f]]
1849 test io-18.2 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} {
1850 file delete $path(test1)
1852 set f [open $path(test1) w]
1853 lappend l [lindex [testchannel info $f] 15]
1855 interp share "" $f x
1856 lappend l [lindex [testchannel info $f] 15]
1858 lappend l [lindex [testchannel info $f] 15]
1860 lappend l [lindex [testchannel info $f] 15]
1862 if {[catch {lindex [testchannel info $f] 15} msg]} {
1865 lappend l "very broken: $f found after being closed"
1867 string compare [string tolower $l] \
1868 [list 1 2 1 1 [format "can not find channel named \"%s\"" $f]]
1870 test io-18.3 {Tcl_RegisterChannel, Tcl_UnregisterChannel} {testchannel} {
1871 file delete $path(test1)
1873 set f [open $path(test1) w]
1874 lappend l [lindex [testchannel info $f] 15]
1876 interp share "" $f x
1877 lappend l [lindex [testchannel info $f] 15]
1879 lappend l [lindex [testchannel info $f] 15]
1881 if {[catch {lindex [testchannel info $f] 15} msg]} {
1884 lappend l "very broken: $f found after being closed"
1886 string compare [string tolower $l] \
1887 [list 1 2 1 [format "can not find channel named \"%s\"" $f]]
1890 test io-19.1 {Tcl_GetChannel->Tcl_GetStdChannel, standard handles} {
1893 test io-19.2 {testing Tcl_GetChannel, user opened handle} {
1894 file delete $path(test1)
1895 set f [open $path(test1) w]
1900 test io-19.3 {Tcl_GetChannel, channel not found} {
1901 list [catch {eof file34} msg] $msg
1902 } {1 {can not find channel named "file34"}}
1903 test io-19.4 {Tcl_CreateChannel, insertion into channel table} {testchannel} {
1904 file delete $path(test1)
1905 set f [open $path(test1) w]
1909 if {[catch {lindex [testchannel info $f] 15} msg]} {
1912 lappend l "very broken: $f found after being closed"
1914 string compare [string tolower $l] \
1915 [list 0 [format "can not find channel named \"%s\"" $f]]
1918 test io-20.1 {Tcl_CreateChannel: initial settings} {
1919 set a [open $path(test2) w]
1920 set old [encoding system]
1921 encoding system ascii
1922 set f [open $path(test1) w]
1923 set x [fconfigure $f -encoding]
1925 encoding system $old
1929 test io-20.2 {Tcl_CreateChannel: initial settings} {pcOnly} {
1930 set f [open $path(test1) w+]
1931 set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]]
1934 } [list [list \x1a ""] {auto crlf}]
1935 test io-20.3 {Tcl_CreateChannel: initial settings} {unixOnly} {
1936 set f [open $path(test1) w+]
1937 set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]]
1940 } {{{} {}} {auto lf}}
1941 test io-20.4 {Tcl_CreateChannel: initial settings} {macOnly} {
1942 set f [open $path(test1) w+]
1943 set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]]
1946 } {{{} {}} {auto cr}}
1948 set path(stdout) [makeFile {} stdout]
1950 test io-20.5 {Tcl_CreateChannel: install channel in empty slot} {stdio openpipe} {
1951 set f [open $path(script) w]
1952 puts -nonewline $f {
1955 puts $f [list open $path(stdout) w]]
1957 fconfigure $f1 -buffersize 777
1958 puts stderr [fconfigure stdout -buffersize]
1961 set f [open "|[list [interpreter] $path(script)]"]
1962 catch {close $f} msg
1966 test io-21.1 {CloseChannelsOnExit} {
1969 # Test management of attributes associated with a channel, such as
1970 # its default translation, its name and type, etc. The functions
1971 # tested in this group are Tcl_GetChannelName,
1972 # Tcl_GetChannelType and Tcl_GetChannelFile. Tcl_GetChannelInstanceData
1973 # not tested because files do not use the instance data.
1975 test io-22.1 {Tcl_GetChannelMode} {
1976 # Not used anywhere in Tcl.
1979 test io-23.1 {Tcl_GetChannelName} {testchannel} {
1980 file delete $path(test1)
1981 set f [open $path(test1) w]
1982 set n [testchannel name $f]
1984 string compare $n $f
1987 test io-24.1 {Tcl_GetChannelType} {testchannel} {
1988 file delete $path(test1)
1989 set f [open $path(test1) w]
1990 set t [testchannel type $f]
1992 string compare $t file
1995 test io-25.1 {Tcl_GetChannelHandle, input} {testchannel} {
1996 set f [open $path(test1) w]
1997 fconfigure $f -translation lf -eofchar {}
1998 puts $f "1234567890\n098765432"
2000 set f [open $path(test1) r]
2003 lappend l [testchannel inputbuffered $f]
2008 test io-25.2 {Tcl_GetChannelHandle, output} {testchannel} {
2009 file delete $path(test1)
2010 set f [open $path(test1) w]
2011 fconfigure $f -translation lf
2014 lappend l [testchannel outputbuffered $f]
2017 lappend l [testchannel outputbuffered $f]
2020 file delete $path(test1)
2024 test io-26.1 {Tcl_GetChannelInstanceData} {stdio openpipe} {
2025 # "pid" command uses Tcl_GetChannelInstanceData
2026 # Don't care what pid is (but must be a number), just want to exercise it.
2028 set f [open "|[list [interpreter] << exit]"]
2033 # Test flushing. The functions tested here are FlushChannel.
2035 test io-27.1 {FlushChannel, no output buffered} {
2036 file delete $path(test1)
2037 set f [open $path(test1) w]
2039 set s [file size $path(test1)]
2043 test io-27.2 {FlushChannel, some output buffered} {
2044 file delete $path(test1)
2045 set f [open $path(test1) w]
2046 fconfigure $f -translation lf -eofchar {}
2049 lappend l [file size $path(test1)]
2051 lappend l [file size $path(test1)]
2053 lappend l [file size $path(test1)]
2056 test io-27.3 {FlushChannel, implicit flush on close} {
2057 file delete $path(test1)
2058 set f [open $path(test1) w]
2059 fconfigure $f -translation lf -eofchar {}
2062 lappend l [file size $path(test1)]
2064 lappend l [file size $path(test1)]
2067 test io-27.4 {FlushChannel, implicit flush when buffer fills} {
2068 file delete $path(test1)
2069 set f [open $path(test1) w]
2070 fconfigure $f -translation lf -eofchar {}
2071 fconfigure $f -buffersize 60
2073 lappend l [file size $path(test1)]
2074 for {set i 0} {$i < 12} {incr i} {
2077 lappend l [file size $path(test1)]
2079 lappend l [file size $path(test1)]
2083 test io-27.5 {FlushChannel, implicit flush when buffer fills and on close} \
2085 file delete $path(test1)
2086 set f [open $path(test1) w]
2087 fconfigure $f -translation lf -buffersize 60 -eofchar {}
2089 lappend l [file size $path(test1)]
2090 for {set i 0} {$i < 12} {incr i} {
2093 lappend l [file size $path(test1)]
2095 lappend l [file size $path(test1)]
2099 set path(pipe) [makeFile {} pipe]
2100 set path(output) [makeFile {} output]
2102 test io-27.6 {FlushChannel, async flushing, async close} \
2103 {stdio asyncPipeClose openpipe} {
2104 file delete $path(pipe)
2105 file delete $path(output)
2106 set f [open $path(pipe) w]
2107 puts $f "set f \[[list open $path(output) w]]"
2109 fconfigure $f -translation lf -buffering none -eofchar {}
2110 while {![eof stdin]} {
2112 puts -nonewline $f [read stdin 1024]
2117 set x 01234567890123456789012345678901
2118 for {set i 0} {$i < 11} {incr i} {
2121 set f [open $path(output) w]
2123 set f [open "|[list [interpreter] $path(pipe)]" w]
2124 fconfigure $f -blocking off
2125 puts -nonewline $f $x
2128 while {([file size $path(output)] < 65536) && ($counter < 1000)} {
2133 if {$counter == 1000} {
2134 set result "file size only [file size $path(output)]"
2140 # Tests closing a channel. The functions tested are CloseChannel and Tcl_Close.
2142 test io-28.1 {CloseChannel called when all references are dropped} {testchannel} {
2143 file delete $path(test1)
2144 set f [open $path(test1) w]
2146 interp share "" $f x
2148 lappend l [testchannel refcount $f]
2151 lappend l [testchannel refcount $f]
2155 test io-28.2 {CloseChannel called when all references are dropped} {
2156 file delete $path(test1)
2157 set f [open $path(test1) w]
2159 interp share "" $f x
2160 puts -nonewline $f abc
2165 set f [open $path(test1) r]
2170 test io-28.3 {CloseChannel, not called before output queue is empty} \
2171 {stdio asyncPipeClose nonPortable openpipe} {
2172 file delete $path(pipe)
2173 file delete $path(output)
2174 set f [open $path(pipe) w]
2177 # Need to not have eof char appended on close, because the other
2178 # side of the pipe already closed, so that writing would cause an
2179 # error "invalid file".
2181 fconfigure stdout -eofchar {}
2182 fconfigure stderr -eofchar {}
2184 set f [open $path(output) w]
2185 fconfigure $f -translation lf -buffering none
2186 for {set x 0} {$x < 20} {incr x} {
2188 puts -nonewline $f [read stdin 1024]
2193 set x 01234567890123456789012345678901
2194 for {set i 0} {$i < 11} {incr i} {
2197 set f [open $path(output) w]
2199 set f [open "|[list [interpreter] pipe]" r+]
2200 fconfigure $f -blocking off -eofchar {}
2202 puts -nonewline $f $x
2205 while {([file size $path(output)] < 20480) && ($counter < 1000)} {
2210 if {$counter == 1000} {
2211 set result probably_broken
2216 test io-28.4 {Tcl_Close} {testchannel} {
2217 file delete $path(test1)
2219 lappend l [lsort [testchannel open]]
2220 set f [open $path(test1) w]
2221 lappend l [lsort [testchannel open]]
2223 lappend l [lsort [testchannel open]]
2224 set x [list $consoleFileNames \
2225 [lsort [eval list $consoleFileNames $f]] \
2227 string compare $l $x
2229 test io-28.5 {Tcl_Close vs standard handles} {stdio unixOnly testchannel openpipe} {
2230 file delete $path(script)
2231 set f [open $path(script) w]
2234 puts [testchannel open]
2237 set f [open "|[list [interpreter] $path(script)]" r]
2243 test io-29.1 {Tcl_WriteChars, channel not writable} {
2244 list [catch {puts stdin hello} msg] $msg
2245 } {1 {channel "stdin" wasn't opened for writing}}
2246 test io-29.2 {Tcl_WriteChars, empty string} {
2247 file delete $path(test1)
2248 set f [open $path(test1) w]
2249 fconfigure $f -eofchar {}
2250 puts -nonewline $f ""
2252 file size $path(test1)
2254 test io-29.3 {Tcl_WriteChars, nonempty string} {
2255 file delete $path(test1)
2256 set f [open $path(test1) w]
2257 fconfigure $f -eofchar {}
2258 puts -nonewline $f hello
2260 file size $path(test1)
2262 test io-29.4 {Tcl_WriteChars, buffering in full buffering mode} {testchannel} {
2263 file delete $path(test1)
2264 set f [open $path(test1) w]
2265 fconfigure $f -translation lf -buffering full -eofchar {}
2268 lappend l [testchannel outputbuffered $f]
2269 lappend l [file size $path(test1)]
2271 lappend l [testchannel outputbuffered $f]
2272 lappend l [file size $path(test1)]
2276 test io-29.5 {Tcl_WriteChars, buffering in line buffering mode} {testchannel} {
2277 file delete $path(test1)
2278 set f [open $path(test1) w]
2279 fconfigure $f -translation lf -buffering line -eofchar {}
2280 puts -nonewline $f hello
2282 lappend l [testchannel outputbuffered $f]
2283 lappend l [file size $path(test1)]
2285 lappend l [testchannel outputbuffered $f]
2286 lappend l [file size $path(test1)]
2290 test io-29.6 {Tcl_WriteChars, buffering in no buffering mode} {testchannel} {
2291 file delete $path(test1)
2292 set f [open $path(test1) w]
2293 fconfigure $f -translation lf -buffering none -eofchar {}
2294 puts -nonewline $f hello
2296 lappend l [testchannel outputbuffered $f]
2297 lappend l [file size $path(test1)]
2299 lappend l [testchannel outputbuffered $f]
2300 lappend l [file size $path(test1)]
2305 test io-29.7 {Tcl_Flush, full buffering} {testchannel} {
2306 file delete $path(test1)
2307 set f [open $path(test1) w]
2308 fconfigure $f -translation lf -buffering full -eofchar {}
2309 puts -nonewline $f hello
2311 lappend l [testchannel outputbuffered $f]
2312 lappend l [file size $path(test1)]
2314 lappend l [testchannel outputbuffered $f]
2315 lappend l [file size $path(test1)]
2317 lappend l [testchannel outputbuffered $f]
2318 lappend l [file size $path(test1)]
2322 test io-29.8 {Tcl_Flush, full buffering} {testchannel} {
2323 file delete $path(test1)
2324 set f [open $path(test1) w]
2325 fconfigure $f -translation lf -buffering line
2326 puts -nonewline $f hello
2328 lappend l [testchannel outputbuffered $f]
2329 lappend l [file size $path(test1)]
2331 lappend l [testchannel outputbuffered $f]
2332 lappend l [file size $path(test1)]
2334 lappend l [testchannel outputbuffered $f]
2335 lappend l [file size $path(test1)]
2337 lappend l [testchannel outputbuffered $f]
2338 lappend l [file size $path(test1)]
2341 } {5 0 0 5 0 11 0 11}
2342 test io-29.9 {Tcl_Flush, channel not writable} {
2343 list [catch {flush stdin} msg] $msg
2344 } {1 {channel "stdin" wasn't opened for writing}}
2345 test io-29.10 {Tcl_WriteChars, looping and buffering} {
2346 file delete $path(test1)
2347 set f1 [open $path(test1) w]
2348 fconfigure $f1 -translation lf -eofchar {}
2349 set f2 [open $path(longfile) r]
2350 for {set x 0} {$x < 10} {incr x} {
2355 file size $path(test1)
2357 test io-29.11 {Tcl_WriteChars, no newline, implicit flush} {
2358 file delete $path(test1)
2359 set f1 [open $path(test1) w]
2360 fconfigure $f1 -eofchar {}
2361 set f2 [open $path(longfile) r]
2362 for {set x 0} {$x < 10} {incr x} {
2363 puts -nonewline $f1 [gets $f2]
2367 file size $path(test1)
2369 test io-29.12 {Tcl_WriteChars on a pipe} {stdio openpipe} {
2370 file delete $path(test1)
2371 file delete $path(pipe)
2372 set f1 [open $path(pipe) w]
2373 puts $f1 "set f1 \[[list open $path(longfile) r]]"
2375 for {set x 0} {$x < 10} {incr x} {
2380 set f1 [open "|[list [interpreter] $path(pipe)]" r]
2381 set f2 [open $path(longfile) r]
2383 for {set x 0} {$x < 10} {incr x} {
2386 if {"$l1" != "$l2"} {
2394 test io-29.13 {Tcl_WriteChars to a pipe, line buffered} {stdio openpipe} {
2395 file delete $path(test1)
2396 file delete $path(pipe)
2397 set f1 [open $path(pipe) w]
2404 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
2405 fconfigure $f1 -buffering line
2406 set f2 [open $path(longfile) r]
2409 set backline [gets $f1]
2410 if {"$line" != "$backline"} {
2415 set backline [gets $f1]
2416 if {"$line" != "$backline"} {
2423 test io-29.14 {Tcl_WriteChars, buffering and implicit flush at close} {
2424 file delete $path(test3)
2425 set f [open $path(test3) w]
2426 puts -nonewline $f "Text1"
2427 puts -nonewline $f " Text 2"
2430 set f [open $path(test3) r]
2434 } {Text1 Text 2 Text 3}
2435 test io-29.15 {Tcl_Flush, channel not open for writing} {
2436 file delete $path(test1)
2437 set fd [open $path(test1) w]
2439 set fd [open $path(test1) r]
2440 set x [list [catch {flush $fd} msg] $msg]
2443 [list 1 "channel \"$fd\" wasn't opened for writing"]
2445 test io-29.16 {Tcl_Flush on pipe opened only for reading} {stdio openpipe} {
2446 set fd [open "|[list [interpreter] cat longfile]" r]
2447 set x [list [catch {flush $fd} msg] $msg]
2450 [list 1 "channel \"$fd\" wasn't opened for writing"]
2452 test io-29.17 {Tcl_WriteChars buffers, then Tcl_Flush flushes} {
2453 file delete $path(test1)
2454 set f1 [open $path(test1) w]
2455 fconfigure $f1 -translation lf
2460 set x [file size $path(test1)]
2464 test io-29.18 {Tcl_WriteChars and Tcl_Flush intermixed} {
2465 file delete $path(test1)
2467 set f1 [open $path(test1) w]
2468 fconfigure $f1 -translation lf
2473 lappend x [file size $path(test1)]
2476 lappend x [file size $path(test1)]
2479 lappend x [file size $path(test1)]
2483 test io-29.19 {Explicit and implicit flushes} {
2484 file delete $path(test1)
2485 set f1 [open $path(test1) w]
2486 fconfigure $f1 -translation lf -eofchar {}
2492 lappend x [file size $path(test1)]
2495 lappend x [file size $path(test1)]
2498 lappend x [file size $path(test1)]
2501 test io-29.20 {Implicit flush when buffer is full} {
2502 file delete $path(test1)
2503 set f1 [open $path(test1) w]
2504 fconfigure $f1 -translation lf -eofchar {}
2505 set line "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
2506 for {set x 0} {$x < 100} {incr x} {
2510 lappend z [file size $path(test1)]
2511 for {set x 0} {$x < 100} {incr x} {
2514 lappend z [file size $path(test1)]
2516 lappend z [file size $path(test1)]
2518 } {4096 12288 12600}
2519 test io-29.21 {Tcl_Flush to pipe} {stdio openpipe} {
2520 file delete $path(pipe)
2521 set f1 [open $path(pipe) w]
2522 puts $f1 {set x [read stdin 6]}
2523 puts $f1 {set cnt [string length $x]}
2524 puts $f1 {puts "read $cnt characters"}
2526 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
2532 } "read 6 characters"
2533 test io-29.22 {Tcl_Flush called at other end of pipe} {stdio openpipe} {
2534 file delete $path(pipe)
2535 set f1 [open $path(pipe) w]
2537 fconfigure stdout -buffering full
2546 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
2548 lappend x [gets $f1]
2549 lappend x [gets $f1]
2552 lappend x [gets $f1]
2556 test io-29.23 {Tcl_Flush and line buffering at end of pipe} {stdio openpipe} {
2557 file delete $path(pipe)
2558 set f1 [open $path(pipe) w]
2566 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
2568 lappend x [gets $f1]
2569 lappend x [gets $f1]
2572 lappend x [gets $f1]
2576 test io-29.24 {Tcl_WriteChars and Tcl_Flush move end of file} {
2577 set f [open $path(test3) w]
2580 set f2 [open $path(test3)]
2582 lappend x [read -nonewline $f2]
2585 set f2 [open $path(test3)]
2586 lappend x [read -nonewline $f2]
2590 } "{} {Line 1\nLine 2}"
2591 test io-29.25 {Implicit flush with Tcl_Flush to command pipelines} {stdio openpipe fileevent} {
2592 file delete $path(test3)
2593 set f [open "|[list [interpreter] $path(cat) | [interpreter] $path(cat) > $path(test3)]" w]
2598 set f [open $path(test3) r]
2602 } "Line 1\nLine 2\n"
2603 test io-29.26 {Tcl_Flush, Tcl_Write on bidirectional pipelines} {stdio unixExecs openpipe} {
2604 set f [open "|[list cat -u]" r+]
2611 test io-29.27 {Tcl_Flush on closed pipeline} {stdio openpipe} {
2612 file delete $path(pipe)
2613 set f [open $path(pipe) w]
2616 set f [open "|[list [interpreter] $path(pipe)]" r+]
2621 # The flush below will get a SIGPIPE. This is an expected part of
2622 # test and indicates that the test operates correctly. If you run
2623 # this test under a debugger, the signal will by intercepted unless
2624 # you disable the debugger's signal interception.
2626 if {[catch {flush $f} msg]} {
2627 set x [list 1 $msg $errorCode]
2630 if {[catch {close $f} msg]} {
2631 set x [list 1 $msg $errorCode]
2633 set x {this was supposed to fail and did not}
2636 regsub {".*":} $x {"":} x
2638 } {1 {error flushing "": broken pipe} {posix epipe {broken pipe}}}
2639 test io-29.28 {Tcl_WriteChars, lf mode} {
2640 file delete $path(test1)
2641 set f [open $path(test1) w]
2642 fconfigure $f -translation lf -eofchar {}
2643 puts $f hello\nthere\nand\nhere
2645 set s [file size $path(test1)]
2649 test io-29.29 {Tcl_WriteChars, cr mode} {
2650 file delete $path(test1)
2651 set f [open $path(test1) w]
2652 fconfigure $f -translation cr -eofchar {}
2653 puts $f hello\nthere\nand\nhere
2655 file size $path(test1)
2657 test io-29.30 {Tcl_WriteChars, crlf mode} {
2658 file delete $path(test1)
2659 set f [open $path(test1) w]
2660 fconfigure $f -translation crlf -eofchar {}
2661 puts $f hello\nthere\nand\nhere
2663 file size $path(test1)
2665 test io-29.31 {Tcl_WriteChars, background flush} {stdio openpipe} {
2666 file delete $path(pipe)
2667 file delete $path(output)
2668 set f [open $path(pipe) w]
2669 puts $f "set f \[[list open $path(output) w]]"
2670 puts $f {fconfigure $f -translation lf}
2671 set x [list while {![eof stdin]}]
2674 puts $f { puts -nonewline $f [read stdin 4096]}
2679 set x 01234567890123456789012345678901
2680 for {set i 0} {$i < 11} {incr i} {
2683 set f [open $path(output) w]
2685 set f [open "|[list [interpreter] $path(pipe)]" r+]
2686 fconfigure $f -blocking off
2687 puts -nonewline $f $x
2690 while {([file size $path(output)] < 65536) && ($counter < 1000)} {
2695 if {$counter == 1000} {
2696 set result "file size only [file size $path(output)]"
2701 test io-29.32 {Tcl_WriteChars, background flush to slow reader} \
2702 {stdio asyncPipeClose openpipe} {
2703 file delete $path(pipe)
2704 file delete $path(output)
2705 set f [open $path(pipe) w]
2706 puts $f "set f \[[list open $path(output) w]]"
2707 puts $f {fconfigure $f -translation lf}
2708 set x [list while {![eof stdin]}]
2712 puts $f { puts -nonewline $f [read stdin 1024]}
2717 set x 01234567890123456789012345678901
2718 for {set i 0} {$i < 11} {incr i} {
2721 set f [open $path(output) w]
2723 set f [open "|[list [interpreter] $path(pipe)]" r+]
2724 fconfigure $f -blocking off
2725 puts -nonewline $f $x
2728 while {([file size $path(output)] < 65536) && ($counter < 1000)} {
2733 if {$counter == 1000} {
2734 set result "file size only [file size $path(output)]"
2739 test io-29.33 {Tcl_Flush, implicit flush on exit} {exec} {
2740 set f [open $path(script) w]
2741 puts $f "set f \[[list open $path(test1) w]]"
2742 puts $f {fconfigure $f -translation lf
2748 exec [interpreter] $path(script)
2749 set f [open $path(test1) r]
2753 } "hello\nbye\nstrange\n"
2754 test io-29.34 {Tcl_Close, async flush on close, using sockets} {socket tempNotMac fileevent} {
2757 set l abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
2758 proc writelots {s l} {
2759 for {set i 0} {$i < 2000} {incr i} {
2763 proc accept {s a p} {
2765 fileevent $s readable [namespace code [list readit $s]]
2766 fconfigure $s -blocking off
2777 } elseif {([string length $l] > 0) || ![fblocked $s]} {
2781 set ss [socket -server [namespace code accept] 0]
2782 set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
2783 vwait [namespace which -variable x]
2784 fconfigure $cs -blocking off
2788 vwait [namespace which -variable x]
2791 test io-29.35 {Tcl_Close vs fileevent vs multiple interpreters} {socket tempNotMac fileevent} {
2792 # On Mac, this test screws up sockets such that subsequent tests using port 2828
2793 # either cause errors or panic().
2795 catch {interp delete x}
2796 catch {interp delete y}
2799 set s [socket -server [namespace code accept] 0]
2800 proc accept {s a p} {
2804 set c [socket [info hostname] [lindex [fconfigure $s -sockname] 2]]
2805 interp share {} $c x
2806 interp share {} $c y
2824 x eval "fileevent $c readable \{readit $c\}"
2825 y eval "fileevent $c readable \{readit $c\}"
2826 y eval [list close $c]
2833 # Test end of line translations. Procedures tested are Tcl_Write, Tcl_Read.
2835 test io-30.1 {Tcl_Write lf, Tcl_Read lf} {
2836 file delete $path(test1)
2837 set f [open $path(test1) w]
2838 fconfigure $f -translation lf
2839 puts $f hello\nthere\nand\nhere
2841 set f [open $path(test1) r]
2842 fconfigure $f -translation lf
2846 } "hello\nthere\nand\nhere\n"
2847 test io-30.2 {Tcl_Write lf, Tcl_Read cr} {
2848 file delete $path(test1)
2849 set f [open $path(test1) w]
2850 fconfigure $f -translation lf
2851 puts $f hello\nthere\nand\nhere
2853 set f [open $path(test1) r]
2854 fconfigure $f -translation cr
2858 } "hello\nthere\nand\nhere\n"
2859 test io-30.3 {Tcl_Write lf, Tcl_Read crlf} {
2860 file delete $path(test1)
2861 set f [open $path(test1) w]
2862 fconfigure $f -translation lf
2863 puts $f hello\nthere\nand\nhere
2865 set f [open $path(test1) r]
2866 fconfigure $f -translation crlf
2870 } "hello\nthere\nand\nhere\n"
2871 test io-30.4 {Tcl_Write cr, Tcl_Read cr} {
2872 file delete $path(test1)
2873 set f [open $path(test1) w]
2874 fconfigure $f -translation cr
2875 puts $f hello\nthere\nand\nhere
2877 set f [open $path(test1) r]
2878 fconfigure $f -translation cr
2882 } "hello\nthere\nand\nhere\n"
2883 test io-30.5 {Tcl_Write cr, Tcl_Read lf} {
2884 file delete $path(test1)
2885 set f [open $path(test1) w]
2886 fconfigure $f -translation cr
2887 puts $f hello\nthere\nand\nhere
2889 set f [open $path(test1) r]
2890 fconfigure $f -translation lf
2894 } "hello\rthere\rand\rhere\r"
2895 test io-30.6 {Tcl_Write cr, Tcl_Read crlf} {
2896 file delete $path(test1)
2897 set f [open $path(test1) w]
2898 fconfigure $f -translation cr
2899 puts $f hello\nthere\nand\nhere
2901 set f [open $path(test1) r]
2902 fconfigure $f -translation crlf
2906 } "hello\rthere\rand\rhere\r"
2907 test io-30.7 {Tcl_Write crlf, Tcl_Read crlf} {
2908 file delete $path(test1)
2909 set f [open $path(test1) w]
2910 fconfigure $f -translation crlf
2911 puts $f hello\nthere\nand\nhere
2913 set f [open $path(test1) r]
2914 fconfigure $f -translation crlf
2918 } "hello\nthere\nand\nhere\n"
2919 test io-30.8 {Tcl_Write crlf, Tcl_Read lf} {
2920 file delete $path(test1)
2921 set f [open $path(test1) w]
2922 fconfigure $f -translation crlf
2923 puts $f hello\nthere\nand\nhere
2925 set f [open $path(test1) r]
2926 fconfigure $f -translation lf
2930 } "hello\r\nthere\r\nand\r\nhere\r\n"
2931 test io-30.9 {Tcl_Write crlf, Tcl_Read cr} {
2932 file delete $path(test1)
2933 set f [open $path(test1) w]
2934 fconfigure $f -translation crlf
2935 puts $f hello\nthere\nand\nhere
2937 set f [open $path(test1) r]
2938 fconfigure $f -translation cr
2942 } "hello\n\nthere\n\nand\n\nhere\n\n"
2943 test io-30.10 {Tcl_Write lf, Tcl_Read auto} {
2944 file delete $path(test1)
2945 set f [open $path(test1) w]
2946 fconfigure $f -translation lf
2947 puts $f hello\nthere\nand\nhere
2949 set f [open $path(test1) r]
2951 set x [fconfigure $f -translation]
2959 test io-30.11 {Tcl_Write cr, Tcl_Read auto} {
2960 file delete $path(test1)
2961 set f [open $path(test1) w]
2962 fconfigure $f -translation cr
2963 puts $f hello\nthere\nand\nhere
2965 set f [open $path(test1) r]
2967 set x [fconfigure $f -translation]
2975 test io-30.12 {Tcl_Write crlf, Tcl_Read auto} {
2976 file delete $path(test1)
2977 set f [open $path(test1) w]
2978 fconfigure $f -translation crlf
2979 puts $f hello\nthere\nand\nhere
2981 set f [open $path(test1) r]
2983 set x [fconfigure $f -translation]
2992 test io-30.13 {Tcl_Write crlf on block boundary, Tcl_Read auto} {
2993 file delete $path(test1)
2994 set f [open $path(test1) w]
2995 fconfigure $f -translation crlf
2996 set line "123456789ABCDE" ;# 14 char plus crlf
2997 puts -nonewline $f x ;# shift crlf across block boundary
2998 for {set i 0} {$i < 700} {incr i} {
3002 set f [open $path(test1) r]
3003 fconfigure $f -translation auto
3009 test io-30.14 {Tcl_Write crlf on block boundary, Tcl_Read crlf} {
3010 file delete $path(test1)
3011 set f [open $path(test1) w]
3012 fconfigure $f -translation crlf
3013 set line "123456789ABCDE" ;# 14 char plus crlf
3014 puts -nonewline $f x ;# shift crlf across block boundary
3015 for {set i 0} {$i < 700} {incr i} {
3019 set f [open $path(test1) r]
3020 fconfigure $f -translation crlf
3026 test io-30.15 {Tcl_Write mixed, Tcl_Read auto} {
3027 file delete $path(test1)
3028 set f [open $path(test1) w]
3029 fconfigure $f -translation lf
3030 puts $f hello\nthere\nand\rhere
3032 set f [open $path(test1) r]
3033 fconfigure $f -translation auto
3042 test io-30.16 {Tcl_Write ^Z at end, Tcl_Read auto} {
3043 file delete $path(test1)
3044 set f [open $path(test1) w]
3045 fconfigure $f -translation lf
3046 puts -nonewline $f hello\nthere\nand\rhere\n\x1a
3048 set f [open $path(test1) r]
3049 fconfigure $f -eofchar \x1a -translation auto
3058 test io-30.17 {Tcl_Write, implicit ^Z at end, Tcl_Read auto} {pcOnly} {
3059 file delete $path(test1)
3060 set f [open $path(test1) w]
3061 fconfigure $f -eofchar \x1a -translation lf
3062 puts $f hello\nthere\nand\rhere
3064 set f [open $path(test1) r]
3065 fconfigure $f -eofchar \x1a -translation auto
3074 test io-30.18 {Tcl_Write, ^Z in middle, Tcl_Read auto} {
3075 file delete $path(test1)
3076 set f [open $path(test1) w]
3077 fconfigure $f -translation lf
3078 set s [format "abc\ndef\n%cghi\nqrs" 26]
3081 set f [open $path(test1) r]
3082 fconfigure $f -eofchar \x1a -translation auto
3093 } {abc def 0 {} 1 {} 1}
3094 test io-30.19 {Tcl_Write, ^Z no newline in middle, Tcl_Read auto} {
3095 file delete $path(test1)
3096 set f [open $path(test1) w]
3097 fconfigure $f -translation lf
3098 set s [format "abc\ndef\n%cghi\nqrs" 26]
3101 set f [open $path(test1) r]
3102 fconfigure $f -eofchar \x1a -translation auto
3113 } {abc def 0 {} 1 {} 1}
3114 test io-30.20 {Tcl_Write, ^Z in middle ignored, Tcl_Read lf} {
3115 file delete $path(test1)
3116 set f [open $path(test1) w]
3117 fconfigure $f -translation lf -eofchar {}
3118 set s [format "abc\ndef\n%cghi\nqrs" 26]
3121 set f [open $path(test1) r]
3122 fconfigure $f -translation lf -eofchar {}
3135 } "abc def 0 \x1aghi 0 qrs 0 {} 1"
3136 test io-30.21 {Tcl_Write, ^Z in middle ignored, Tcl_Read cr} {
3137 file delete $path(test1)
3138 set f [open $path(test1) w]
3139 fconfigure $f -translation lf -eofchar {}
3140 set s [format "abc\ndef\n%cghi\nqrs" 26]
3143 set f [open $path(test1) r]
3144 fconfigure $f -translation cr -eofchar {}
3147 lappend l [string compare $x "abc\ndef\n\x1aghi\nqrs\n"]
3154 test io-30.22 {Tcl_Write, ^Z in middle ignored, Tcl_Read crlf} {
3155 file delete $path(test1)
3156 set f [open $path(test1) w]
3157 fconfigure $f -translation lf -eofchar {}
3158 set s [format "abc\ndef\n%cghi\nqrs" 26]
3161 set f [open $path(test1) r]
3162 fconfigure $f -translation crlf -eofchar {}
3165 lappend l [string compare $x "abc\ndef\n\x1aghi\nqrs\n"]
3172 test io-30.23 {Tcl_Write lf, ^Z in middle, Tcl_Read auto} {
3173 file delete $path(test1)
3174 set f [open $path(test1) w]
3175 fconfigure $f -translation lf
3176 set c [format abc\ndef\n%cqrs\ntuv 26]
3179 set f [open $path(test1) r]
3180 fconfigure $f -translation auto -eofchar \x1a
3181 set c [string length [read $f]]
3186 test io-30.24 {Tcl_Write lf, ^Z in middle, Tcl_Read lf} {
3187 file delete $path(test1)
3188 set f [open $path(test1) w]
3189 fconfigure $f -translation lf
3190 set c [format abc\ndef\n%cqrs\ntuv 26]
3193 set f [open $path(test1) r]
3194 fconfigure $f -translation lf -eofchar \x1a
3195 set c [string length [read $f]]
3200 test io-30.25 {Tcl_Write cr, ^Z in middle, Tcl_Read auto} {
3201 file delete $path(test1)
3202 set f [open $path(test1) w]
3203 fconfigure $f -translation cr
3204 set c [format abc\ndef\n%cqrs\ntuv 26]
3207 set f [open $path(test1) r]
3208 fconfigure $f -translation auto -eofchar \x1a
3209 set c [string length [read $f]]
3214 test io-30.26 {Tcl_Write cr, ^Z in middle, Tcl_Read cr} {
3215 file delete $path(test1)
3216 set f [open $path(test1) w]
3217 fconfigure $f -translation cr
3218 set c [format abc\ndef\n%cqrs\ntuv 26]
3221 set f [open $path(test1) r]
3222 fconfigure $f -translation cr -eofchar \x1a
3223 set c [string length [read $f]]
3228 test io-30.27 {Tcl_Write crlf, ^Z in middle, Tcl_Read auto} {
3229 file delete $path(test1)
3230 set f [open $path(test1) w]
3231 fconfigure $f -translation crlf
3232 set c [format abc\ndef\n%cqrs\ntuv 26]
3235 set f [open $path(test1) r]
3236 fconfigure $f -translation auto -eofchar \x1a
3237 set c [string length [read $f]]
3242 test io-30.28 {Tcl_Write crlf, ^Z in middle, Tcl_Read crlf} {
3243 file delete $path(test1)
3244 set f [open $path(test1) w]
3245 fconfigure $f -translation crlf
3246 set c [format abc\ndef\n%cqrs\ntuv 26]
3249 set f [open $path(test1) r]
3250 fconfigure $f -translation crlf -eofchar \x1a
3251 set c [string length [read $f]]
3257 # Test end of line translations. Functions tested are Tcl_Write and Tcl_Gets.
3259 test io-31.1 {Tcl_Write lf, Tcl_Gets auto} {
3260 file delete $path(test1)
3261 set f [open $path(test1) w]
3262 fconfigure $f -translation lf
3263 puts $f hello\nthere\nand\nhere
3265 set f [open $path(test1) r]
3269 lappend l [fconfigure $f -translation]
3272 lappend l [fconfigure $f -translation]
3275 } {hello 6 auto there 12 auto}
3276 test io-31.2 {Tcl_Write cr, Tcl_Gets auto} {
3277 file delete $path(test1)
3278 set f [open $path(test1) w]
3279 fconfigure $f -translation cr
3280 puts $f hello\nthere\nand\nhere
3282 set f [open $path(test1) r]
3286 lappend l [fconfigure $f -translation]
3289 lappend l [fconfigure $f -translation]
3292 } {hello 6 auto there 12 auto}
3293 test io-31.3 {Tcl_Write crlf, Tcl_Gets auto} {
3294 file delete $path(test1)
3295 set f [open $path(test1) w]
3296 fconfigure $f -translation crlf
3297 puts $f hello\nthere\nand\nhere
3299 set f [open $path(test1) r]
3303 lappend l [fconfigure $f -translation]
3306 lappend l [fconfigure $f -translation]
3309 } {hello 7 auto there 14 auto}
3310 test io-31.4 {Tcl_Write lf, Tcl_Gets lf} {
3311 file delete $path(test1)
3312 set f [open $path(test1) w]
3313 fconfigure $f -translation lf
3314 puts $f hello\nthere\nand\nhere
3316 set f [open $path(test1) r]
3317 fconfigure $f -translation lf
3321 lappend l [fconfigure $f -translation]
3324 lappend l [fconfigure $f -translation]
3327 } {hello 6 lf there 12 lf}
3328 test io-31.5 {Tcl_Write lf, Tcl_Gets cr} {
3329 file delete $path(test1)
3330 set f [open $path(test1) w]
3331 fconfigure $f -translation lf
3332 puts $f hello\nthere\nand\nhere
3334 set f [open $path(test1) r]
3335 fconfigure $f -translation cr
3337 lappend l [string length [gets $f]]
3339 lappend l [fconfigure $f -translation]
3343 lappend l [fconfigure $f -translation]
3347 } {21 21 cr 1 {} 21 cr 1}
3348 test io-31.6 {Tcl_Write lf, Tcl_Gets crlf} {
3349 file delete $path(test1)
3350 set f [open $path(test1) w]
3351 fconfigure $f -translation lf
3352 puts $f hello\nthere\nand\nhere
3354 set f [open $path(test1) r]
3355 fconfigure $f -translation crlf
3357 lappend l [string length [gets $f]]
3359 lappend l [fconfigure $f -translation]
3363 lappend l [fconfigure $f -translation]
3367 } {21 21 crlf 1 {} 21 crlf 1}
3368 test io-31.7 {Tcl_Write cr, Tcl_Gets cr} {
3369 file delete $path(test1)
3370 set f [open $path(test1) w]
3371 fconfigure $f -translation cr
3372 puts $f hello\nthere\nand\nhere
3374 set f [open $path(test1) r]
3375 fconfigure $f -translation cr
3379 lappend l [fconfigure $f -translation]
3383 lappend l [fconfigure $f -translation]
3387 } {hello 6 cr 0 there 12 cr 0}
3388 test io-31.8 {Tcl_Write cr, Tcl_Gets lf} {
3389 file delete $path(test1)
3390 set f [open $path(test1) w]
3391 fconfigure $f -translation cr
3392 puts $f hello\nthere\nand\nhere
3394 set f [open $path(test1) r]
3395 fconfigure $f -translation lf
3397 lappend l [string length [gets $f]]
3399 lappend l [fconfigure $f -translation]
3403 lappend l [fconfigure $f -translation]
3407 } {21 21 lf 1 {} 21 lf 1}
3408 test io-31.9 {Tcl_Write cr, Tcl_Gets crlf} {
3409 file delete $path(test1)
3410 set f [open $path(test1) w]
3411 fconfigure $f -translation cr
3412 puts $f hello\nthere\nand\nhere
3414 set f [open $path(test1) r]
3415 fconfigure $f -translation crlf
3417 lappend l [string length [gets $f]]
3419 lappend l [fconfigure $f -translation]
3423 lappend l [fconfigure $f -translation]
3427 } {21 21 crlf 1 {} 21 crlf 1}
3428 test io-31.10 {Tcl_Write crlf, Tcl_Gets crlf} {
3429 file delete $path(test1)
3430 set f [open $path(test1) w]
3431 fconfigure $f -translation crlf
3432 puts $f hello\nthere\nand\nhere
3434 set f [open $path(test1) r]
3435 fconfigure $f -translation crlf
3439 lappend l [fconfigure $f -translation]
3443 lappend l [fconfigure $f -translation]
3447 } {hello 7 crlf 0 there 14 crlf 0}
3448 test io-31.11 {Tcl_Write crlf, Tcl_Gets cr} {
3449 file delete $path(test1)
3450 set f [open $path(test1) w]
3451 fconfigure $f -translation crlf
3452 puts $f hello\nthere\nand\nhere
3454 set f [open $path(test1) r]
3455 fconfigure $f -translation cr
3459 lappend l [fconfigure $f -translation]
3461 lappend l [string length [gets $f]]
3463 lappend l [fconfigure $f -translation]
3467 } {hello 6 cr 0 6 13 cr 0}
3468 test io-31.12 {Tcl_Write crlf, Tcl_Gets lf} {
3469 file delete $path(test1)
3470 set f [open $path(test1) w]
3471 fconfigure $f -translation crlf
3472 puts $f hello\nthere\nand\nhere
3474 set f [open $path(test1) r]
3475 fconfigure $f -translation lf
3477 lappend l [string length [gets $f]]
3479 lappend l [fconfigure $f -translation]
3481 lappend l [string length [gets $f]]
3483 lappend l [fconfigure $f -translation]
3487 } {6 7 lf 0 6 14 lf 0}
3488 test io-31.13 {binary mode is synonym of lf mode} {
3489 file delete $path(test1)
3490 set f [open $path(test1) w]
3491 fconfigure $f -translation binary
3492 set x [fconfigure $f -translation]
3497 # Test io-9.14 has been removed because "auto" output translation mode is
3500 test io-31.14 {Tcl_Write mixed, Tcl_Gets auto} {
3501 file delete $path(test1)
3502 set f [open $path(test1) w]
3503 fconfigure $f -translation lf
3504 puts $f hello\nthere\rand\r\nhere
3506 set f [open $path(test1) r]
3507 fconfigure $f -translation auto
3518 } {hello there and here 0 {} 1}
3519 test io-31.15 {Tcl_Write mixed, Tcl_Gets auto} {
3520 file delete $path(test1)
3521 set f [open $path(test1) w]
3522 fconfigure $f -translation lf
3523 puts -nonewline $f hello\nthere\rand\r\nhere\r
3525 set f [open $path(test1) r]
3526 fconfigure $f -translation auto
3537 } {hello there and here 0 {} 1}
3538 test io-31.16 {Tcl_Write mixed, Tcl_Gets auto} {
3539 file delete $path(test1)
3540 set f [open $path(test1) w]
3541 fconfigure $f -translation lf
3542 puts -nonewline $f hello\nthere\rand\r\nhere\n
3544 set f [open $path(test1) r]
3555 } {hello there and here 0 {} 1}
3556 test io-31.17 {Tcl_Write mixed, Tcl_Gets auto} {
3557 file delete $path(test1)
3558 set f [open $path(test1) w]
3559 fconfigure $f -translation lf
3560 puts -nonewline $f hello\nthere\rand\r\nhere\r\n
3562 set f [open $path(test1) r]
3563 fconfigure $f -translation auto
3574 } {hello there and here 0 {} 1}
3575 test io-31.18 {Tcl_Write ^Z at end, Tcl_Gets auto} {
3576 file delete $path(test1)
3577 set f [open $path(test1) w]
3578 fconfigure $f -translation lf
3579 set s [format "hello\nthere\nand\rhere\n\%c" 26]
3582 set f [open $path(test1) r]
3583 fconfigure $f -eofchar \x1a -translation auto
3594 } {hello there and here 0 {} 1}
3595 test io-31.19 {Tcl_Write, implicit ^Z at end, Tcl_Gets auto} {
3596 file delete $path(test1)
3597 set f [open $path(test1) w]
3598 fconfigure $f -eofchar \x1a -translation lf
3599 puts $f hello\nthere\nand\rhere
3601 set f [open $path(test1) r]
3602 fconfigure $f -eofchar \x1a -translation auto
3613 } {hello there and here 0 {} 1}
3614 test io-31.20 {Tcl_Write, ^Z in middle, Tcl_Gets auto, eofChar} {
3615 file delete $path(test1)
3616 set f [open $path(test1) w]
3617 fconfigure $f -translation lf
3618 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3621 set f [open $path(test1) r]
3622 fconfigure $f -eofchar \x1a
3623 fconfigure $f -translation auto
3633 test io-31.21 {Tcl_Write, no newline ^Z in middle, Tcl_Gets auto, eofChar} {
3634 file delete $path(test1)
3635 set f [open $path(test1) w]
3636 fconfigure $f -translation lf
3637 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3640 set f [open $path(test1) r]
3641 fconfigure $f -eofchar \x1a -translation auto
3651 test io-31.22 {Tcl_Write, ^Z in middle ignored, Tcl_Gets lf} {
3652 file delete $path(test1)
3653 set f [open $path(test1) w]
3654 fconfigure $f -translation lf -eofchar {}
3655 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3658 set f [open $path(test1) r]
3659 fconfigure $f -translation lf -eofchar {}
3672 } "abc def 0 \x1aqrs 0 tuv 0 {} 1"
3673 test io-31.23 {Tcl_Write, ^Z in middle ignored, Tcl_Gets cr} {
3674 file delete $path(test1)
3675 set f [open $path(test1) w]
3676 fconfigure $f -translation cr -eofchar {}
3677 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3680 set f [open $path(test1) r]
3681 fconfigure $f -translation cr -eofchar {}
3694 } "abc def 0 \x1aqrs 0 tuv 0 {} 1"
3695 test io-31.24 {Tcl_Write, ^Z in middle ignored, Tcl_Gets crlf} {
3696 file delete $path(test1)
3697 set f [open $path(test1) w]
3698 fconfigure $f -translation crlf -eofchar {}
3699 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3702 set f [open $path(test1) r]
3703 fconfigure $f -translation crlf -eofchar {}
3716 } "abc def 0 \x1aqrs 0 tuv 0 {} 1"
3717 test io-31.25 {Tcl_Write lf, ^Z in middle, Tcl_Gets auto} {
3718 file delete $path(test1)
3719 set f [open $path(test1) w]
3720 fconfigure $f -translation lf
3721 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3724 set f [open $path(test1) r]
3725 fconfigure $f -translation auto -eofchar \x1a
3735 test io-31.26 {Tcl_Write lf, ^Z in middle, Tcl_Gets lf} {
3736 file delete $path(test1)
3737 set f [open $path(test1) w]
3738 fconfigure $f -translation lf
3739 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3742 set f [open $path(test1) r]
3743 fconfigure $f -translation lf -eofchar \x1a
3753 test io-31.27 {Tcl_Write cr, ^Z in middle, Tcl_Gets auto} {
3754 file delete $path(test1)
3755 set f [open $path(test1) w]
3756 fconfigure $f -translation cr -eofchar {}
3757 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3760 set f [open $path(test1) r]
3761 fconfigure $f -translation auto -eofchar \x1a
3771 test io-31.28 {Tcl_Write cr, ^Z in middle, Tcl_Gets cr} {
3772 file delete $path(test1)
3773 set f [open $path(test1) w]
3774 fconfigure $f -translation cr -eofchar {}
3775 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3778 set f [open $path(test1) r]
3779 fconfigure $f -translation cr -eofchar \x1a
3789 test io-31.29 {Tcl_Write crlf, ^Z in middle, Tcl_Gets auto} {
3790 file delete $path(test1)
3791 set f [open $path(test1) w]
3792 fconfigure $f -translation crlf -eofchar {}
3793 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3796 set f [open $path(test1) r]
3797 fconfigure $f -translation auto -eofchar \x1a
3807 test io-31.30 {Tcl_Write crlf, ^Z in middle, Tcl_Gets crlf} {
3808 file delete $path(test1)
3809 set f [open $path(test1) w]
3810 fconfigure $f -translation crlf -eofchar {}
3811 set s [format "abc\ndef\n%cqrs\ntuv" 26]
3814 set f [open $path(test1) r]
3815 fconfigure $f -translation crlf -eofchar \x1a
3825 test io-31.31 {Tcl_Write crlf on block boundary, Tcl_Gets crlf} {
3826 file delete $path(test1)
3827 set f [open $path(test1) w]
3828 fconfigure $f -translation crlf
3829 set line "123456789ABCDE" ;# 14 char plus crlf
3830 puts -nonewline $f x ;# shift crlf across block boundary
3831 for {set i 0} {$i < 700} {incr i} {
3835 set f [open $path(test1) r]
3836 fconfigure $f -translation crlf
3838 while {[gets $f line] >= 0} {
3844 test io-31.32 {Tcl_Write crlf on block boundary, Tcl_Gets auto} {
3845 file delete $path(test1)
3846 set f [open $path(test1) w]
3847 fconfigure $f -translation crlf
3848 set line "123456789ABCDE" ;# 14 char plus crlf
3849 puts -nonewline $f x ;# shift crlf across block boundary
3850 for {set i 0} {$i < 700} {incr i} {
3854 set f [open $path(test1) r]
3855 fconfigure $f -translation auto
3857 while {[gets $f line] >= 0} {
3865 # Test Tcl_Read and buffering.
3867 test io-32.1 {Tcl_Read, channel not readable} {
3868 list [catch {read stdout} msg] $msg
3869 } {1 {channel "stdout" wasn't opened for reading}}
3870 test io-32.2 {Tcl_Read, zero byte count} {
3873 test io-32.3 {Tcl_Read, negative byte count} {
3874 set f [open $path(longfile) r]
3875 set l [list [catch {read $f -1} msg] $msg]
3878 } {1 {bad argument "-1": should be "nonewline"}}
3879 test io-32.4 {Tcl_Read, positive byte count} {
3880 set f [open $path(longfile) r]
3881 set x [read $f 1024]
3882 set s [string length $x]
3887 test io-32.5 {Tcl_Read, multiple buffers} {
3888 set f [open $path(longfile) r]
3889 fconfigure $f -buffersize 100
3890 set x [read $f 1024]
3891 set s [string length $x]
3896 test io-32.6 {Tcl_Read, very large read} {
3897 set f1 [open $path(longfile) r]
3898 set z [read $f1 1000000]
3900 set l [string length $z]
3902 set z [file size $path(longfile)]
3908 test io-32.7 {Tcl_Read, nonblocking, file} {nonBlockFiles} {
3909 set f1 [open $path(longfile) r]
3910 fconfigure $f1 -blocking off
3913 set l [string length $z]
3920 test io-32.8 {Tcl_Read, nonblocking, file} {nonBlockFiles} {
3921 set f1 [open $path(longfile) r]
3922 fconfigure $f1 -blocking off
3923 set z [read $f1 1000000]
3926 set l [string length $z]
3927 set z [file size $path(longfile)]
3933 test io-32.9 {Tcl_Read, read to end of file} {
3934 set f1 [open $path(longfile) r]
3937 set l [string length $z]
3939 set z [file size $path(longfile)]
3945 test io-32.10 {Tcl_Read from a pipe} {stdio openpipe} {
3946 file delete $path(pipe)
3947 set f1 [open $path(pipe) w]
3948 puts $f1 {puts [gets stdin]}
3950 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
3957 test io-32.11 {Tcl_Read from a pipe} {stdio openpipe} {
3958 file delete $path(pipe)
3959 set f1 [open $path(pipe) w]
3960 puts $f1 {puts [gets stdin]}
3961 puts $f1 {puts [gets stdin]}
3963 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
3967 lappend x [read $f1 6]
3970 lappend x [read $f1]
3976 test io-32.12 {Tcl_Read, -nonewline} {
3977 file delete $path(test1)
3978 set f1 [open $path(test1) w]
3982 set f1 [open $path(test1) r]
3983 set c [read -nonewline $f1]
3988 test io-32.13 {Tcl_Read, -nonewline} {
3989 file delete $path(test1)
3990 set f1 [open $path(test1) w]
3994 set f1 [open $path(test1) r]
3995 set c [read -nonewline $f1]
3997 list [string length $c] $c
4000 test io-32.14 {Tcl_Read, reading in small chunks} {
4001 file delete $path(test1)
4002 set f [open $path(test1) w]
4003 puts $f "Two lines: this one"
4004 puts $f "and this one"
4006 set f [open $path(test1)]
4007 set x [list [read $f 1] [read $f 2] [read $f]]
4010 } {T wo { lines: this one
4013 test io-32.15 {Tcl_Read, asking for more input than available} {
4014 file delete $path(test1)
4015 set f [open $path(test1) w]
4016 puts $f "Two lines: this one"
4017 puts $f "and this one"
4019 set f [open $path(test1)]
4023 } {Two lines: this one
4026 test io-32.16 {Tcl_Read, read to end of file with -nonewline} {
4027 file delete $path(test1)
4028 set f [open $path(test1) w]
4029 puts $f "Two lines: this one"
4030 puts $f "and this one"
4032 set f [open $path(test1)]
4033 set x [read -nonewline $f]
4036 } {Two lines: this one
4041 test io-33.1 {Tcl_Gets, reading what was written} {
4042 file delete $path(test1)
4043 set f1 [open $path(test1) w]
4047 set f1 [open $path(test1) r]
4056 test io-33.2 {Tcl_Gets into variable} {
4057 set f1 [open $path(longfile) r]
4059 set l [string length x]
4067 test io-33.3 {Tcl_Gets from pipe} {stdio openpipe} {
4068 file delete $path(pipe)
4069 set f1 [open $path(pipe) w]
4070 puts $f1 {puts [gets stdin]}
4072 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
4078 if {"$x" != "hello"} {
4083 test io-33.4 {Tcl_Gets with long line} {
4084 file delete $path(test3)
4085 set f [open $path(test3) w]
4086 puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4087 puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4088 puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4089 puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4090 puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4092 set f [open $path(test3)]
4096 } {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
4097 test io-33.5 {Tcl_Gets with long line} {
4098 set f [open $path(test3)]
4102 } {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
4103 test io-33.6 {Tcl_Gets and end of file} {
4104 file delete $path(test3)
4105 set f [open $path(test3) w]
4106 puts -nonewline $f "Test1\nTest2"
4108 set f [open $path(test3)]
4111 lappend x [gets $f y] $y
4113 lappend x [gets $f y] $y
4115 lappend x [gets $f y] $y
4118 } {5 Test1 5 Test2 -1 {}}
4119 test io-33.7 {Tcl_Gets and bad variable} {
4120 set f [open $path(test3) w]
4126 set f [open $path(test3) r]
4127 set result [list [catch {gets $f x(0)} msg] $msg]
4130 } {1 {can't set "x(0)": variable isn't array}}
4131 test io-33.8 {Tcl_Gets, exercising double buffering} {
4132 set f [open $path(test3) w]
4133 fconfigure $f -translation lf -eofchar {}
4135 for {set y 0} {$y < 99} {incr y} {set x "a$x"}
4136 for {set y 0} {$y < 100} {incr y} {puts $f $x}
4138 set f [open $path(test3) r]
4139 fconfigure $f -translation lf
4140 for {set y 0} {$y < 100} {incr y} {gets $f}
4144 test io-33.9 {Tcl_Gets, exercising double buffering} {
4145 set f [open $path(test3) w]
4146 fconfigure $f -translation lf -eofchar {}
4148 for {set y 0} {$y < 99} {incr y} {set x "a$x"}
4149 for {set y 0} {$y < 200} {incr y} {puts $f $x}
4151 set f [open $path(test3) r]
4152 fconfigure $f -translation lf
4153 for {set y 0} {$y < 200} {incr y} {gets $f}
4157 test io-33.10 {Tcl_Gets, exercising double buffering} {
4158 set f [open $path(test3) w]
4159 fconfigure $f -translation lf -eofchar {}
4161 for {set y 0} {$y < 99} {incr y} {set x "a$x"}
4162 for {set y 0} {$y < 300} {incr y} {puts $f $x}
4164 set f [open $path(test3) r]
4165 fconfigure $f -translation lf
4166 for {set y 0} {$y < 300} {incr y} {gets $f}
4171 # Test Tcl_Seek and Tcl_Tell.
4173 test io-34.1 {Tcl_Seek to current position at start of file} {
4174 set f1 [open $path(longfile) r]
4180 test io-34.2 {Tcl_Seek to offset from start} {
4181 file delete $path(test1)
4182 set f1 [open $path(test1) w]
4183 fconfigure $f1 -translation lf -eofchar {}
4184 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4185 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4187 set f1 [open $path(test1) r]
4193 test io-34.3 {Tcl_Seek to end of file} {
4194 file delete $path(test1)
4195 set f1 [open $path(test1) w]
4196 fconfigure $f1 -translation lf -eofchar {}
4197 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4198 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4200 set f1 [open $path(test1) r]
4206 test io-34.4 {Tcl_Seek to offset from end of file} {
4207 file delete $path(test1)
4208 set f1 [open $path(test1) w]
4209 fconfigure $f1 -translation lf -eofchar {}
4210 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4211 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4213 set f1 [open $path(test1) r]
4219 test io-34.5 {Tcl_Seek to offset from current position} {
4220 file delete $path(test1)
4221 set f1 [open $path(test1) w]
4222 fconfigure $f1 -translation lf -eofchar {}
4223 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4224 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4226 set f1 [open $path(test1) r]
4233 test io-34.6 {Tcl_Seek to offset from end of file} {
4234 file delete $path(test1)
4235 set f1 [open $path(test1) w]
4236 fconfigure $f1 -translation lf -eofchar {}
4237 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4238 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4240 set f1 [open $path(test1) r]
4248 test io-34.7 {Tcl_Seek to offset from end of file, then to current position} {
4249 file delete $path(test1)
4250 set f1 [open $path(test1) w]
4251 fconfigure $f1 -translation lf -eofchar {}
4252 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4253 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4255 set f1 [open $path(test1) r]
4264 test io-34.8 {Tcl_Seek on pipes: not supported} {stdio openpipe} {
4265 set f1 [open "|[list [interpreter]]" r+]
4266 set x [list [catch {seek $f1 0 current} msg] $msg]
4268 regsub {".*":} $x {"":} x
4270 } {1 {error during seek on "": invalid argument}}
4271 test io-34.9 {Tcl_Seek, testing buffered input flushing} {
4272 file delete $path(test3)
4273 set f [open $path(test3) w]
4274 fconfigure $f -eofchar {}
4275 puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4277 set f [open $path(test3) RDWR]
4280 lappend x [read $f 1]
4282 lappend x [read $f 1]
4284 lappend x [read $f 1]
4286 lappend x [read $f 1]
4288 lappend x [read $f 1]
4290 lappend x [read $f 1]
4295 set path(test3) [makeFile {} test3]
4297 test io-34.10 {Tcl_Seek testing flushing of buffered input} {
4298 set f [open $path(test3) w]
4299 fconfigure $f -translation lf
4302 set f [open $path(test3) r+]
4303 fconfigure $f -translation lf
4308 list $x [viewFile test3]
4311 test io-34.11 {Tcl_Seek testing flushing of buffered output} {
4312 set f [open $path(test3) w]
4315 set f [open $path(test3) w+]
4320 list $x [viewFile test3]
4322 test io-34.12 {Tcl_Seek testing combination of write, seek back and read} {
4323 set f [open $path(test3) w]
4324 fconfigure $f -translation lf -eofchar {}
4327 set f [open $path(test3) a+]
4328 fconfigure $f -translation lf -eofchar {}
4335 list $x [viewFile test3] $y
4339 test io-34.13 {Tcl_Tell at start of file} {
4340 file delete $path(test1)
4341 set f1 [open $path(test1) w]
4346 test io-34.14 {Tcl_Tell after seek to end of file} {
4347 file delete $path(test1)
4348 set f1 [open $path(test1) w]
4349 fconfigure $f1 -translation lf -eofchar {}
4350 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4351 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4353 set f1 [open $path(test1) r]
4359 test io-34.15 {Tcl_Tell combined with seeking} {
4360 file delete $path(test1)
4361 set f1 [open $path(test1) w]
4362 fconfigure $f1 -translation lf -eofchar {}
4363 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4364 puts $f1 "abcdefghijklmnopqrstuvwxyz"
4366 set f1 [open $path(test1) r]
4374 test io-34.16 {Tcl_tell on pipe: always -1} {stdio openpipe} {
4375 set f1 [open "|[list [interpreter]]" r+]
4380 test io-34.17 {Tcl_Tell on pipe: always -1} {stdio openpipe} {
4381 set f1 [open "|[list [interpreter]]" r+]
4382 puts $f1 {puts hello}
4389 test io-34.18 {Tcl_Tell combined with seeking and reading} {
4390 file delete $path(test2)
4391 set f [open $path(test2) w]
4392 fconfigure $f -translation lf -eofchar {}
4393 puts -nonewline $f "line1\nline2\nline3\nline4\nline5\n"
4395 set f [open $path(test2)]
4396 fconfigure $f -translation lf
4409 test io-34.19 {Tcl_Tell combined with opening in append mode} {
4410 set f [open $path(test3) w]
4411 fconfigure $f -translation lf -eofchar {}
4412 puts $f "abcdefghijklmnopqrstuvwxyz"
4413 puts $f "abcdefghijklmnopqrstuvwxyz"
4415 set f [open $path(test3) a]
4420 test io-34.20 {Tcl_Tell combined with writing} {
4421 set f [open $path(test3) w]
4425 puts -nonewline $f a
4428 puts -nonewline $f a
4435 test io-34.21 {Tcl_Seek and Tcl_Tell on large files} {largefileSupport} {
4436 file delete $path(test3)
4437 set f [open $path(test3) w]
4438 fconfigure $f -encoding binary
4441 puts -nonewline $f abcdef
4448 puts -nonewline $f abcdef
4451 lappend l [file size $f]
4453 close [open $path(test3) w]
4454 lappend l [file size $f]
4456 } {0 6 6 4294967296 4294967302 4294967302 0}
4460 test io-35.1 {Tcl_Eof} {
4461 file delete $path(test1)
4462 set f [open $path(test1) w]
4466 set f [open $path(test1)]
4479 test io-35.2 {Tcl_Eof with pipe} {stdio openpipe} {
4480 file delete $path(pipe)
4481 set f1 [open $path(pipe) w]
4482 puts $f1 {gets stdin}
4483 puts $f1 {puts hello}
4485 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
4497 test io-35.3 {Tcl_Eof with pipe} {stdio openpipe} {
4498 file delete $path(pipe)
4499 set f1 [open $path(pipe) w]
4500 puts $f1 {gets stdin}
4501 puts $f1 {puts hello}
4503 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
4519 test io-35.4 {Tcl_Eof, eof detection on nonblocking file} {nonBlockFiles} {
4520 file delete $path(test1)
4521 set f [open $path(test1) w]
4523 set f [open $path(test1) r]
4524 fconfigure $f -blocking off
4531 test io-35.5 {Tcl_Eof, eof detection on nonblocking pipe} {stdio openpipe} {
4532 file delete $path(pipe)
4533 set f [open $path(pipe) w]
4538 set f [open "|[list [interpreter] $path(pipe)]" r]
4545 test io-35.6 {Tcl_Eof, eof char, lf write, auto read} {
4546 file delete $path(test1)
4547 set f [open $path(test1) w]
4548 fconfigure $f -translation lf -eofchar \x1a
4551 set s [file size $path(test1)]
4552 set f [open $path(test1) r]
4553 fconfigure $f -translation auto -eofchar \x1a
4554 set l [string length [read $f]]
4559 test io-35.7 {Tcl_Eof, eof char, lf write, lf read} {
4560 file delete $path(test1)
4561 set f [open $path(test1) w]
4562 fconfigure $f -translation lf -eofchar \x1a
4565 set s [file size $path(test1)]
4566 set f [open $path(test1) r]
4567 fconfigure $f -translation lf -eofchar \x1a
4568 set l [string length [read $f]]
4573 test io-35.8 {Tcl_Eof, eof char, cr write, auto read} {
4574 file delete $path(test1)
4575 set f [open $path(test1) w]
4576 fconfigure $f -translation cr -eofchar \x1a
4579 set s [file size $path(test1)]
4580 set f [open $path(test1) r]
4581 fconfigure $f -translation auto -eofchar \x1a
4582 set l [string length [read $f]]
4587 test io-35.9 {Tcl_Eof, eof char, cr write, cr read} {
4588 file delete $path(test1)
4589 set f [open $path(test1) w]
4590 fconfigure $f -translation cr -eofchar \x1a
4593 set s [file size $path(test1)]
4594 set f [open $path(test1) r]
4595 fconfigure $f -translation cr -eofchar \x1a
4596 set l [string length [read $f]]
4601 test io-35.10 {Tcl_Eof, eof char, crlf write, auto read} {
4602 file delete $path(test1)
4603 set f [open $path(test1) w]
4604 fconfigure $f -translation crlf -eofchar \x1a
4607 set s [file size $path(test1)]
4608 set f [open $path(test1) r]
4609 fconfigure $f -translation auto -eofchar \x1a
4610 set l [string length [read $f]]
4615 test io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} {
4616 file delete $path(test1)
4617 set f [open $path(test1) w]
4618 fconfigure $f -translation crlf -eofchar \x1a
4621 set s [file size $path(test1)]
4622 set f [open $path(test1) r]
4623 fconfigure $f -translation crlf -eofchar \x1a
4624 set l [string length [read $f]]
4629 test io-35.12 {Tcl_Eof, eof char in middle, lf write, auto read} {
4630 file delete $path(test1)
4631 set f [open $path(test1) w]
4632 fconfigure $f -translation lf -eofchar {}
4633 set i [format abc\ndef\n%cqrs\nuvw 26]
4636 set c [file size $path(test1)]
4637 set f [open $path(test1) r]
4638 fconfigure $f -translation auto -eofchar \x1a
4639 set l [string length [read $f]]
4644 test io-35.13 {Tcl_Eof, eof char in middle, lf write, lf read} {
4645 file delete $path(test1)
4646 set f [open $path(test1) w]
4647 fconfigure $f -translation lf -eofchar {}
4648 set i [format abc\ndef\n%cqrs\nuvw 26]
4651 set c [file size $path(test1)]
4652 set f [open $path(test1) r]
4653 fconfigure $f -translation lf -eofchar \x1a
4654 set l [string length [read $f]]
4659 test io-35.14 {Tcl_Eof, eof char in middle, cr write, auto read} {
4660 file delete $path(test1)
4661 set f [open $path(test1) w]
4662 fconfigure $f -translation cr -eofchar {}
4663 set i [format abc\ndef\n%cqrs\nuvw 26]
4666 set c [file size $path(test1)]
4667 set f [open $path(test1) r]
4668 fconfigure $f -translation auto -eofchar \x1a
4669 set l [string length [read $f]]
4674 test io-35.15 {Tcl_Eof, eof char in middle, cr write, cr read} {
4675 file delete $path(test1)
4676 set f [open $path(test1) w]
4677 fconfigure $f -translation cr -eofchar {}
4678 set i [format abc\ndef\n%cqrs\nuvw 26]
4681 set c [file size $path(test1)]
4682 set f [open $path(test1) r]
4683 fconfigure $f -translation cr -eofchar \x1a
4684 set l [string length [read $f]]
4689 test io-35.16 {Tcl_Eof, eof char in middle, crlf write, auto read} {
4690 file delete $path(test1)
4691 set f [open $path(test1) w]
4692 fconfigure $f -translation crlf -eofchar {}
4693 set i [format abc\ndef\n%cqrs\nuvw 26]
4696 set c [file size $path(test1)]
4697 set f [open $path(test1) r]
4698 fconfigure $f -translation auto -eofchar \x1a
4699 set l [string length [read $f]]
4704 test io-35.17 {Tcl_Eof, eof char in middle, crlf write, crlf read} {
4705 file delete $path(test1)
4706 set f [open $path(test1) w]
4707 fconfigure $f -translation crlf -eofchar {}
4708 set i [format abc\ndef\n%cqrs\nuvw 26]
4711 set c [file size $path(test1)]
4712 set f [open $path(test1) r]
4713 fconfigure $f -translation crlf -eofchar \x1a
4714 set l [string length [read $f]]
4720 # Test Tcl_InputBlocked
4722 test io-36.1 {Tcl_InputBlocked on nonblocking pipe} {stdio openpipe} {
4723 set f1 [open "|[list [interpreter]]" r+]
4724 puts $f1 {puts hello_from_pipe}
4727 fconfigure $f1 -blocking off -buffering full
4728 puts $f1 {puts hello}
4730 lappend x [gets $f1]
4731 lappend x [fblocked $f1]
4734 lappend x [gets $f1]
4735 lappend x [fblocked $f1]
4736 lappend x [gets $f1]
4737 lappend x [fblocked $f1]
4740 } {{} 1 hello 0 {} 1}
4741 test io-36.2 {Tcl_InputBlocked on blocking pipe} {stdio openpipe} {
4742 set f1 [open "|[list [interpreter]]" r+]
4743 fconfigure $f1 -buffering line
4744 puts $f1 {puts hello_from_pipe}
4746 lappend x [gets $f1]
4747 lappend x [fblocked $f1]
4749 lappend x [gets $f1]
4750 lappend x [fblocked $f1]
4754 } {hello_from_pipe 0 {} 0 1}
4755 test io-36.3 {Tcl_InputBlocked vs files, short read} {
4756 file delete $path(test1)
4757 set f [open $path(test1) w]
4758 puts $f abcdefghijklmnop
4760 set f [open $path(test1) r]
4762 lappend l [fblocked $f]
4763 lappend l [read $f 3]
4764 lappend l [fblocked $f]
4765 lappend l [read -nonewline $f]
4766 lappend l [fblocked $f]
4770 } {0 abc 0 defghijklmnop 0 1}
4771 test io-36.4 {Tcl_InputBlocked vs files, event driven read} {fileevent} {
4775 lappend l [read $f 3]
4776 if {[eof $f]} {lappend l eof; close $f; set x done}
4778 file delete $path(test1)
4779 set f [open $path(test1) w]
4780 puts $f abcdefghijklmnop
4782 set f [open $path(test1) r]
4784 fileevent $f readable [namespace code [list in $f]]
4786 vwait [namespace which -variable x]
4788 } {abc def ghi jkl mno {p
4790 test io-36.5 {Tcl_InputBlocked vs files, short read, nonblocking} {nonBlockFiles} {
4791 file delete $path(test1)
4792 set f [open $path(test1) w]
4793 puts $f abcdefghijklmnop
4795 set f [open $path(test1) r]
4796 fconfigure $f -blocking off
4798 lappend l [fblocked $f]
4799 lappend l [read $f 3]
4800 lappend l [fblocked $f]
4801 lappend l [read -nonewline $f]
4802 lappend l [fblocked $f]
4806 } {0 abc 0 defghijklmnop 0 1}
4807 test io-36.6 {Tcl_InputBlocked vs files, event driven read} {nonBlockFiles fileevent} {
4811 lappend l [read $f 3]
4812 if {[eof $f]} {lappend l eof; close $f; set x done}
4814 file delete $path(test1)
4815 set f [open $path(test1) w]
4816 puts $f abcdefghijklmnop
4818 set f [open $path(test1) r]
4819 fconfigure $f -blocking off
4821 fileevent $f readable [namespace code [list in $f]]
4823 vwait [namespace which -variable x]
4825 } {abc def ghi jkl mno {p
4828 # Test Tcl_InputBuffered
4830 test io-37.1 {Tcl_InputBuffered} {testchannel} {
4831 set f [open $path(longfile) r]
4832 fconfigure $f -buffersize 4096
4835 lappend l [testchannel inputbuffered $f]
4840 test io-37.2 {Tcl_InputBuffered, test input flushing on seek} {testchannel} {
4841 set f [open $path(longfile) r]
4842 fconfigure $f -buffersize 4096
4845 lappend l [testchannel inputbuffered $f]
4848 lappend l [testchannel inputbuffered $f]
4854 # Test Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize
4856 test io-38.1 {Tcl_GetChannelBufferSize, default buffer size} {
4857 set f [open $path(longfile) r]
4858 set s [fconfigure $f -buffersize]
4862 test io-38.2 {Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize} {
4863 set f [open $path(longfile) r]
4865 lappend l [fconfigure $f -buffersize]
4866 fconfigure $f -buffersize 10000
4867 lappend l [fconfigure $f -buffersize]
4868 fconfigure $f -buffersize 1
4869 lappend l [fconfigure $f -buffersize]
4870 fconfigure $f -buffersize -1
4871 lappend l [fconfigure $f -buffersize]
4872 fconfigure $f -buffersize 0
4873 lappend l [fconfigure $f -buffersize]
4874 fconfigure $f -buffersize 100000
4875 lappend l [fconfigure $f -buffersize]
4876 fconfigure $f -buffersize 10000000
4877 lappend l [fconfigure $f -buffersize]
4880 } {4096 10000 1 1 1 100000 100000}
4882 test io-38.3 {Tcl_SetChannelBufferSize, changing buffersize between reads} {
4883 # This test crashes the interp if Bug #427196 is not fixed
4885 set chan [open [info script] r]
4886 fconfigure $chan -buffersize 10
4887 set var [read $chan 2]
4888 fconfigure $chan -buffersize 32
4889 append var [read $chan]
4893 # Test Tcl_SetChannelOption, Tcl_GetChannelOption
4895 test io-39.1 {Tcl_GetChannelOption} {
4896 file delete $path(test1)
4897 set f1 [open $path(test1) w]
4898 set x [fconfigure $f1 -blocking]
4903 # Test 17.2 was removed.
4905 test io-39.2 {Tcl_GetChannelOption} {
4906 file delete $path(test1)
4907 set f1 [open $path(test1) w]
4908 set x [fconfigure $f1 -buffering]
4912 test io-39.3 {Tcl_GetChannelOption} {
4913 file delete $path(test1)
4914 set f1 [open $path(test1) w]
4915 fconfigure $f1 -buffering line
4916 set x [fconfigure $f1 -buffering]
4920 test io-39.4 {Tcl_GetChannelOption, Tcl_SetChannelOption} {
4921 file delete $path(test1)
4922 set f1 [open $path(test1) w]
4924 lappend l [fconfigure $f1 -buffering]
4925 fconfigure $f1 -buffering line
4926 lappend l [fconfigure $f1 -buffering]
4927 fconfigure $f1 -buffering none
4928 lappend l [fconfigure $f1 -buffering]
4929 fconfigure $f1 -buffering line
4930 lappend l [fconfigure $f1 -buffering]
4931 fconfigure $f1 -buffering full
4932 lappend l [fconfigure $f1 -buffering]
4935 } {full line none line full}
4936 test io-39.5 {Tcl_GetChannelOption, invariance} {
4937 file delete $path(test1)
4938 set f1 [open $path(test1) w]
4940 lappend l [fconfigure $f1 -buffering]
4941 lappend l [list [catch {fconfigure $f1 -buffering green} msg] $msg]
4942 lappend l [fconfigure $f1 -buffering]
4945 } {full {1 {bad value for -buffering: must be one of full, line, or none}} full}
4946 test io-39.6 {Tcl_SetChannelOption, multiple options} {
4947 file delete $path(test1)
4948 set f1 [open $path(test1) w]
4949 fconfigure $f1 -translation lf -buffering line
4952 set x [file size $path(test1)]
4956 test io-39.7 {Tcl_SetChannelOption, buffering, translation} {
4957 file delete $path(test1)
4958 set f1 [open $path(test1) w]
4959 fconfigure $f1 -translation lf
4963 fconfigure $f1 -buffering line
4964 lappend x [file size $path(test1)]
4966 lappend x [file size $path(test1)]
4970 test io-39.8 {Tcl_SetChannelOption, different buffering options} {
4971 file delete $path(test1)
4972 set f1 [open $path(test1) w]
4974 fconfigure $f1 -translation lf -buffering none -eofchar {}
4975 puts -nonewline $f1 hello
4976 lappend l [file size $path(test1)]
4977 puts -nonewline $f1 hello
4978 lappend l [file size $path(test1)]
4979 fconfigure $f1 -buffering full
4980 puts -nonewline $f1 hello
4981 lappend l [file size $path(test1)]
4982 fconfigure $f1 -buffering none
4983 lappend l [file size $path(test1)]
4984 puts -nonewline $f1 hello
4985 lappend l [file size $path(test1)]
4987 lappend l [file size $path(test1)]
4989 } {5 10 10 10 20 20}
4990 test io-39.9 {Tcl_SetChannelOption, blocking mode} {nonBlockFiles} {
4991 file delete $path(test1)
4992 set f1 [open $path(test1) w]
4994 set f1 [open $path(test1) r]
4996 lappend x [fconfigure $f1 -blocking]
4997 fconfigure $f1 -blocking off
4998 lappend x [fconfigure $f1 -blocking]
4999 lappend x [gets $f1]
5000 lappend x [read $f1 1000]
5001 lappend x [fblocked $f1]
5006 test io-39.10 {Tcl_SetChannelOption, blocking mode} {stdio openpipe} {
5007 file delete $path(pipe)
5008 set f1 [open $path(pipe) w]
5017 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
5018 fconfigure $f1 -blocking off -buffering line
5019 lappend x [fconfigure $f1 -blocking]
5020 lappend x [gets $f1]
5021 lappend x [fblocked $f1]
5022 fconfigure $f1 -blocking on
5024 fconfigure $f1 -blocking off
5025 lappend x [gets $f1]
5026 lappend x [fblocked $f1]
5027 fconfigure $f1 -blocking on
5029 fconfigure $f1 -blocking off
5030 lappend x [gets $f1]
5031 lappend x [fblocked $f1]
5032 fconfigure $f1 -blocking on
5033 lappend x [fconfigure $f1 -blocking]
5034 lappend x [gets $f1]
5035 lappend x [fblocked $f1]
5037 lappend x [gets $f1]
5041 } {0 {} 1 {} 1 {} 1 1 hi 0 0 {} 1}
5042 test io-39.11 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size} {
5043 file delete $path(test1)
5044 set f [open $path(test1) w]
5045 fconfigure $f -buffersize -10
5046 set x [fconfigure $f -buffersize]
5050 test io-39.12 {Tcl_SetChannelOption, Tcl_GetChannelOption buffer size} {
5051 file delete $path(test1)
5052 set f [open $path(test1) w]
5053 fconfigure $f -buffersize 10000000
5054 set x [fconfigure $f -buffersize]
5058 test io-39.13 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size} {
5059 file delete $path(test1)
5060 set f [open $path(test1) w]
5061 fconfigure $f -buffersize 40000
5062 set x [fconfigure $f -buffersize]
5066 test io-39.14 {Tcl_SetChannelOption: -encoding, binary & utf-8} {
5067 file delete $path(test1)
5068 set f [open $path(test1) w]
5069 fconfigure $f -encoding {}
5070 puts -nonewline $f \xe7\x89\xa6
5072 set f [open $path(test1) r]
5073 fconfigure $f -encoding utf-8
5078 test io-39.15 {Tcl_SetChannelOption: -encoding, binary & utf-8} {
5079 file delete $path(test1)
5080 set f [open $path(test1) w]
5081 fconfigure $f -encoding binary
5082 puts -nonewline $f \xe7\x89\xa6
5084 set f [open $path(test1) r]
5085 fconfigure $f -encoding utf-8
5090 test io-39.16 {Tcl_SetChannelOption: -encoding, errors} {
5091 file delete $path(test1)
5092 set f [open $path(test1) w]
5093 set result [list [catch {fconfigure $f -encoding foobar} msg] $msg]
5096 } {1 {unknown encoding "foobar"}}
5097 test io-39.17 {Tcl_SetChannelOption: -encoding, clearing CHANNEL_NEED_MORE_DATA} {stdio openpipe fileevent} {
5098 set f [open "|[list [interpreter] $path(cat)]" r+]
5099 fconfigure $f -encoding binary
5100 puts -nonewline $f "\xe7"
5102 fconfigure $f -encoding utf-8 -blocking 0
5104 fileevent $f readable [namespace code { lappend x [read $f] }]
5105 vwait [namespace which -variable x]
5106 after 300 [namespace code { lappend x timeout }]
5107 vwait [namespace which -variable x]
5108 fconfigure $f -encoding utf-8
5109 vwait [namespace which -variable x]
5110 after 300 [namespace code { lappend x timeout }]
5111 vwait [namespace which -variable x]
5112 fconfigure $f -encoding binary
5113 vwait [namespace which -variable x]
5114 after 300 [namespace code { lappend x timeout }]
5115 vwait [namespace which -variable x]
5118 } "{} timeout {} timeout \xe7 timeout"
5120 test io-39.18 {Tcl_SetChannelOption, setting read mode independently} \
5122 proc accept {s a p} {close $s}
5123 set s1 [socket -server [namespace code accept] 0]
5124 set port [lindex [fconfigure $s1 -sockname] 2]
5125 set s2 [socket 127.0.0.1 $port]
5127 fconfigure $s2 -translation {auto lf}
5128 set modes [fconfigure $s2 -translation]
5133 test io-39.19 {Tcl_SetChannelOption, setting read mode independently} \
5135 proc accept {s a p} {close $s}
5136 set s1 [socket -server [namespace code accept] 0]
5137 set port [lindex [fconfigure $s1 -sockname] 2]
5138 set s2 [socket 127.0.0.1 $port]
5140 fconfigure $s2 -translation {auto crlf}
5141 set modes [fconfigure $s2 -translation]
5146 test io-39.20 {Tcl_SetChannelOption, setting read mode independently} \
5148 proc accept {s a p} {close $s}
5149 set s1 [socket -server [namespace code accept] 0]
5150 set port [lindex [fconfigure $s1 -sockname] 2]
5151 set s2 [socket 127.0.0.1 $port]
5153 fconfigure $s2 -translation {auto cr}
5154 set modes [fconfigure $s2 -translation]
5159 test io-39.21 {Tcl_SetChannelOption, setting read mode independently} \
5161 proc accept {s a p} {close $s}
5162 set s1 [socket -server [namespace code accept] 0]
5163 set port [lindex [fconfigure $s1 -sockname] 2]
5164 set s2 [socket 127.0.0.1 $port]
5166 fconfigure $s2 -translation {auto auto}
5167 set modes [fconfigure $s2 -translation]
5173 test io-39.22 {Tcl_SetChannelOption, invariance} {unixOnly} {
5174 file delete $path(test1)
5175 set f1 [open $path(test1) w+]
5177 lappend l [fconfigure $f1 -eofchar]
5178 fconfigure $f1 -eofchar {ON GO}
5179 lappend l [fconfigure $f1 -eofchar]
5180 fconfigure $f1 -eofchar D
5181 lappend l [fconfigure $f1 -eofchar]
5184 } {{{} {}} {O G} {D D}}
5186 test io-39.22a {Tcl_SetChannelOption, invariance} {
5187 file delete $path(test1)
5188 set f1 [open $path(test1) w+]
5190 fconfigure $f1 -eofchar {ON GO}
5191 lappend l [fconfigure $f1 -eofchar]
5192 fconfigure $f1 -eofchar D
5193 lappend l [fconfigure $f1 -eofchar]
5194 lappend l [list [catch {fconfigure $f1 -eofchar {1 2 3}} msg] $msg]
5197 } {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
5200 test io-39.23 {Tcl_GetChannelOption, server socket is not readable or
5201 writeable, it should still have valid -eofchar and -translation options } {
5203 set sock [socket -server [namespace code accept] 0]
5204 lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation]
5208 test io-39.24 {Tcl_SetChannelOption, server socket is not readable or
5209 writable so we can't change -eofchar or -translation } {
5211 set sock [socket -server [namespace code accept] 0]
5212 fconfigure $sock -eofchar D -translation lf
5213 lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation]
5218 test io-40.1 {POSIX open access modes: RDWR} {
5219 file delete $path(test3)
5220 set f [open $path(test3) w]
5223 set f [open $path(test3) RDWR]
5224 puts -nonewline $f "ab"
5228 set f [open $path(test3) r]
5233 test io-40.2 {POSIX open access modes: CREAT} {unixOnly} {
5234 file delete $path(test3)
5235 set f [open $path(test3) {WRONLY CREAT} 0600]
5236 file stat $path(test3) stats
5237 set x [format "0%o" [expr $stats(mode)&0777]]
5240 set f [open $path(test3) r]
5246 # some tests can only be run is umask is 2
5247 # if "umask" cannot be run, the tests will be skipped.
5248 catch {testConstraint umask2 [expr {[exec umask] == 2}]}
5250 test io-40.3 {POSIX open access modes: CREAT} {unixOnly umask2} {
5251 # This test only works if your umask is 2, like ouster's.
5252 file delete $path(test3)
5253 set f [open $path(test3) {WRONLY CREAT}]
5255 file stat test3 stats
5256 format "0%o" [expr $stats(mode)&0777]
5258 test io-40.4 {POSIX open access modes: CREAT} {
5259 file delete $path(test3)
5260 set f [open $path(test3) w]
5261 fconfigure $f -eofchar {}
5264 set f [open $path(test3) {WRONLY CREAT}]
5265 fconfigure $f -eofchar {}
5266 puts -nonewline $f "ab"
5268 set f [open $path(test3) r]
5273 test io-40.5 {POSIX open access modes: APPEND} {
5274 file delete $path(test3)
5275 set f [open $path(test3) w]
5276 fconfigure $f -translation lf -eofchar {}
5279 set f [open $path(test3) {WRONLY APPEND}]
5280 fconfigure $f -translation lf
5285 set f [open $path(test3) r]
5286 fconfigure $f -translation lf
5294 test io-40.6 {POSIX open access modes: EXCL} -match regexp -body {
5295 file delete $path(test3)
5296 set f [open $path(test3) w]
5299 open $path(test3) {WRONLY CREAT EXCL}
5300 } -returnCodes error -result {(?i)couldn't open ".*test3": file (already )?exists}
5301 test io-40.7 {POSIX open access modes: EXCL} {
5302 file delete $path(test3)
5303 set f [open $path(test3) {WRONLY CREAT EXCL}]
5304 fconfigure $f -eofchar {}
5305 puts $f "A test line"
5309 test io-40.8 {POSIX open access modes: TRUNC} {
5310 file delete $path(test3)
5311 set f [open $path(test3) w]
5314 set f [open $path(test3) {WRONLY TRUNC}]
5317 set f [open $path(test3) r]
5322 test io-40.9 {POSIX open access modes: NONBLOCK} {nonPortable macOrUnix} {
5323 file delete $path(test3)
5324 set f [open $path(test3) {WRONLY NONBLOCK CREAT}]
5325 puts $f "NONBLOCK test"
5327 set f [open $path(test3) r]
5332 test io-40.10 {POSIX open access modes: RDONLY} {
5333 set f [open $path(test1) w]
5334 puts $f "two lines: this one"
5337 set f [open $path(test1) RDONLY]
5338 set x [list [gets $f] [catch {puts $f Test} msg] $msg]
5340 string compare [string tolower $x] \
5341 [list {two lines: this one} 1 \
5342 [format "channel \"%s\" wasn't opened for writing" $f]]
5344 test io-40.11 {POSIX open access modes: RDONLY} -match regexp -body {
5345 file delete $path(test3)
5346 open $path(test3) RDONLY
5347 } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
5348 test io-40.12 {POSIX open access modes: WRONLY} -match regexp -body {
5349 file delete $path(test3)
5350 open $path(test3) WRONLY
5351 } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
5352 test io-40.13 {POSIX open access modes: WRONLY} {
5353 makeFile xyzzy test3
5354 set f [open $path(test3) WRONLY]
5355 fconfigure $f -eofchar {}
5356 puts -nonewline $f "ab"
5358 set x [list [catch {gets $f} msg] $msg]
5360 lappend x [viewFile test3]
5361 string compare [string tolower $x] \
5362 [list 1 "channel \"$f\" wasn't opened for reading" abzzy]
5364 test io-40.14 {POSIX open access modes: RDWR} -match regexp -body {
5365 file delete $path(test3)
5366 open $path(test3) RDWR
5367 } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
5368 test io-40.15 {POSIX open access modes: RDWR} {
5369 makeFile xyzzy test3
5370 set f [open $path(test3) RDWR]
5371 puts -nonewline $f "ab"
5375 lappend x [viewFile test3]
5377 if {![file exists ~/_test_] && [file writable ~]} {
5378 test io-40.16 {tilde substitution in open} -setup {
5379 makeFile {Some text} _test_ ~
5381 file exists [file join $env(HOME) _test_]
5386 test io-40.17 {tilde substitution in open} {
5389 set x [list [catch {open ~/foo} msg] $msg]
5392 } {1 {couldn't find HOME environment variable to expand path}}
5394 test io-41.1 {Tcl_FileeventCmd: errors} {fileevent} {
5395 list [catch {fileevent foo} msg] $msg
5396 } {1 {wrong # args: should be "fileevent channelId event ?script?"}}
5397 test io-41.2 {Tcl_FileeventCmd: errors} {fileevent} {
5398 list [catch {fileevent foo bar baz q} msg] $msg
5399 } {1 {wrong # args: should be "fileevent channelId event ?script?"}}
5400 test io-41.3 {Tcl_FileeventCmd: errors} {fileevent} {
5401 list [catch {fileevent gorp readable} msg] $msg
5402 } {1 {can not find channel named "gorp"}}
5403 test io-41.4 {Tcl_FileeventCmd: errors} {fileevent} {
5404 list [catch {fileevent gorp writable} msg] $msg
5405 } {1 {can not find channel named "gorp"}}
5406 test io-41.5 {Tcl_FileeventCmd: errors} {fileevent} {
5407 list [catch {fileevent gorp who-knows} msg] $msg
5408 } {1 {bad event name "who-knows": must be readable or writable}}
5411 # Test fileevent on a file
5414 set path(foo) [makeFile {} foo]
5415 set f [open $path(foo) w+]
5417 test io-42.1 {Tcl_FileeventCmd: creating, deleting, querying} {fileevent} {
5418 list [fileevent $f readable] [fileevent $f writable]
5420 test io-42.2 {Tcl_FileeventCmd: replacing} {fileevent} {
5422 fileevent $f r "first script"
5423 lappend result [fileevent $f readable]
5424 fileevent $f r "new script"
5425 lappend result [fileevent $f readable]
5426 fileevent $f r "yet another"
5427 lappend result [fileevent $f readable]
5429 lappend result [fileevent $f readable]
5430 } {{first script} {new script} {yet another} {}}
5431 test io-42.3 {Tcl_FileeventCmd: replacing, with NULL chars in script} {fileevent} {
5433 fileevent $f r "first scr\0ipt"
5434 lappend result [string length [fileevent $f readable]]
5435 fileevent $f r "new scr\0ipt"
5436 lappend result [string length [fileevent $f readable]]
5437 fileevent $f r "yet ano\0ther"
5438 lappend result [string length [fileevent $f readable]]
5440 lappend result [fileevent $f readable]
5443 test io-43.1 {Tcl_FileeventCmd: creating, deleting, querying} {stdio unixExecs fileevent} {
5445 fileevent $f readable "script 1"
5446 lappend result [fileevent $f readable] [fileevent $f writable]
5447 fileevent $f writable "write script"
5448 lappend result [fileevent $f readable] [fileevent $f writable]
5449 fileevent $f readable {}
5450 lappend result [fileevent $f readable] [fileevent $f writable]
5451 fileevent $f writable {}
5452 lappend result [fileevent $f readable] [fileevent $f writable]
5453 } {{script 1} {} {script 1} {write script} {} {write script} {} {}}
5454 test io-43.2 {Tcl_FileeventCmd: deleting when many present} -setup {
5455 set f2 [open "|[list cat -u]" r+]
5456 set f3 [open "|[list cat -u]" r+]
5457 } -constraints {stdio unixExecs fileevent openpipe} -body {
5459 lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r]
5460 fileevent $f r "read f"
5461 fileevent $f2 r "read f2"
5462 fileevent $f3 r "read f3"
5463 lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r]
5465 lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r]
5467 lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r]
5469 lappend result [fileevent $f r] [fileevent $f2 r] [fileevent $f3 r]
5473 } -result {{} {} {} {read f} {read f2} {read f3} {read f} {} {read f3} {read f} {} {} {} {} {}}
5475 test io-44.1 {FileEventProc procedure: normal read event} -setup {
5476 set f2 [open "|[list cat -u]" r+]
5477 set f3 [open "|[list cat -u]" r+]
5478 } -constraints {stdio unixExecs fileevent openpipe} -body {
5479 fileevent $f2 readable [namespace code {
5480 set x [gets $f2]; fileevent $f2 readable {}
5482 puts $f2 text; flush $f2
5484 vwait [namespace which -variable x]
5490 test io-44.2 {FileEventProc procedure: error in read event} -setup {
5491 set f2 [open "|[list cat -u]" r+]
5492 set f3 [open "|[list cat -u]" r+]
5493 } -constraints {stdio unixExecs fileevent openpipe} -body {
5494 proc ::bgerror args "set [namespace which -variable x] \$args"
5495 fileevent $f2 readable {error bogus}
5496 puts $f2 text; flush $f2
5498 vwait [namespace which -variable x]
5500 list $x [fileevent $f2 readable]
5504 } -result {bogus {}}
5505 test io-44.3 {FileEventProc procedure: normal write event} -setup {
5506 set f2 [open "|[list cat -u]" r+]
5507 set f3 [open "|[list cat -u]" r+]
5508 } -constraints {stdio unixExecs fileevent openpipe} -body {
5509 fileevent $f2 writable [namespace code {
5510 lappend x "triggered"
5513 fileevent $f2 writable {}
5518 vwait [namespace which -variable x]
5519 vwait [namespace which -variable x]
5520 vwait [namespace which -variable x]
5525 } -result {initial triggered triggered triggered}
5526 test io-44.4 {FileEventProc procedure: eror in write event} -setup {
5527 set f2 [open "|[list cat -u]" r+]
5528 set f3 [open "|[list cat -u]" r+]
5529 } -constraints {stdio unixExecs fileevent openpipe} -body {
5530 proc ::bgerror args "set [namespace which -variable x] \$args"
5531 fileevent $f2 writable {error bad-write}
5533 vwait [namespace which -variable x]
5535 list $x [fileevent $f2 writable]
5539 } -result {bad-write {}}
5540 test io-44.5 {FileEventProc procedure: end of file} {stdio unixExecs openpipe fileevent} {
5541 set f4 [open "|[list [interpreter] $path(cat) << foo]" r]
5542 fileevent $f4 readable [namespace code {
5543 if {[gets $f4 line] < 0} {
5545 fileevent $f4 readable {}
5551 vwait [namespace which -variable x]
5552 vwait [namespace which -variable x]
5559 makeFile "foo bar" foo
5560 test io-45.1 {DeleteFileEvent, cleanup on close} {fileevent} {
5561 set f [open $path(foo) r]
5562 fileevent $f readable [namespace code {
5563 lappend x "binding triggered: \"[gets $f]\""
5564 fileevent $f readable {}
5568 after 100 [namespace code { set y done }]
5570 vwait [namespace which -variable y]
5573 test io-45.2 {DeleteFileEvent, cleanup on close} {fileevent} {
5574 set f [open $path(foo) r]
5575 set f2 [open $path(foo) r]
5576 fileevent $f readable [namespace code {
5577 lappend x "f triggered: \"[gets $f]\""
5578 fileevent $f readable {}
5580 fileevent $f2 readable [namespace code {
5581 lappend x "f2 triggered: \"[gets $f2]\""
5582 fileevent $f2 readable {}
5586 vwait [namespace which -variable x]
5589 } {initial {f2 triggered: "foo bar"}}
5590 test io-45.3 {DeleteFileEvent, cleanup on close} {fileevent} {
5591 set f [open $path(foo) r]
5592 set f2 [open $path(foo) r]
5593 set f3 [open $path(foo) r]
5594 fileevent $f readable {f script}
5595 fileevent $f2 readable {f2 script}
5596 fileevent $f3 readable {f3 script}
5599 lappend x [catch {fileevent $f readable} msg] $msg \
5600 [catch {fileevent $f2 readable}] \
5601 [catch {fileevent $f3 readable} msg] $msg
5603 lappend x [catch {fileevent $f readable} msg] $msg \
5604 [catch {fileevent $f2 readable}] \
5605 [catch {fileevent $f3 readable}]
5607 lappend x [catch {fileevent $f readable}] \
5608 [catch {fileevent $f2 readable}] \
5609 [catch {fileevent $f3 readable}]
5610 } {0 {f script} 1 0 {f3 script} 0 {f script} 1 1 1 1 1}
5612 # Execute these tests only if the "testfevent" command is present.
5613 testConstraint testfevent [llength [info commands testfevent]]
5615 test io-46.1 {Tcl event loop vs multiple interpreters} {testfevent fileevent} {
5617 set script "set f \[[list open $path(foo) r]]\n"
5620 fileevent $f readable [namespace code {
5621 set x "f triggered: [gets $f]"
5622 fileevent $f readable {}
5625 testfevent cmd $script
5626 after 1 ;# We must delay because Windows takes a little time to notice
5628 testfevent cmd {close $f}
5629 list [testfevent cmd {set x}] [testfevent cmd {info commands after}]
5630 } {{f triggered: foo bar} after}
5631 test io-46.2 {Tcl event loop vs multiple interpreters} testfevent {
5635 after 100 {set x triggered}
5636 vwait [namespace which -variable x]
5640 test io-46.3 {Tcl event loop vs multiple interpreters} testfevent {
5644 after 10 {lappend x timer}
5654 test io-47.1 {fileevent vs multiple interpreters} {testfevent fileevent} {
5655 set f [open $path(foo) r]
5656 set f2 [open $path(foo) r]
5657 set f3 [open $path(foo) r]
5658 fileevent $f readable {script 1}
5660 testfevent share $f2
5661 testfevent cmd "fileevent $f2 readable {script 2}"
5662 fileevent $f3 readable {sript 3}
5664 lappend x [fileevent $f2 readable]
5666 lappend x [fileevent $f readable] [fileevent $f2 readable] \
5667 [fileevent $f3 readable]
5672 } {{} {script 1} {} {sript 3}}
5673 test io-47.2 {deleting fileevent on interpreter delete} {testfevent fileevent} {
5674 set f [open $path(foo) r]
5675 set f2 [open $path(foo) r]
5676 set f3 [open $path(foo) r]
5677 set f4 [open $path(foo) r]
5678 fileevent $f readable {script 1}
5680 testfevent share $f2
5681 testfevent share $f3
5682 testfevent cmd "fileevent $f2 readable {script 2}
5683 fileevent $f3 readable {script 3}"
5684 fileevent $f4 readable {script 4}
5686 set x [list [fileevent $f readable] [fileevent $f2 readable] \
5687 [fileevent $f3 readable] [fileevent $f4 readable]]
5693 } {{script 1} {} {} {script 4}}
5694 test io-47.3 {deleting fileevent on interpreter delete} {testfevent fileevent} {
5695 set f [open $path(foo) r]
5696 set f2 [open $path(foo) r]
5697 set f3 [open $path(foo) r]
5698 set f4 [open $path(foo) r]
5700 testfevent share $f3
5701 testfevent share $f4
5702 fileevent $f readable {script 1}
5703 fileevent $f2 readable {script 2}
5704 testfevent cmd "fileevent $f3 readable {script 3}
5705 fileevent $f4 readable {script 4}"
5707 set x [list [fileevent $f readable] [fileevent $f2 readable] \
5708 [fileevent $f3 readable] [fileevent $f4 readable]]
5714 } {{script 1} {script 2} {} {}}
5715 test io-47.4 {file events on shared files and multiple interpreters} {testfevent fileevent} {
5716 set f [open $path(foo) r]
5717 set f2 [open $path(foo) r]
5720 testfevent cmd "fileevent $f readable {script 1}"
5721 fileevent $f readable {script 2}
5722 fileevent $f2 readable {script 3}
5723 set x [list [fileevent $f2 readable] \
5724 [testfevent cmd "fileevent $f readable"] \
5725 [fileevent $f readable]]
5730 } {{script 3} {script 1} {script 2}}
5731 test io-47.5 {file events on shared files, deleting file events} {testfevent fileevent} {
5732 set f [open $path(foo) r]
5735 testfevent cmd "fileevent $f readable {script 1}"
5736 fileevent $f readable {script 2}
5737 testfevent cmd "fileevent $f readable {}"
5738 set x [list [testfevent cmd "fileevent $f readable"] \
5739 [fileevent $f readable]]
5744 test io-47.6 {file events on shared files, deleting file events} {testfevent fileevent} {
5745 set f [open $path(foo) r]
5748 testfevent cmd "fileevent $f readable {script 1}"
5749 fileevent $f readable {script 2}
5750 fileevent $f readable {}
5751 set x [list [testfevent cmd "fileevent $f readable"] \
5752 [fileevent $f readable]]
5758 set path(bar) [makeFile {} bar]
5760 test io-48.1 {testing readability conditions} {fileevent} {
5761 set f [open $path(bar) w]
5768 set f [open $path(bar) r]
5769 fileevent $f readable [namespace code [list consume $f]]
5783 vwait [namespace which -variable x]
5785 } {done {called called called called called called called}}
5786 test io-48.2 {testing readability conditions} {nonBlockFiles fileevent} {
5787 set f [open $path(bar) w]
5794 set f [open $path(bar) r]
5795 fileevent $f readable [namespace code [list consume $f]]
5796 fconfigure $f -blocking off
5810 vwait [namespace which -variable x]
5812 } {done {called called called called called called called}}
5814 set path(my_script) [makeFile {} my_script]
5816 test io-48.3 {testing readability conditions} {stdio unixOnly nonBlockFiles openpipe fileevent} {
5817 set f [open $path(bar) w]
5824 set f [open $path(my_script) w]
5826 proc copy_slowly {f} {
5835 set f [open "|[list [interpreter]]" r+]
5836 fileevent $f readable [namespace code [list consume $f]]
5837 fconfigure $f -buffering line
5838 fconfigure $f -blocking off
5846 lappend l [fblocked $f]
5848 lappend l [fblocked $f]
5853 puts $f [list source $path(my_script)]
5854 puts $f "set f \[[list open $path(bar) r]]"
5855 puts $f {copy_slowly $f}
5857 vwait [namespace which -variable x]
5860 } {done {0 1 0 1 0 1 0 1 0 1 0 1 0 0}}
5861 test io-48.4 {lf write, testing readability, ^Z termination, auto read mode} {fileevent} {
5862 file delete $path(test1)
5863 set f [open $path(test1) w]
5864 fconfigure $f -translation lf
5865 variable c [format "abc\ndef\n%c" 26]
5866 puts -nonewline $f $c
5882 set f [open $path(test1) r]
5883 fconfigure $f -translation auto -eofchar \x1a
5884 fileevent $f readable [namespace code [list consume $f]]
5886 vwait [namespace which -variable x]
5889 test io-48.5 {lf write, testing readability, ^Z in middle, auto read mode} {fileevent} {
5890 file delete $path(test1)
5891 set f [open $path(test1) w]
5892 fconfigure $f -translation lf
5893 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
5894 puts -nonewline $f $c
5910 set f [open $path(test1) r]
5911 fconfigure $f -eofchar \x1a -translation auto
5912 fileevent $f readable [namespace code [list consume $f]]
5914 vwait [namespace which -variable x]
5917 test io-48.6 {cr write, testing readability, ^Z termination, auto read mode} {fileevent} {
5918 file delete $path(test1)
5919 set f [open $path(test1) w]
5920 fconfigure $f -translation cr
5921 set c [format "abc\ndef\n%c" 26]
5922 puts -nonewline $f $c
5938 set f [open $path(test1) r]
5939 fconfigure $f -translation auto -eofchar \x1a
5940 fileevent $f readable [namespace code [list consume $f]]
5942 vwait [namespace which -variable x]
5945 test io-48.7 {cr write, testing readability, ^Z in middle, auto read mode} {fileevent} {
5946 file delete $path(test1)
5947 set f [open $path(test1) w]
5948 fconfigure $f -translation cr
5949 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
5950 puts -nonewline $f $c
5966 set f [open $path(test1) r]
5967 fconfigure $f -eofchar \x1a -translation auto
5968 fileevent $f readable [namespace code [list consume $f]]
5970 vwait [namespace which -variable x]
5973 test io-48.8 {crlf write, testing readability, ^Z termination, auto read mode} {fileevent} {
5974 file delete $path(test1)
5975 set f [open $path(test1) w]
5976 fconfigure $f -translation crlf
5977 set c [format "abc\ndef\n%c" 26]
5978 puts -nonewline $f $c
5994 set f [open $path(test1) r]
5995 fconfigure $f -translation auto -eofchar \x1a
5996 fileevent $f readable [namespace code [list consume $f]]
5998 vwait [namespace which -variable x]
6001 test io-48.9 {crlf write, testing readability, ^Z in middle, auto read mode} {fileevent} {
6002 file delete $path(test1)
6003 set f [open $path(test1) w]
6004 fconfigure $f -translation crlf
6005 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
6006 puts -nonewline $f $c
6022 set f [open $path(test1) r]
6023 fconfigure $f -eofchar \x1a -translation auto
6024 fileevent $f readable [namespace code [list consume $f]]
6026 vwait [namespace which -variable x]
6029 test io-48.10 {lf write, testing readability, ^Z in middle, lf read mode} {fileevent} {
6030 file delete $path(test1)
6031 set f [open $path(test1) w]
6032 fconfigure $f -translation lf
6033 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
6034 puts -nonewline $f $c
6050 set f [open $path(test1) r]
6051 fconfigure $f -eofchar \x1a -translation lf
6052 fileevent $f readable [namespace code [list consume $f]]
6054 vwait [namespace which -variable x]
6057 test io-48.11 {lf write, testing readability, ^Z termination, lf read mode} {fileevent} {
6058 file delete $path(test1)
6059 set f [open $path(test1) w]
6060 fconfigure $f -translation lf
6061 set c [format "abc\ndef\n%c" 26]
6062 puts -nonewline $f $c
6078 set f [open $path(test1) r]
6079 fconfigure $f -translation lf -eofchar \x1a
6080 fileevent $f readable [namespace code [list consume $f]]
6082 vwait [namespace which -variable x]
6085 test io-48.12 {cr write, testing readability, ^Z in middle, cr read mode} {fileevent} {
6086 file delete $path(test1)
6087 set f [open $path(test1) w]
6088 fconfigure $f -translation cr
6089 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
6090 puts -nonewline $f $c
6106 set f [open $path(test1) r]
6107 fconfigure $f -eofchar \x1a -translation cr
6108 fileevent $f readable [namespace code [list consume $f]]
6110 vwait [namespace which -variable x]
6113 test io-48.13 {cr write, testing readability, ^Z termination, cr read mode} {fileevent} {
6114 file delete $path(test1)
6115 set f [open $path(test1) w]
6116 fconfigure $f -translation cr
6117 set c [format "abc\ndef\n%c" 26]
6118 puts -nonewline $f $c
6134 set f [open $path(test1) r]
6135 fconfigure $f -translation cr -eofchar \x1a
6136 fileevent $f readable [namespace code [list consume $f]]
6138 vwait [namespace which -variable x]
6141 test io-48.14 {crlf write, testing readability, ^Z in middle, crlf read mode} {fileevent} {
6142 file delete $path(test1)
6143 set f [open $path(test1) w]
6144 fconfigure $f -translation crlf
6145 set c [format "abc\ndef\n%cfoo\nbar\n" 26]
6146 puts -nonewline $f $c
6162 set f [open $path(test1) r]
6163 fconfigure $f -eofchar \x1a -translation crlf
6164 fileevent $f readable [namespace code [list consume $f]]
6166 vwait [namespace which -variable x]
6169 test io-48.15 {crlf write, testing readability, ^Z termi, crlf read mode} {fileevent} {
6170 file delete $path(test1)
6171 set f [open $path(test1) w]
6172 fconfigure $f -translation crlf
6173 set c [format "abc\ndef\n%c" 26]
6174 puts -nonewline $f $c
6190 set f [open $path(test1) r]
6191 fconfigure $f -translation crlf -eofchar \x1a
6192 fileevent $f readable [namespace code [list consume $f]]
6194 vwait [namespace which -variable x]
6198 test io-49.1 {testing crlf reading, leftover cr disgorgment} {
6199 file delete $path(test1)
6200 set f [open $path(test1) w]
6201 fconfigure $f -translation lf
6202 puts -nonewline $f "a\rb\rc\r\n"
6204 set f [open $path(test1) r]
6206 lappend l [file size $path(test1)]
6207 fconfigure $f -translation crlf
6208 lappend l [read $f 1]
6210 lappend l [read $f 1]
6212 lappend l [read $f 1]
6214 lappend l [read $f 1]
6216 lappend l [read $f 1]
6218 lappend l [read $f 1]
6221 lappend l [read $f 1]
6225 } "7 a 1 [list \r] 2 b 3 [list \r] 4 c 5 {
6227 test io-49.2 {testing crlf reading, leftover cr disgorgment} {
6228 file delete $path(test1)
6229 set f [open $path(test1) w]
6230 fconfigure $f -translation lf
6231 puts -nonewline $f "a\rb\rc\r\n"
6233 set f [open $path(test1) r]
6235 lappend l [file size $path(test1)]
6236 fconfigure $f -translation crlf
6237 lappend l [read $f 2]
6239 lappend l [read $f 2]
6241 lappend l [read $f 2]
6244 lappend l [read $f 2]
6249 } "7 [list a\r] 2 [list b\r] 4 [list c\n] 7 0 {} 7 1"
6250 test io-49.3 {testing crlf reading, leftover cr disgorgment} {
6251 file delete $path(test1)
6252 set f [open $path(test1) w]
6253 fconfigure $f -translation lf
6254 puts -nonewline $f "a\rb\rc\r\n"
6256 set f [open $path(test1) r]
6258 lappend l [file size $path(test1)]
6259 fconfigure $f -translation crlf
6260 lappend l [read $f 3]
6262 lappend l [read $f 3]
6265 lappend l [read $f 3]
6270 } "7 [list a\rb] 3 [list \rc\n] 7 0 {} 7 1"
6271 test io-49.4 {testing crlf reading, leftover cr disgorgment} {
6272 file delete $path(test1)
6273 set f [open $path(test1) w]
6274 fconfigure $f -translation lf
6275 puts -nonewline $f "a\rb\rc\r\n"
6277 set f [open $path(test1) r]
6279 lappend l [file size $path(test1)]
6280 fconfigure $f -translation crlf
6281 lappend l [read $f 3]
6291 } "7 [list a\rb] 3 [list \rc] 7 0 {} 7 1"
6292 test io-49.5 {testing crlf reading, leftover cr disgorgment} {
6293 file delete $path(test1)
6294 set f [open $path(test1) w]
6295 fconfigure $f -translation lf
6296 puts -nonewline $f "a\rb\rc\r\n"
6298 set f [open $path(test1) r]
6300 lappend l [file size $path(test1)]
6301 fconfigure $f -translation crlf
6302 lappend l [set x [gets $f]]
6309 } [list 7 a\rb\rc 7 {} 7 1]
6311 testConstraint testchannelevent [llength [info commands testchannelevent]]
6312 test io-50.1 {testing handler deletion} {testchannelevent} {
6313 file delete $path(test1)
6314 set f [open $path(test1) w]
6316 set f [open $path(test1) r]
6317 testchannelevent $f add readable [namespace code [list delhandler $f]]
6318 proc delhandler {f} {
6321 testchannelevent $f delete 0
6328 test io-50.2 {testing handler deletion with multiple handlers} {testchannelevent} {
6329 file delete $path(test1)
6330 set f [open $path(test1) w]
6332 set f [open $path(test1) r]
6333 testchannelevent $f add readable [namespace code [list delhandler $f 1]]
6334 testchannelevent $f add readable [namespace code [list delhandler $f 0]]
6335 proc delhandler {f i} {
6337 lappend z "called delhandler $f $i"
6338 testchannelevent $f delete 0
6343 string compare [string tolower $z] \
6344 [list [list called delhandler $f 0] [list called delhandler $f 1]]
6346 test io-50.3 {testing handler deletion with multiple handlers} {testchannelevent} {
6347 file delete $path(test1)
6348 set f [open $path(test1) w]
6350 set f [open $path(test1) r]
6351 testchannelevent $f add readable [namespace code [list notcalled $f 1]]
6352 testchannelevent $f add readable [namespace code [list delhandler $f 0]]
6354 proc notcalled {f i} {
6356 lappend z "notcalled was called!! $f $i"
6358 proc delhandler {f i} {
6360 testchannelevent $f delete 1
6361 lappend z "delhandler $f $i called"
6362 testchannelevent $f delete 0
6363 lappend z "delhandler $f $i deleted myself"
6368 string compare [string tolower $z] \
6369 [list [list delhandler $f 0 called] \
6370 [list delhandler $f 0 deleted myself]]
6372 test io-50.4 {testing handler deletion vs reentrant calls} {testchannelevent} {
6373 file delete $path(test1)
6374 set f [open $path(test1) w]
6376 set f [open $path(test1) r]
6377 testchannelevent $f add readable [namespace code [list delrecursive $f]]
6378 proc delrecursive {f} {
6381 if {"$u" == "recursive"} {
6382 testchannelevent $f delete 0
6383 lappend z "delrecursive deleting recursive"
6385 lappend z "delrecursive calling recursive"
6394 string compare [string tolower $z] \
6395 {{delrecursive calling recursive} {delrecursive deleting recursive}}
6397 test io-50.5 {testing handler deletion vs reentrant calls} {testchannelevent} {
6398 file delete $path(test1)
6399 set f [open $path(test1) w]
6401 set f [open $path(test1) r]
6402 testchannelevent $f add readable [namespace code [list notcalled $f]]
6403 testchannelevent $f add readable [namespace code [list del $f]]
6404 proc notcalled {f} {
6406 lappend z "notcalled was called!! $f"
6411 if {"$u" == "recursive"} {
6412 testchannelevent $f delete 1
6413 testchannelevent $f delete 0
6414 lappend z "del deleted notcalled"
6415 lappend z "del deleted myself"
6418 lappend z "del calling recursive"
6420 lappend z "del after update"
6427 string compare [string tolower $z] \
6428 [list {del calling recursive} {del deleted notcalled} \
6429 {del deleted myself} {del after update}]
6431 test io-50.6 {testing handler deletion vs reentrant calls} {testchannelevent} {
6432 file delete $path(test1)
6433 set f [open $path(test1) w]
6435 set f [open $path(test1) r]
6436 testchannelevent $f add readable [namespace code [list second $f]]
6437 testchannelevent $f add readable [namespace code [list first $f]]
6441 if {"$u" == "toplevel"} {
6442 lappend z "first called"
6445 lappend z "first after update"
6447 lappend z "first called not toplevel"
6453 if {"$u" == "first"} {
6454 lappend z "second called, first time"
6456 testchannelevent $f delete 0
6457 } elseif {"$u" == "second"} {
6458 lappend z "second called, second time"
6459 testchannelevent $f delete 0
6461 lappend z "second called, cannot happen!"
6462 testchannelevent $f removeall
6469 string compare [string tolower $z] \
6470 [list {first called} {first called not toplevel} \
6471 {second called, first time} {second called, second time} \
6472 {first after update}]
6475 test io-51.1 {Test old socket deletion on Macintosh} {socket} {
6478 proc accept {s a p} {
6481 fconfigure $s -blocking off
6482 puts $s "sock[incr x]"
6486 set ss [socket -server [namespace code accept] 0]
6488 set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
6489 vwait [namespace which -variable wait]
6490 lappend result [gets $cs]
6494 set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
6495 vwait [namespace which -variable wait]
6496 lappend result [gets $cs]
6500 set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
6501 vwait [namespace which -variable wait]
6502 lappend result [gets $cs]
6506 set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
6507 vwait [namespace which -variable wait]
6508 lappend result [gets $cs]
6512 } {sock1 sock2 sock3 sock4}
6514 test io-52.1 {TclCopyChannel} {fcopy} {
6515 file delete $path(test1)
6516 set f1 [open $thisScript]
6517 set f2 [open $path(test1) w]
6518 fcopy $f1 $f2 -command { # }
6519 catch { fcopy $f1 $f2 } msg
6522 string compare $msg "channel \"$f1\" is busy"
6524 test io-52.2 {TclCopyChannel} {fcopy} {
6525 file delete $path(test1)
6526 set f1 [open $thisScript]
6527 set f2 [open $path(test1) w]
6528 set f3 [open $thisScript]
6529 fcopy $f1 $f2 -command { # }
6530 catch { fcopy $f3 $f2 } msg
6534 string compare $msg "channel \"$f2\" is busy"
6536 test io-52.3 {TclCopyChannel} {fcopy} {
6537 file delete $path(test1)
6538 set f1 [open $thisScript]
6539 set f2 [open $path(test1) w]
6540 fconfigure $f1 -translation lf -blocking 0
6541 fconfigure $f2 -translation cr -blocking 0
6542 set s0 [fcopy $f1 $f2]
6543 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6546 set s1 [file size $thisScript]
6547 set s2 [file size $path(test1)]
6548 if {("$s1" == "$s2") && ($s0 == $s1)} {
6553 test io-52.4 {TclCopyChannel} {fcopy} {
6554 file delete $path(test1)
6555 set f1 [open $thisScript]
6556 set f2 [open $path(test1) w]
6557 fconfigure $f1 -translation lf -blocking 0
6558 fconfigure $f2 -translation cr -blocking 0
6559 fcopy $f1 $f2 -size 40
6560 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6563 lappend result [file size $path(test1)]
6565 test io-52.5 {TclCopyChannel} {fcopy} {
6566 file delete $path(test1)
6567 set f1 [open $thisScript]
6568 set f2 [open $path(test1) w]
6569 fconfigure $f1 -translation lf -blocking 0
6570 fconfigure $f2 -translation lf -blocking 0
6571 fcopy $f1 $f2 -size -1
6572 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6575 set s1 [file size $thisScript]
6576 set s2 [file size $path(test1)]
6577 if {"$s1" == "$s2"} {
6582 test io-52.6 {TclCopyChannel} {fcopy} {
6583 file delete $path(test1)
6584 set f1 [open $thisScript]
6585 set f2 [open $path(test1) w]
6586 fconfigure $f1 -translation lf -blocking 0
6587 fconfigure $f2 -translation lf -blocking 0
6588 set s0 [fcopy $f1 $f2 -size [expr [file size $thisScript] + 5]]
6589 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6592 set s1 [file size $thisScript]
6593 set s2 [file size $path(test1)]
6594 if {("$s1" == "$s2") && ($s0 == $s1)} {
6599 test io-52.7 {TclCopyChannel} {fcopy} {
6600 file delete $path(test1)
6601 set f1 [open $thisScript]
6602 set f2 [open $path(test1) w]
6603 fconfigure $f1 -translation lf -blocking 0
6604 fconfigure $f2 -translation lf -blocking 0
6606 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6607 set s1 [file size $thisScript]
6608 set s2 [file size $path(test1)]
6611 if {"$s1" == "$s2"} {
6616 test io-52.8 {TclCopyChannel} {stdio openpipe fcopy} {
6617 file delete $path(test1)
6618 file delete $path(pipe)
6619 set f1 [open $path(pipe) w]
6620 fconfigure $f1 -translation lf
6624 set f1 \[open [list $thisScript] r\]
6625 fconfigure \$f1 -translation lf
6626 puts \[read \$f1 100\]
6630 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
6631 fconfigure $f1 -translation lf
6635 set f2 [open $path(test1) w]
6636 fconfigure $f2 -translation lf
6637 set s0 [fcopy $f1 $f2 -size 40]
6640 list $s0 [file size $path(test1)]
6643 # Empty files, to register them with the test facility
6644 set path(kyrillic.txt) [makeFile {} kyrillic.txt]
6645 set path(utf8-fcopy.txt) [makeFile {} utf8-fcopy.txt]
6646 set path(utf8-rp.txt) [makeFile {} utf8-rp.txt]
6648 # Create kyrillic file, use lf translation to avoid os eol issues
6649 set out [open $path(kyrillic.txt) w]
6650 fconfigure $out -encoding koi8-r -translation lf
6651 puts $out "\u0410\u0410"
6654 test io-52.9 {TclCopyChannel & encodings} {fcopy} {
6655 # Copy kyrillic to UTF-8, using fcopy.
6657 set in [open $path(kyrillic.txt) r]
6658 set out [open $path(utf8-fcopy.txt) w]
6660 fconfigure $in -encoding koi8-r -translation lf
6661 fconfigure $out -encoding utf-8 -translation lf
6667 # Do the same again, but differently (read/puts).
6669 set in [open $path(kyrillic.txt) r]
6670 set out [open $path(utf8-rp.txt) w]
6672 fconfigure $in -encoding koi8-r -translation lf
6673 fconfigure $out -encoding utf-8 -translation lf
6675 puts -nonewline $out [read $in]
6680 list [file size $path(kyrillic.txt)] \
6681 [file size $path(utf8-fcopy.txt)] \
6682 [file size $path(utf8-rp.txt)]
6685 test io-52.10 {TclCopyChannel & encodings} {fcopy} {
6686 # encoding to binary (=> implies that the
6687 # internal utf-8 is written)
6689 set in [open $path(kyrillic.txt) r]
6690 set out [open $path(utf8-fcopy.txt) w]
6692 fconfigure $in -encoding koi8-r -translation lf
6693 # -translation binary is also -encoding binary
6694 fconfigure $out -translation binary
6700 file size $path(utf8-fcopy.txt)
6703 test io-52.11 {TclCopyChannel & encodings} {fcopy} {
6704 # binary to encoding => the input has to be
6705 # in utf-8 to make sense to the encoder
6707 set in [open $path(utf8-fcopy.txt) r]
6708 set out [open $path(kyrillic.txt) w]
6710 # -translation binary is also -encoding binary
6711 fconfigure $in -translation binary
6712 fconfigure $out -encoding koi8-r -translation lf
6718 file size $path(kyrillic.txt)
6721 test io-53.1 {CopyData} {fcopy} {
6722 file delete $path(test1)
6723 set f1 [open $thisScript]
6724 set f2 [open $path(test1) w]
6725 fconfigure $f1 -translation lf -blocking 0
6726 fconfigure $f2 -translation cr -blocking 0
6727 fcopy $f1 $f2 -size 0
6728 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6731 lappend result [file size $path(test1)]
6733 test io-53.2 {CopyData} {fcopy} {
6734 file delete $path(test1)
6735 set f1 [open $thisScript]
6736 set f2 [open $path(test1) w]
6737 fconfigure $f1 -translation lf -blocking 0
6738 fconfigure $f2 -translation cr -blocking 0
6739 fcopy $f1 $f2 -command [namespace code {set s0}]
6740 set result [list [fconfigure $f1 -blocking] [fconfigure $f2 -blocking]]
6742 vwait [namespace which -variable s0]
6745 set s1 [file size $thisScript]
6746 set s2 [file size $path(test1)]
6747 if {("$s1" == "$s2") && ($s0 == $s1)} {
6752 test io-53.3 {CopyData: background read underflow} {stdio unixOnly openpipe fcopy} {
6753 file delete $path(test1)
6754 file delete $path(pipe)
6755 set f1 [open $path(pipe) w]
6756 puts -nonewline $f1 {
6758 flush stdout ;# Don't assume line buffered!
6759 fcopy stdin stdout -command { set x }
6762 puts $f1 [list open $path(test1) w]]
6764 fconfigure $f -translation lf
6769 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
6770 set result [gets $f1]
6773 lappend result [gets $f1]
6776 lappend result [gets $f1]
6779 set f [open $path(test1)]
6780 lappend result [read $f]
6783 } "ready line1 line2 {done\n}"
6784 test io-53.4 {CopyData: background write overflow} {stdio unixOnly openpipe fileevent fcopy} {
6785 set big bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n
6787 for {set x 0} {$x < 12} {incr x} {
6790 file delete $path(test1)
6791 file delete $path(pipe)
6792 set f1 [open $path(pipe) w]
6795 fcopy stdin stdout -command { set x }
6797 set f [open $path(test1) w]
6798 fconfigure $f -translation lf
6803 set f1 [open "|[list [interpreter] $path(pipe)]" r+]
6804 set result [gets $f1]
6805 fconfigure $f1 -blocking 0
6810 fileevent $f1 read [namespace code {
6811 append result [read $f1 1024]
6812 if {[string length $result] >= [string length $big]} {
6816 vwait [namespace which -variable x]
6823 proc FcopyTestAccept {sock args} {
6824 after 1000 "close $sock"
6826 proc FcopyTestDone {bytes {error {}}} {
6827 variable fcopyTestDone
6828 if {[string length $error]} {
6835 test io-53.5 {CopyData: error during fcopy} {socket fcopy} {
6836 variable fcopyTestDone
6837 set listen [socket -server [namespace code FcopyTestAccept] 0]
6838 set in [open $thisScript] ;# 126 K
6839 set out [socket 127.0.0.1 [lindex [fconfigure $listen -sockname] 2]]
6840 catch {unset fcopyTestDone}
6841 close $listen ;# This means the socket open never really succeeds
6842 fcopy $in $out -command [namespace code FcopyTestDone]
6843 variable fcopyTestDone
6844 if ![info exists fcopyTestDone] {
6845 vwait [namespace which -variable fcopyTestDone] ;# The error occurs here in the b.g.
6849 set fcopyTestDone ;# 1 for error condition
6851 test io-53.6 {CopyData: error during fcopy} {stdio openpipe fcopy} {
6852 variable fcopyTestDone
6853 file delete $path(pipe)
6854 file delete $path(test1)
6855 catch {unset fcopyTestDone}
6856 set f1 [open $path(pipe) w]
6859 set in [open "|[list [interpreter] $path(pipe)]" r+]
6860 set out [open $path(test1) w]
6861 fcopy $in $out -command [namespace code FcopyTestDone]
6862 variable fcopyTestDone
6863 if ![info exists fcopyTestDone] {
6864 vwait [namespace which -variable fcopyTestDone]
6868 set fcopyTestDone ;# 0 for plain end of file
6871 proc doFcopy {in out {bytes 0} {error {}}} {
6872 variable fcopyTestDone
6873 variable fcopyTestCount
6874 incr fcopyTestCount $bytes
6875 if {[string length $error]} {
6877 } elseif {[eof $in]} {
6880 # Delay next fcopy to wait for size>0 input bytes
6882 fcopy $in $out -size 1000 \
6883 -command [namespace code [list doFcopy $in $out]]
6888 test io-53.7 {CopyData: Flooding fcopy from pipe} {stdio openpipe fcopy} {
6889 variable fcopyTestDone
6890 file delete $path(pipe)
6891 catch {unset fcopyTestDone}
6892 set fcopyTestCount 0
6893 set f1 [open $path(pipe) w]
6895 # Write 10 bytes / 10 msec
6896 proc Write {count} {
6897 puts -nonewline "1234567890"
6898 if {[incr count -1]} {
6899 after 10 [list Write $count]
6904 fconfigure stdout -buffering none
6905 Write 345 ;# 3450 bytes ~3.45 sec
6910 set in [open "|[list [interpreter] $path(pipe) &]" r+]
6911 set out [open $path(test1) w]
6913 variable fcopyTestDone
6914 if ![info exists fcopyTestDone] {
6915 vwait [namespace which -variable fcopyTestDone]
6919 # -1=error 0=script error N=number of bytes
6920 expr ($fcopyTestDone == 0) ? $fcopyTestCount : -1
6923 test io-54.1 {Recursive channel events} {socket fileevent} {
6924 # This test checks to see if file events are delivered during recursive
6925 # event loops when there is buffered data on the channel.
6927 proc accept {s a p} {
6929 fconfigure $s -translation lf
6930 puts $s "line 1\nline2\nline3"
6934 proc readit {s next} {
6937 lappend result $next
6939 fileevent $s readable [namespace code [list readit $s 2]]
6940 vwait [namespace which -variable x]
6944 set ss [socket -server [namespace code accept] 0]
6946 # We need to delay on some systems until the creation of the
6947 # server socket completes.
6950 for {set i 0} {$i < 10} {incr i} {
6951 if {![catch {set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]}]} {
6959 error "failed to connect to server"
6964 vwait [namespace which -variable as]
6965 fconfigure $cs -translation lf
6966 lappend result [gets $cs]
6967 fconfigure $cs -blocking off
6968 fileevent $cs readable [namespace code [list readit $cs 1]]
6969 set a [after 2000 [namespace code { set x failure }]]
6970 vwait [namespace which -variable x]
6976 } {{{line 1} 1 2} 2}
6977 test io-54.2 {Testing for busy-wait in recursive channel events} {socket fileevent} {
6980 variable s [socket -server [namespace code accept] 0]
6981 proc accept {s a p} {
6987 fconfigure $s -blocking off -buffering line -translation lf
6988 fileevent $s readable [namespace code "doit $s"]
6997 fileevent $s readable [namespace code "doit1 $s"]
6998 set after [after 1000 [namespace code newline]]
7014 set writer [socket 127.0.0.1 [lindex [fconfigure $s -sockname] 2]]
7015 fconfigure $writer -buffering line
7016 puts -nonewline $writer hello
7029 vwait [namespace which -variable done]
7033 if {$accept != {}} {close $accept}
7037 set path(fooBar) [makeFile {} fooBar]
7039 test io-55.1 {ChannelEventScriptInvoker: deletion} {fileevent} {
7041 proc eventScript {fd} {
7044 error "planned error"
7047 proc ::bgerror {args} "set [namespace which -variable x] got_error"
7048 set f [open $path(fooBar) w]
7049 fileevent $f writable [namespace code [list eventScript $f]]
7051 vwait [namespace which -variable x]
7055 test io-56.1 {ChannelTimerProc} {testchannelevent} {
7056 set f [open $path(fooBar) w]
7057 puts $f "this is a test"
7059 set f [open $path(fooBar) r]
7060 testchannelevent $f add readable [namespace code {
7065 vwait [namespace which -variable x]
7066 vwait [namespace which -variable x]
7068 testchannelevent $f set 0 none
7069 after idle [namespace code {set y done}]
7071 vwait [namespace which -variable y]
7076 test io-57.1 {buffered data and file events, gets} {fileevent} {
7077 proc accept {sock args} {
7081 set server [socket -server [namespace code accept] 0]
7082 set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]]
7084 vwait [namespace which -variable s2]
7086 fileevent $s2 readable [namespace code {lappend result readable}]
7087 puts $s "12\n34567890"
7089 variable result [gets $s2]
7090 after 1000 [namespace code {lappend result timer}]
7091 vwait [namespace which -variable result]
7092 lappend result [gets $s2]
7093 vwait [namespace which -variable result]
7098 } {12 readable 34567890 timer}
7099 test io-57.2 {buffered data and file events, read} {fileevent} {
7100 proc accept {sock args} {
7104 set server [socket -server [namespace code accept] 0]
7105 set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]]
7107 vwait [namespace which -variable s2]
7109 fileevent $s2 readable [namespace code {lappend result readable}]
7110 puts -nonewline $s "1234567890"
7112 variable result [read $s2 1]
7113 after 1000 [namespace code {lappend result timer}]
7114 vwait [namespace which -variable result]
7115 lappend result [read $s2 9]
7116 vwait [namespace which -variable result]
7121 } {1 readable 234567890 timer}
7123 test io-58.1 {Tcl_NotifyChannel and error when closing} {stdio unixOrPc openpipe fileevent} {
7124 set out [open $path(script) w]
7126 puts "normal message from pipe"
7127 puts stderr "error message from pipe"
7130 proc readit {pipe} {
7134 set x [catch {close $pipe} line]
7135 lappend result catch $line
7138 lappend result gets $line
7142 set pipe [open "|[list [interpreter] $path(script)]" r]
7143 fileevent $pipe readable [namespace code [list readit $pipe]]
7146 vwait [namespace which -variable x]
7148 } {1 {gets {normal message from pipe} gets {} catch {error message from pipe}}}
7151 testConstraint testmainthread [llength [info commands testmainthread]]
7152 test io-59.1 {Thread reference of channels} {testmainthread testchannel} {
7154 # More complicated tests (like that the reference changes as a
7155 # channel is moved from thread to thread) can be done only in the
7156 # extension which fully implements the moving of channels between
7157 # threads, i.e. 'Threads'. Or we have to extend [testthread] as well.
7159 set f [open $path(longfile) r]
7160 set result [testchannel mthread $f]
7162 string equal $result [testmainthread]
7166 test io-60.1 {writing illegal utf sequences} {openpipe fileevent} {
7167 # This test will hang in older revisions of the core.
7169 set out [open $path(script) w]
7171 puts [encoding convertfrom identity \xe2]
7174 proc readit {pipe} {
7178 set x [catch {close $pipe} line]
7179 lappend result catch $line
7182 lappend result gets $line
7186 set pipe [open "|[list [interpreter] $path(script)]" r]
7187 fileevent $pipe readable [namespace code [list readit $pipe]]
7190 vwait [namespace which -variable x]
7192 # cut of the remainder of the error stack, especially the filename
7193 set result [lreplace $result 3 3 [lindex [split [lindex $result 3] \n] 0]]
7195 } {1 {gets {} catch {error writing "stdout": invalid argument}}}
7197 test io-61.1 {Reset eof state after changing the eof char} -setup {
7198 set datafile [makeFile {} eofchar]
7199 set f [open $datafile w]
7200 fconfigure $f -translation binary
7201 puts -nonewline $f [string repeat "Ho hum\n" 11]
7203 set line [string repeat "Ge gla " 4]
7204 puts -nonewline $f [string repeat [string trimright $line]\n 834]
7207 set f [open $datafile r]
7208 fconfigure $f -eofchar =
7210 lappend res [read $f; tell $f]
7211 fconfigure $f -eofchar {}
7212 lappend res [read $f 1]
7213 lappend res [read $f; tell $f]
7214 # Any seek zaps the internals into a good state.
7217 #lappend res [read $f; tell $f]
7222 } -result {77 = 23431}
7225 foreach file [list fooBar longfile script output test1 pipe my_script foo \
7226 bar test2 test3 cat stdout kyrillic.txt utf8-fcopy.txt utf8-rp.txt] {
7231 namespace delete ::tcl::test::io