| 1 |
# -*- tcl -*- |
| 2 |
# Functionality covered: operation of all IO commands, and all procedures |
| 3 |
# defined in generic/tclIO.c. |
| 4 |
# |
| 5 |
# This file contains a collection of tests for one or more of the Tcl built-in |
| 6 |
# commands. Sourcing this file into Tcl runs the tests and generates output |
| 7 |
# for errors. No output means no errors were found. |
| 8 |
# |
| 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 Scriptics Corporation. |
| 12 |
# |
| 13 |
# See the file "license.terms" for information on usage and redistribution of |
| 14 |
# this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 15 |
|
| 16 |
if {"::tcltest" ni [namespace children]} { |
| 17 |
package require tcltest 2.5 |
| 18 |
} |
| 19 |
|
| 20 |
namespace eval ::tcl::test::io { |
| 21 |
namespace import ::tcltest::* |
| 22 |
|
| 23 |
variable umaskValue |
| 24 |
variable path |
| 25 |
variable f |
| 26 |
variable i |
| 27 |
variable n |
| 28 |
variable v |
| 29 |
variable msg |
| 30 |
variable expected |
| 31 |
|
| 32 |
set ::tcltestlib {} |
| 33 |
catch { |
| 34 |
::tcltest::loadTestedCommands |
| 35 |
package require -exact Tcltest [info patchlevel] |
| 36 |
set ::tcltestlib [lindex [package ifneeded Tcltest [info patchlevel]] 1] |
| 37 |
} |
| 38 |
source [file join [file dirname [info script]] tcltests.tcl] |
| 39 |
|
| 40 |
testConstraint testbytestring [llength [info commands testbytestring]] |
| 41 |
testConstraint testchannel [llength [info commands testchannel]] |
| 42 |
testConstraint testfevent [llength [info commands testfevent]] |
| 43 |
testConstraint testchannelevent [llength [info commands testchannelevent]] |
| 44 |
testConstraint testmainthread [llength [info commands testmainthread]] |
| 45 |
testConstraint testservicemode [llength [info commands testservicemode]] |
| 46 |
testConstraint notWinCI [expr { |
| 47 |
$::tcl_platform(platform) ne "windows" || ![info exists ::env(CI)]}] |
| 48 |
testConstraint notOSX [expr {$::tcl_platform(os) ne "Darwin"}] |
| 49 |
# File permissions broken on wsl without some "exotic" wsl configuration |
| 50 |
testConstraint notWsl [expr {[llength [array names ::env *WSL*]] == 0}] |
| 51 |
|
| 52 |
# You need a *very* special environment to do some tests. In particular, |
| 53 |
# many file systems do not support large-files... |
| 54 |
testConstraint largefileSupport [expr {$::tcl_platform(os) ne "Darwin"}] |
| 55 |
|
| 56 |
# some tests can only be run is umask is 2 if "umask" cannot be run, the |
| 57 |
# tests will be skipped. |
| 58 |
set umaskValue 0 |
| 59 |
testConstraint umask [expr {![catch {set umaskValue [scan [exec /bin/sh -c umask] %o]}]}] |
| 60 |
|
| 61 |
testConstraint makeFileInHome [expr {![file exists ~/_test_] && [file writable ~]}] |
| 62 |
|
| 63 |
# set up a long data file for some of the following tests |
| 64 |
|
| 65 |
set path(longfile) [makeFile {} longfile] |
| 66 |
set f [open $path(longfile) w] |
| 67 |
chan configure $f -eofchar {} -translation lf |
| 68 |
for { set i 0 } { $i < 100 } { incr i} { |
| 69 |
chan puts $f "#123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef |
| 70 |
\#123456789abcdef01 |
| 71 |
\#" |
| 72 |
} |
| 73 |
chan close $f |
| 74 |
|
| 75 |
set path(cat) [makeFile { |
| 76 |
set f stdin |
| 77 |
if {$argv ne ""} { |
| 78 |
set f [open [lindex $argv 0]] |
| 79 |
} |
| 80 |
chan configure $f -encoding binary -translation lf -blocking 0 -eofchar \x1A |
| 81 |
chan configure stdout -encoding binary -translation lf -buffering none |
| 82 |
chan event $f readable "foo $f" |
| 83 |
proc foo {f} { |
| 84 |
set x [chan read $f] |
| 85 |
catch {chan puts -nonewline $x} |
| 86 |
if {[chan eof $f]} { |
| 87 |
chan close $f |
| 88 |
exit 0 |
| 89 |
} |
| 90 |
} |
| 91 |
vwait forever |
| 92 |
} cat] |
| 93 |
|
| 94 |
set thisScript [file join [pwd] [info script]] |
| 95 |
|
| 96 |
proc contents {file} { |
| 97 |
set f [open $file] |
| 98 |
chan configure $f -translation binary |
| 99 |
set a [chan read $f] |
| 100 |
chan close $f |
| 101 |
return $a |
| 102 |
} |
| 103 |
|
| 104 |
# Wrapper round butt-ugly pipe syntax |
| 105 |
proc openpipe {{mode r+} args} { |
| 106 |
open "|[list [interpreter] {*}$args]" $mode |
| 107 |
} |
| 108 |
|
| 109 |
test chan-io-1.5 {Tcl_WriteChars: CheckChannelErrors} {emptyTest} { |
| 110 |
# no test, need to cause an async error. |
| 111 |
} {} |
| 112 |
set path(test1) [makeFile {} test1] |
| 113 |
test chan-io-1.6 {Tcl_WriteChars: WriteBytes} { |
| 114 |
set f [open $path(test1) w] |
| 115 |
chan configure $f -encoding binary |
| 116 |
chan puts -nonewline $f a\u4E4D\x00 |
| 117 |
chan close $f |
| 118 |
contents $path(test1) |
| 119 |
} aM\x00 |
| 120 |
test chan-io-1.7 {Tcl_WriteChars: WriteChars} { |
| 121 |
set f [open $path(test1) w] |
| 122 |
chan configure $f -encoding shiftjis |
| 123 |
chan puts -nonewline $f "a\u4E4D\0" |
| 124 |
chan close $f |
| 125 |
contents $path(test1) |
| 126 |
} "a\x93\xE1\x00" |
| 127 |
set path(test2) [makeFile {} test2] |
| 128 |
test chan-io-1.8 {Tcl_WriteChars: WriteChars} { |
| 129 |
# This test written for SF bug #506297. |
| 130 |
# |
| 131 |
# Executing this test without the fix for the referenced bug applied to |
| 132 |
# tcl will cause tcl, more specifically WriteChars, to go into an infinite |
| 133 |
# loop. |
| 134 |
set f [open $path(test2) w] |
| 135 |
chan configure $f -encoding iso2022-jp |
| 136 |
chan puts -nonewline $f [format %s%c [string repeat " " 4] 12399] |
| 137 |
chan close $f |
| 138 |
contents $path(test2) |
| 139 |
} " \x1B\$B\$O\x1B(B" |
| 140 |
test chan-io-1.9 {Tcl_WriteChars: WriteChars} { |
| 141 |
# When closing a channel with an encoding that appends escape bytes, check |
| 142 |
# for the case where the escape bytes overflow the current IO buffer. The |
| 143 |
# bytes should be moved into a new buffer. |
| 144 |
set data "1234567890 [format %c 12399]" |
| 145 |
set sizes [list] |
| 146 |
# With default buffer size |
| 147 |
set f [open $path(test2) w] |
| 148 |
chan configure $f -encoding iso2022-jp |
| 149 |
chan puts -nonewline $f $data |
| 150 |
chan close $f |
| 151 |
lappend sizes [file size $path(test2)] |
| 152 |
# With buffer size equal to the length of the data, the escape bytes would |
| 153 |
# go into the next buffer. |
| 154 |
set f [open $path(test2) w] |
| 155 |
chan configure $f -encoding iso2022-jp -buffersize 16 |
| 156 |
chan puts -nonewline $f $data |
| 157 |
chan close $f |
| 158 |
lappend sizes [file size $path(test2)] |
| 159 |
# With buffer size that is large enough to hold 1 byte of escaped data, |
| 160 |
# but not all 3. This should not write the escape bytes to the first |
| 161 |
# buffer and then again to the second buffer. |
| 162 |
set f [open $path(test2) w] |
| 163 |
chan configure $f -encoding iso2022-jp -buffersize 17 |
| 164 |
chan puts -nonewline $f $data |
| 165 |
chan close $f |
| 166 |
lappend sizes [file size $path(test2)] |
| 167 |
# With buffer size that can hold 2 out of 3 bytes of escaped data. |
| 168 |
set f [open $path(test2) w] |
| 169 |
chan configure $f -encoding iso2022-jp -buffersize 18 |
| 170 |
chan puts -nonewline $f $data |
| 171 |
chan close $f |
| 172 |
lappend sizes [file size $path(test2)] |
| 173 |
# With buffer size that can hold all the data and escape bytes. |
| 174 |
set f [open $path(test2) w] |
| 175 |
chan configure $f -encoding iso2022-jp -buffersize 19 |
| 176 |
chan puts -nonewline $f $data |
| 177 |
chan close $f |
| 178 |
lappend sizes [file size $path(test2)] |
| 179 |
} {19 19 19 19 19} |
| 180 |
|
| 181 |
test chan-io-2.1 {WriteBytes} { |
| 182 |
# loop until all bytes are written |
| 183 |
set f [open $path(test1) w] |
| 184 |
chan configure $f -encoding binary -buffersize 16 -translation crlf |
| 185 |
chan puts $f "abcdefghijklmnopqrstuvwxyz" |
| 186 |
chan close $f |
| 187 |
contents $path(test1) |
| 188 |
} "abcdefghijklmnopqrstuvwxyz\r\n" |
| 189 |
test chan-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. |
| 192 |
set f [open $path(test1) w] |
| 193 |
chan configure $f -encoding binary -buffersize 16 -translation crlf |
| 194 |
chan puts -nonewline $f "123456789012345\n12" |
| 195 |
set x [list [contents $path(test1)]] |
| 196 |
chan close $f |
| 197 |
lappend x [contents $path(test1)] |
| 198 |
} [list "123456789012345\r" "123456789012345\r\n12"] |
| 199 |
test chan-io-2.3 {WriteBytes: flush on line} -body { |
| 200 |
# Tcl "line" buffering has weird behavior: if current buffer contains a |
| 201 |
# \n, entire buffer gets flushed. Logical behavior would be to flush only |
| 202 |
# up to the \n. |
| 203 |
set f [open $path(test1) w] |
| 204 |
chan configure $f -encoding binary -buffering line -translation crlf |
| 205 |
chan puts -nonewline $f "\n12" |
| 206 |
contents $path(test1) |
| 207 |
} -cleanup { |
| 208 |
chan close $f |
| 209 |
} -result "\r\n12" |
| 210 |
test chan-io-2.4 {WriteBytes: reset sawLF after each buffer} { |
| 211 |
set f [open $path(test1) w] |
| 212 |
chan configure $f -encoding binary -buffering line -translation lf \ |
| 213 |
-buffersize 16 |
| 214 |
chan puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz" |
| 215 |
set x [list [contents $path(test1)]] |
| 216 |
chan close $f |
| 217 |
lappend x [contents $path(test1)] |
| 218 |
} [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] |
| 219 |
|
| 220 |
test chan-io-3.1 {WriteChars: compatibility with WriteBytes} { |
| 221 |
# loop until all bytes are written |
| 222 |
set f [open $path(test1) w] |
| 223 |
chan configure $f -encoding ascii -buffersize 16 -translation crlf |
| 224 |
chan puts $f "abcdefghijklmnopqrstuvwxyz" |
| 225 |
chan close $f |
| 226 |
contents $path(test1) |
| 227 |
} "abcdefghijklmnopqrstuvwxyz\r\n" |
| 228 |
test chan-io-3.2 {WriteChars: compatibility with WriteBytes: savedLF > 0} { |
| 229 |
# After flushing buffer, there was a \n left over from the last |
| 230 |
# \n -> \r\n expansion. It gets stuck at beginning of this buffer. |
| 231 |
set f [open $path(test1) w] |
| 232 |
chan configure $f -encoding ascii -buffersize 16 -translation crlf |
| 233 |
chan puts -nonewline $f "123456789012345\n12" |
| 234 |
set x [list [contents $path(test1)]] |
| 235 |
chan close $f |
| 236 |
lappend x [contents $path(test1)] |
| 237 |
} [list "123456789012345\r" "123456789012345\r\n12"] |
| 238 |
test chan-io-3.3 {WriteChars: compatibility with WriteBytes: flush on line} -body { |
| 239 |
# Tcl "line" buffering has weird behavior: if current buffer contains a |
| 240 |
# \n, entire buffer gets flushed. Logical behavior would be to flush only |
| 241 |
# up to the \n. |
| 242 |
set f [open $path(test1) w] |
| 243 |
chan configure $f -encoding ascii -buffering line -translation crlf |
| 244 |
chan puts -nonewline $f "\n12" |
| 245 |
contents $path(test1) |
| 246 |
} -cleanup { |
| 247 |
chan close $f |
| 248 |
} -result "\r\n12" |
| 249 |
test chan-io-3.4 {WriteChars: loop over stage buffer} -body { |
| 250 |
# stage buffer maps to more than can be queued at once. |
| 251 |
set f [open $path(test1) w] |
| 252 |
chan configure $f -encoding jis0208 -buffersize 16 |
| 253 |
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" |
| 254 |
set x [list [contents $path(test1)]] |
| 255 |
chan close $f |
| 256 |
lappend x [contents $path(test1)] |
| 257 |
} -cleanup { |
| 258 |
catch {chan close $f} |
| 259 |
} -result [list "!)!)!)!)!)!)!)!)" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] |
| 260 |
test chan-io-3.5 {WriteChars: saved != 0} -body { |
| 261 |
# Bytes produced by UtfToExternal from end of last channel buffer had to |
| 262 |
# be moved to beginning of next channel buffer to preserve requested |
| 263 |
# buffersize. |
| 264 |
set f [open $path(test1) w] |
| 265 |
chan configure $f -encoding jis0208 -buffersize 17 |
| 266 |
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" |
| 267 |
set x [list [contents $path(test1)]] |
| 268 |
chan close $f |
| 269 |
lappend x [contents $path(test1)] |
| 270 |
} -cleanup { |
| 271 |
catch {chan close $f} |
| 272 |
} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] |
| 273 |
test chan-io-3.6 {WriteChars: (stageRead + dstWrote == 0)} -body { |
| 274 |
# One incomplete UTF-8 character at end of staging buffer. Backup in src |
| 275 |
# to the beginning of that UTF-8 character and try again. |
| 276 |
# |
| 277 |
# Translate the first 16 bytes, produce 14 bytes of output, 2 left over |
| 278 |
# (first two bytes of \uFF21 in UTF-8). Given those two bytes try |
| 279 |
# translating them again, find that no bytes are read produced, and break |
| 280 |
# to outer loop where those two bytes will have the remaining 4 bytes (the |
| 281 |
# last byte of \uFF21 plus the all of \uFF22) appended. |
| 282 |
set f [open $path(test1) w] |
| 283 |
chan configure $f -encoding shiftjis -buffersize 16 |
| 284 |
chan puts -nonewline $f 12345678901234\uFF21\uFF22 |
| 285 |
set x [list [contents $path(test1)]] |
| 286 |
chan close $f |
| 287 |
lappend x [contents $path(test1)] |
| 288 |
} -cleanup { |
| 289 |
catch {chan close $f} |
| 290 |
} -result [list "12345678901234\x82\x60" "12345678901234\x82\x60\x82\x61"] |
| 291 |
test chan-io-3.7 {WriteChars: (bufPtr->nextAdded > bufPtr->length)} -body { |
| 292 |
# When translating UTF-8 to external, the produced bytes went past end of |
| 293 |
# the channel buffer. This is done on purpose - we then truncate the bytes |
| 294 |
# at the end of the partial character to preserve the requested blocksize |
| 295 |
# on flush. The truncated bytes are moved to the beginning of the next |
| 296 |
# channel buffer. |
| 297 |
set f [open $path(test1) w] |
| 298 |
chan configure $f -encoding jis0208 -buffersize 17 |
| 299 |
chan puts -nonewline $f "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" |
| 300 |
set x [list [contents $path(test1)]] |
| 301 |
chan close $f |
| 302 |
lappend x [contents $path(test1)] |
| 303 |
} -cleanup { |
| 304 |
catch {chan close $f} |
| 305 |
} -result [list "!)!)!)!)!)!)!)!)!" "!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)"] |
| 306 |
test chan-io-3.8 {WriteChars: reset sawLF after each buffer} -body { |
| 307 |
set f [open $path(test1) w] |
| 308 |
chan configure $f -encoding ascii -buffering line -translation lf \ |
| 309 |
-buffersize 16 |
| 310 |
chan puts -nonewline $f "abcdefg\nhijklmnopqrstuvwxyz" |
| 311 |
set x [list [contents $path(test1)]] |
| 312 |
chan close $f |
| 313 |
lappend x [contents $path(test1)] |
| 314 |
} -cleanup { |
| 315 |
catch {chan close $f} |
| 316 |
} -result [list "abcdefg\nhijklmno" "abcdefg\nhijklmnopqrstuvwxyz"] |
| 317 |
|
| 318 |
test chan-io-4.1 {TranslateOutputEOL: lf} { |
| 319 |
# search for \n |
| 320 |
set f [open $path(test1) w] |
| 321 |
chan configure $f -buffering line -translation lf |
| 322 |
chan puts $f "abcde" |
| 323 |
set x [list [contents $path(test1)]] |
| 324 |
chan close $f |
| 325 |
lappend x [contents $path(test1)] |
| 326 |
} [list "abcde\n" "abcde\n"] |
| 327 |
test chan-io-4.2 {TranslateOutputEOL: cr} { |
| 328 |
# search for \n, replace with \r |
| 329 |
set f [open $path(test1) w] |
| 330 |
chan configure $f -buffering line -translation cr |
| 331 |
chan puts $f "abcde" |
| 332 |
set x [list [contents $path(test1)]] |
| 333 |
chan close $f |
| 334 |
lappend x [contents $path(test1)] |
| 335 |
} [list "abcde\r" "abcde\r"] |
| 336 |
test chan-io-4.3 {TranslateOutputEOL: crlf} { |
| 337 |
# simple case: search for \n, replace with \r |
| 338 |
set f [open $path(test1) w] |
| 339 |
chan configure $f -buffering line -translation crlf |
| 340 |
chan puts $f "abcde" |
| 341 |
set x [list [contents $path(test1)]] |
| 342 |
chan close $f |
| 343 |
lappend x [contents $path(test1)] |
| 344 |
} [list "abcde\r\n" "abcde\r\n"] |
| 345 |
test chan-io-4.4 {TranslateOutputEOL: crlf} { |
| 346 |
# Keep storing more bytes in output buffer until output buffer is full. We |
| 347 |
# have 13 bytes initially that would turn into 18 bytes. Fill dest buffer |
| 348 |
# while (dstEnd < dstMax). |
| 349 |
set f [open $path(test1) w] |
| 350 |
chan configure $f -translation crlf -buffersize 16 |
| 351 |
chan puts -nonewline $f "1234567\n\n\n\n\nA" |
| 352 |
set x [list [contents $path(test1)]] |
| 353 |
chan close $f |
| 354 |
lappend x [contents $path(test1)] |
| 355 |
} [list "1234567\r\n\r\n\r\n\r\n\r" "1234567\r\n\r\n\r\n\r\n\r\nA"] |
| 356 |
test chan-io-4.5 {TranslateOutputEOL: crlf} { |
| 357 |
# Check for overflow of the destination buffer |
| 358 |
set f [open $path(test1) w] |
| 359 |
chan configure $f -translation crlf -buffersize 12 |
| 360 |
chan puts -nonewline $f "12345678901\n456789012345678901234" |
| 361 |
chan close $f |
| 362 |
set x [contents $path(test1)] |
| 363 |
} "12345678901\r\n456789012345678901234" |
| 364 |
|
| 365 |
test chan-io-5.1 {CheckFlush: not full} { |
| 366 |
set f [open $path(test1) w] |
| 367 |
chan configure $f |
| 368 |
chan puts -nonewline $f "12345678901234567890" |
| 369 |
set x [list [contents $path(test1)]] |
| 370 |
chan close $f |
| 371 |
lappend x [contents $path(test1)] |
| 372 |
} [list "" "12345678901234567890"] |
| 373 |
test chan-io-5.2 {CheckFlush: full} { |
| 374 |
set f [open $path(test1) w] |
| 375 |
chan configure $f -buffersize 16 |
| 376 |
chan puts -nonewline $f "12345678901234567890" |
| 377 |
set x [list [contents $path(test1)]] |
| 378 |
chan close $f |
| 379 |
lappend x [contents $path(test1)] |
| 380 |
} [list "1234567890123456" "12345678901234567890"] |
| 381 |
test chan-io-5.3 {CheckFlush: not line} { |
| 382 |
set f [open $path(test1) w] |
| 383 |
chan configure $f -buffering line |
| 384 |
chan puts -nonewline $f "12345678901234567890" |
| 385 |
set x [list [contents $path(test1)]] |
| 386 |
chan close $f |
| 387 |
lappend x [contents $path(test1)] |
| 388 |
} [list "" "12345678901234567890"] |
| 389 |
test chan-io-5.4 {CheckFlush: line} { |
| 390 |
set f [open $path(test1) w] |
| 391 |
chan configure $f -buffering line -translation lf -encoding ascii |
| 392 |
chan puts -nonewline $f "1234567890\n1234567890" |
| 393 |
set x [list [contents $path(test1)]] |
| 394 |
chan close $f |
| 395 |
lappend x [contents $path(test1)] |
| 396 |
} [list "1234567890\n1234567890" "1234567890\n1234567890"] |
| 397 |
test chan-io-5.5 {CheckFlush: none} { |
| 398 |
set f [open $path(test1) w] |
| 399 |
chan configure $f -buffering none |
| 400 |
chan puts -nonewline $f "1234567890" |
| 401 |
set x [list [contents $path(test1)]] |
| 402 |
chan close $f |
| 403 |
lappend x [contents $path(test1)] |
| 404 |
} [list "1234567890" "1234567890"] |
| 405 |
|
| 406 |
test chan-io-6.1 {Tcl_GetsObj: working} -body { |
| 407 |
set f [open $path(test1) w] |
| 408 |
chan puts $f "foo\nboo" |
| 409 |
chan close $f |
| 410 |
set f [open $path(test1)] |
| 411 |
chan gets $f |
| 412 |
} -cleanup { |
| 413 |
chan close $f |
| 414 |
} -result {foo} |
| 415 |
test chan-io-6.2 {Tcl_GetsObj: CheckChannelErrors() != 0} emptyTest { |
| 416 |
# no test, need to cause an async error. |
| 417 |
} {} |
| 418 |
test chan-io-6.3 {Tcl_GetsObj: how many have we used?} -body { |
| 419 |
# if (bufPtr != NULL) {oldRemoved = bufPtr->nextRemoved} |
| 420 |
set f [open $path(test1) w] |
| 421 |
chan configure $f -translation crlf |
| 422 |
chan puts $f "abc\ndefg" |
| 423 |
chan close $f |
| 424 |
set f [open $path(test1)] |
| 425 |
list [chan tell $f] [chan gets $f line] [chan tell $f] [chan gets $f line] $line |
| 426 |
} -cleanup { |
| 427 |
chan close $f |
| 428 |
} -result {0 3 5 4 defg} |
| 429 |
test chan-io-6.4 {Tcl_GetsObj: encoding == NULL} -body { |
| 430 |
set f [open $path(test1) w] |
| 431 |
chan configure $f -translation binary |
| 432 |
chan puts $f "\x81\u1234\x00" |
| 433 |
chan close $f |
| 434 |
set f [open $path(test1)] |
| 435 |
chan configure $f -translation binary |
| 436 |
list [chan gets $f line] $line |
| 437 |
} -cleanup { |
| 438 |
chan close $f |
| 439 |
} -result [list 3 "\x81\x34\x00"] |
| 440 |
test chan-io-6.5 {Tcl_GetsObj: encoding != NULL} -body { |
| 441 |
set f [open $path(test1) w] |
| 442 |
chan configure $f -translation binary |
| 443 |
chan puts $f "\x88\xEA\x92\x9A" |
| 444 |
chan close $f |
| 445 |
set f [open $path(test1)] |
| 446 |
chan configure $f -encoding shiftjis |
| 447 |
list [chan gets $f line] $line |
| 448 |
} -cleanup { |
| 449 |
chan close $f |
| 450 |
} -result [list 2 "\u4E00\u4E01"] |
| 451 |
set a "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" |
| 452 |
append a $a |
| 453 |
append a $a |
| 454 |
test chan-io-6.6 {Tcl_GetsObj: loop test} -body { |
| 455 |
# if (dst >= dstEnd) |
| 456 |
set f [open $path(test1) w] |
| 457 |
chan puts $f $a |
| 458 |
chan puts $f hi |
| 459 |
chan close $f |
| 460 |
set f [open $path(test1)] |
| 461 |
list [chan gets $f line] $line |
| 462 |
} -cleanup { |
| 463 |
chan close $f |
| 464 |
} -result [list 256 $a] |
| 465 |
test chan-io-6.7 {Tcl_GetsObj: error in input} -constraints stdio -body { |
| 466 |
# if (FilterInputBytes(chanPtr, &gs) != 0) |
| 467 |
set f [openpipe w+ $path(cat)] |
| 468 |
chan puts -nonewline $f "hi\nwould" |
| 469 |
chan flush $f |
| 470 |
chan gets $f |
| 471 |
chan configure $f -blocking 0 |
| 472 |
chan gets $f line |
| 473 |
} -cleanup { |
| 474 |
chan close $f |
| 475 |
} -result {-1} |
| 476 |
test chan-io-6.8 {Tcl_GetsObj: remember if EOF is seen} -body { |
| 477 |
set f [open $path(test1) w] |
| 478 |
chan puts $f "abcdef\x1Aghijk\nwombat" |
| 479 |
chan close $f |
| 480 |
set f [open $path(test1)] |
| 481 |
chan configure $f -eofchar \x1A |
| 482 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 483 |
} -cleanup { |
| 484 |
chan close $f |
| 485 |
} -result {6 abcdef -1 {}} |
| 486 |
test chan-io-6.9 {Tcl_GetsObj: remember if EOF is seen} -body { |
| 487 |
set f [open $path(test1) w] |
| 488 |
chan puts $f "abcdefghijk\nwom\u001Abat" |
| 489 |
chan close $f |
| 490 |
set f [open $path(test1)] |
| 491 |
chan configure $f -eofchar \x1A |
| 492 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 493 |
} -cleanup { |
| 494 |
chan close $f |
| 495 |
} -result {11 abcdefghijk 3 wom} |
| 496 |
# Comprehensive tests |
| 497 |
test chan-io-6.10 {Tcl_GetsObj: lf mode: no chars} -body { |
| 498 |
set f [open $path(test1) w] |
| 499 |
chan close $f |
| 500 |
set f [open $path(test1)] |
| 501 |
chan configure $f -translation lf |
| 502 |
list [chan gets $f line] $line |
| 503 |
} -cleanup { |
| 504 |
chan close $f |
| 505 |
} -result {-1 {}} |
| 506 |
test chan-io-6.11 {Tcl_GetsObj: lf mode: lone \n} -body { |
| 507 |
set f [open $path(test1) w] |
| 508 |
chan configure $f -translation lf |
| 509 |
chan puts -nonewline $f "\n" |
| 510 |
chan close $f |
| 511 |
set f [open $path(test1)] |
| 512 |
chan configure $f -translation lf |
| 513 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 514 |
} -cleanup { |
| 515 |
chan close $f |
| 516 |
} -result {0 {} -1 {}} |
| 517 |
test chan-io-6.12 {Tcl_GetsObj: lf mode: lone \r} -body { |
| 518 |
set f [open $path(test1) w] |
| 519 |
chan configure $f -translation lf |
| 520 |
chan puts -nonewline $f "\r" |
| 521 |
chan close $f |
| 522 |
set f [open $path(test1)] |
| 523 |
chan configure $f -translation lf |
| 524 |
set x [list [chan gets $f line] $line [chan gets $f line] $line] |
| 525 |
} -cleanup { |
| 526 |
chan close $f |
| 527 |
} -result [list 1 "\r" -1 ""] |
| 528 |
test chan-io-6.13 {Tcl_GetsObj: lf mode: 1 char} -body { |
| 529 |
set f [open $path(test1) w] |
| 530 |
chan configure $f -translation lf |
| 531 |
chan puts -nonewline $f a |
| 532 |
chan close $f |
| 533 |
set f [open $path(test1)] |
| 534 |
chan configure $f -translation lf |
| 535 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 536 |
} -cleanup { |
| 537 |
chan close $f |
| 538 |
} -result {1 a -1 {}} |
| 539 |
test chan-io-6.14 {Tcl_GetsObj: lf mode: 1 char followed by EOL} -body { |
| 540 |
set f [open $path(test1) w] |
| 541 |
chan configure $f -translation lf |
| 542 |
chan puts -nonewline $f "a\n" |
| 543 |
chan close $f |
| 544 |
set f [open $path(test1)] |
| 545 |
chan configure $f -translation lf |
| 546 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 547 |
} -cleanup { |
| 548 |
chan close $f |
| 549 |
} -result {1 a -1 {}} |
| 550 |
test chan-io-6.15 {Tcl_GetsObj: lf mode: several chars} -body { |
| 551 |
set f [open $path(test1) w] |
| 552 |
chan configure $f -translation lf |
| 553 |
chan puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" |
| 554 |
chan close $f |
| 555 |
set f [open $path(test1)] |
| 556 |
chan configure $f -translation lf |
| 557 |
list [chan gets $f line] $line [chan gets $f line] $line \ |
| 558 |
[chan gets $f line] $line [chan gets $f line] $line |
| 559 |
} -cleanup { |
| 560 |
chan close $f |
| 561 |
} -result [list 4 "abcd" 10 "efgh\rijkl\r" 4 "mnop" -1 ""] |
| 562 |
test chan-io-6.16 {Tcl_GetsObj: cr mode: no chars} -body { |
| 563 |
set f [open $path(test1) w] |
| 564 |
chan close $f |
| 565 |
set f [open $path(test1)] |
| 566 |
chan configure $f -translation cr |
| 567 |
list [chan gets $f line] $line |
| 568 |
} -cleanup { |
| 569 |
chan close $f |
| 570 |
} -result {-1 {}} |
| 571 |
test chan-io-6.17 {Tcl_GetsObj: cr mode: lone \n} -body { |
| 572 |
set f [open $path(test1) w] |
| 573 |
chan configure $f -translation lf |
| 574 |
chan puts -nonewline $f "\n" |
| 575 |
chan close $f |
| 576 |
set f [open $path(test1)] |
| 577 |
chan configure $f -translation cr |
| 578 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 579 |
} -cleanup { |
| 580 |
chan close $f |
| 581 |
} -result [list 1 "\n" -1 ""] |
| 582 |
test chan-io-6.18 {Tcl_GetsObj: cr mode: lone \r} -body { |
| 583 |
set f [open $path(test1) w] |
| 584 |
chan configure $f -translation lf |
| 585 |
chan puts -nonewline $f "\r" |
| 586 |
chan close $f |
| 587 |
set f [open $path(test1)] |
| 588 |
chan configure $f -translation cr |
| 589 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 590 |
} -cleanup { |
| 591 |
chan close $f |
| 592 |
} -result {0 {} -1 {}} |
| 593 |
test chan-io-6.19 {Tcl_GetsObj: cr mode: 1 char} -body { |
| 594 |
set f [open $path(test1) w] |
| 595 |
chan configure $f -translation lf |
| 596 |
chan puts -nonewline $f a |
| 597 |
chan close $f |
| 598 |
set f [open $path(test1)] |
| 599 |
chan configure $f -translation cr |
| 600 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 601 |
} -cleanup { |
| 602 |
chan close $f |
| 603 |
} -result {1 a -1 {}} |
| 604 |
test chan-io-6.20 {Tcl_GetsObj: cr mode: 1 char followed by EOL} -body { |
| 605 |
set f [open $path(test1) w] |
| 606 |
chan configure $f -translation lf |
| 607 |
chan puts -nonewline $f "a\r" |
| 608 |
chan close $f |
| 609 |
set f [open $path(test1)] |
| 610 |
chan configure $f -translation cr |
| 611 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 612 |
} -cleanup { |
| 613 |
chan close $f |
| 614 |
} -result {1 a -1 {}} |
| 615 |
test chan-io-6.21 {Tcl_GetsObj: cr mode: several chars} -body { |
| 616 |
set f [open $path(test1) w] |
| 617 |
chan configure $f -translation lf |
| 618 |
chan puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" |
| 619 |
chan close $f |
| 620 |
set f [open $path(test1)] |
| 621 |
chan configure $f -translation cr |
| 622 |
list [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line |
| 623 |
} -cleanup { |
| 624 |
chan close $f |
| 625 |
} -result [list 9 "abcd\nefgh" 4 "ijkl" 5 "\nmnop" -1 ""] |
| 626 |
test chan-io-6.22 {Tcl_GetsObj: crlf mode: no chars} -body { |
| 627 |
set f [open $path(test1) w] |
| 628 |
chan close $f |
| 629 |
set f [open $path(test1)] |
| 630 |
chan configure $f -translation crlf |
| 631 |
list [chan gets $f line] $line |
| 632 |
} -cleanup { |
| 633 |
chan close $f |
| 634 |
} -result {-1 {}} |
| 635 |
test chan-io-6.23 {Tcl_GetsObj: crlf mode: lone \n} -body { |
| 636 |
set f [open $path(test1) w] |
| 637 |
chan configure $f -translation lf |
| 638 |
chan puts -nonewline $f "\n" |
| 639 |
chan close $f |
| 640 |
set f [open $path(test1)] |
| 641 |
chan configure $f -translation crlf |
| 642 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 643 |
} -cleanup { |
| 644 |
chan close $f |
| 645 |
} -result [list 1 "\n" -1 ""] |
| 646 |
test chan-io-6.24 {Tcl_GetsObj: crlf mode: lone \r} -body { |
| 647 |
set f [open $path(test1) w] |
| 648 |
chan configure $f -translation lf |
| 649 |
chan puts -nonewline $f "\r" |
| 650 |
chan close $f |
| 651 |
set f [open $path(test1)] |
| 652 |
chan configure $f -translation crlf |
| 653 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 654 |
} -cleanup { |
| 655 |
chan close $f |
| 656 |
} -result [list 1 "\r" -1 ""] |
| 657 |
test chan-io-6.25 {Tcl_GetsObj: crlf mode: \r\r} -body { |
| 658 |
set f [open $path(test1) w] |
| 659 |
chan configure $f -translation lf |
| 660 |
chan puts -nonewline $f "\r\r" |
| 661 |
chan close $f |
| 662 |
set f [open $path(test1)] |
| 663 |
chan configure $f -translation crlf |
| 664 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 665 |
} -cleanup { |
| 666 |
chan close $f |
| 667 |
} -result [list 2 "\r\r" -1 ""] |
| 668 |
test chan-io-6.26 {Tcl_GetsObj: crlf mode: \r\n} -body { |
| 669 |
set f [open $path(test1) w] |
| 670 |
chan configure $f -translation lf |
| 671 |
chan puts -nonewline $f "\r\n" |
| 672 |
chan close $f |
| 673 |
set f [open $path(test1)] |
| 674 |
chan configure $f -translation crlf |
| 675 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 676 |
} -cleanup { |
| 677 |
chan close $f |
| 678 |
} -result {0 {} -1 {}} |
| 679 |
test chan-io-6.27 {Tcl_GetsObj: crlf mode: 1 char} -body { |
| 680 |
set f [open $path(test1) w] |
| 681 |
chan configure $f -translation lf |
| 682 |
chan puts -nonewline $f a |
| 683 |
chan close $f |
| 684 |
set f [open $path(test1)] |
| 685 |
chan configure $f -translation crlf |
| 686 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 687 |
} -cleanup { |
| 688 |
chan close $f |
| 689 |
} -result {1 a -1 {}} |
| 690 |
test chan-io-6.28 {Tcl_GetsObj: crlf mode: 1 char followed by EOL} -body { |
| 691 |
set f [open $path(test1) w] |
| 692 |
chan configure $f -translation lf |
| 693 |
chan puts -nonewline $f "a\r\n" |
| 694 |
chan close $f |
| 695 |
set f [open $path(test1)] |
| 696 |
chan configure $f -translation crlf |
| 697 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 698 |
} -cleanup { |
| 699 |
chan close $f |
| 700 |
} -result {1 a -1 {}} |
| 701 |
test chan-io-6.29 {Tcl_GetsObj: crlf mode: several chars} -body { |
| 702 |
set f [open $path(test1) w] |
| 703 |
chan configure $f -translation lf |
| 704 |
chan puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" |
| 705 |
chan close $f |
| 706 |
set f [open $path(test1)] |
| 707 |
chan configure $f -translation crlf |
| 708 |
list [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line |
| 709 |
} -cleanup { |
| 710 |
chan close $f |
| 711 |
} -result [list 14 "abcd\nefgh\rijkl" 4 "mnop" -1 ""] |
| 712 |
test chan-io-6.30 {Tcl_GetsObj: crlf mode: buffer exhausted} -constraints {testchannel} -body { |
| 713 |
# if (eol >= dstEnd) |
| 714 |
set f [open $path(test1) w] |
| 715 |
chan configure $f -translation lf |
| 716 |
chan puts -nonewline $f "123456789012345\r\nabcdefghijklmnoprstuvwxyz" |
| 717 |
chan close $f |
| 718 |
set f [open $path(test1)] |
| 719 |
chan configure $f -translation crlf -buffersize 16 |
| 720 |
list [chan gets $f line] $line [testchannel inputbuffered $f] |
| 721 |
} -cleanup { |
| 722 |
chan close $f |
| 723 |
} -result [list 15 "123456789012345" 15] |
| 724 |
test chan-io-6.31 {Tcl_GetsObj: crlf mode: buffer exhausted, blocked} -setup { |
| 725 |
set x "" |
| 726 |
} -constraints {stdio testchannel fileevent} -body { |
| 727 |
# (FilterInputBytes() != 0) |
| 728 |
set f [openpipe w+ $path(cat)] |
| 729 |
chan configure $f -translation {crlf lf} -buffering none |
| 730 |
chan puts -nonewline $f "bbbbbbbbbbbbbb\r\n123456789012345\r" |
| 731 |
chan configure $f -buffersize 16 |
| 732 |
lappend x [chan gets $f] |
| 733 |
chan configure $f -blocking 0 |
| 734 |
lappend x [chan gets $f line] $line [chan blocked $f] \ |
| 735 |
[testchannel inputbuffered $f] |
| 736 |
} -cleanup { |
| 737 |
chan close $f |
| 738 |
} -result {bbbbbbbbbbbbbb -1 {} 1 16} |
| 739 |
test chan-io-6.32 {Tcl_GetsObj: crlf mode: buffer exhausted, more data} -constraints {testchannel} -body { |
| 740 |
# not (FilterInputBytes() != 0) |
| 741 |
set f [open $path(test1) w] |
| 742 |
chan configure $f -translation lf |
| 743 |
chan puts -nonewline $f "123456789012345\r\n123" |
| 744 |
chan close $f |
| 745 |
set f [open $path(test1)] |
| 746 |
chan configure $f -translation crlf -buffersize 16 |
| 747 |
list [chan gets $f line] $line [chan tell $f] [testchannel inputbuffered $f] |
| 748 |
} -cleanup { |
| 749 |
chan close $f |
| 750 |
} -result {15 123456789012345 17 3} |
| 751 |
test chan-io-6.33 {Tcl_GetsObj: crlf mode: buffer exhausted, at eof} -body { |
| 752 |
# eol still equals dstEnd |
| 753 |
set f [open $path(test1) w] |
| 754 |
chan configure $f -translation lf |
| 755 |
chan puts -nonewline $f "123456789012345\r" |
| 756 |
chan close $f |
| 757 |
set f [open $path(test1)] |
| 758 |
chan configure $f -translation crlf -buffersize 16 |
| 759 |
list [chan gets $f line] $line [chan eof $f] |
| 760 |
} -cleanup { |
| 761 |
chan close $f |
| 762 |
} -result [list 16 "123456789012345\r" 1] |
| 763 |
test chan-io-6.34 {Tcl_GetsObj: crlf mode: buffer exhausted, not followed by \n} -body { |
| 764 |
# not (*eol == '\n') |
| 765 |
set f [open $path(test1) w] |
| 766 |
chan configure $f -translation lf |
| 767 |
chan puts -nonewline $f "123456789012345\rabcd\r\nefg" |
| 768 |
chan close $f |
| 769 |
set f [open $path(test1)] |
| 770 |
chan configure $f -translation crlf -buffersize 16 |
| 771 |
list [chan gets $f line] $line [chan tell $f] |
| 772 |
} -cleanup { |
| 773 |
chan close $f |
| 774 |
} -result [list 20 "123456789012345\rabcd" 22] |
| 775 |
test chan-io-6.35 {Tcl_GetsObj: auto mode: no chars} -body { |
| 776 |
set f [open $path(test1) w] |
| 777 |
chan close $f |
| 778 |
set f [open $path(test1)] |
| 779 |
chan configure $f -translation auto |
| 780 |
list [chan gets $f line] $line |
| 781 |
} -cleanup { |
| 782 |
chan close $f |
| 783 |
} -result {-1 {}} |
| 784 |
test chan-io-6.36 {Tcl_GetsObj: auto mode: lone \n} -body { |
| 785 |
set f [open $path(test1) w] |
| 786 |
chan configure $f -translation lf |
| 787 |
chan puts -nonewline $f "\n" |
| 788 |
chan close $f |
| 789 |
set f [open $path(test1)] |
| 790 |
chan configure $f -translation auto |
| 791 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 792 |
} -cleanup { |
| 793 |
chan close $f |
| 794 |
} -result {0 {} -1 {}} |
| 795 |
test chan-io-6.37 {Tcl_GetsObj: auto mode: lone \r} -body { |
| 796 |
set f [open $path(test1) w] |
| 797 |
chan configure $f -translation lf |
| 798 |
chan puts -nonewline $f "\r" |
| 799 |
chan close $f |
| 800 |
set f [open $path(test1)] |
| 801 |
chan configure $f -translation auto |
| 802 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 803 |
} -cleanup { |
| 804 |
chan close $f |
| 805 |
} -result {0 {} -1 {}} |
| 806 |
test chan-io-6.38 {Tcl_GetsObj: auto mode: \r\r} -body { |
| 807 |
set f [open $path(test1) w] |
| 808 |
chan configure $f -translation lf |
| 809 |
chan puts -nonewline $f "\r\r" |
| 810 |
chan close $f |
| 811 |
set f [open $path(test1)] |
| 812 |
chan configure $f -translation auto |
| 813 |
list [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line |
| 814 |
} -cleanup { |
| 815 |
chan close $f |
| 816 |
} -result {0 {} 0 {} -1 {}} |
| 817 |
test chan-io-6.39 {Tcl_GetsObj: auto mode: \r\n} -body { |
| 818 |
set f [open $path(test1) w] |
| 819 |
chan configure $f -translation lf |
| 820 |
chan puts -nonewline $f "\r\n" |
| 821 |
chan close $f |
| 822 |
set f [open $path(test1)] |
| 823 |
chan configure $f -translation auto |
| 824 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 825 |
} -cleanup { |
| 826 |
chan close $f |
| 827 |
} -result {0 {} -1 {}} |
| 828 |
test chan-io-6.40 {Tcl_GetsObj: auto mode: 1 char} -body { |
| 829 |
set f [open $path(test1) w] |
| 830 |
chan configure $f -translation lf |
| 831 |
chan puts -nonewline $f a |
| 832 |
chan close $f |
| 833 |
set f [open $path(test1)] |
| 834 |
chan configure $f -translation auto |
| 835 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 836 |
} -cleanup { |
| 837 |
chan close $f |
| 838 |
} -result {1 a -1 {}} |
| 839 |
test chan-io-6.41 {Tcl_GetsObj: auto mode: 1 char followed by EOL} -body { |
| 840 |
set f [open $path(test1) w] |
| 841 |
chan configure $f -translation lf |
| 842 |
chan puts -nonewline $f "a\r\n" |
| 843 |
chan close $f |
| 844 |
set f [open $path(test1)] |
| 845 |
chan configure $f -translation auto |
| 846 |
list [chan gets $f line] $line [chan gets $f line] $line |
| 847 |
} -cleanup { |
| 848 |
chan close $f |
| 849 |
} -result {1 a -1 {}} |
| 850 |
test chan-io-6.42 {Tcl_GetsObj: auto mode: several chars} -setup { |
| 851 |
set x "" |
| 852 |
} -body { |
| 853 |
set f [open $path(test1) w] |
| 854 |
chan configure $f -translation lf |
| 855 |
chan puts -nonewline $f "abcd\nefgh\rijkl\r\nmnop" |
| 856 |
chan close $f |
| 857 |
set f [open $path(test1)] |
| 858 |
chan configure $f -translation auto |
| 859 |
lappend x [chan gets $f line] $line [chan gets $f line] $line |
| 860 |
lappend x [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line |
| 861 |
} -cleanup { |
| 862 |
chan close $f |
| 863 |
} -result {4 abcd 4 efgh 4 ijkl 4 mnop -1 {}} |
| 864 |
test chan-io-6.43 {Tcl_GetsObj: input saw cr} -setup { |
| 865 |
set x "" |
| 866 |
} -constraints {stdio testchannel fileevent} -body { |
| 867 |
# if (chanPtr->flags & INPUT_SAW_CR) |
| 868 |
set f [openpipe w+ $path(cat)] |
| 869 |
chan configure $f -translation {auto lf} -buffering none |
| 870 |
chan puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" |
| 871 |
chan configure $f -buffersize 16 |
| 872 |
lappend x [chan gets $f] |
| 873 |
chan configure $f -blocking 0 |
| 874 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 875 |
chan configure $f -blocking 1 |
| 876 |
chan puts -nonewline $f "\nabcd\refg\x1A" |
| 877 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 878 |
lappend x [chan gets $f line] $line |
| 879 |
} -cleanup { |
| 880 |
chan close $f |
| 881 |
} -result {bbbbbbbbbbbbbbb 15 123456789abcdef 1 4 abcd 0 3 efg} |
| 882 |
test chan-io-6.44 {Tcl_GetsObj: input saw cr, not followed by cr} -setup { |
| 883 |
set x "" |
| 884 |
} -constraints {stdio testchannel fileevent} -body { |
| 885 |
# not (*eol == '\n') |
| 886 |
set f [openpipe w+ $path(cat)] |
| 887 |
chan configure $f -translation {auto lf} -buffering none |
| 888 |
chan puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" |
| 889 |
chan configure $f -buffersize 16 |
| 890 |
lappend x [chan gets $f] |
| 891 |
chan configure $f -blocking 0 |
| 892 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 893 |
chan configure $f -blocking 1 |
| 894 |
chan puts -nonewline $f "abcd\refg\x1A" |
| 895 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 896 |
lappend x [chan gets $f line] $line |
| 897 |
} -cleanup { |
| 898 |
chan close $f |
| 899 |
} -result {bbbbbbbbbbbbbbb 15 123456789abcdef 1 4 abcd 0 3 efg} |
| 900 |
test chan-io-6.45 {Tcl_GetsObj: input saw cr, skip right number of bytes} -setup { |
| 901 |
set x "" |
| 902 |
} -constraints {stdio testchannel fileevent} -body { |
| 903 |
# Tcl_ExternalToUtf() |
| 904 |
set f [openpipe w+ $path(cat)] |
| 905 |
chan configure $f -translation {auto lf} -buffering none |
| 906 |
chan configure $f -encoding unicode |
| 907 |
chan puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" |
| 908 |
chan configure $f -buffersize 16 |
| 909 |
chan gets $f |
| 910 |
chan configure $f -blocking 0 |
| 911 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 912 |
chan configure $f -blocking 1 |
| 913 |
chan puts -nonewline $f "\nabcd\refg" |
| 914 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 915 |
} -cleanup { |
| 916 |
chan close $f |
| 917 |
} -result {15 123456789abcdef 1 4 abcd 0} |
| 918 |
test chan-io-6.46 {Tcl_GetsObj: input saw cr, followed by just \n should give eof} -setup { |
| 919 |
set x "" |
| 920 |
} -constraints {stdio testchannel fileevent} -body { |
| 921 |
# memmove() |
| 922 |
set f [openpipe w+ $path(cat)] |
| 923 |
chan configure $f -translation {auto lf} -buffering none |
| 924 |
chan puts -nonewline $f "bbbbbbbbbbbbbbb\n123456789abcdef\r" |
| 925 |
chan configure $f -buffersize 16 |
| 926 |
chan gets $f |
| 927 |
chan configure $f -blocking 0 |
| 928 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 929 |
chan configure $f -blocking 1 |
| 930 |
chan puts -nonewline $f "\n\x1A" |
| 931 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 932 |
} -cleanup { |
| 933 |
chan close $f |
| 934 |
} -result {15 123456789abcdef 1 -1 {} 0} |
| 935 |
test chan-io-6.47 {Tcl_GetsObj: auto mode: \r at end of buffer, peek for \n} -constraints {testchannel} -body { |
| 936 |
# (eol == dstEnd) |
| 937 |
set f [open $path(test1) w] |
| 938 |
chan configure $f -translation lf |
| 939 |
chan puts -nonewline $f "123456789012345\r\nabcdefghijklmnopq" |
| 940 |
chan close $f |
| 941 |
set f [open $path(test1)] |
| 942 |
chan configure $f -translation auto -buffersize 16 |
| 943 |
list [chan gets $f] [testchannel inputbuffered $f] |
| 944 |
} -cleanup { |
| 945 |
chan close $f |
| 946 |
} -result {123456789012345 15} |
| 947 |
test chan-io-6.48 {Tcl_GetsObj: auto mode: \r at end of buffer, no more avail} -constraints {testchannel} -body { |
| 948 |
# PeekAhead() did not get any, so (eol >= dstEnd) |
| 949 |
set f [open $path(test1) w] |
| 950 |
chan configure $f -translation lf |
| 951 |
chan puts -nonewline $f "123456789012345\r" |
| 952 |
chan close $f |
| 953 |
set f [open $path(test1)] |
| 954 |
chan configure $f -translation auto -buffersize 16 |
| 955 |
list [chan gets $f] [testchannel queuedcr $f] |
| 956 |
} -cleanup { |
| 957 |
chan close $f |
| 958 |
} -result {123456789012345 1} |
| 959 |
test chan-io-6.49 {Tcl_GetsObj: auto mode: \r followed by \n} -constraints {testchannel} -body { |
| 960 |
# if (*eol == '\n') {skip++} |
| 961 |
set f [open $path(test1) w] |
| 962 |
chan configure $f -translation lf |
| 963 |
chan puts -nonewline $f "123456\r\n78901" |
| 964 |
chan close $f |
| 965 |
set f [open $path(test1)] |
| 966 |
list [chan gets $f] [testchannel queuedcr $f] [chan tell $f] [chan gets $f] |
| 967 |
} -cleanup { |
| 968 |
chan close $f |
| 969 |
} -result {123456 0 8 78901} |
| 970 |
test chan-io-6.50 {Tcl_GetsObj: auto mode: \r not followed by \n} -constraints {testchannel} -body { |
| 971 |
# not (*eol == '\n') |
| 972 |
set f [open $path(test1) w] |
| 973 |
chan configure $f -translation lf |
| 974 |
chan puts -nonewline $f "123456\r78901" |
| 975 |
chan close $f |
| 976 |
set f [open $path(test1)] |
| 977 |
list [chan gets $f] [testchannel queuedcr $f] [chan tell $f] [chan gets $f] |
| 978 |
} -cleanup { |
| 979 |
chan close $f |
| 980 |
} -result {123456 0 7 78901} |
| 981 |
test chan-io-6.51 {Tcl_GetsObj: auto mode: \n} -body { |
| 982 |
# else if (*eol == '\n') {goto gotoeol;} |
| 983 |
set f [open $path(test1) w] |
| 984 |
chan configure $f -translation lf |
| 985 |
chan puts -nonewline $f "123456\n78901" |
| 986 |
chan close $f |
| 987 |
set f [open $path(test1)] |
| 988 |
list [chan gets $f] [chan tell $f] [chan gets $f] |
| 989 |
} -cleanup { |
| 990 |
chan close $f |
| 991 |
} -result {123456 7 78901} |
| 992 |
test chan-io-6.52 {Tcl_GetsObj: saw EOF character} -constraints {testchannel} -body { |
| 993 |
# if (eof != NULL) |
| 994 |
set f [open $path(test1) w] |
| 995 |
chan configure $f -translation lf |
| 996 |
chan puts -nonewline $f "123456\x1Ak9012345\r" |
| 997 |
chan close $f |
| 998 |
set f [open $path(test1)] |
| 999 |
chan configure $f -eofchar \x1A |
| 1000 |
list [chan gets $f] [testchannel queuedcr $f] [chan tell $f] [chan gets $f] |
| 1001 |
} -cleanup { |
| 1002 |
chan close $f |
| 1003 |
} -result {123456 0 6 {}} |
| 1004 |
test chan-io-6.53 {Tcl_GetsObj: device EOF} -body { |
| 1005 |
# didn't produce any bytes |
| 1006 |
set f [open $path(test1) w] |
| 1007 |
chan close $f |
| 1008 |
set f [open $path(test1)] |
| 1009 |
list [chan gets $f line] $line [chan eof $f] |
| 1010 |
} -cleanup { |
| 1011 |
chan close $f |
| 1012 |
} -result {-1 {} 1} |
| 1013 |
test chan-io-6.54 {Tcl_GetsObj: device EOF} -body { |
| 1014 |
# got some bytes before EOF. |
| 1015 |
set f [open $path(test1) w] |
| 1016 |
chan puts -nonewline $f abc |
| 1017 |
chan close $f |
| 1018 |
set f [open $path(test1)] |
| 1019 |
list [chan gets $f line] $line [chan eof $f] |
| 1020 |
} -cleanup { |
| 1021 |
chan close $f |
| 1022 |
} -result {3 abc 1} |
| 1023 |
test chan-io-6.55 {Tcl_GetsObj: overconverted} -body { |
| 1024 |
# Tcl_ExternalToUtf(), make sure state updated |
| 1025 |
set f [open $path(test1) w] |
| 1026 |
chan configure $f -encoding iso2022-jp |
| 1027 |
chan puts $f "there\u4E00ok\n\u4E01more bytes\nhere" |
| 1028 |
chan close $f |
| 1029 |
set f [open $path(test1)] |
| 1030 |
chan configure $f -encoding iso2022-jp |
| 1031 |
list [chan gets $f line] $line [chan gets $f line] $line [chan gets $f line] $line |
| 1032 |
} -cleanup { |
| 1033 |
chan close $f |
| 1034 |
} -result [list 8 "there\u4E00ok" 11 "\u4E01more bytes" 4 "here"] |
| 1035 |
test chan-io-6.56 {Tcl_GetsObj: incomplete lines should disable file events} -setup { |
| 1036 |
update |
| 1037 |
variable x {} |
| 1038 |
} -constraints {stdio fileevent} -body { |
| 1039 |
set f [openpipe w+ $path(cat)] |
| 1040 |
chan configure $f -buffering none |
| 1041 |
chan puts -nonewline $f "foobar" |
| 1042 |
chan configure $f -blocking 0 |
| 1043 |
after 500 [namespace code { |
| 1044 |
lappend x timeout |
| 1045 |
}] |
| 1046 |
chan event $f readable [namespace code { |
| 1047 |
lappend x [chan gets $f] |
| 1048 |
}] |
| 1049 |
vwait [namespace which -variable x] |
| 1050 |
vwait [namespace which -variable x] |
| 1051 |
chan configure $f -blocking 1 |
| 1052 |
chan puts -nonewline $f "baz\n" |
| 1053 |
after 500 [namespace code { |
| 1054 |
lappend x timeout |
| 1055 |
}] |
| 1056 |
chan configure $f -blocking 0 |
| 1057 |
vwait [namespace which -variable x] |
| 1058 |
vwait [namespace which -variable x] |
| 1059 |
return $x |
| 1060 |
} -cleanup { |
| 1061 |
chan close $f |
| 1062 |
} -result {{} timeout foobarbaz timeout} |
| 1063 |
|
| 1064 |
test chan-io-7.1 {FilterInputBytes: split up character at end of buffer} -body { |
| 1065 |
# (result == TCL_CONVERT_MULTIBYTE) |
| 1066 |
set f [open $path(test1) w] |
| 1067 |
chan configure $f -encoding shiftjis |
| 1068 |
chan puts $f "1234567890123\uFF10\uFF11\uFF12\uFF13\uFF14\nend" |
| 1069 |
chan close $f |
| 1070 |
set f [open $path(test1)] |
| 1071 |
chan configure $f -encoding shiftjis -buffersize 16 |
| 1072 |
chan gets $f |
| 1073 |
} -cleanup { |
| 1074 |
chan close $f |
| 1075 |
} -result "1234567890123\uFF10\uFF11\uFF12\uFF13\uFF14" |
| 1076 |
test chan-io-7.2 {FilterInputBytes: split up character in middle of buffer} -body { |
| 1077 |
# (bufPtr->nextAdded < bufPtr->bufLength) |
| 1078 |
set f [open $path(test1) w] |
| 1079 |
chan configure $f -encoding binary |
| 1080 |
chan puts -nonewline $f "1234567890\n123\x82\x4F\x82\x50\x82" |
| 1081 |
chan close $f |
| 1082 |
set f [open $path(test1)] |
| 1083 |
chan configure $f -encoding shiftjis |
| 1084 |
list [chan gets $f line] $line [chan eof $f] |
| 1085 |
} -cleanup { |
| 1086 |
chan close $f |
| 1087 |
} -result {10 1234567890 0} |
| 1088 |
test chan-io-7.3 {FilterInputBytes: split up character at EOF} -setup { |
| 1089 |
set x "" |
| 1090 |
} -constraints {testchannel} -body { |
| 1091 |
set f [open $path(test1) w] |
| 1092 |
chan configure $f -encoding binary |
| 1093 |
chan puts -nonewline $f "1234567890123\x82\x4F\x82\x50\x82" |
| 1094 |
chan close $f |
| 1095 |
set f [open $path(test1)] |
| 1096 |
chan configure $f -encoding shiftjis |
| 1097 |
lappend x [chan gets $f line] $line |
| 1098 |
lappend x [chan tell $f] [testchannel inputbuffered $f] [chan eof $f] |
| 1099 |
lappend x [chan gets $f line] $line |
| 1100 |
} -cleanup { |
| 1101 |
chan close $f |
| 1102 |
} -result [list 16 "1234567890123\uFF10\uFF11\x82" 18 0 1 -1 ""] |
| 1103 |
test chan-io-7.4 {FilterInputBytes: recover from split up character} -setup { |
| 1104 |
variable x "" |
| 1105 |
} -constraints {stdio fileevent} -body { |
| 1106 |
set f [openpipe w+ $path(cat)] |
| 1107 |
chan configure $f -encoding binary -buffering none |
| 1108 |
chan puts -nonewline $f "1234567890123\x82\x4F\x82\x50\x82" |
| 1109 |
chan configure $f -encoding shiftjis -blocking 0 |
| 1110 |
chan event $f read [namespace code { |
| 1111 |
lappend x [chan gets $f line] $line [chan blocked $f] |
| 1112 |
}] |
| 1113 |
vwait [namespace which -variable x] |
| 1114 |
chan configure $f -encoding binary -blocking 1 |
| 1115 |
chan puts $f "\x51\x82\x52" |
| 1116 |
chan configure $f -encoding shiftjis |
| 1117 |
vwait [namespace which -variable x] |
| 1118 |
return $x |
| 1119 |
} -cleanup { |
| 1120 |
chan close $f |
| 1121 |
} -result [list -1 "" 1 17 "1234567890123\uFF10\uFF11\uFF12\uFF13" 0] |
| 1122 |
|
| 1123 |
test chan-io-8.1 {PeekAhead: only go to device if no more cached data} -constraints {testchannel} -body { |
| 1124 |
# (bufPtr->nextPtr == NULL) |
| 1125 |
set f [open $path(test1) w] |
| 1126 |
chan configure $f -encoding ascii -translation lf |
| 1127 |
chan puts -nonewline $f "123456789012345\r\n2345678" |
| 1128 |
chan close $f |
| 1129 |
set f [open $path(test1)] |
| 1130 |
chan configure $f -encoding ascii -translation auto -buffersize 16 |
| 1131 |
# here |
| 1132 |
chan gets $f |
| 1133 |
testchannel inputbuffered $f |
| 1134 |
} -cleanup { |
| 1135 |
chan close $f |
| 1136 |
} -result 7 |
| 1137 |
test chan-io-8.2 {PeekAhead: only go to device if no more cached data} -setup { |
| 1138 |
variable x {} |
| 1139 |
} -constraints {stdio testchannel fileevent} -body { |
| 1140 |
# not (bufPtr->nextPtr == NULL) |
| 1141 |
set f [openpipe w+ $path(cat)] |
| 1142 |
chan configure $f -translation lf -encoding ascii -buffering none |
| 1143 |
chan puts -nonewline $f "123456789012345\r\nbcdefghijklmnopqrstuvwxyz" |
| 1144 |
chan event $f read [namespace code { |
| 1145 |
lappend x [chan gets $f line] $line [testchannel inputbuffered $f] |
| 1146 |
}] |
| 1147 |
chan configure $f -encoding unicode -buffersize 16 -blocking 0 |
| 1148 |
vwait [namespace which -variable x] |
| 1149 |
chan configure $f -translation auto -encoding ascii -blocking 1 |
| 1150 |
# here |
| 1151 |
vwait [namespace which -variable x] |
| 1152 |
return $x |
| 1153 |
} -cleanup { |
| 1154 |
chan close $f |
| 1155 |
} -result {-1 {} 42 15 123456789012345 25} |
| 1156 |
test chan-io-8.3 {PeekAhead: no cached data available} -constraints {stdio testchannel fileevent} -body { |
| 1157 |
# (bytesLeft == 0) |
| 1158 |
set f [openpipe w+ $path(cat)] |
| 1159 |
chan configure $f -translation {auto binary} |
| 1160 |
chan puts -nonewline $f "abcdefghijklmno\r" |
| 1161 |
chan flush $f |
| 1162 |
list [chan gets $f line] $line [testchannel queuedcr $f] |
| 1163 |
} -cleanup { |
| 1164 |
chan close $f |
| 1165 |
} -result {15 abcdefghijklmno 1} |
| 1166 |
set a "123456789012345678901234567890" |
| 1167 |
append a "123456789012345678901234567890" |
| 1168 |
append a "1234567890123456789012345678901" |
| 1169 |
test chan-io-8.4 {PeekAhead: cached data available in this buffer} -body { |
| 1170 |
# not (bytesLeft == 0) |
| 1171 |
set f [open $path(test1) w+] |
| 1172 |
chan configure $f -translation binary |
| 1173 |
chan puts $f "${a}\r\nabcdef" |
| 1174 |
chan close $f |
| 1175 |
set f [open $path(test1)] |
| 1176 |
chan configure $f -encoding binary -translation auto |
| 1177 |
# "${a}\r" was converted in one operation (because ENCODING_LINESIZE is |
| 1178 |
# 30). To check if "\n" follows, calls PeekAhead and determines that |
| 1179 |
# cached data is available in buffer w/o having to call driver. |
| 1180 |
chan gets $f |
| 1181 |
} -cleanup { |
| 1182 |
chan close $f |
| 1183 |
} -result $a |
| 1184 |
unset a |
| 1185 |
test chan-io-8.5 {PeekAhead: don't peek if last read was short} -constraints {stdio testchannel fileevent} -body { |
| 1186 |
# (bufPtr->nextAdded < bufPtr->length) |
| 1187 |
set f [openpipe w+ $path(cat)] |
| 1188 |
chan configure $f -translation {auto binary} |
| 1189 |
chan puts -nonewline $f "abcdefghijklmno\r" |
| 1190 |
chan flush $f |
| 1191 |
# here |
| 1192 |
list [chan gets $f line] $line [testchannel queuedcr $f] |
| 1193 |
} -cleanup { |
| 1194 |
chan close $f |
| 1195 |
} -result {15 abcdefghijklmno 1} |
| 1196 |
test chan-io-8.6 {PeekAhead: change to non-blocking mode} -constraints {stdio testchannel fileevent} -body { |
| 1197 |
# ((chanPtr->flags & CHANNEL_NONBLOCKING) == 0) |
| 1198 |
set f [openpipe w+ $path(cat)] |
| 1199 |
chan configure $f -translation {auto binary} -buffersize 16 |
| 1200 |
chan puts -nonewline $f "abcdefghijklmno\r" |
| 1201 |
chan flush $f |
| 1202 |
# here |
| 1203 |
list [chan gets $f line] $line [testchannel queuedcr $f] |
| 1204 |
} -cleanup { |
| 1205 |
chan close $f |
| 1206 |
} -result {15 abcdefghijklmno 1} |
| 1207 |
test chan-io-8.7 {PeekAhead: cleanup} -setup { |
| 1208 |
set x "" |
| 1209 |
} -constraints {stdio testchannel fileevent} -body { |
| 1210 |
# Make sure bytes are removed from buffer. |
| 1211 |
set f [openpipe w+ $path(cat)] |
| 1212 |
chan configure $f -translation {auto binary} -buffering none |
| 1213 |
chan puts -nonewline $f "abcdefghijklmno\r" |
| 1214 |
# here |
| 1215 |
lappend x [chan gets $f line] $line [testchannel queuedcr $f] |
| 1216 |
chan puts -nonewline $f \x1A |
| 1217 |
lappend x [chan gets $f line] $line |
| 1218 |
} -cleanup { |
| 1219 |
chan close $f |
| 1220 |
} -result {15 abcdefghijklmno 1 -1 {}} |
| 1221 |
|
| 1222 |
test chan-io-9.1 {CommonGetsCleanup} emptyTest { |
| 1223 |
} {} |
| 1224 |
|
| 1225 |
test chan-io-10.1 {Tcl_ReadChars: CheckChannelErrors} emptyTest { |
| 1226 |
# no test, need to cause an async error. |
| 1227 |
} {} |
| 1228 |
test chan-io-10.2 {Tcl_ReadChars: loop until enough copied} -body { |
| 1229 |
# one time |
| 1230 |
# for (copied = 0; (unsigned) toRead > 0; ) |
| 1231 |
set f [open $path(test1) w] |
| 1232 |
chan puts $f abcdefghijklmnop |
| 1233 |
chan close $f |
| 1234 |
set f [open $path(test1)] |
| 1235 |
chan read $f 5 |
| 1236 |
} -cleanup { |
| 1237 |
chan close $f |
| 1238 |
} -result {abcde} |
| 1239 |
test chan-io-10.3 {Tcl_ReadChars: loop until enough copied} -body { |
| 1240 |
# multiple times |
| 1241 |
# for (copied = 0; (unsigned) toRead > 0; ) |
| 1242 |
set f [open $path(test1) w] |
| 1243 |
chan puts $f abcdefghijklmnopqrstuvwxyz |
| 1244 |
chan close $f |
| 1245 |
set f [open $path(test1)] |
| 1246 |
chan configure $f -buffersize 16 |
| 1247 |
# here |
| 1248 |
chan read $f 19 |
| 1249 |
} -cleanup { |
| 1250 |
chan close $f |
| 1251 |
} -result {abcdefghijklmnopqrs} |
| 1252 |
test chan-io-10.4 {Tcl_ReadChars: no more in channel buffer} -body { |
| 1253 |
# (copiedNow < 0) |
| 1254 |
set f [open $path(test1) w] |
| 1255 |
chan puts -nonewline $f abcdefghijkl |
| 1256 |
chan close $f |
| 1257 |
set f [open $path(test1)] |
| 1258 |
# here |
| 1259 |
chan read $f 1000 |
| 1260 |
} -cleanup { |
| 1261 |
chan close $f |
| 1262 |
} -result {abcdefghijkl} |
| 1263 |
test chan-io-10.5 {Tcl_ReadChars: stop on EOF} -body { |
| 1264 |
# (chanPtr->flags & CHANNEL_EOF) |
| 1265 |
set f [open $path(test1) w] |
| 1266 |
chan puts -nonewline $f abcdefghijkl |
| 1267 |
chan close $f |
| 1268 |
set f [open $path(test1)] |
| 1269 |
# here |
| 1270 |
chan read $f 1000 |
| 1271 |
} -cleanup { |
| 1272 |
chan close $f |
| 1273 |
} -result {abcdefghijkl} |
| 1274 |
|
| 1275 |
test chan-io-11.1 {ReadBytes: want to read a lot} -body { |
| 1276 |
# ((unsigned) toRead > (unsigned) srcLen) |
| 1277 |
set f [open $path(test1) w] |
| 1278 |
chan puts -nonewline $f abcdefghijkl |
| 1279 |
chan close $f |
| 1280 |
set f [open $path(test1)] |
| 1281 |
chan configure $f -encoding binary |
| 1282 |
# here |
| 1283 |
chan read $f 1000 |
| 1284 |
} -cleanup { |
| 1285 |
chan close $f |
| 1286 |
} -result {abcdefghijkl} |
| 1287 |
test chan-io-11.2 {ReadBytes: want to read all} -body { |
| 1288 |
# ((unsigned) toRead > (unsigned) srcLen) |
| 1289 |
set f [open $path(test1) w] |
| 1290 |
chan puts -nonewline $f abcdefghijkl |
| 1291 |
chan close $f |
| 1292 |
set f [open $path(test1)] |
| 1293 |
chan configure $f -encoding binary |
| 1294 |
# here |
| 1295 |
chan read $f |
| 1296 |
} -cleanup { |
| 1297 |
chan close $f |
| 1298 |
} -result {abcdefghijkl} |
| 1299 |
test chan-io-11.3 {ReadBytes: allocate more space} -body { |
| 1300 |
# (toRead > length - offset - 1) |
| 1301 |
set f [open $path(test1) w] |
| 1302 |
chan puts -nonewline $f abcdefghijklmnopqrstuvwxyz |
| 1303 |
chan close $f |
| 1304 |
set f [open $path(test1)] |
| 1305 |
chan configure $f -buffersize 16 -encoding binary |
| 1306 |
# here |
| 1307 |
chan read $f |
| 1308 |
} -cleanup { |
| 1309 |
chan close $f |
| 1310 |
} -result {abcdefghijklmnopqrstuvwxyz} |
| 1311 |
test chan-io-11.4 {ReadBytes: EOF char found} -body { |
| 1312 |
# (TranslateInputEOL() != 0) |
| 1313 |
set f [open $path(test1) w] |
| 1314 |
chan puts $f abcdefghijklmnopqrstuvwxyz |
| 1315 |
chan close $f |
| 1316 |
set f [open $path(test1)] |
| 1317 |
chan configure $f -eofchar m -encoding binary |
| 1318 |
# here |
| 1319 |
list [chan read $f] [chan eof $f] [chan read $f] [chan eof $f] |
| 1320 |
} -cleanup { |
| 1321 |
chan close $f |
| 1322 |
} -result {abcdefghijkl 1 {} 1} |
| 1323 |
|
| 1324 |
test chan-io-12.1 {ReadChars: want to read a lot} -body { |
| 1325 |
# ((unsigned) toRead > (unsigned) srcLen) |
| 1326 |
set f [open $path(test1) w] |
| 1327 |
chan puts -nonewline $f abcdefghijkl |
| 1328 |
chan close $f |
| 1329 |
set f [open $path(test1)] |
| 1330 |
# here |
| 1331 |
chan read $f 1000 |
| 1332 |
} -cleanup { |
| 1333 |
chan close $f |
| 1334 |
} -result {abcdefghijkl} |
| 1335 |
test chan-io-12.2 {ReadChars: want to read all} -body { |
| 1336 |
# ((unsigned) toRead > (unsigned) srcLen) |
| 1337 |
set f [open $path(test1) w] |
| 1338 |
chan puts -nonewline $f abcdefghijkl |
| 1339 |
chan close $f |
| 1340 |
set f [open $path(test1)] |
| 1341 |
# here |
| 1342 |
chan read $f |
| 1343 |
} -cleanup { |
| 1344 |
chan close $f |
| 1345 |
} -result {abcdefghijkl} |
| 1346 |
test chan-io-12.3 {ReadChars: allocate more space} -body { |
| 1347 |
# (toRead > length - offset - 1) |
| 1348 |
set f [open $path(test1) w] |
| 1349 |
chan puts -nonewline $f abcdefghijklmnopqrstuvwxyz |
| 1350 |
chan close $f |
| 1351 |
set f [open $path(test1)] |
| 1352 |
chan configure $f -buffersize 16 |
| 1353 |
# here |
| 1354 |
chan read $f |
| 1355 |
} -cleanup { |
| 1356 |
chan close $f |
| 1357 |
} -result {abcdefghijklmnopqrstuvwxyz} |
| 1358 |
test chan-io-12.4 {ReadChars: split-up char} -setup { |
| 1359 |
variable x {} |
| 1360 |
} -constraints {stdio testchannel fileevent} -body { |
| 1361 |
# (srcRead == 0) |
| 1362 |
set f [openpipe w+ $path(cat)] |
| 1363 |
chan configure $f -encoding binary -buffering none -buffersize 16 |
| 1364 |
chan puts -nonewline $f "123456789012345\x96" |
| 1365 |
chan configure $f -encoding shiftjis -blocking 0 |
| 1366 |
chan event $f read [namespace code { |
| 1367 |
lappend x [chan read $f] [testchannel inputbuffered $f] |
| 1368 |
}] |
| 1369 |
chan configure $f -encoding shiftjis |
| 1370 |
vwait [namespace which -variable x] |
| 1371 |
chan configure $f -encoding binary -blocking 1 |
| 1372 |
chan puts -nonewline $f \x7B |
| 1373 |
after 500 ;# Give the cat process time to catch up |
| 1374 |
chan configure $f -encoding shiftjis -blocking 0 |
| 1375 |
vwait [namespace which -variable x] |
| 1376 |
return $x |
| 1377 |
} -cleanup { |
| 1378 |
chan close $f |
| 1379 |
} -result [list "123456789012345" 1 \u672C 0] |
| 1380 |
test chan-io-12.5 {ReadChars: chan events on partial characters} -setup { |
| 1381 |
variable x {} |
| 1382 |
} -constraints {stdio fileevent} -body { |
| 1383 |
set path(test1) [makeFile { |
| 1384 |
chan configure stdout -encoding binary -buffering none |
| 1385 |
chan gets stdin; chan puts -nonewline \xE7 |
| 1386 |
chan gets stdin; chan puts -nonewline \x89 |
| 1387 |
chan gets stdin; chan puts -nonewline \xA6 |
| 1388 |
} test1] |
| 1389 |
set f [openpipe r+ $path(test1)] |
| 1390 |
chan event $f readable [namespace code { |
| 1391 |
lappend x [chan read $f] |
| 1392 |
if {[chan eof $f]} { |
| 1393 |
lappend x eof |
| 1394 |
} |
| 1395 |
}] |
| 1396 |
chan puts $f "go1" |
| 1397 |
chan flush $f |
| 1398 |
chan configure $f -blocking 0 -encoding utf-8 |
| 1399 |
vwait [namespace which -variable x] |
| 1400 |
after 500 [namespace code { lappend x timeout }] |
| 1401 |
vwait [namespace which -variable x] |
| 1402 |
chan puts $f "go2" |
| 1403 |
chan flush $f |
| 1404 |
vwait [namespace which -variable x] |
| 1405 |
after 500 [namespace code { lappend x timeout }] |
| 1406 |
vwait [namespace which -variable x] |
| 1407 |
chan puts $f "go3" |
| 1408 |
chan flush $f |
| 1409 |
vwait [namespace which -variable x] |
| 1410 |
vwait [namespace which -variable x] |
| 1411 |
lappend x [catch {chan close $f} msg] $msg |
| 1412 |
} -result "{} timeout {} timeout \u7266 {} eof 0 {}" |
| 1413 |
|
| 1414 |
test chan-io-13.1 {TranslateInputEOL: cr mode} -body { |
| 1415 |
set f [open $path(test1) w] |
| 1416 |
chan configure $f -translation lf |
| 1417 |
chan puts -nonewline $f "abcd\rdef\r" |
| 1418 |
chan close $f |
| 1419 |
set f [open $path(test1)] |
| 1420 |
chan configure $f -translation cr |
| 1421 |
chan read $f |
| 1422 |
} -cleanup { |
| 1423 |
chan close $f |
| 1424 |
} -result "abcd\ndef\n" |
| 1425 |
test chan-io-13.2 {TranslateInputEOL: crlf mode} -body { |
| 1426 |
set f [open $path(test1) w] |
| 1427 |
chan configure $f -translation lf |
| 1428 |
chan puts -nonewline $f "abcd\r\ndef\r\n" |
| 1429 |
chan close $f |
| 1430 |
set f [open $path(test1)] |
| 1431 |
chan configure $f -translation crlf |
| 1432 |
chan read $f |
| 1433 |
} -cleanup { |
| 1434 |
chan close $f |
| 1435 |
} -result "abcd\ndef\n" |
| 1436 |
test chan-io-13.3 {TranslateInputEOL: crlf mode: naked cr} -body { |
| 1437 |
# (src >= srcMax) |
| 1438 |
set f [open $path(test1) w] |
| 1439 |
chan configure $f -translation lf |
| 1440 |
chan puts -nonewline $f "abcd\r\ndef\r" |
| 1441 |
chan close $f |
| 1442 |
set f [open $path(test1)] |
| 1443 |
chan configure $f -translation crlf |
| 1444 |
chan read $f |
| 1445 |
} -cleanup { |
| 1446 |
chan close $f |
| 1447 |
} -result "abcd\ndef\r" |
| 1448 |
test chan-io-13.4 {TranslateInputEOL: crlf mode: cr followed by not \n} -body { |
| 1449 |
# (src >= srcMax) |
| 1450 |
set f [open $path(test1) w] |
| 1451 |
chan configure $f -translation lf |
| 1452 |
chan puts -nonewline $f "abcd\r\ndef\rfgh" |
| 1453 |
chan close $f |
| 1454 |
set f [open $path(test1)] |
| 1455 |
chan configure $f -translation crlf |
| 1456 |
chan read $f |
| 1457 |
} -cleanup { |
| 1458 |
chan close $f |
| 1459 |
} -result "abcd\ndef\rfgh" |
| 1460 |
test chan-io-13.5 {TranslateInputEOL: crlf mode: naked lf} -body { |
| 1461 |
# (src >= srcMax) |
| 1462 |
set f [open $path(test1) w] |
| 1463 |
chan configure $f -translation lf |
| 1464 |
chan puts -nonewline $f "abcd\r\ndef\nfgh" |
| 1465 |
chan close $f |
| 1466 |
set f [open $path(test1)] |
| 1467 |
chan configure $f -translation crlf |
| 1468 |
chan read $f |
| 1469 |
} -cleanup { |
| 1470 |
chan close $f |
| 1471 |
} -result "abcd\ndef\nfgh" |
| 1472 |
test chan-io-13.6 {TranslateInputEOL: auto mode: saw cr in last segment} -setup { |
| 1473 |
variable x {} |
| 1474 |
variable y {} |
| 1475 |
} -constraints {stdio testchannel fileevent} -body { |
| 1476 |
# (chanPtr->flags & INPUT_SAW_CR) |
| 1477 |
# This test may fail on slower machines. |
| 1478 |
set f [openpipe w+ $path(cat)] |
| 1479 |
chan configure $f -blocking 0 -buffering none -translation {auto lf} |
| 1480 |
chan event $f read [namespace code { |
| 1481 |
lappend x [chan read $f] [testchannel queuedcr $f] |
| 1482 |
}] |
| 1483 |
chan puts -nonewline $f "abcdefghj\r" |
| 1484 |
after 500 [namespace code {set y ok}] |
| 1485 |
vwait [namespace which -variable y] |
| 1486 |
chan puts -nonewline $f "\n01234" |
| 1487 |
after 500 [namespace code {set y ok}] |
| 1488 |
vwait [namespace which -variable y] |
| 1489 |
return $x |
| 1490 |
} -cleanup { |
| 1491 |
chan close $f |
| 1492 |
} -result [list "abcdefghj\n" 1 "01234" 0] |
| 1493 |
test chan-io-13.7 {TranslateInputEOL: auto mode: naked \r} -constraints testchannel -body { |
| 1494 |
# (src >= srcMax) |
| 1495 |
set f [open $path(test1) w] |
| 1496 |
chan configure $f -translation lf |
| 1497 |
chan puts -nonewline $f "abcd\r" |
| 1498 |
chan close $f |
| 1499 |
set f [open $path(test1)] |
| 1500 |
chan configure $f -translation auto |
| 1501 |
list [chan read $f] [testchannel queuedcr $f] |
| 1502 |
} -cleanup { |
| 1503 |
chan close $f |
| 1504 |
} -result [list "abcd\n" 1] |
| 1505 |
test chan-io-13.8 {TranslateInputEOL: auto mode: \r\n} -body { |
| 1506 |
# (*src == '\n') |
| 1507 |
set f [open $path(test1) w] |
| 1508 |
chan configure $f -translation lf |
| 1509 |
chan puts -nonewline $f "abcd\r\ndef" |
| 1510 |
chan close $f |
| 1511 |
set f [open $path(test1)] |
| 1512 |
chan configure $f -translation auto |
| 1513 |
chan read $f |
| 1514 |
} -cleanup { |
| 1515 |
chan close $f |
| 1516 |
} -result "abcd\ndef" |
| 1517 |
test chan-io-13.9 {TranslateInputEOL: auto mode: \r followed by not \n} -body { |
| 1518 |
set f [open $path(test1) w] |
| 1519 |
chan configure $f -translation lf |
| 1520 |
chan puts -nonewline $f "abcd\rdef" |
| 1521 |
chan close $f |
| 1522 |
set f [open $path(test1)] |
| 1523 |
chan configure $f -translation auto |
| 1524 |
chan read $f |
| 1525 |
} -cleanup { |
| 1526 |
chan close $f |
| 1527 |
} -result "abcd\ndef" |
| 1528 |
test chan-io-13.10 {TranslateInputEOL: auto mode: \n} -body { |
| 1529 |
# not (*src == '\r') |
| 1530 |
set f [open $path(test1) w] |
| 1531 |
chan configure $f -translation lf |
| 1532 |
chan puts -nonewline $f "abcd\ndef" |
| 1533 |
chan close $f |
| 1534 |
set f [open $path(test1)] |
| 1535 |
chan configure $f -translation auto |
| 1536 |
chan read $f |
| 1537 |
} -cleanup { |
| 1538 |
chan close $f |
| 1539 |
} -result "abcd\ndef" |
| 1540 |
test chan-io-13.11 {TranslateInputEOL: EOF char} -body { |
| 1541 |
# (*chanPtr->inEofChar != '\x00') |
| 1542 |
set f [open $path(test1) w] |
| 1543 |
chan configure $f -translation lf |
| 1544 |
chan puts -nonewline $f "abcd\ndefgh" |
| 1545 |
chan close $f |
| 1546 |
set f [open $path(test1)] |
| 1547 |
chan configure $f -translation auto -eofchar e |
| 1548 |
chan read $f |
| 1549 |
} -cleanup { |
| 1550 |
chan close $f |
| 1551 |
} -result "abcd\nd" |
| 1552 |
test chan-io-13.12 {TranslateInputEOL: find EOF char in src} -body { |
| 1553 |
# (*chanPtr->inEofChar != '\x00') |
| 1554 |
set f [open $path(test1) w] |
| 1555 |
chan configure $f -translation lf |
| 1556 |
chan puts -nonewline $f "\r\n\r\n\r\nab\r\n\r\ndef\r\n\r\n\r\n" |
| 1557 |
chan close $f |
| 1558 |
set f [open $path(test1)] |
| 1559 |
chan configure $f -translation auto -eofchar e |
| 1560 |
chan read $f |
| 1561 |
} -cleanup { |
| 1562 |
chan close $f |
| 1563 |
} -result "\n\n\nab\n\nd" |
| 1564 |
|
| 1565 |
# Test standard handle management. The functions tested are Tcl_SetStdChannel |
| 1566 |
# and Tcl_GetStdChannel. Incidentally we are also testing channel table |
| 1567 |
# management. |
| 1568 |
|
| 1569 |
if {[testConstraint testchannel]} { |
| 1570 |
set consoleFileNames [lsort [testchannel open]] |
| 1571 |
} else { |
| 1572 |
# just to avoid an error |
| 1573 |
set consoleFileNames [list] |
| 1574 |
} |
| 1575 |
|
| 1576 |
test chan-io-14.1 {Tcl_SetStdChannel and Tcl_GetStdChannel} {testchannel} { |
| 1577 |
set result "" |
| 1578 |
lappend result [chan configure stdin -buffering] |
| 1579 |
lappend result [chan configure stdout -buffering] |
| 1580 |
lappend result [chan configure stderr -buffering] |
| 1581 |
lappend result [lsort [testchannel open]] |
| 1582 |
} [list line line none $consoleFileNames] |
| 1583 |
test chan-io-14.2 {Tcl_SetStdChannel and Tcl_GetStdChannel} -setup { |
| 1584 |
interp create x |
| 1585 |
set result "" |
| 1586 |
} -body { |
| 1587 |
lappend result [x eval {chan configure stdin -buffering}] |
| 1588 |
lappend result [x eval {chan configure stdout -buffering}] |
| 1589 |
lappend result [x eval {chan configure stderr -buffering}] |
| 1590 |
} -cleanup { |
| 1591 |
interp delete x |
| 1592 |
} -result {line line none} |
| 1593 |
set path(test3) [makeFile {} test3] |
| 1594 |
test chan-io-14.3 {Tcl_SetStdChannel & Tcl_GetStdChannel} -constraints exec -body { |
| 1595 |
set f [open $path(test1) w] |
| 1596 |
chan puts -nonewline $f { |
| 1597 |
chan close stdin |
| 1598 |
chan close stdout |
| 1599 |
chan close stderr |
| 1600 |
set f [} |
| 1601 |
chan puts $f [list open $path(test1) r]] |
| 1602 |
chan puts $f "set f2 \[[list open $path(test2) w]]" |
| 1603 |
chan puts $f "set f3 \[[list open $path(test3) w]]" |
| 1604 |
chan puts $f { chan puts stdout [chan gets stdin] |
| 1605 |
chan puts stdout out |
| 1606 |
chan puts stderr err |
| 1607 |
chan close $f |
| 1608 |
chan close $f2 |
| 1609 |
chan close $f3 |
| 1610 |
} |
| 1611 |
chan close $f |
| 1612 |
set result [exec [interpreter] $path(test1)] |
| 1613 |
set f [open $path(test2) r] |
| 1614 |
set f2 [open $path(test3) r] |
| 1615 |
lappend result [chan read $f] [chan read $f2] |
| 1616 |
} -cleanup { |
| 1617 |
chan close $f |
| 1618 |
chan close $f2 |
| 1619 |
} -result {{ |
| 1620 |
out |
| 1621 |
} {err |
| 1622 |
}} |
| 1623 |
# This test relies on the fact that stdout is used before stderr. |
| 1624 |
test chan-io-14.4 {Tcl_SetStdChannel & Tcl_GetStdChannel} -constraints {exec} -body { |
| 1625 |
set f [open $path(test1) w] |
| 1626 |
chan puts -nonewline $f { chan close stdin |
| 1627 |
chan close stdout |
| 1628 |
chan close stderr |
| 1629 |
set f [} |
| 1630 |
chan puts $f [list open $path(test1) r]] |
| 1631 |
chan puts $f "set f2 \[[list open $path(test2) w]]" |
| 1632 |
chan puts $f "set f3 \[[list open $path(test3) w]]" |
| 1633 |
chan puts $f { |
| 1634 |
chan puts stdout [chan gets stdin] |
| 1635 |
chan puts stdout $f2 |
| 1636 |
chan puts stderr $f3 |
| 1637 |
chan close $f |
| 1638 |
chan close $f2 |
| 1639 |
chan close $f3 |
| 1640 |
} |
| 1641 |
chan close $f |
| 1642 |
set result [exec [interpreter] $path(test1)] |
| 1643 |
set f [open $path(test2) r] |
| 1644 |
set f2 [open $path(test3) r] |
| 1645 |
lappend result [chan read $f] [chan read $f2] |
| 1646 |
} -cleanup { |
| 1647 |
chan close $f |
| 1648 |
chan close $f2 |
| 1649 |
} -result {{ chan close stdin |
| 1650 |
stdout |
| 1651 |
} {stderr |
| 1652 |
}} |
| 1653 |
catch {interp delete z} |
| 1654 |
test chan-io-14.5 {Tcl_GetChannel: stdio name translation} -setup { |
| 1655 |
interp create z |
| 1656 |
} -body { |
| 1657 |
chan eof stdin |
| 1658 |
catch {z eval chan flush stdin} msg1 |
| 1659 |
catch {z eval chan close stdin} msg2 |
| 1660 |
catch {z eval chan flush stdin} msg3 |
| 1661 |
list $msg1 $msg2 $msg3 |
| 1662 |
} -cleanup { |
| 1663 |
interp delete z |
| 1664 |
} -result {{channel "stdin" wasn't opened for writing} {} {can not find channel named "stdin"}} |
| 1665 |
test chan-io-14.6 {Tcl_GetChannel: stdio name translation} -setup { |
| 1666 |
interp create z |
| 1667 |
} -body { |
| 1668 |
chan eof stdout |
| 1669 |
catch {z eval chan flush stdout} msg1 |
| 1670 |
catch {z eval chan close stdout} msg2 |
| 1671 |
catch {z eval chan flush stdout} msg3 |
| 1672 |
list $msg1 $msg2 $msg3 |
| 1673 |
} -cleanup { |
| 1674 |
interp delete z |
| 1675 |
} -result {{} {} {can not find channel named "stdout"}} |
| 1676 |
test chan-io-14.7 {Tcl_GetChannel: stdio name translation} -setup { |
| 1677 |
interp create z |
| 1678 |
} -body { |
| 1679 |
chan eof stderr |
| 1680 |
catch {z eval chan flush stderr} msg1 |
| 1681 |
catch {z eval chan close stderr} msg2 |
| 1682 |
catch {z eval chan flush stderr} msg3 |
| 1683 |
list $msg1 $msg2 $msg3 |
| 1684 |
} -cleanup { |
| 1685 |
interp delete z |
| 1686 |
} -result {{} {} {can not find channel named "stderr"}} |
| 1687 |
set path(script) [makeFile {} script] |
| 1688 |
test chan-io-14.8 {reuse of stdio special channels} -setup { |
| 1689 |
file delete $path(script) |
| 1690 |
file delete $path(test1) |
| 1691 |
} -constraints stdio -body { |
| 1692 |
set f [open $path(script) w] |
| 1693 |
chan puts -nonewline $f { |
| 1694 |
chan close stderr |
| 1695 |
set f [} |
| 1696 |
chan puts $f [list open $path(test1) w]] |
| 1697 |
chan puts -nonewline $f { |
| 1698 |
chan puts stderr hello |
| 1699 |
chan close $f |
| 1700 |
set f [} |
| 1701 |
chan puts $f [list open $path(test1) r]] |
| 1702 |
chan puts $f { |
| 1703 |
chan puts [chan gets $f] |
| 1704 |
} |
| 1705 |
chan close $f |
| 1706 |
set f [openpipe r $path(script)] |
| 1707 |
chan gets $f |
| 1708 |
} -cleanup { |
| 1709 |
chan close $f |
| 1710 |
} -result hello |
| 1711 |
test chan-io-14.9 {reuse of stdio special channels} -setup { |
| 1712 |
file delete $path(script) |
| 1713 |
file delete $path(test1) |
| 1714 |
} -constraints {stdio fileevent} -body { |
| 1715 |
set f [open $path(script) w] |
| 1716 |
chan puts $f { |
| 1717 |
array set path [lindex $argv 0] |
| 1718 |
set f [open $path(test1) w] |
| 1719 |
chan puts $f hello |
| 1720 |
chan close $f |
| 1721 |
chan close stderr |
| 1722 |
set f [open "|[list [info nameofexecutable] $path(cat) $path(test1)]" r] |
| 1723 |
chan puts [chan gets $f] |
| 1724 |
} |
| 1725 |
chan close $f |
| 1726 |
set f [openpipe r $path(script) [array get path]] |
| 1727 |
chan gets $f |
| 1728 |
} -cleanup { |
| 1729 |
chan close $f |
| 1730 |
# Added delay to give Windows time to stop the spawned process and clean |
| 1731 |
# up its grip on the file test1. Added delete as proper test cleanup. |
| 1732 |
# The failing tests were 18.1 and 18.2 as first re-users of file "test1". |
| 1733 |
after [expr {[testConstraint win] ? 10000 : 500}] |
| 1734 |
file delete $path(script) |
| 1735 |
file delete $path(test1) |
| 1736 |
} -result hello |
| 1737 |
|
| 1738 |
test chan-io-15.1 {Tcl_CreateChan CloseHandler} emptyTest { |
| 1739 |
} {} |
| 1740 |
|
| 1741 |
test chan-io-16.1 {Tcl_DeleteChan CloseHandler} emptyTest { |
| 1742 |
} {} |
| 1743 |
|
| 1744 |
# Test channel table management. The functions tested are GetChannelTable, |
| 1745 |
# DeleteChannelTable, Tcl_RegisterChannel, Tcl_UnregisterChannel, |
| 1746 |
# Tcl_GetChannel and Tcl_CreateChannel. |
| 1747 |
# |
| 1748 |
# These functions use "eof stdin" to ensure that the standard channels are |
| 1749 |
# added to the channel table of the interpreter. |
| 1750 |
|
| 1751 |
test chan-io-17.1 {GetChannelTable, DeleteChannelTable on std handles} -setup { |
| 1752 |
set l "" |
| 1753 |
} -constraints {testchannel} -body { |
| 1754 |
set l1 [testchannel refcount stdin] |
| 1755 |
chan eof stdin |
| 1756 |
interp create x |
| 1757 |
lappend l [expr {[testchannel refcount stdin] - $l1}] |
| 1758 |
x eval {chan eof stdin} |
| 1759 |
lappend l [expr {[testchannel refcount stdin] - $l1}] |
| 1760 |
interp delete x |
| 1761 |
lappend l [expr {[testchannel refcount stdin] - $l1}] |
| 1762 |
} -result {0 1 0} |
| 1763 |
test chan-io-17.2 {GetChannelTable, DeleteChannelTable on std handles} -setup { |
| 1764 |
set l "" |
| 1765 |
} -constraints {testchannel} -body { |
| 1766 |
set l1 [testchannel refcount stdout] |
| 1767 |
chan eof stdin |
| 1768 |
interp create x |
| 1769 |
lappend l [expr {[testchannel refcount stdout] - $l1}] |
| 1770 |
x eval {chan eof stdout} |
| 1771 |
lappend l [expr {[testchannel refcount stdout] - $l1}] |
| 1772 |
interp delete x |
| 1773 |
lappend l [expr {[testchannel refcount stdout] - $l1}] |
| 1774 |
} -result {0 1 0} |
| 1775 |
test chan-io-17.3 {GetChannelTable, DeleteChannelTable on std handles} -setup { |
| 1776 |
set l "" |
| 1777 |
} -constraints {testchannel} -body { |
| 1778 |
set l1 [testchannel refcount stderr] |
| 1779 |
chan eof stdin |
| 1780 |
interp create x |
| 1781 |
lappend l [expr {[testchannel refcount stderr] - $l1}] |
| 1782 |
x eval {chan eof stderr} |
| 1783 |
lappend l [expr {[testchannel refcount stderr] - $l1}] |
| 1784 |
interp delete x |
| 1785 |
lappend l [expr {[testchannel refcount stderr] - $l1}] |
| 1786 |
} -result {0 1 0} |
| 1787 |
|
| 1788 |
test chan-io-18.1 {Tcl_RegisterChannel, Tcl_UnregisterChannel} -setup { |
| 1789 |
file delete -force $path(test1) |
| 1790 |
set l "" |
| 1791 |
} -constraints {testchannel} -body { |
| 1792 |
set f [open $path(test1) w] |
| 1793 |
lappend l [lindex [testchannel info $f] 15] |
| 1794 |
chan close $f |
| 1795 |
if {[catch {lindex [testchannel info $f] 15} msg]} { |
| 1796 |
lappend l $msg |
| 1797 |
} else { |
| 1798 |
lappend l "very broken: $f found after being chan closed" |
| 1799 |
} |
| 1800 |
string equal $l [list 1 "can not find channel named \"$f\""] |
| 1801 |
} -result 1 |
| 1802 |
test chan-io-18.2 {Tcl_RegisterChannel, Tcl_UnregisterChannel} -setup { |
| 1803 |
file delete -force $path(test1) |
| 1804 |
set l "" |
| 1805 |
} -constraints {testchannel} -body { |
| 1806 |
set f [open $path(test1) w] |
| 1807 |
lappend l [lindex [testchannel info $f] 15] |
| 1808 |
interp create x |
| 1809 |
interp share "" $f x |
| 1810 |
lappend l [lindex [testchannel info $f] 15] |
| 1811 |
x eval chan close $f |
| 1812 |
lappend l [lindex [testchannel info $f] 15] |
| 1813 |
interp delete x |
| 1814 |
lappend l [lindex [testchannel info $f] 15] |
| 1815 |
chan close $f |
| 1816 |
if {[catch {lindex [testchannel info $f] 15} msg]} { |
| 1817 |
lappend l $msg |
| 1818 |
} else { |
| 1819 |
lappend l "very broken: $f found after being chan closed" |
| 1820 |
} |
| 1821 |
string equal $l [list 1 2 1 1 "can not find channel named \"$f\""] |
| 1822 |
} -result 1 |
| 1823 |
test chan-io-18.3 {Tcl_RegisterChannel, Tcl_UnregisterChannel} -setup { |
| 1824 |
file delete $path(test1) |
| 1825 |
set l "" |
| 1826 |
} -constraints {testchannel} -body { |
| 1827 |
set f [open $path(test1) w] |
| 1828 |
lappend l [lindex [testchannel info $f] 15] |
| 1829 |
interp create x |
| 1830 |
interp share "" $f x |
| 1831 |
lappend l [lindex [testchannel info $f] 15] |
| 1832 |
interp delete x |
| 1833 |
lappend l [lindex [testchannel info $f] 15] |
| 1834 |
chan close $f |
| 1835 |
if {[catch {lindex [testchannel info $f] 15} msg]} { |
| 1836 |
lappend l $msg |
| 1837 |
} else { |
| 1838 |
lappend l "very broken: $f found after being chan closed" |
| 1839 |
} |
| 1840 |
string equal $l [list 1 2 1 "can not find channel named \"$f\""] |
| 1841 |
} -result 1 |
| 1842 |
|
| 1843 |
test chan-io-19.1 {Tcl_GetChannel->Tcl_GetStdChannel, standard handles} { |
| 1844 |
chan eof stdin |
| 1845 |
} 0 |
| 1846 |
test chan-io-19.2 {testing Tcl_GetChannel, user opened handle} -setup { |
| 1847 |
file delete $path(test1) |
| 1848 |
} -body { |
| 1849 |
set f [open $path(test1) w] |
| 1850 |
chan eof $f |
| 1851 |
} -cleanup { |
| 1852 |
chan close $f |
| 1853 |
} -result 0 |
| 1854 |
test chan-io-19.3 {Tcl_GetChannel, channel not found} -body { |
| 1855 |
chan eof file34 |
| 1856 |
} -returnCodes error -result {can not find channel named "file34"} |
| 1857 |
test chan-io-19.4 {Tcl_CreateChannel, insertion into channel table} -setup { |
| 1858 |
file delete $path(test1) |
| 1859 |
set l "" |
| 1860 |
} -constraints {testchannel} -body { |
| 1861 |
set f [open $path(test1) w] |
| 1862 |
lappend l [chan eof $f] |
| 1863 |
chan close $f |
| 1864 |
if {[catch {lindex [testchannel info $f] 15} msg]} { |
| 1865 |
lappend l $msg |
| 1866 |
} else { |
| 1867 |
lappend l "very broken: $f found after being chan closed" |
| 1868 |
} |
| 1869 |
string equal $l [list 0 "can not find channel named \"$f\""] |
| 1870 |
} -result 1 |
| 1871 |
|
| 1872 |
test chan-io-20.1 {Tcl_CreateChannel: initial settings} -setup { |
| 1873 |
set old [encoding system] |
| 1874 |
} -body { |
| 1875 |
set a [open $path(test2) w] |
| 1876 |
encoding system ascii |
| 1877 |
set f [open $path(test1) w] |
| 1878 |
chan configure $f -encoding |
| 1879 |
} -cleanup { |
| 1880 |
encoding system $old |
| 1881 |
chan close $f |
| 1882 |
chan close $a |
| 1883 |
} -result {ascii} |
| 1884 |
test chan-io-20.2 {Tcl_CreateChannel: initial settings} -constraints {win} -body { |
| 1885 |
set f [open $path(test1) w+] |
| 1886 |
list [chan configure $f -eofchar] [chan configure $f -translation] |
| 1887 |
} -cleanup { |
| 1888 |
chan close $f |
| 1889 |
} -result [list [list \x1A ""] {auto crlf}] |
| 1890 |
test chan-io-20.3 {Tcl_CreateChannel: initial settings} -constraints {unix} -body { |
| 1891 |
set f [open $path(test1) w+] |
| 1892 |
list [chan configure $f -eofchar] [chan configure $f -translation] |
| 1893 |
} -cleanup { |
| 1894 |
chan close $f |
| 1895 |
} -result {{{} {}} {auto lf}} |
| 1896 |
test chan-io-20.5 {Tcl_CreateChannel: install channel in empty slot} -setup { |
| 1897 |
set path(stdout) [makeFile {} stdout] |
| 1898 |
} -constraints {stdio notWinCI} -body { |
| 1899 |
set f [open $path(script) w] |
| 1900 |
chan puts -nonewline $f { |
| 1901 |
chan close stdout |
| 1902 |
set f1 [} |
| 1903 |
chan puts $f [list open $path(stdout) w]] |
| 1904 |
chan puts $f { |
| 1905 |
chan configure $f1 -buffersize 777 |
| 1906 |
chan puts stderr [chan configure stdout -buffersize] |
| 1907 |
} |
| 1908 |
chan close $f |
| 1909 |
set f [openpipe r $path(script)] |
| 1910 |
chan close $f |
| 1911 |
} -cleanup { |
| 1912 |
removeFile $path(stdout) |
| 1913 |
} -returnCodes error -result {777} |
| 1914 |
|
| 1915 |
test chan-io-21.1 {Chan CloseChannelsOnExit} emptyTest { |
| 1916 |
} {} |
| 1917 |
|
| 1918 |
# Test management of attributes associated with a channel, such as its default |
| 1919 |
# translation, its name and type, etc. The functions tested in this group are |
| 1920 |
# Tcl_GetChannelName, Tcl_GetChannelType and Tcl_GetChannelFile. |
| 1921 |
# Tcl_GetChannelInstanceData not tested because files do not use the instance |
| 1922 |
# data. |
| 1923 |
|
| 1924 |
test chan-io-22.1 {Tcl_GetChannelMode} emptyTest { |
| 1925 |
# Not used anywhere in Tcl. |
| 1926 |
} {} |
| 1927 |
|
| 1928 |
test chan-io-23.1 {Tcl_GetChannelName} -constraints {testchannel} -setup { |
| 1929 |
file delete $path(test1) |
| 1930 |
} -body { |
| 1931 |
set f [open $path(test1) w] |
| 1932 |
set n [testchannel name $f] |
| 1933 |
expr {$n eq $f ? "ok" : "$n != $f"} |
| 1934 |
} -cleanup { |
| 1935 |
chan close $f |
| 1936 |
} -result ok |
| 1937 |
|
| 1938 |
test chan-io-24.1 {Tcl_GetChannelType} -constraints {testchannel} -setup { |
| 1939 |
file delete $path(test1) |
| 1940 |
} -body { |
| 1941 |
set f [open $path(test1) w] |
| 1942 |
testchannel type $f |
| 1943 |
} -cleanup { |
| 1944 |
chan close $f |
| 1945 |
} -result "file" |
| 1946 |
|
| 1947 |
test chan-io-25.1 {Tcl_GetChannelHandle, input} -setup { |
| 1948 |
set l "" |
| 1949 |
} -constraints {testchannel} -body { |
| 1950 |
set f [open $path(test1) w] |
| 1951 |
chan configure $f -translation lf -eofchar {} |
| 1952 |
chan puts $f "1234567890\n098765432" |
| 1953 |
chan close $f |
| 1954 |
set f [open $path(test1) r] |
| 1955 |
chan gets $f |
| 1956 |
lappend l [testchannel inputbuffered $f] |
| 1957 |
lappend l [chan tell $f] |
| 1958 |
} -cleanup { |
| 1959 |
chan close $f |
| 1960 |
} -result {10 11} |
| 1961 |
test chan-io-25.2 {Tcl_GetChannelHandle, output} -setup { |
| 1962 |
file delete $path(test1) |
| 1963 |
set l "" |
| 1964 |
} -constraints {testchannel} -body { |
| 1965 |
set f [open $path(test1) w] |
| 1966 |
chan configure $f -translation lf |
| 1967 |
chan puts $f hello |
| 1968 |
lappend l [testchannel outputbuffered $f] |
| 1969 |
lappend l [chan tell $f] |
| 1970 |
chan flush $f |
| 1971 |
lappend l [testchannel outputbuffered $f] |
| 1972 |
lappend l [chan tell $f] |
| 1973 |
} -cleanup { |
| 1974 |
chan close $f |
| 1975 |
file delete $path(test1) |
| 1976 |
} -result {6 6 0 6} |
| 1977 |
|
| 1978 |
test chan-io-26.1 {Tcl_GetChannelInstanceData} -body { |
| 1979 |
# "pid" command uses Tcl_GetChannelInstanceData |
| 1980 |
# Don't care what pid is (but must be a number), just want to exercise it. |
| 1981 |
set f [openpipe r << exit] |
| 1982 |
pid $f |
| 1983 |
} -constraints stdio -cleanup { |
| 1984 |
chan close $f |
| 1985 |
} -match regexp -result {^\d+$} |
| 1986 |
|
| 1987 |
# Test flushing. The functions tested here are FlushChannel. |
| 1988 |
|
| 1989 |
test chan-io-27.1 {FlushChannel, no output buffered} -setup { |
| 1990 |
file delete $path(test1) |
| 1991 |
} -body { |
| 1992 |
set f [open $path(test1) w] |
| 1993 |
chan flush $f |
| 1994 |
file size $path(test1) |
| 1995 |
} -cleanup { |
| 1996 |
chan close $f |
| 1997 |
} -result 0 |
| 1998 |
test chan-io-27.2 {FlushChannel, some output buffered} -setup { |
| 1999 |
file delete $path(test1) |
| 2000 |
set l "" |
| 2001 |
} -body { |
| 2002 |
set f [open $path(test1) w] |
| 2003 |
chan configure $f -translation lf -eofchar {} |
| 2004 |
chan puts $f hello |
| 2005 |
lappend l [file size $path(test1)] |
| 2006 |
chan flush $f |
| 2007 |
lappend l [file size $path(test1)] |
| 2008 |
chan close $f |
| 2009 |
lappend l [file size $path(test1)] |
| 2010 |
} -result {0 6 6} |
| 2011 |
test chan-io-27.3 {FlushChannel, implicit flush on chan close} -setup { |
| 2012 |
file delete $path(test1) |
| 2013 |
set l "" |
| 2014 |
} -body { |
| 2015 |
set f [open $path(test1) w] |
| 2016 |
chan configure $f -translation lf -eofchar {} |
| 2017 |
chan puts $f hello |
| 2018 |
lappend l [file size $path(test1)] |
| 2019 |
chan close $f |
| 2020 |
lappend l [file size $path(test1)] |
| 2021 |
} -result {0 6} |
| 2022 |
test chan-io-27.4 {FlushChannel, implicit flush when buffer fills} -setup { |
| 2023 |
file delete $path(test1) |
| 2024 |
set l "" |
| 2025 |
} -body { |
| 2026 |
set f [open $path(test1) w] |
| 2027 |
chan configure $f -translation lf -eofchar {} |
| 2028 |
chan configure $f -buffersize 60 |
| 2029 |
lappend l [file size $path(test1)] |
| 2030 |
for {set i 0} {$i < 12} {incr i} { |
| 2031 |
chan puts $f hello |
| 2032 |
} |
| 2033 |
lappend l [file size $path(test1)] |
| 2034 |
chan flush $f |
| 2035 |
lappend l [file size $path(test1)] |
| 2036 |
} -cleanup { |
| 2037 |
chan close $f |
| 2038 |
} -result {0 60 72} |
| 2039 |
test chan-io-27.5 {FlushChannel, implicit flush when buffer fills and on chan close} -setup { |
| 2040 |
file delete $path(test1) |
| 2041 |
set l "" |
| 2042 |
} -constraints {unixOrWin} -body { |
| 2043 |
set f [open $path(test1) w] |
| 2044 |
chan configure $f -translation lf -buffersize 60 -eofchar {} |
| 2045 |
lappend l [file size $path(test1)] |
| 2046 |
for {set i 0} {$i < 12} {incr i} { |
| 2047 |
chan puts $f hello |
| 2048 |
} |
| 2049 |
lappend l [file size $path(test1)] |
| 2050 |
chan close $f |
| 2051 |
lappend l [file size $path(test1)] |
| 2052 |
} -result {0 60 72} |
| 2053 |
set path(pipe) [makeFile {} pipe] |
| 2054 |
set path(output) [makeFile {} output] |
| 2055 |
test chan-io-27.6 {FlushChannel, async flushing, async chan close} -setup { |
| 2056 |
file delete $path(pipe) |
| 2057 |
file delete $path(output) |
| 2058 |
} -constraints {stdio asyncPipeChan Close} -body { |
| 2059 |
set f [open $path(pipe) w] |
| 2060 |
chan puts $f "set f \[[list open $path(output) w]]" |
| 2061 |
chan puts $f { |
| 2062 |
chan configure $f -translation lf -buffering none -eofchar {} |
| 2063 |
while {![chan eof stdin]} { |
| 2064 |
after 20 |
| 2065 |
chan puts -nonewline $f [chan read stdin 1024] |
| 2066 |
} |
| 2067 |
chan close $f |
| 2068 |
} |
| 2069 |
chan close $f |
| 2070 |
set x 01234567890123456789012345678901 |
| 2071 |
for {set i 0} {$i < 11} {incr i} { |
| 2072 |
set x "$x$x" |
| 2073 |
} |
| 2074 |
set f [open $path(output) w] |
| 2075 |
chan close $f |
| 2076 |
set f [openpipe w $path(pipe)] |
| 2077 |
chan configure $f -blocking off |
| 2078 |
chan puts -nonewline $f $x |
| 2079 |
chan close $f |
| 2080 |
set counter 0 |
| 2081 |
while {([file size $path(output)] < 65536) && ($counter < 1000)} { |
| 2082 |
after 20 [list incr [namespace which -variable counter]] |
| 2083 |
vwait [namespace which -variable counter] |
| 2084 |
} |
| 2085 |
if {$counter == 1000} { |
| 2086 |
set result "file size only [file size $path(output)]" |
| 2087 |
} else { |
| 2088 |
set result ok |
| 2089 |
} |
| 2090 |
} -result ok |
| 2091 |
|
| 2092 |
# Tests closing a channel. The functions tested are Chan CloseChannel and |
| 2093 |
# Tcl_Chan Close. |
| 2094 |
|
| 2095 |
test chan-io-28.1 {Chan CloseChannel called when all references are dropped} -setup { |
| 2096 |
file delete $path(test1) |
| 2097 |
set l "" |
| 2098 |
} -constraints {testchannel} -body { |
| 2099 |
set f [open $path(test1) w] |
| 2100 |
interp create x |
| 2101 |
interp share "" $f x |
| 2102 |
lappend l [testchannel refcount $f] |
| 2103 |
x eval chan close $f |
| 2104 |
interp delete x |
| 2105 |
lappend l [testchannel refcount $f] |
| 2106 |
} -cleanup { |
| 2107 |
chan close $f |
| 2108 |
} -result {2 1} |
| 2109 |
test chan-io-28.2 {Chan CloseChannel called when all references are dropped} -setup { |
| 2110 |
file delete $path(test1) |
| 2111 |
} -body { |
| 2112 |
set f [open $path(test1) w] |
| 2113 |
interp create x |
| 2114 |
interp share "" $f x |
| 2115 |
chan puts -nonewline $f abc |
| 2116 |
chan close $f |
| 2117 |
x eval chan puts $f def |
| 2118 |
x eval chan close $f |
| 2119 |
interp delete x |
| 2120 |
set f [open $path(test1) r] |
| 2121 |
chan gets $f |
| 2122 |
} -cleanup { |
| 2123 |
chan close $f |
| 2124 |
} -result abcdef |
| 2125 |
test chan-io-28.3 {Chan CloseChannel, not called before output queue is empty} -setup { |
| 2126 |
file delete $path(pipe) |
| 2127 |
file delete $path(output) |
| 2128 |
} -constraints {stdio asyncPipeChan Close nonPortable} -body { |
| 2129 |
set f [open $path(pipe) w] |
| 2130 |
chan puts $f { |
| 2131 |
# Need to not have eof char appended on chan close, because the other |
| 2132 |
# side of the pipe already chan closed, so that writing would cause an |
| 2133 |
# error "invalid file". |
| 2134 |
chan configure stdout -eofchar {} |
| 2135 |
chan configure stderr -eofchar {} |
| 2136 |
set f [open $path(output) w] |
| 2137 |
chan configure $f -translation lf -buffering none |
| 2138 |
for {set x 0} {$x < 20} {incr x} { |
| 2139 |
after 20 |
| 2140 |
chan puts -nonewline $f [chan read stdin 1024] |
| 2141 |
} |
| 2142 |
chan close $f |
| 2143 |
} |
| 2144 |
chan close $f |
| 2145 |
set x 01234567890123456789012345678901 |
| 2146 |
for {set i 0} {$i < 11} {incr i} { |
| 2147 |
set x "$x$x" |
| 2148 |
} |
| 2149 |
set f [open $path(output) w] |
| 2150 |
chan close $f |
| 2151 |
set f [openpipe r+ $path(pipe)] |
| 2152 |
chan configure $f -blocking off -eofchar {} |
| 2153 |
chan puts -nonewline $f $x |
| 2154 |
chan close $f |
| 2155 |
set counter 0 |
| 2156 |
while {([file size $path(output)] < 20480) && ($counter < 1000)} { |
| 2157 |
after 20 [list incr [namespace which -variable counter]] |
| 2158 |
vwait [namespace which -variable counter] |
| 2159 |
} |
| 2160 |
if {$counter == 1000} { |
| 2161 |
set result probably_broken |
| 2162 |
} else { |
| 2163 |
set result ok |
| 2164 |
} |
| 2165 |
} -result ok |
| 2166 |
test chan-io-28.4 {Tcl_Chan Close} -constraints {testchannel} -setup { |
| 2167 |
file delete $path(test1) |
| 2168 |
set l "" |
| 2169 |
} -body { |
| 2170 |
lappend l [lsort [testchannel open]] |
| 2171 |
set f [open $path(test1) w] |
| 2172 |
lappend l [lsort [testchannel open]] |
| 2173 |
chan close $f |
| 2174 |
lappend l [lsort [testchannel open]] |
| 2175 |
set x [list $consoleFileNames \ |
| 2176 |
[lsort [list {*}$consoleFileNames $f]] \ |
| 2177 |
$consoleFileNames] |
| 2178 |
expr {$l eq $x ? "ok" : "{$l} != {$x}"} |
| 2179 |
} -result ok |
| 2180 |
test chan-io-28.5 {Tcl_Chan Close vs standard handles} -setup { |
| 2181 |
file delete $path(script) |
| 2182 |
} -constraints {stdio unix testchannel} -body { |
| 2183 |
set f [open $path(script) w] |
| 2184 |
chan puts $f { |
| 2185 |
chan close stdin |
| 2186 |
chan puts [testchannel open] |
| 2187 |
} |
| 2188 |
chan close $f |
| 2189 |
set f [openpipe r $path(script)] |
| 2190 |
set l [chan gets $f] |
| 2191 |
chan close $f |
| 2192 |
lsort $l |
| 2193 |
} -result {file1 file2} |
| 2194 |
test chan-io-28.6 {Tcl_CloseEx (half-close) pipe} -setup { |
| 2195 |
set cat [makeFile { |
| 2196 |
fconfigure stdout -buffering line |
| 2197 |
while {[gets stdin line] >= 0} {puts $line} |
| 2198 |
puts DONE |
| 2199 |
exit 0 |
| 2200 |
} cat.tcl] |
| 2201 |
variable done |
| 2202 |
} -body { |
| 2203 |
set ff [openpipe r+ $cat] |
| 2204 |
puts $ff Hey |
| 2205 |
close $ff w |
| 2206 |
set timer [after 1000 [namespace code {set done Failed}]] |
| 2207 |
set acc {} |
| 2208 |
fileevent $ff readable [namespace code { |
| 2209 |
if {[gets $ff line] < 0} { |
| 2210 |
set done Succeeded |
| 2211 |
} else { |
| 2212 |
lappend acc $line |
| 2213 |
} |
| 2214 |
}] |
| 2215 |
vwait [namespace which -variable done] |
| 2216 |
after cancel $timer |
| 2217 |
close $ff r |
| 2218 |
list $done $acc |
| 2219 |
} -cleanup { |
| 2220 |
removeFile cat.tcl |
| 2221 |
} -result {Succeeded {Hey DONE}} |
| 2222 |
test chan-io-28.7 {Tcl_CloseEx (half-close) socket} -setup { |
| 2223 |
set echo [makeFile { |
| 2224 |
proc accept {s args} {set ::sok $s} |
| 2225 |
set s [socket -server accept 0] |
| 2226 |
puts [lindex [fconfigure $s -sockname] 2] |
| 2227 |
flush stdout |
| 2228 |
vwait ::sok |
| 2229 |
fconfigure $sok -buffering line |
| 2230 |
while {[gets $sok line]>=0} {puts $sok $line} |
| 2231 |
puts $sok DONE |
| 2232 |
exit 0 |
| 2233 |
} echo.tcl] |
| 2234 |
variable done |
| 2235 |
unset -nocomplain done |
| 2236 |
set done "" |
| 2237 |
set timer "" |
| 2238 |
set ff [openpipe r $echo] |
| 2239 |
gets $ff port |
| 2240 |
} -body { |
| 2241 |
set s [socket 127.0.0.1 $port] |
| 2242 |
puts $s Hey |
| 2243 |
close $s w |
| 2244 |
set timer [after 1000 [namespace code {set done Failed}]] |
| 2245 |
set acc {} |
| 2246 |
fileevent $s readable [namespace code { |
| 2247 |
if {[gets $s line]<0} { |
| 2248 |
set done Succeeded |
| 2249 |
} else { |
| 2250 |
lappend acc $line |
| 2251 |
} |
| 2252 |
}] |
| 2253 |
vwait [namespace which -variable done] |
| 2254 |
list $done $acc |
| 2255 |
} -cleanup { |
| 2256 |
catch {close $s} |
| 2257 |
close $ff |
| 2258 |
after cancel $timer |
| 2259 |
removeFile echo.tcl |
| 2260 |
} -result {Succeeded {Hey DONE}} |
| 2261 |
|
| 2262 |
test chan-io-29.1 {Tcl_WriteChars, channel not writable} -body { |
| 2263 |
chan puts stdin hello |
| 2264 |
} -returnCodes error -result {channel "stdin" wasn't opened for writing} |
| 2265 |
test chan-io-29.2 {Tcl_WriteChars, empty string} -setup { |
| 2266 |
file delete $path(test1) |
| 2267 |
} -body { |
| 2268 |
set f [open $path(test1) w] |
| 2269 |
chan configure $f -eofchar {} |
| 2270 |
chan puts -nonewline $f "" |
| 2271 |
chan close $f |
| 2272 |
file size $path(test1) |
| 2273 |
} -result 0 |
| 2274 |
test chan-io-29.3 {Tcl_WriteChars, nonempty string} -setup { |
| 2275 |
file delete $path(test1) |
| 2276 |
} -body { |
| 2277 |
set f [open $path(test1) w] |
| 2278 |
chan configure $f -eofchar {} |
| 2279 |
chan puts -nonewline $f hello |
| 2280 |
chan close $f |
| 2281 |
file size $path(test1) |
| 2282 |
} -result 5 |
| 2283 |
test chan-io-29.4 {Tcl_WriteChars, buffering in full buffering mode} -setup { |
| 2284 |
file delete $path(test1) |
| 2285 |
set l "" |
| 2286 |
} -constraints {testchannel} -body { |
| 2287 |
set f [open $path(test1) w] |
| 2288 |
chan configure $f -translation lf -buffering full -eofchar {} |
| 2289 |
chan puts $f hello |
| 2290 |
lappend l [testchannel outputbuffered $f] |
| 2291 |
lappend l [file size $path(test1)] |
| 2292 |
chan flush $f |
| 2293 |
lappend l [testchannel outputbuffered $f] |
| 2294 |
lappend l [file size $path(test1)] |
| 2295 |
} -cleanup { |
| 2296 |
chan close $f |
| 2297 |
} -result {6 0 0 6} |
| 2298 |
test chan-io-29.5 {Tcl_WriteChars, buffering in line buffering mode} -setup { |
| 2299 |
file delete $path(test1) |
| 2300 |
set l "" |
| 2301 |
} -constraints {testchannel} -body { |
| 2302 |
set f [open $path(test1) w] |
| 2303 |
chan configure $f -translation lf -buffering line -eofchar {} |
| 2304 |
chan puts -nonewline $f hello |
| 2305 |
lappend l [testchannel outputbuffered $f] |
| 2306 |
lappend l [file size $path(test1)] |
| 2307 |
chan puts $f hello |
| 2308 |
lappend l [testchannel outputbuffered $f] |
| 2309 |
lappend l [file size $path(test1)] |
| 2310 |
} -cleanup { |
| 2311 |
chan close $f |
| 2312 |
} -result {5 0 0 11} |
| 2313 |
test chan-io-29.6 {Tcl_WriteChars, buffering in no buffering mode} -setup { |
| 2314 |
file delete $path(test1) |
| 2315 |
set l "" |
| 2316 |
} -constraints {testchannel} -body { |
| 2317 |
set f [open $path(test1) w] |
| 2318 |
chan configure $f -translation lf -buffering none -eofchar {} |
| 2319 |
chan puts -nonewline $f hello |
| 2320 |
lappend l [testchannel outputbuffered $f] |
| 2321 |
lappend l [file size $path(test1)] |
| 2322 |
chan puts $f hello |
| 2323 |
lappend l [testchannel outputbuffered $f] |
| 2324 |
lappend l [file size $path(test1)] |
| 2325 |
} -cleanup { |
| 2326 |
chan close $f |
| 2327 |
} -result {0 5 0 11} |
| 2328 |
test chan-io-29.7 {Tcl_Flush, full buffering} -setup { |
| 2329 |
file delete $path(test1) |
| 2330 |
set l "" |
| 2331 |
} -constraints {testchannel} -body { |
| 2332 |
set f [open $path(test1) w] |
| 2333 |
chan configure $f -translation lf -buffering full -eofchar {} |
| 2334 |
chan puts -nonewline $f hello |
| 2335 |
lappend l [testchannel outputbuffered $f] |
| 2336 |
lappend l [file size $path(test1)] |
| 2337 |
chan puts $f hello |
| 2338 |
lappend l [testchannel outputbuffered $f] |
| 2339 |
lappend l [file size $path(test1)] |
| 2340 |
chan flush $f |
| 2341 |
lappend l [testchannel outputbuffered $f] |
| 2342 |
lappend l [file size $path(test1)] |
| 2343 |
} -cleanup { |
| 2344 |
chan close $f |
| 2345 |
} -result {5 0 11 0 0 11} |
| 2346 |
test chan-io-29.8 {Tcl_Flush, full buffering} -setup { |
| 2347 |
file delete $path(test1) |
| 2348 |
set l "" |
| 2349 |
} -constraints {testchannel} -body { |
| 2350 |
set f [open $path(test1) w] |
| 2351 |
chan configure $f -translation lf -buffering line |
| 2352 |
chan puts -nonewline $f hello |
| 2353 |
lappend l [testchannel outputbuffered $f] |
| 2354 |
lappend l [file size $path(test1)] |
| 2355 |
chan flush $f |
| 2356 |
lappend l [testchannel outputbuffered $f] |
| 2357 |
lappend l [file size $path(test1)] |
| 2358 |
chan puts $f hello |
| 2359 |
lappend l [testchannel outputbuffered $f] |
| 2360 |
lappend l [file size $path(test1)] |
| 2361 |
chan flush $f |
| 2362 |
lappend l [testchannel outputbuffered $f] |
| 2363 |
lappend l [file size $path(test1)] |
| 2364 |
} -cleanup { |
| 2365 |
chan close $f |
| 2366 |
} -result {5 0 0 5 0 11 0 11} |
| 2367 |
test chan-io-29.9 {Tcl_Flush, channel not writable} -body { |
| 2368 |
chan flush stdin |
| 2369 |
} -returnCodes error -result {channel "stdin" wasn't opened for writing} |
| 2370 |
test chan-io-29.10 {Tcl_WriteChars, looping and buffering} -setup { |
| 2371 |
file delete $path(test1) |
| 2372 |
} -body { |
| 2373 |
set f1 [open $path(test1) w] |
| 2374 |
chan configure $f1 -translation lf -eofchar {} |
| 2375 |
set f2 [open $path(longfile) r] |
| 2376 |
for {set x 0} {$x < 10} {incr x} { |
| 2377 |
chan puts $f1 [chan gets $f2] |
| 2378 |
} |
| 2379 |
chan close $f2 |
| 2380 |
chan close $f1 |
| 2381 |
file size $path(test1) |
| 2382 |
} -result 387 |
| 2383 |
test chan-io-29.11 {Tcl_WriteChars, no newline, implicit flush} -setup { |
| 2384 |
file delete $path(test1) |
| 2385 |
} -body { |
| 2386 |
set f1 [open $path(test1) w] |
| 2387 |
chan configure $f1 -eofchar {} |
| 2388 |
set f2 [open $path(longfile) r] |
| 2389 |
for {set x 0} {$x < 10} {incr x} { |
| 2390 |
chan puts -nonewline $f1 [chan gets $f2] |
| 2391 |
} |
| 2392 |
chan close $f1 |
| 2393 |
chan close $f2 |
| 2394 |
file size $path(test1) |
| 2395 |
} -result 377 |
| 2396 |
test chan-io-29.12 {Tcl_WriteChars on a pipe} -setup { |
| 2397 |
file delete $path(test1) |
| 2398 |
file delete $path(pipe) |
| 2399 |
} -constraints stdio -body { |
| 2400 |
set f1 [open $path(pipe) w] |
| 2401 |
chan puts $f1 "set f1 \[[list open $path(longfile) r]]" |
| 2402 |
chan puts $f1 { |
| 2403 |
for {set x 0} {$x < 10} {incr x} { |
| 2404 |
chan puts [chan gets $f1] |
| 2405 |
} |
| 2406 |
} |
| 2407 |
chan close $f1 |
| 2408 |
set f1 [openpipe r $path(pipe)] |
| 2409 |
set f2 [open $path(longfile) r] |
| 2410 |
set y ok |
| 2411 |
for {set x 0} {$x < 10} {incr x} { |
| 2412 |
set l1 [chan gets $f1] |
| 2413 |
set l2 [chan gets $f2] |
| 2414 |
if {$l1 ne $l2} { |
| 2415 |
set y broken:$x |
| 2416 |
} |
| 2417 |
} |
| 2418 |
return $y |
| 2419 |
} -cleanup { |
| 2420 |
chan close $f1 |
| 2421 |
chan close $f2 |
| 2422 |
} -result ok |
| 2423 |
test chan-io-29.13 {Tcl_WriteChars to a pipe, line buffered} -setup { |
| 2424 |
file delete $path(test1) |
| 2425 |
file delete $path(pipe) |
| 2426 |
} -constraints stdio -body { |
| 2427 |
set f1 [open $path(pipe) w] |
| 2428 |
chan puts $f1 { |
| 2429 |
chan puts [chan gets stdin] |
| 2430 |
chan puts [chan gets stdin] |
| 2431 |
} |
| 2432 |
chan close $f1 |
| 2433 |
set y ok |
| 2434 |
set f1 [openpipe r+ $path(pipe)] |
| 2435 |
chan configure $f1 -buffering line |
| 2436 |
set f2 [open $path(longfile) r] |
| 2437 |
set line [chan gets $f2] |
| 2438 |
chan puts $f1 $line |
| 2439 |
set backline [chan gets $f1] |
| 2440 |
if {$line ne $backline} { |
| 2441 |
set y broken1 |
| 2442 |
} |
| 2443 |
set line [chan gets $f2] |
| 2444 |
chan puts $f1 $line |
| 2445 |
set backline [chan gets $f1] |
| 2446 |
if {$line ne $backline} { |
| 2447 |
set y broken2 |
| 2448 |
} |
| 2449 |
return $y |
| 2450 |
} -cleanup { |
| 2451 |
chan close $f1 |
| 2452 |
chan close $f2 |
| 2453 |
} -result ok |
| 2454 |
test chan-io-29.14 {Tcl_WriteChars, buffering and implicit flush at chan close} -setup { |
| 2455 |
file delete $path(test3) |
| 2456 |
} -body { |
| 2457 |
set f [open $path(test3) w] |
| 2458 |
chan puts -nonewline $f "Text1" |
| 2459 |
chan puts -nonewline $f " Text 2" |
| 2460 |
chan puts $f " Text 3" |
| 2461 |
chan close $f |
| 2462 |
set f [open $path(test3) r] |
| 2463 |
chan gets $f |
| 2464 |
} -cleanup { |
| 2465 |
chan close $f |
| 2466 |
} -result {Text1 Text 2 Text 3} |
| 2467 |
test chan-io-29.15 {Tcl_Flush, channel not open for writing} -setup { |
| 2468 |
file delete $path(test1) |
| 2469 |
set fd [open $path(test1) w] |
| 2470 |
chan close $fd |
| 2471 |
} -body { |
| 2472 |
set fd [open $path(test1) r] |
| 2473 |
chan flush $fd |
| 2474 |
} -returnCodes error -cleanup { |
| 2475 |
catch {chan close $fd} |
| 2476 |
} -match glob -result {channel "*" wasn't opened for writing} |
| 2477 |
test chan-io-29.16 {Tcl_Flush on pipe opened only for reading} -setup { |
| 2478 |
set fd [openpipe r cat longfile] |
| 2479 |
} -constraints stdio -body { |
| 2480 |
chan flush $fd |
| 2481 |
} -returnCodes error -cleanup { |
| 2482 |
catch {chan close $fd} |
| 2483 |
} -match glob -result {channel "*" wasn't opened for writing} |
| 2484 |
test chan-io-29.17 {Tcl_WriteChars buffers, then Tcl_Flush flushes} -setup { |
| 2485 |
file delete $path(test1) |
| 2486 |
} -body { |
| 2487 |
set f1 [open $path(test1) w] |
| 2488 |
chan configure $f1 -translation lf |
| 2489 |
chan puts $f1 hello |
| 2490 |
chan puts $f1 hello |
| 2491 |
chan puts $f1 hello |
| 2492 |
chan flush $f1 |
| 2493 |
file size $path(test1) |
| 2494 |
} -cleanup { |
| 2495 |
chan close $f1 |
| 2496 |
} -result 18 |
| 2497 |
test chan-io-29.18 {Tcl_WriteChars and Tcl_Flush intermixed} -setup { |
| 2498 |
file delete $path(test1) |
| 2499 |
set x "" |
| 2500 |
set f1 [open $path(test1) w] |
| 2501 |
} -body { |
| 2502 |
chan configure $f1 -translation lf |
| 2503 |
chan puts $f1 hello |
| 2504 |
chan puts $f1 hello |
| 2505 |
chan puts $f1 hello |
| 2506 |
chan flush $f1 |
| 2507 |
lappend x [file size $path(test1)] |
| 2508 |
chan puts $f1 hello |
| 2509 |
chan flush $f1 |
| 2510 |
lappend x [file size $path(test1)] |
| 2511 |
chan puts $f1 hello |
| 2512 |
chan flush $f1 |
| 2513 |
lappend x [file size $path(test1)] |
| 2514 |
} -cleanup { |
| 2515 |
chan close $f1 |
| 2516 |
} -result {18 24 30} |
| 2517 |
test chan-io-29.19 {Explicit and implicit flushes} -setup { |
| 2518 |
file delete $path(test1) |
| 2519 |
} -body { |
| 2520 |
set f1 [open $path(test1) w] |
| 2521 |
chan configure $f1 -translation lf -eofchar {} |
| 2522 |
set x "" |
| 2523 |
chan puts $f1 hello |
| 2524 |
chan puts $f1 hello |
| 2525 |
chan puts $f1 hello |
| 2526 |
chan flush $f1 |
| 2527 |
lappend x [file size $path(test1)] |
| 2528 |
chan puts $f1 hello |
| 2529 |
chan flush $f1 |
| 2530 |
lappend x [file size $path(test1)] |
| 2531 |
chan puts $f1 hello |
| 2532 |
chan close $f1 |
| 2533 |
lappend x [file size $path(test1)] |
| 2534 |
} -result {18 24 30} |
| 2535 |
test chan-io-29.20 {Implicit flush when buffer is full} -setup { |
| 2536 |
file delete $path(test1) |
| 2537 |
} -body { |
| 2538 |
set f1 [open $path(test1) w] |
| 2539 |
chan configure $f1 -translation lf -eofchar {} |
| 2540 |
set line "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
| 2541 |
for {set x 0} {$x < 100} {incr x} { |
| 2542 |
chan puts $f1 $line |
| 2543 |
} |
| 2544 |
set z "" |
| 2545 |
lappend z [file size $path(test1)] |
| 2546 |
for {set x 0} {$x < 100} {incr x} { |
| 2547 |
chan puts $f1 $line |
| 2548 |
} |
| 2549 |
lappend z [file size $path(test1)] |
| 2550 |
chan close $f1 |
| 2551 |
lappend z [file size $path(test1)] |
| 2552 |
} -result {4096 12288 12600} |
| 2553 |
test chan-io-29.21 {Tcl_Flush to pipe} -setup { |
| 2554 |
file delete $path(pipe) |
| 2555 |
} -constraints stdio -body { |
| 2556 |
set f1 [open $path(pipe) w] |
| 2557 |
chan puts $f1 {set x [chan read stdin 6]} |
| 2558 |
chan puts $f1 {set cnt [string length $x]} |
| 2559 |
chan puts $f1 {chan puts "read $cnt characters"} |
| 2560 |
chan close $f1 |
| 2561 |
set f1 [openpipe r+ $path(pipe)] |
| 2562 |
chan puts $f1 hello |
| 2563 |
chan flush $f1 |
| 2564 |
chan gets $f1 |
| 2565 |
} -cleanup { |
| 2566 |
catch {chan close $f1} |
| 2567 |
} -result "read 6 characters" |
| 2568 |
test chan-io-29.22 {Tcl_Flush called at other end of pipe} -setup { |
| 2569 |
file delete $path(pipe) |
| 2570 |
} -constraints stdio -body { |
| 2571 |
set f1 [open $path(pipe) w] |
| 2572 |
chan puts $f1 { |
| 2573 |
chan configure stdout -buffering full |
| 2574 |
chan puts hello |
| 2575 |
chan puts hello |
| 2576 |
chan flush stdout |
| 2577 |
chan gets stdin |
| 2578 |
chan puts bye |
| 2579 |
chan flush stdout |
| 2580 |
} |
| 2581 |
chan close $f1 |
| 2582 |
set f1 [openpipe r+ $path(pipe)] |
| 2583 |
set x "" |
| 2584 |
lappend x [chan gets $f1] |
| 2585 |
lappend x [chan gets $f1] |
| 2586 |
chan puts $f1 hello |
| 2587 |
chan flush $f1 |
| 2588 |
lappend x [chan gets $f1] |
| 2589 |
} -cleanup { |
| 2590 |
chan close $f1 |
| 2591 |
} -result {hello hello bye} |
| 2592 |
test chan-io-29.23 {Tcl_Flush and line buffering at end of pipe} -setup { |
| 2593 |
file delete $path(pipe) |
| 2594 |
} -constraints stdio -body { |
| 2595 |
set f1 [open $path(pipe) w] |
| 2596 |
chan puts $f1 { |
| 2597 |
chan puts hello |
| 2598 |
chan puts hello |
| 2599 |
chan gets stdin |
| 2600 |
chan puts bye |
| 2601 |
} |
| 2602 |
chan close $f1 |
| 2603 |
set f1 [openpipe r+ $path(pipe)] |
| 2604 |
set x "" |
| 2605 |
lappend x [chan gets $f1] |
| 2606 |
lappend x [chan gets $f1] |
| 2607 |
chan puts $f1 hello |
| 2608 |
chan flush $f1 |
| 2609 |
lappend x [chan gets $f1] |
| 2610 |
} -cleanup { |
| 2611 |
chan close $f1 |
| 2612 |
} -result {hello hello bye} |
| 2613 |
test chan-io-29.24 {Tcl_WriteChars and Tcl_Flush move end of file} -setup { |
| 2614 |
variable x {} |
| 2615 |
} -body { |
| 2616 |
set f [open $path(test3) w] |
| 2617 |
chan puts $f "Line 1" |
| 2618 |
chan puts $f "Line 2" |
| 2619 |
set f2 [open $path(test3)] |
| 2620 |
lappend x [chan read -nonewline $f2] |
| 2621 |
chan close $f2 |
| 2622 |
chan flush $f |
| 2623 |
set f2 [open $path(test3)] |
| 2624 |
lappend x [chan read -nonewline $f2] |
| 2625 |
} -cleanup { |
| 2626 |
chan close $f2 |
| 2627 |
chan close $f |
| 2628 |
} -result "{} {Line 1\nLine 2}" |
| 2629 |
test chan-io-29.25 {Implicit flush with Tcl_Flush to command pipelines} -setup { |
| 2630 |
file delete $path(test3) |
| 2631 |
} -constraints {stdio fileevent} -body { |
| 2632 |
set f [openpipe w $path(cat) | [interpreter] $path(cat) > $path(test3)] |
| 2633 |
chan puts $f "Line 1" |
| 2634 |
chan puts $f "Line 2" |
| 2635 |
chan close $f |
| 2636 |
after 100 |
| 2637 |
set f [open $path(test3) r] |
| 2638 |
chan read $f |
| 2639 |
} -cleanup { |
| 2640 |
chan close $f |
| 2641 |
} -result "Line 1\nLine 2\n" |
| 2642 |
test chan-io-29.26 {Tcl_Flush, Tcl_Write on bidirectional pipelines} -constraints {stdio unixExecs} -body { |
| 2643 |
set f [open "|[list cat -u]" r+] |
| 2644 |
chan puts $f "Line1" |
| 2645 |
chan flush $f |
| 2646 |
chan gets $f |
| 2647 |
} -cleanup { |
| 2648 |
chan close $f |
| 2649 |
} -result {Line1} |
| 2650 |
test chan-io-29.27 {Tcl_Flush on chan closed pipeline} -setup { |
| 2651 |
file delete $path(pipe) |
| 2652 |
set f [open $path(pipe) w] |
| 2653 |
chan puts $f {exit} |
| 2654 |
chan close $f |
| 2655 |
} -constraints stdio -body { |
| 2656 |
set f [openpipe r+ $path(pipe)] |
| 2657 |
chan gets $f |
| 2658 |
chan puts $f output |
| 2659 |
after 50 |
| 2660 |
# |
| 2661 |
# The flush below will get a SIGPIPE. This is an expected part of the test |
| 2662 |
# and indicates that the test operates correctly. If you run this test |
| 2663 |
# under a debugger, the signal will by intercepted unless you disable the |
| 2664 |
# debugger's signal interception. |
| 2665 |
# |
| 2666 |
if {[catch {chan flush $f} msg]} { |
| 2667 |
set x [list 1 $msg $::errorCode] |
| 2668 |
catch {chan close $f} |
| 2669 |
} elseif {[catch {chan close $f} msg]} { |
| 2670 |
set x [list 1 $msg $::errorCode] |
| 2671 |
} else { |
| 2672 |
set x {this was supposed to fail and did not} |
| 2673 |
} |
| 2674 |
string tolower $x |
| 2675 |
} -match glob -result {1 {error flushing "*": broken pipe} {posix epipe {broken pipe}}} |
| 2676 |
test chan-io-29.28 {Tcl_WriteChars, lf mode} -setup { |
| 2677 |
file delete $path(test1) |
| 2678 |
} -body { |
| 2679 |
set f [open $path(test1) w] |
| 2680 |
chan configure $f -translation lf -eofchar {} |
| 2681 |
chan puts $f hello\nthere\nand\nhere |
| 2682 |
chan flush $f |
| 2683 |
file size $path(test1) |
| 2684 |
} -cleanup { |
| 2685 |
chan close $f |
| 2686 |
} -result 21 |
| 2687 |
test chan-io-29.29 {Tcl_WriteChars, cr mode} -setup { |
| 2688 |
file delete $path(test1) |
| 2689 |
} -body { |
| 2690 |
set f [open $path(test1) w] |
| 2691 |
chan configure $f -translation cr -eofchar {} |
| 2692 |
chan puts $f hello\nthere\nand\nhere |
| 2693 |
chan close $f |
| 2694 |
file size $path(test1) |
| 2695 |
} -result 21 |
| 2696 |
test chan-io-29.30 {Tcl_WriteChars, crlf mode} -setup { |
| 2697 |
file delete $path(test1) |
| 2698 |
} -body { |
| 2699 |
set f [open $path(test1) w] |
| 2700 |
chan configure $f -translation crlf -eofchar {} |
| 2701 |
chan puts $f hello\nthere\nand\nhere |
| 2702 |
chan close $f |
| 2703 |
file size $path(test1) |
| 2704 |
} -result 25 |
| 2705 |
test chan-io-29.31 {Tcl_WriteChars, background flush} -setup { |
| 2706 |
file delete $path(pipe) |
| 2707 |
file delete $path(output) |
| 2708 |
} -constraints stdio -body { |
| 2709 |
set f [open $path(pipe) w] |
| 2710 |
chan puts $f "set f \[[list open $path(output) w]]" |
| 2711 |
chan puts $f {chan configure $f -translation lf} |
| 2712 |
set x [list while {![chan eof stdin]}] |
| 2713 |
set x "$x {" |
| 2714 |
chan puts $f $x |
| 2715 |
chan puts $f { chan puts -nonewline $f [chan read stdin 4096]} |
| 2716 |
chan puts $f { chan flush $f} |
| 2717 |
chan puts $f "}" |
| 2718 |
chan puts $f {chan close $f} |
| 2719 |
chan close $f |
| 2720 |
set x 01234567890123456789012345678901 |
| 2721 |
for {set i 0} {$i < 11} {incr i} { |
| 2722 |
set x "$x$x" |
| 2723 |
} |
| 2724 |
set f [open $path(output) w] |
| 2725 |
chan close $f |
| 2726 |
set f [openpipe r+ $path(pipe)] |
| 2727 |
chan configure $f -blocking off |
| 2728 |
chan puts -nonewline $f $x |
| 2729 |
chan close $f |
| 2730 |
set counter 0 |
| 2731 |
while {([file size $path(output)] < 65536) && ($counter < 1000)} { |
| 2732 |
after 10 [list incr [namespace which -variable counter]] |
| 2733 |
vwait [namespace which -variable counter] |
| 2734 |
} |
| 2735 |
if {$counter == 1000} { |
| 2736 |
set result "file size only [file size $path(output)]" |
| 2737 |
} else { |
| 2738 |
set result ok |
| 2739 |
} |
| 2740 |
# allow a little time for the background process to chan close. |
| 2741 |
# otherwise, the following test fails on the [file delete $path(output)] |
| 2742 |
# on Windows because a process still has the file open. |
| 2743 |
after 100 set v 1; vwait v |
| 2744 |
return $result |
| 2745 |
} -result ok |
| 2746 |
test chan-io-29.32 {Tcl_WriteChars, background flush to slow reader} -setup { |
| 2747 |
file delete $path(pipe) |
| 2748 |
file delete $path(output) |
| 2749 |
} -constraints {stdio asyncPipeChan Close} -body { |
| 2750 |
set f [open $path(pipe) w] |
| 2751 |
chan puts $f "set f \[[list open $path(output) w]]" |
| 2752 |
chan puts $f {chan configure $f -translation lf} |
| 2753 |
set x [list while {![chan eof stdin]}] |
| 2754 |
set x "$x \{" |
| 2755 |
chan puts $f $x |
| 2756 |
chan puts $f { after 20} |
| 2757 |
chan puts $f { chan puts -nonewline $f [chan read stdin 1024]} |
| 2758 |
chan puts $f { chan flush $f} |
| 2759 |
chan puts $f "\}" |
| 2760 |
chan puts $f {chan close $f} |
| 2761 |
chan close $f |
| 2762 |
set x 01234567890123456789012345678901 |
| 2763 |
for {set i 0} {$i < 11} {incr i} { |
| 2764 |
set x "$x$x" |
| 2765 |
} |
| 2766 |
set f [open $path(output) w] |
| 2767 |
chan close $f |
| 2768 |
set f [openpipe r+ $path(pipe)] |
| 2769 |
chan configure $f -blocking off |
| 2770 |
chan puts -nonewline $f $x |
| 2771 |
chan close $f |
| 2772 |
set counter 0 |
| 2773 |
while {([file size $path(output)] < 65536) && ($counter < 1000)} { |
| 2774 |
after 20 [list incr [namespace which -variable counter]] |
| 2775 |
vwait [namespace which -variable counter] |
| 2776 |
} |
| 2777 |
if {$counter == 1000} { |
| 2778 |
set result "file size only [file size $path(output)]" |
| 2779 |
} else { |
| 2780 |
set result ok |
| 2781 |
} |
| 2782 |
} -result ok |
| 2783 |
test chan-io-29.33 {Tcl_Flush, implicit flush on exit} -setup { |
| 2784 |
set f [open $path(script) w] |
| 2785 |
chan puts $f "set f \[[list open $path(test1) w]]" |
| 2786 |
chan puts $f {chan configure $f -translation lf |
| 2787 |
chan puts $f hello |
| 2788 |
chan puts $f bye |
| 2789 |
chan puts $f strange |
| 2790 |
} |
| 2791 |
chan close $f |
| 2792 |
} -constraints exec -body { |
| 2793 |
exec [interpreter] $path(script) |
| 2794 |
set f [open $path(test1) r] |
| 2795 |
chan read $f |
| 2796 |
} -cleanup { |
| 2797 |
chan close $f |
| 2798 |
} -result "hello\nbye\nstrange\n" |
| 2799 |
test chan-io-29.34 {Tcl_Chan Close, async flush on chan close, using sockets} -setup { |
| 2800 |
variable c 0 |
| 2801 |
variable x running |
| 2802 |
set l abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz |
| 2803 |
proc writelots {s l} { |
| 2804 |
for {set i 0} {$i < 2000} {incr i} { |
| 2805 |
chan puts $s $l |
| 2806 |
} |
| 2807 |
} |
| 2808 |
} -constraints {socket tempNotMac fileevent notWinCI} -body { |
| 2809 |
proc accept {s a p} { |
| 2810 |
variable x |
| 2811 |
chan event $s readable [namespace code [list readit $s]] |
| 2812 |
chan configure $s -blocking off |
| 2813 |
set x accepted |
| 2814 |
} |
| 2815 |
proc readit {s} { |
| 2816 |
variable c |
| 2817 |
variable x |
| 2818 |
set l [chan gets $s] |
| 2819 |
if {[chan eof $s]} { |
| 2820 |
chan close $s |
| 2821 |
set x done |
| 2822 |
} elseif {([string length $l] > 0) || ![chan blocked $s]} { |
| 2823 |
incr c |
| 2824 |
} |
| 2825 |
} |
| 2826 |
set ss [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 2827 |
set cs [socket 127.0.0.1 [lindex [chan configure $ss -sockname] 2]] |
| 2828 |
vwait [namespace which -variable x] |
| 2829 |
chan configure $cs -blocking off |
| 2830 |
writelots $cs $l |
| 2831 |
chan close $cs |
| 2832 |
chan close $ss |
| 2833 |
vwait [namespace which -variable x] |
| 2834 |
set c |
| 2835 |
} -result 2000 |
| 2836 |
test chan-io-29.35 {Tcl_Chan Close vs chan event vs multiple interpreters} -setup { |
| 2837 |
catch {interp delete x} |
| 2838 |
catch {interp delete y} |
| 2839 |
} -constraints {socket tempNotMac fileevent} -body { |
| 2840 |
# On Mac, this test screws up sockets such that subsequent tests using |
| 2841 |
# port 2828 either cause errors or panic(). |
| 2842 |
interp create x |
| 2843 |
interp create y |
| 2844 |
set s [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 2845 |
proc accept {s a p} { |
| 2846 |
chan puts $s hello |
| 2847 |
chan close $s |
| 2848 |
} |
| 2849 |
set c [socket 127.0.0.1 [lindex [chan configure $s -sockname] 2]] |
| 2850 |
interp share {} $c x |
| 2851 |
interp share {} $c y |
| 2852 |
chan close $c |
| 2853 |
x eval { |
| 2854 |
proc readit {s} { |
| 2855 |
chan gets $s |
| 2856 |
if {[chan eof $s]} { |
| 2857 |
chan close $s |
| 2858 |
} |
| 2859 |
} |
| 2860 |
} |
| 2861 |
y eval { |
| 2862 |
proc readit {s} { |
| 2863 |
chan gets $s |
| 2864 |
if {[chan eof $s]} { |
| 2865 |
chan close $s |
| 2866 |
} |
| 2867 |
} |
| 2868 |
} |
| 2869 |
x eval "chan event $c readable \{readit $c\}" |
| 2870 |
y eval "chan event $c readable \{readit $c\}" |
| 2871 |
y eval [list chan close $c] |
| 2872 |
update |
| 2873 |
} -cleanup { |
| 2874 |
chan close $s |
| 2875 |
interp delete x |
| 2876 |
interp delete y |
| 2877 |
} -result "" |
| 2878 |
|
| 2879 |
# Test end of line translations. Procedures tested are Tcl_Write, Tcl_Read. |
| 2880 |
|
| 2881 |
test chan-io-30.1 {Tcl_Write lf, Tcl_Read lf} -setup { |
| 2882 |
file delete $path(test1) |
| 2883 |
} -body { |
| 2884 |
set f [open $path(test1) w] |
| 2885 |
chan configure $f -translation lf |
| 2886 |
chan puts $f hello\nthere\nand\nhere |
| 2887 |
chan close $f |
| 2888 |
set f [open $path(test1) r] |
| 2889 |
chan configure $f -translation lf |
| 2890 |
chan read $f |
| 2891 |
} -cleanup { |
| 2892 |
chan close $f |
| 2893 |
} -result "hello\nthere\nand\nhere\n" |
| 2894 |
test chan-io-30.2 {Tcl_Write lf, Tcl_Read cr} -setup { |
| 2895 |
file delete $path(test1) |
| 2896 |
} -body { |
| 2897 |
set f [open $path(test1) w] |
| 2898 |
chan configure $f -translation lf |
| 2899 |
chan puts $f hello\nthere\nand\nhere |
| 2900 |
chan close $f |
| 2901 |
set f [open $path(test1) r] |
| 2902 |
chan configure $f -translation cr |
| 2903 |
chan read $f |
| 2904 |
} -cleanup { |
| 2905 |
chan close $f |
| 2906 |
} -result "hello\nthere\nand\nhere\n" |
| 2907 |
test chan-io-30.3 {Tcl_Write lf, Tcl_Read crlf} -setup { |
| 2908 |
file delete $path(test1) |
| 2909 |
} -body { |
| 2910 |
set f [open $path(test1) w] |
| 2911 |
chan configure $f -translation lf |
| 2912 |
chan puts $f hello\nthere\nand\nhere |
| 2913 |
chan close $f |
| 2914 |
set f [open $path(test1) r] |
| 2915 |
chan configure $f -translation crlf |
| 2916 |
chan read $f |
| 2917 |
} -cleanup { |
| 2918 |
chan close $f |
| 2919 |
} -result "hello\nthere\nand\nhere\n" |
| 2920 |
test chan-io-30.4 {Tcl_Write cr, Tcl_Read cr} -setup { |
| 2921 |
file delete $path(test1) |
| 2922 |
} -body { |
| 2923 |
set f [open $path(test1) w] |
| 2924 |
chan configure $f -translation cr |
| 2925 |
chan puts $f hello\nthere\nand\nhere |
| 2926 |
chan close $f |
| 2927 |
set f [open $path(test1) r] |
| 2928 |
chan configure $f -translation cr |
| 2929 |
chan read $f |
| 2930 |
} -cleanup { |
| 2931 |
chan close $f |
| 2932 |
} -result "hello\nthere\nand\nhere\n" |
| 2933 |
test chan-io-30.5 {Tcl_Write cr, Tcl_Read lf} -setup { |
| 2934 |
file delete $path(test1) |
| 2935 |
} -body { |
| 2936 |
set f [open $path(test1) w] |
| 2937 |
chan configure $f -translation cr |
| 2938 |
chan puts $f hello\nthere\nand\nhere |
| 2939 |
chan close $f |
| 2940 |
set f [open $path(test1) r] |
| 2941 |
chan configure $f -translation lf |
| 2942 |
chan read $f |
| 2943 |
} -cleanup { |
| 2944 |
chan close $f |
| 2945 |
} -result "hello\rthere\rand\rhere\r" |
| 2946 |
test chan-io-30.6 {Tcl_Write cr, Tcl_Read crlf} -setup { |
| 2947 |
file delete $path(test1) |
| 2948 |
} -body { |
| 2949 |
set f [open $path(test1) w] |
| 2950 |
chan configure $f -translation cr |
| 2951 |
chan puts $f hello\nthere\nand\nhere |
| 2952 |
chan close $f |
| 2953 |
set f [open $path(test1) r] |
| 2954 |
chan configure $f -translation crlf |
| 2955 |
chan read $f |
| 2956 |
} -cleanup { |
| 2957 |
chan close $f |
| 2958 |
} -result "hello\rthere\rand\rhere\r" |
| 2959 |
test chan-io-30.7 {Tcl_Write crlf, Tcl_Read crlf} -setup { |
| 2960 |
file delete $path(test1) |
| 2961 |
} -body { |
| 2962 |
set f [open $path(test1) w] |
| 2963 |
chan configure $f -translation crlf |
| 2964 |
chan puts $f hello\nthere\nand\nhere |
| 2965 |
chan close $f |
| 2966 |
set f [open $path(test1) r] |
| 2967 |
chan configure $f -translation crlf |
| 2968 |
chan read $f |
| 2969 |
} -cleanup { |
| 2970 |
chan close $f |
| 2971 |
} -result "hello\nthere\nand\nhere\n" |
| 2972 |
test chan-io-30.8 {Tcl_Write crlf, Tcl_Read lf} -setup { |
| 2973 |
file delete $path(test1) |
| 2974 |
} -body { |
| 2975 |
set f [open $path(test1) w] |
| 2976 |
chan configure $f -translation crlf |
| 2977 |
chan puts $f hello\nthere\nand\nhere |
| 2978 |
chan close $f |
| 2979 |
set f [open $path(test1) r] |
| 2980 |
chan configure $f -translation lf |
| 2981 |
chan read $f |
| 2982 |
} -cleanup { |
| 2983 |
chan close $f |
| 2984 |
} -result "hello\r\nthere\r\nand\r\nhere\r\n" |
| 2985 |
test chan-io-30.9 {Tcl_Write crlf, Tcl_Read cr} -setup { |
| 2986 |
file delete $path(test1) |
| 2987 |
} -body { |
| 2988 |
set f [open $path(test1) w] |
| 2989 |
chan configure $f -translation crlf |
| 2990 |
chan puts $f hello\nthere\nand\nhere |
| 2991 |
chan close $f |
| 2992 |
set f [open $path(test1) r] |
| 2993 |
chan configure $f -translation cr |
| 2994 |
chan read $f |
| 2995 |
} -cleanup { |
| 2996 |
chan close $f |
| 2997 |
} -result "hello\n\nthere\n\nand\n\nhere\n\n" |
| 2998 |
test chan-io-30.10 {Tcl_Write lf, Tcl_Read auto} -setup { |
| 2999 |
file delete $path(test1) |
| 3000 |
} -body { |
| 3001 |
set f [open $path(test1) w] |
| 3002 |
chan configure $f -translation lf |
| 3003 |
chan puts $f hello\nthere\nand\nhere |
| 3004 |
chan close $f |
| 3005 |
set f [open $path(test1) r] |
| 3006 |
list [chan read $f] [chan configure $f -translation] |
| 3007 |
} -cleanup { |
| 3008 |
chan close $f |
| 3009 |
} -result {{hello |
| 3010 |
there |
| 3011 |
and |
| 3012 |
here |
| 3013 |
} auto} |
| 3014 |
test chan-io-30.11 {Tcl_Write cr, Tcl_Read auto} -setup { |
| 3015 |
file delete $path(test1) |
| 3016 |
} -body { |
| 3017 |
set f [open $path(test1) w] |
| 3018 |
chan configure $f -translation cr |
| 3019 |
chan puts $f hello\nthere\nand\nhere |
| 3020 |
chan close $f |
| 3021 |
set f [open $path(test1) r] |
| 3022 |
list [chan read $f] [chan configure $f -translation] |
| 3023 |
} -cleanup { |
| 3024 |
chan close $f |
| 3025 |
} -result {{hello |
| 3026 |
there |
| 3027 |
and |
| 3028 |
here |
| 3029 |
} auto} |
| 3030 |
test chan-io-30.12 {Tcl_Write crlf, Tcl_Read auto} -setup { |
| 3031 |
file delete $path(test1) |
| 3032 |
} -body { |
| 3033 |
set f [open $path(test1) w] |
| 3034 |
chan configure $f -translation crlf |
| 3035 |
chan puts $f hello\nthere\nand\nhere |
| 3036 |
chan close $f |
| 3037 |
set f [open $path(test1) r] |
| 3038 |
list [chan read $f] [chan configure $f -translation] |
| 3039 |
} -cleanup { |
| 3040 |
chan close $f |
| 3041 |
} -result {{hello |
| 3042 |
there |
| 3043 |
and |
| 3044 |
here |
| 3045 |
} auto} |
| 3046 |
test chan-io-30.13 {Tcl_Write crlf on block boundary, Tcl_Read auto} -setup { |
| 3047 |
file delete $path(test1) |
| 3048 |
} -body { |
| 3049 |
set f [open $path(test1) w] |
| 3050 |
chan configure $f -translation crlf |
| 3051 |
set line "123456789ABCDE" ;# 14 char plus crlf |
| 3052 |
chan puts -nonewline $f x ;# shift crlf across block boundary |
| 3053 |
for {set i 0} {$i < 700} {incr i} { |
| 3054 |
chan puts $f $line |
| 3055 |
} |
| 3056 |
chan close $f |
| 3057 |
set f [open $path(test1) r] |
| 3058 |
chan configure $f -translation auto |
| 3059 |
string length [chan read $f] |
| 3060 |
} -cleanup { |
| 3061 |
chan close $f |
| 3062 |
} -result [expr {700*15 + 1}] |
| 3063 |
test chan-io-30.14 {Tcl_Write crlf on block boundary, Tcl_Read crlf} -setup { |
| 3064 |
file delete $path(test1) |
| 3065 |
} -body { |
| 3066 |
set f [open $path(test1) w] |
| 3067 |
chan configure $f -translation crlf |
| 3068 |
set line "123456789ABCDE" ;# 14 char plus crlf |
| 3069 |
chan puts -nonewline $f x ;# shift crlf across block boundary |
| 3070 |
for {set i 0} {$i < 700} {incr i} { |
| 3071 |
chan puts $f $line |
| 3072 |
} |
| 3073 |
chan close $f |
| 3074 |
set f [open $path(test1) r] |
| 3075 |
chan configure $f -translation crlf |
| 3076 |
string length [chan read $f] |
| 3077 |
} -cleanup { |
| 3078 |
chan close $f |
| 3079 |
} -result [expr {700*15 + 1}] |
| 3080 |
test chan-io-30.15 {Tcl_Write mixed, Tcl_Read auto} -setup { |
| 3081 |
file delete $path(test1) |
| 3082 |
} -body { |
| 3083 |
set f [open $path(test1) w] |
| 3084 |
chan configure $f -translation lf |
| 3085 |
chan puts $f hello\nthere\nand\rhere |
| 3086 |
chan close $f |
| 3087 |
set f [open $path(test1) r] |
| 3088 |
chan configure $f -translation auto |
| 3089 |
chan read $f |
| 3090 |
} -cleanup { |
| 3091 |
chan close $f |
| 3092 |
} -result {hello |
| 3093 |
there |
| 3094 |
and |
| 3095 |
here |
| 3096 |
} |
| 3097 |
test chan-io-30.16 {Tcl_Write ^Z at end, Tcl_Read auto} -setup { |
| 3098 |
file delete $path(test1) |
| 3099 |
} -body { |
| 3100 |
set f [open $path(test1) w] |
| 3101 |
chan configure $f -translation lf |
| 3102 |
chan puts -nonewline $f hello\nthere\nand\rhere\n\x1A |
| 3103 |
chan close $f |
| 3104 |
set f [open $path(test1) r] |
| 3105 |
chan configure $f -translation auto -eofchar \x1A |
| 3106 |
chan read $f |
| 3107 |
} -cleanup { |
| 3108 |
chan close $f |
| 3109 |
} -result {hello |
| 3110 |
there |
| 3111 |
and |
| 3112 |
here |
| 3113 |
} |
| 3114 |
test chan-io-30.17 {Tcl_Write, implicit ^Z at end, Tcl_Read auto} -setup { |
| 3115 |
file delete $path(test1) |
| 3116 |
} -constraints {win} -body { |
| 3117 |
set f [open $path(test1) w] |
| 3118 |
chan configure $f -translation lf -eofchar \x1A |
| 3119 |
chan puts $f hello\nthere\nand\rhere |
| 3120 |
chan close $f |
| 3121 |
set f [open $path(test1) r] |
| 3122 |
chan configure $f -translation auto -eofchar \x1A |
| 3123 |
chan read $f |
| 3124 |
} -cleanup { |
| 3125 |
chan close $f |
| 3126 |
} -result {hello |
| 3127 |
there |
| 3128 |
and |
| 3129 |
here |
| 3130 |
} |
| 3131 |
test chan-io-30.18 {Tcl_Write, ^Z in middle, Tcl_Read auto} -setup { |
| 3132 |
file delete $path(test1) |
| 3133 |
} -body { |
| 3134 |
set f [open $path(test1) w] |
| 3135 |
chan configure $f -translation lf |
| 3136 |
set s [format "abc\ndef\n%cghi\nqrs" 26] |
| 3137 |
chan puts $f $s |
| 3138 |
chan close $f |
| 3139 |
set f [open $path(test1) r] |
| 3140 |
chan configure $f -translation auto -eofchar \x1A |
| 3141 |
set l "" |
| 3142 |
lappend l [chan gets $f] |
| 3143 |
lappend l [chan gets $f] |
| 3144 |
lappend l [chan eof $f] |
| 3145 |
lappend l [chan gets $f] |
| 3146 |
lappend l [chan eof $f] |
| 3147 |
lappend l [chan gets $f] |
| 3148 |
lappend l [chan eof $f] |
| 3149 |
} -cleanup { |
| 3150 |
chan close $f |
| 3151 |
} -result {abc def 0 {} 1 {} 1} |
| 3152 |
test chan-io-30.19 {Tcl_Write, ^Z no newline in middle, Tcl_Read auto} -setup { |
| 3153 |
file delete $path(test1) |
| 3154 |
} -body { |
| 3155 |
set f [open $path(test1) w] |
| 3156 |
chan configure $f -translation lf |
| 3157 |
set s [format "abc\ndef\n%cghi\nqrs" 26] |
| 3158 |
chan puts $f $s |
| 3159 |
chan close $f |
| 3160 |
set f [open $path(test1) r] |
| 3161 |
chan configure $f -translation auto -eofchar \x1A |
| 3162 |
set l "" |
| 3163 |
lappend l [chan gets $f] |
| 3164 |
lappend l [chan gets $f] |
| 3165 |
lappend l [chan eof $f] |
| 3166 |
lappend l [chan gets $f] |
| 3167 |
lappend l [chan eof $f] |
| 3168 |
lappend l [chan gets $f] |
| 3169 |
lappend l [chan eof $f] |
| 3170 |
} -cleanup { |
| 3171 |
chan close $f |
| 3172 |
} -result {abc def 0 {} 1 {} 1} |
| 3173 |
test chan-io-30.20 {Tcl_Write, ^Z in middle ignored, Tcl_Read lf} -setup { |
| 3174 |
file delete $path(test1) |
| 3175 |
set l "" |
| 3176 |
} -body { |
| 3177 |
set f [open $path(test1) w] |
| 3178 |
chan configure $f -translation lf -eofchar {} |
| 3179 |
chan puts $f [format "abc\ndef\n%cghi\nqrs" 26] |
| 3180 |
chan close $f |
| 3181 |
set f [open $path(test1) r] |
| 3182 |
chan configure $f -translation lf -eofchar {} |
| 3183 |
lappend l [chan gets $f] |
| 3184 |
lappend l [chan gets $f] |
| 3185 |
lappend l [chan eof $f] |
| 3186 |
lappend l [chan gets $f] |
| 3187 |
lappend l [chan eof $f] |
| 3188 |
lappend l [chan gets $f] |
| 3189 |
lappend l [chan eof $f] |
| 3190 |
lappend l [chan gets $f] |
| 3191 |
lappend l [chan eof $f] |
| 3192 |
} -cleanup { |
| 3193 |
chan close $f |
| 3194 |
} -result "abc def 0 \x1Aghi 0 qrs 0 {} 1" |
| 3195 |
test chan-io-30.21 {Tcl_Write, ^Z in middle ignored, Tcl_Read cr} -setup { |
| 3196 |
file delete $path(test1) |
| 3197 |
set l "" |
| 3198 |
} -body { |
| 3199 |
set f [open $path(test1) w] |
| 3200 |
chan configure $f -translation lf -eofchar {} |
| 3201 |
chan puts $f [format "abc\ndef\n%cghi\nqrs" 26] |
| 3202 |
chan close $f |
| 3203 |
set f [open $path(test1) r] |
| 3204 |
chan configure $f -translation cr -eofchar {} |
| 3205 |
set x [chan gets $f] |
| 3206 |
lappend l [string equal $x "abc\ndef\n\x1Aghi\nqrs\n"] |
| 3207 |
lappend l [chan eof $f] |
| 3208 |
lappend l [chan gets $f] |
| 3209 |
lappend l [chan eof $f] |
| 3210 |
} -cleanup { |
| 3211 |
chan close $f |
| 3212 |
} -result {1 1 {} 1} |
| 3213 |
test chan-io-30.22 {Tcl_Write, ^Z in middle ignored, Tcl_Read crlf} -setup { |
| 3214 |
file delete $path(test1) |
| 3215 |
set l "" |
| 3216 |
} -body { |
| 3217 |
set f [open $path(test1) w] |
| 3218 |
chan configure $f -translation lf -eofchar {} |
| 3219 |
chan puts $f [format "abc\ndef\n%cghi\nqrs" 26] |
| 3220 |
chan close $f |
| 3221 |
set f [open $path(test1) r] |
| 3222 |
chan configure $f -translation crlf -eofchar {} |
| 3223 |
set x [chan gets $f] |
| 3224 |
lappend l [string equal $x "abc\ndef\n\x1Aghi\nqrs\n"] |
| 3225 |
lappend l [chan eof $f] |
| 3226 |
lappend l [chan gets $f] |
| 3227 |
lappend l [chan eof $f] |
| 3228 |
} -cleanup { |
| 3229 |
chan close $f |
| 3230 |
} -result {1 1 {} 1} |
| 3231 |
test chan-io-30.23 {Tcl_Write lf, ^Z in middle, Tcl_Read auto} -setup { |
| 3232 |
file delete $path(test1) |
| 3233 |
} -body { |
| 3234 |
set f [open $path(test1) w] |
| 3235 |
chan configure $f -translation lf |
| 3236 |
chan puts $f [format abc\ndef\n%cqrs\ntuv 26] |
| 3237 |
chan close $f |
| 3238 |
set f [open $path(test1) r] |
| 3239 |
chan configure $f -translation auto -eofchar \x1A |
| 3240 |
list [string length [chan read $f]] [chan eof $f] |
| 3241 |
} -cleanup { |
| 3242 |
chan close $f |
| 3243 |
} -result {8 1} |
| 3244 |
test chan-io-30.24 {Tcl_Write lf, ^Z in middle, Tcl_Read lf} -setup { |
| 3245 |
file delete $path(test1) |
| 3246 |
} -body { |
| 3247 |
set f [open $path(test1) w] |
| 3248 |
chan configure $f -translation lf |
| 3249 |
set c [format abc\ndef\n%cqrs\ntuv 26] |
| 3250 |
chan puts $f $c |
| 3251 |
chan close $f |
| 3252 |
set f [open $path(test1) r] |
| 3253 |
chan configure $f -translation lf -eofchar \x1A |
| 3254 |
list [string length [chan read $f]] [chan eof $f] |
| 3255 |
} -cleanup { |
| 3256 |
chan close $f |
| 3257 |
} -result {8 1} |
| 3258 |
test chan-io-30.25 {Tcl_Write cr, ^Z in middle, Tcl_Read auto} -setup { |
| 3259 |
file delete $path(test1) |
| 3260 |
} -body { |
| 3261 |
set f [open $path(test1) w] |
| 3262 |
chan configure $f -translation cr |
| 3263 |
set c [format abc\ndef\n%cqrs\ntuv 26] |
| 3264 |
chan puts $f $c |
| 3265 |
chan close $f |
| 3266 |
set f [open $path(test1) r] |
| 3267 |
chan configure $f -translation auto -eofchar \x1A |
| 3268 |
list [string length [chan read $f]] [chan eof $f] |
| 3269 |
} -cleanup { |
| 3270 |
chan close $f |
| 3271 |
} -result {8 1} |
| 3272 |
test chan-io-30.26 {Tcl_Write cr, ^Z in middle, Tcl_Read cr} -setup { |
| 3273 |
file delete $path(test1) |
| 3274 |
} -body { |
| 3275 |
set f [open $path(test1) w] |
| 3276 |
chan configure $f -translation cr |
| 3277 |
set c [format abc\ndef\n%cqrs\ntuv 26] |
| 3278 |
chan puts $f $c |
| 3279 |
chan close $f |
| 3280 |
set f [open $path(test1) r] |
| 3281 |
chan configure $f -translation cr -eofchar \x1A |
| 3282 |
list [string length [chan read $f]] [chan eof $f] |
| 3283 |
} -cleanup { |
| 3284 |
chan close $f |
| 3285 |
} -result {8 1} |
| 3286 |
test chan-io-30.27 {Tcl_Write crlf, ^Z in middle, Tcl_Read auto} -setup { |
| 3287 |
file delete $path(test1) |
| 3288 |
} -body { |
| 3289 |
set f [open $path(test1) w] |
| 3290 |
chan configure $f -translation crlf |
| 3291 |
set c [format abc\ndef\n%cqrs\ntuv 26] |
| 3292 |
chan puts $f $c |
| 3293 |
chan close $f |
| 3294 |
set f [open $path(test1) r] |
| 3295 |
chan configure $f -translation auto -eofchar \x1A |
| 3296 |
list [string length [chan read $f]] [chan eof $f] |
| 3297 |
} -cleanup { |
| 3298 |
chan close $f |
| 3299 |
} -result {8 1} |
| 3300 |
test chan-io-30.28 {Tcl_Write crlf, ^Z in middle, Tcl_Read crlf} -setup { |
| 3301 |
file delete $path(test1) |
| 3302 |
} -body { |
| 3303 |
set f [open $path(test1) w] |
| 3304 |
chan configure $f -translation crlf |
| 3305 |
set c [format abc\ndef\n%cqrs\ntuv 26] |
| 3306 |
chan puts $f $c |
| 3307 |
chan close $f |
| 3308 |
set f [open $path(test1) r] |
| 3309 |
chan configure $f -translation crlf -eofchar \x1A |
| 3310 |
list [string length [chan read $f]] [chan eof $f] |
| 3311 |
} -cleanup { |
| 3312 |
chan close $f |
| 3313 |
} -result {8 1} |
| 3314 |
|
| 3315 |
# Test end of line translations. Functions tested are Tcl_Write and |
| 3316 |
# Tcl_Gets. |
| 3317 |
|
| 3318 |
test chan-io-31.1 {Tcl_Write lf, Tcl_Gets auto} -setup { |
| 3319 |
file delete $path(test1) |
| 3320 |
set l "" |
| 3321 |
} -body { |
| 3322 |
set f [open $path(test1) w] |
| 3323 |
chan configure $f -translation lf |
| 3324 |
chan puts $f hello\nthere\nand\nhere |
| 3325 |
chan close $f |
| 3326 |
set f [open $path(test1) r] |
| 3327 |
lappend l [chan gets $f] |
| 3328 |
lappend l [chan tell $f] |
| 3329 |
lappend l [chan configure $f -translation] |
| 3330 |
lappend l [chan gets $f] |
| 3331 |
lappend l [chan tell $f] |
| 3332 |
lappend l [chan configure $f -translation] |
| 3333 |
} -cleanup { |
| 3334 |
chan close $f |
| 3335 |
} -result {hello 6 auto there 12 auto} |
| 3336 |
test chan-io-31.2 {Tcl_Write cr, Tcl_Gets auto} -setup { |
| 3337 |
file delete $path(test1) |
| 3338 |
set l "" |
| 3339 |
} -body { |
| 3340 |
set f [open $path(test1) w] |
| 3341 |
chan configure $f -translation cr |
| 3342 |
chan puts $f hello\nthere\nand\nhere |
| 3343 |
chan close $f |
| 3344 |
set f [open $path(test1) r] |
| 3345 |
lappend l [chan gets $f] |
| 3346 |
lappend l [chan tell $f] |
| 3347 |
lappend l [chan configure $f -translation] |
| 3348 |
lappend l [chan gets $f] |
| 3349 |
lappend l [chan tell $f] |
| 3350 |
lappend l [chan configure $f -translation] |
| 3351 |
} -cleanup { |
| 3352 |
chan close $f |
| 3353 |
} -result {hello 6 auto there 12 auto} |
| 3354 |
test chan-io-31.3 {Tcl_Write crlf, Tcl_Gets auto} -setup { |
| 3355 |
file delete $path(test1) |
| 3356 |
set l "" |
| 3357 |
} -body { |
| 3358 |
set f [open $path(test1) w] |
| 3359 |
chan configure $f -translation crlf |
| 3360 |
chan puts $f hello\nthere\nand\nhere |
| 3361 |
chan close $f |
| 3362 |
set f [open $path(test1) r] |
| 3363 |
lappend l [chan gets $f] |
| 3364 |
lappend l [chan tell $f] |
| 3365 |
lappend l [chan configure $f -translation] |
| 3366 |
lappend l [chan gets $f] |
| 3367 |
lappend l [chan tell $f] |
| 3368 |
lappend l [chan configure $f -translation] |
| 3369 |
} -cleanup { |
| 3370 |
chan close $f |
| 3371 |
} -result {hello 7 auto there 14 auto} |
| 3372 |
test chan-io-31.4 {Tcl_Write lf, Tcl_Gets lf} -setup { |
| 3373 |
file delete $path(test1) |
| 3374 |
set l "" |
| 3375 |
} -body { |
| 3376 |
set f [open $path(test1) w] |
| 3377 |
chan configure $f -translation lf |
| 3378 |
chan puts $f hello\nthere\nand\nhere |
| 3379 |
chan close $f |
| 3380 |
set f [open $path(test1) r] |
| 3381 |
chan configure $f -translation lf |
| 3382 |
lappend l [chan gets $f] |
| 3383 |
lappend l [chan tell $f] |
| 3384 |
lappend l [chan configure $f -translation] |
| 3385 |
lappend l [chan gets $f] |
| 3386 |
lappend l [chan tell $f] |
| 3387 |
lappend l [chan configure $f -translation] |
| 3388 |
} -cleanup { |
| 3389 |
chan close $f |
| 3390 |
} -result {hello 6 lf there 12 lf} |
| 3391 |
test chan-io-31.5 {Tcl_Write lf, Tcl_Gets cr} -setup { |
| 3392 |
file delete $path(test1) |
| 3393 |
set l "" |
| 3394 |
} -body { |
| 3395 |
set f [open $path(test1) w] |
| 3396 |
chan configure $f -translation lf |
| 3397 |
chan puts $f hello\nthere\nand\nhere |
| 3398 |
chan close $f |
| 3399 |
set f [open $path(test1) r] |
| 3400 |
chan configure $f -translation cr |
| 3401 |
lappend l [string length [chan gets $f]] |
| 3402 |
lappend l [chan tell $f] |
| 3403 |
lappend l [chan configure $f -translation] |
| 3404 |
lappend l [chan eof $f] |
| 3405 |
lappend l [chan gets $f] |
| 3406 |
lappend l [chan tell $f] |
| 3407 |
lappend l [chan configure $f -translation] |
| 3408 |
lappend l [chan eof $f] |
| 3409 |
} -cleanup { |
| 3410 |
chan close $f |
| 3411 |
} -result {21 21 cr 1 {} 21 cr 1} |
| 3412 |
test chan-io-31.6 {Tcl_Write lf, Tcl_Gets crlf} -setup { |
| 3413 |
file delete $path(test1) |
| 3414 |
set l "" |
| 3415 |
} -body { |
| 3416 |
set f [open $path(test1) w] |
| 3417 |
chan configure $f -translation lf |
| 3418 |
chan puts $f hello\nthere\nand\nhere |
| 3419 |
chan close $f |
| 3420 |
set f [open $path(test1) r] |
| 3421 |
chan configure $f -translation crlf |
| 3422 |
lappend l [string length [chan gets $f]] |
| 3423 |
lappend l [chan tell $f] |
| 3424 |
lappend l [chan configure $f -translation] |
| 3425 |
lappend l [chan eof $f] |
| 3426 |
lappend l [chan gets $f] |
| 3427 |
lappend l [chan tell $f] |
| 3428 |
lappend l [chan configure $f -translation] |
| 3429 |
lappend l [chan eof $f] |
| 3430 |
} -cleanup { |
| 3431 |
chan close $f |
| 3432 |
} -result {21 21 crlf 1 {} 21 crlf 1} |
| 3433 |
test chan-io-31.7 {Tcl_Write cr, Tcl_Gets cr} -setup { |
| 3434 |
file delete $path(test1) |
| 3435 |
set l "" |
| 3436 |
} -body { |
| 3437 |
set f [open $path(test1) w] |
| 3438 |
chan configure $f -translation cr |
| 3439 |
chan puts $f hello\nthere\nand\nhere |
| 3440 |
chan close $f |
| 3441 |
set f [open $path(test1) r] |
| 3442 |
chan configure $f -translation cr |
| 3443 |
lappend l [chan gets $f] |
| 3444 |
lappend l [chan tell $f] |
| 3445 |
lappend l [chan configure $f -translation] |
| 3446 |
lappend l [chan eof $f] |
| 3447 |
lappend l [chan gets $f] |
| 3448 |
lappend l [chan tell $f] |
| 3449 |
lappend l [chan configure $f -translation] |
| 3450 |
lappend l [chan eof $f] |
| 3451 |
} -cleanup { |
| 3452 |
chan close $f |
| 3453 |
} -result {hello 6 cr 0 there 12 cr 0} |
| 3454 |
test chan-io-31.8 {Tcl_Write cr, Tcl_Gets lf} -setup { |
| 3455 |
file delete $path(test1) |
| 3456 |
set l "" |
| 3457 |
} -body { |
| 3458 |
set f [open $path(test1) w] |
| 3459 |
chan configure $f -translation cr |
| 3460 |
chan puts $f hello\nthere\nand\nhere |
| 3461 |
chan close $f |
| 3462 |
set f [open $path(test1) r] |
| 3463 |
chan configure $f -translation lf |
| 3464 |
lappend l [string length [chan gets $f]] |
| 3465 |
lappend l [chan tell $f] |
| 3466 |
lappend l [chan configure $f -translation] |
| 3467 |
lappend l [chan eof $f] |
| 3468 |
lappend l [chan gets $f] |
| 3469 |
lappend l [chan tell $f] |
| 3470 |
lappend l [chan configure $f -translation] |
| 3471 |
lappend l [chan eof $f] |
| 3472 |
} -cleanup { |
| 3473 |
chan close $f |
| 3474 |
} -result {21 21 lf 1 {} 21 lf 1} |
| 3475 |
test chan-io-31.9 {Tcl_Write cr, Tcl_Gets crlf} -setup { |
| 3476 |
file delete $path(test1) |
| 3477 |
set l "" |
| 3478 |
} -body { |
| 3479 |
set f [open $path(test1) w] |
| 3480 |
chan configure $f -translation cr |
| 3481 |
chan puts $f hello\nthere\nand\nhere |
| 3482 |
chan close $f |
| 3483 |
set f [open $path(test1) r] |
| 3484 |
chan configure $f -translation crlf |
| 3485 |
lappend l [string length [chan gets $f]] |
| 3486 |
lappend l [chan tell $f] |
| 3487 |
lappend l [chan configure $f -translation] |
| 3488 |
lappend l [chan eof $f] |
| 3489 |
lappend l [chan gets $f] |
| 3490 |
lappend l [chan tell $f] |
| 3491 |
lappend l [chan configure $f -translation] |
| 3492 |
lappend l [chan eof $f] |
| 3493 |
} -cleanup { |
| 3494 |
chan close $f |
| 3495 |
} -result {21 21 crlf 1 {} 21 crlf 1} |
| 3496 |
test chan-io-31.10 {Tcl_Write crlf, Tcl_Gets crlf} -setup { |
| 3497 |
file delete $path(test1) |
| 3498 |
set l "" |
| 3499 |
} -body { |
| 3500 |
set f [open $path(test1) w] |
| 3501 |
chan configure $f -translation crlf |
| 3502 |
chan puts $f hello\nthere\nand\nhere |
| 3503 |
chan close $f |
| 3504 |
set f [open $path(test1) r] |
| 3505 |
chan configure $f -translation crlf |
| 3506 |
lappend l [chan gets $f] |
| 3507 |
lappend l [chan tell $f] |
| 3508 |
lappend l [chan configure $f -translation] |
| 3509 |
lappend l [chan eof $f] |
| 3510 |
lappend l [chan gets $f] |
| 3511 |
lappend l [chan tell $f] |
| 3512 |
lappend l [chan configure $f -translation] |
| 3513 |
lappend l [chan eof $f] |
| 3514 |
} -cleanup { |
| 3515 |
chan close $f |
| 3516 |
} -result {hello 7 crlf 0 there 14 crlf 0} |
| 3517 |
test chan-io-31.11 {Tcl_Write crlf, Tcl_Gets cr} -setup { |
| 3518 |
file delete $path(test1) |
| 3519 |
set l "" |
| 3520 |
} -body { |
| 3521 |
set f [open $path(test1) w] |
| 3522 |
chan configure $f -translation crlf |
| 3523 |
chan puts $f hello\nthere\nand\nhere |
| 3524 |
chan close $f |
| 3525 |
set f [open $path(test1) r] |
| 3526 |
chan configure $f -translation cr |
| 3527 |
lappend l [chan gets $f] |
| 3528 |
lappend l [chan tell $f] |
| 3529 |
lappend l [chan configure $f -translation] |
| 3530 |
lappend l [chan eof $f] |
| 3531 |
lappend l [string length [chan gets $f]] |
| 3532 |
lappend l [chan tell $f] |
| 3533 |
lappend l [chan configure $f -translation] |
| 3534 |
lappend l [chan eof $f] |
| 3535 |
} -cleanup { |
| 3536 |
chan close $f |
| 3537 |
} -result {hello 6 cr 0 6 13 cr 0} |
| 3538 |
test chan-io-31.12 {Tcl_Write crlf, Tcl_Gets lf} -setup { |
| 3539 |
file delete $path(test1) |
| 3540 |
set l "" |
| 3541 |
} -body { |
| 3542 |
set f [open $path(test1) w] |
| 3543 |
chan configure $f -translation crlf |
| 3544 |
chan puts $f hello\nthere\nand\nhere |
| 3545 |
chan close $f |
| 3546 |
set f [open $path(test1) r] |
| 3547 |
chan configure $f -translation lf |
| 3548 |
lappend l [string length [chan gets $f]] |
| 3549 |
lappend l [chan tell $f] |
| 3550 |
lappend l [chan configure $f -translation] |
| 3551 |
lappend l [chan eof $f] |
| 3552 |
lappend l [string length [chan gets $f]] |
| 3553 |
lappend l [chan tell $f] |
| 3554 |
lappend l [chan configure $f -translation] |
| 3555 |
lappend l [chan eof $f] |
| 3556 |
} -cleanup { |
| 3557 |
chan close $f |
| 3558 |
} -result {6 7 lf 0 6 14 lf 0} |
| 3559 |
test chan-io-31.13 {binary mode is synonym of lf mode} -setup { |
| 3560 |
file delete $path(test1) |
| 3561 |
} -body { |
| 3562 |
set f [open $path(test1) w] |
| 3563 |
chan configure $f -translation binary |
| 3564 |
chan configure $f -translation |
| 3565 |
} -cleanup { |
| 3566 |
chan close $f |
| 3567 |
} -result lf |
| 3568 |
# |
| 3569 |
# Test chan-io-9.14 has been removed because "auto" output translation mode is |
| 3570 |
# not supported. |
| 3571 |
# |
| 3572 |
test chan-io-31.14 {Tcl_Write mixed, Tcl_Gets auto} -setup { |
| 3573 |
file delete $path(test1) |
| 3574 |
set l "" |
| 3575 |
} -body { |
| 3576 |
set f [open $path(test1) w] |
| 3577 |
chan configure $f -translation lf |
| 3578 |
chan puts $f hello\nthere\rand\r\nhere |
| 3579 |
chan close $f |
| 3580 |
set f [open $path(test1) r] |
| 3581 |
chan configure $f -translation auto |
| 3582 |
lappend l [chan gets $f] |
| 3583 |
lappend l [chan gets $f] |
| 3584 |
lappend l [chan gets $f] |
| 3585 |
lappend l [chan gets $f] |
| 3586 |
lappend l [chan eof $f] |
| 3587 |
lappend l [chan gets $f] |
| 3588 |
lappend l [chan eof $f] |
| 3589 |
} -cleanup { |
| 3590 |
chan close $f |
| 3591 |
} -result {hello there and here 0 {} 1} |
| 3592 |
test chan-io-31.15 {Tcl_Write mixed, Tcl_Gets auto} -setup { |
| 3593 |
file delete $path(test1) |
| 3594 |
set l "" |
| 3595 |
} -body { |
| 3596 |
set f [open $path(test1) w] |
| 3597 |
chan configure $f -translation lf |
| 3598 |
chan puts -nonewline $f hello\nthere\rand\r\nhere\r |
| 3599 |
chan close $f |
| 3600 |
set f [open $path(test1) r] |
| 3601 |
chan configure $f -translation auto |
| 3602 |
lappend l [chan gets $f] |
| 3603 |
lappend l [chan gets $f] |
| 3604 |
lappend l [chan gets $f] |
| 3605 |
lappend l [chan gets $f] |
| 3606 |
lappend l [chan eof $f] |
| 3607 |
lappend l [chan gets $f] |
| 3608 |
lappend l [chan eof $f] |
| 3609 |
} -cleanup { |
| 3610 |
chan close $f |
| 3611 |
} -result {hello there and here 0 {} 1} |
| 3612 |
test chan-io-31.16 {Tcl_Write mixed, Tcl_Gets auto} -setup { |
| 3613 |
file delete $path(test1) |
| 3614 |
set l "" |
| 3615 |
} -body { |
| 3616 |
set f [open $path(test1) w] |
| 3617 |
chan configure $f -translation lf |
| 3618 |
chan puts -nonewline $f hello\nthere\rand\r\nhere\n |
| 3619 |
chan close $f |
| 3620 |
set f [open $path(test1) r] |
| 3621 |
lappend l [chan gets $f] |
| 3622 |
lappend l [chan gets $f] |
| 3623 |
lappend l [chan gets $f] |
| 3624 |
lappend l [chan gets $f] |
| 3625 |
lappend l [chan eof $f] |
| 3626 |
lappend l [chan gets $f] |
| 3627 |
lappend l [chan eof $f] |
| 3628 |
} -cleanup { |
| 3629 |
chan close $f |
| 3630 |
} -result {hello there and here 0 {} 1} |
| 3631 |
test chan-io-31.17 {Tcl_Write mixed, Tcl_Gets auto} -setup { |
| 3632 |
file delete $path(test1) |
| 3633 |
set l "" |
| 3634 |
} -body { |
| 3635 |
set f [open $path(test1) w] |
| 3636 |
chan configure $f -translation lf |
| 3637 |
chan puts -nonewline $f hello\nthere\rand\r\nhere\r\n |
| 3638 |
chan close $f |
| 3639 |
set f [open $path(test1) r] |
| 3640 |
chan configure $f -translation auto |
| 3641 |
lappend l [chan gets $f] |
| 3642 |
lappend l [chan gets $f] |
| 3643 |
lappend l [chan gets $f] |
| 3644 |
lappend l [chan gets $f] |
| 3645 |
lappend l [chan eof $f] |
| 3646 |
lappend l [chan gets $f] |
| 3647 |
lappend l [chan eof $f] |
| 3648 |
} -cleanup { |
| 3649 |
chan close $f |
| 3650 |
} -result {hello there and here 0 {} 1} |
| 3651 |
test chan-io-31.18 {Tcl_Write ^Z at end, Tcl_Gets auto} -setup { |
| 3652 |
file delete $path(test1) |
| 3653 |
set l "" |
| 3654 |
} -body { |
| 3655 |
set f [open $path(test1) w] |
| 3656 |
chan configure $f -translation lf |
| 3657 |
chan puts $f [format "hello\nthere\nand\rhere\n\%c" 26] |
| 3658 |
chan close $f |
| 3659 |
set f [open $path(test1) r] |
| 3660 |
chan configure $f -translation auto -eofchar \x1A |
| 3661 |
lappend l [chan gets $f] |
| 3662 |
lappend l [chan gets $f] |
| 3663 |
lappend l [chan gets $f] |
| 3664 |
lappend l [chan gets $f] |
| 3665 |
lappend l [chan eof $f] |
| 3666 |
lappend l [chan gets $f] |
| 3667 |
lappend l [chan eof $f] |
| 3668 |
} -cleanup { |
| 3669 |
chan close $f |
| 3670 |
} -result {hello there and here 0 {} 1} |
| 3671 |
test chan-io-31.19 {Tcl_Write, implicit ^Z at end, Tcl_Gets auto} -setup { |
| 3672 |
file delete $path(test1) |
| 3673 |
set l "" |
| 3674 |
} -body { |
| 3675 |
set f [open $path(test1) w] |
| 3676 |
chan configure $f -translation lf -eofchar \x1A |
| 3677 |
chan puts $f hello\nthere\nand\rhere |
| 3678 |
chan close $f |
| 3679 |
set f [open $path(test1) r] |
| 3680 |
chan configure $f -translation auto -eofchar \x1A |
| 3681 |
lappend l [chan gets $f] |
| 3682 |
lappend l [chan gets $f] |
| 3683 |
lappend l [chan gets $f] |
| 3684 |
lappend l [chan gets $f] |
| 3685 |
lappend l [chan eof $f] |
| 3686 |
lappend l [chan gets $f] |
| 3687 |
lappend l [chan eof $f] |
| 3688 |
} -cleanup { |
| 3689 |
chan close $f |
| 3690 |
} -result {hello there and here 0 {} 1} |
| 3691 |
test chan-io-31.20 {Tcl_Write, ^Z in middle, Tcl_Gets auto, eofChar} -setup { |
| 3692 |
file delete $path(test1) |
| 3693 |
set l "" |
| 3694 |
} -body { |
| 3695 |
set f [open $path(test1) w] |
| 3696 |
chan configure $f -translation lf |
| 3697 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3698 |
chan close $f |
| 3699 |
set f [open $path(test1) r] |
| 3700 |
chan configure $f -translation auto -eofchar \x1A |
| 3701 |
lappend l [chan gets $f] |
| 3702 |
lappend l [chan gets $f] |
| 3703 |
lappend l [chan eof $f] |
| 3704 |
lappend l [chan gets $f] |
| 3705 |
lappend l [chan eof $f] |
| 3706 |
} -cleanup { |
| 3707 |
chan close $f |
| 3708 |
} -result {abc def 0 {} 1} |
| 3709 |
test chan-io-31.21 {Tcl_Write, no newline ^Z in middle, Tcl_Gets auto, eofChar} -setup { |
| 3710 |
file delete $path(test1) |
| 3711 |
set l "" |
| 3712 |
} -body { |
| 3713 |
set f [open $path(test1) w] |
| 3714 |
chan configure $f -translation lf |
| 3715 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3716 |
chan close $f |
| 3717 |
set f [open $path(test1) r] |
| 3718 |
chan configure $f -translation auto -eofchar \x1A |
| 3719 |
lappend l [chan gets $f] |
| 3720 |
lappend l [chan gets $f] |
| 3721 |
lappend l [chan eof $f] |
| 3722 |
lappend l [chan gets $f] |
| 3723 |
lappend l [chan eof $f] |
| 3724 |
} -cleanup { |
| 3725 |
chan close $f |
| 3726 |
} -result {abc def 0 {} 1} |
| 3727 |
test chan-io-31.22 {Tcl_Write, ^Z in middle ignored, Tcl_Gets lf} -setup { |
| 3728 |
file delete $path(test1) |
| 3729 |
set l "" |
| 3730 |
} -body { |
| 3731 |
set f [open $path(test1) w] |
| 3732 |
chan configure $f -translation lf -eofchar {} |
| 3733 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3734 |
chan close $f |
| 3735 |
set f [open $path(test1) r] |
| 3736 |
chan configure $f -translation lf -eofchar {} |
| 3737 |
lappend l [chan gets $f] |
| 3738 |
lappend l [chan gets $f] |
| 3739 |
lappend l [chan eof $f] |
| 3740 |
lappend l [chan gets $f] |
| 3741 |
lappend l [chan eof $f] |
| 3742 |
lappend l [chan gets $f] |
| 3743 |
lappend l [chan eof $f] |
| 3744 |
lappend l [chan gets $f] |
| 3745 |
lappend l [chan eof $f] |
| 3746 |
} -cleanup { |
| 3747 |
chan close $f |
| 3748 |
} -result "abc def 0 \x1Aqrs 0 tuv 0 {} 1" |
| 3749 |
test chan-io-31.23 {Tcl_Write, ^Z in middle ignored, Tcl_Gets cr} -setup { |
| 3750 |
file delete $path(test1) |
| 3751 |
set l "" |
| 3752 |
} -body { |
| 3753 |
set f [open $path(test1) w] |
| 3754 |
chan configure $f -translation cr -eofchar {} |
| 3755 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3756 |
chan close $f |
| 3757 |
set f [open $path(test1) r] |
| 3758 |
chan configure $f -translation cr -eofchar {} |
| 3759 |
lappend l [chan gets $f] |
| 3760 |
lappend l [chan gets $f] |
| 3761 |
lappend l [chan eof $f] |
| 3762 |
lappend l [chan gets $f] |
| 3763 |
lappend l [chan eof $f] |
| 3764 |
lappend l [chan gets $f] |
| 3765 |
lappend l [chan eof $f] |
| 3766 |
lappend l [chan gets $f] |
| 3767 |
lappend l [chan eof $f] |
| 3768 |
} -cleanup { |
| 3769 |
chan close $f |
| 3770 |
} -result "abc def 0 \x1Aqrs 0 tuv 0 {} 1" |
| 3771 |
test chan-io-31.24 {Tcl_Write, ^Z in middle ignored, Tcl_Gets crlf} -setup { |
| 3772 |
file delete $path(test1) |
| 3773 |
set l "" |
| 3774 |
} -body { |
| 3775 |
set f [open $path(test1) w] |
| 3776 |
chan configure $f -translation crlf -eofchar {} |
| 3777 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3778 |
chan close $f |
| 3779 |
set f [open $path(test1) r] |
| 3780 |
chan configure $f -translation crlf -eofchar {} |
| 3781 |
lappend l [chan gets $f] |
| 3782 |
lappend l [chan gets $f] |
| 3783 |
lappend l [chan eof $f] |
| 3784 |
lappend l [chan gets $f] |
| 3785 |
lappend l [chan eof $f] |
| 3786 |
lappend l [chan gets $f] |
| 3787 |
lappend l [chan eof $f] |
| 3788 |
lappend l [chan gets $f] |
| 3789 |
lappend l [chan eof $f] |
| 3790 |
} -cleanup { |
| 3791 |
chan close $f |
| 3792 |
} -result "abc def 0 \x1Aqrs 0 tuv 0 {} 1" |
| 3793 |
test chan-io-31.25 {Tcl_Write lf, ^Z in middle, Tcl_Gets auto} -setup { |
| 3794 |
file delete $path(test1) |
| 3795 |
set l "" |
| 3796 |
} -body { |
| 3797 |
set f [open $path(test1) w] |
| 3798 |
chan configure $f -translation lf |
| 3799 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3800 |
chan close $f |
| 3801 |
set f [open $path(test1) r] |
| 3802 |
chan configure $f -translation auto -eofchar \x1A |
| 3803 |
lappend l [chan gets $f] |
| 3804 |
lappend l [chan gets $f] |
| 3805 |
lappend l [chan eof $f] |
| 3806 |
lappend l [chan gets $f] |
| 3807 |
lappend l [chan eof $f] |
| 3808 |
} -cleanup { |
| 3809 |
chan close $f |
| 3810 |
} -result {abc def 0 {} 1} |
| 3811 |
test chan-io-31.26 {Tcl_Write lf, ^Z in middle, Tcl_Gets lf} -setup { |
| 3812 |
file delete $path(test1) |
| 3813 |
set l "" |
| 3814 |
} -body { |
| 3815 |
set f [open $path(test1) w] |
| 3816 |
chan configure $f -translation lf |
| 3817 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3818 |
chan close $f |
| 3819 |
set f [open $path(test1) r] |
| 3820 |
chan configure $f -translation lf -eofchar \x1A |
| 3821 |
lappend l [chan gets $f] |
| 3822 |
lappend l [chan gets $f] |
| 3823 |
lappend l [chan eof $f] |
| 3824 |
lappend l [chan gets $f] |
| 3825 |
lappend l [chan eof $f] |
| 3826 |
} -cleanup { |
| 3827 |
chan close $f |
| 3828 |
} -result {abc def 0 {} 1} |
| 3829 |
test chan-io-31.27 {Tcl_Write cr, ^Z in middle, Tcl_Gets auto} -setup { |
| 3830 |
file delete $path(test1) |
| 3831 |
set l "" |
| 3832 |
} -body { |
| 3833 |
set f [open $path(test1) w] |
| 3834 |
chan configure $f -translation cr -eofchar {} |
| 3835 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3836 |
chan close $f |
| 3837 |
set f [open $path(test1) r] |
| 3838 |
chan configure $f -translation auto -eofchar \x1A |
| 3839 |
lappend l [chan gets $f] |
| 3840 |
lappend l [chan gets $f] |
| 3841 |
lappend l [chan eof $f] |
| 3842 |
lappend l [chan gets $f] |
| 3843 |
lappend l [chan eof $f] |
| 3844 |
} -cleanup { |
| 3845 |
chan close $f |
| 3846 |
} -result {abc def 0 {} 1} |
| 3847 |
test chan-io-31.28 {Tcl_Write cr, ^Z in middle, Tcl_Gets cr} -setup { |
| 3848 |
file delete $path(test1) |
| 3849 |
set l "" |
| 3850 |
} -body { |
| 3851 |
set f [open $path(test1) w] |
| 3852 |
chan configure $f -translation cr -eofchar {} |
| 3853 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3854 |
chan close $f |
| 3855 |
set f [open $path(test1) r] |
| 3856 |
chan configure $f -translation cr -eofchar \x1A |
| 3857 |
lappend l [chan gets $f] |
| 3858 |
lappend l [chan gets $f] |
| 3859 |
lappend l [chan eof $f] |
| 3860 |
lappend l [chan gets $f] |
| 3861 |
lappend l [chan eof $f] |
| 3862 |
} -cleanup { |
| 3863 |
chan close $f |
| 3864 |
} -result {abc def 0 {} 1} |
| 3865 |
test chan-io-31.29 {Tcl_Write crlf, ^Z in middle, Tcl_Gets auto} -setup { |
| 3866 |
file delete $path(test1) |
| 3867 |
set l "" |
| 3868 |
} -body { |
| 3869 |
set f [open $path(test1) w] |
| 3870 |
chan configure $f -translation crlf -eofchar {} |
| 3871 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3872 |
chan close $f |
| 3873 |
set f [open $path(test1) r] |
| 3874 |
chan configure $f -translation auto -eofchar \x1A |
| 3875 |
lappend l [chan gets $f] |
| 3876 |
lappend l [chan gets $f] |
| 3877 |
lappend l [chan eof $f] |
| 3878 |
lappend l [chan gets $f] |
| 3879 |
lappend l [chan eof $f] |
| 3880 |
} -cleanup { |
| 3881 |
chan close $f |
| 3882 |
} -result {abc def 0 {} 1} |
| 3883 |
test chan-io-31.30 {Tcl_Write crlf, ^Z in middle, Tcl_Gets crlf} -setup { |
| 3884 |
file delete $path(test1) |
| 3885 |
set l "" |
| 3886 |
} -body { |
| 3887 |
set f [open $path(test1) w] |
| 3888 |
chan configure $f -translation crlf -eofchar {} |
| 3889 |
chan puts $f [format "abc\ndef\n%cqrs\ntuv" 26] |
| 3890 |
chan close $f |
| 3891 |
set f [open $path(test1) r] |
| 3892 |
chan configure $f -translation crlf -eofchar \x1A |
| 3893 |
lappend l [chan gets $f] |
| 3894 |
lappend l [chan gets $f] |
| 3895 |
lappend l [chan eof $f] |
| 3896 |
lappend l [chan gets $f] |
| 3897 |
lappend l [chan eof $f] |
| 3898 |
} -cleanup { |
| 3899 |
chan close $f |
| 3900 |
} -result {abc def 0 {} 1} |
| 3901 |
test chan-io-31.31 {Tcl_Write crlf on block boundary, Tcl_Gets crlf} -setup { |
| 3902 |
file delete $path(test1) |
| 3903 |
set c "" |
| 3904 |
} -body { |
| 3905 |
set f [open $path(test1) w] |
| 3906 |
chan configure $f -translation crlf |
| 3907 |
set line "123456789ABCDE" ;# 14 char plus crlf |
| 3908 |
chan puts -nonewline $f x ;# shift crlf across block boundary |
| 3909 |
for {set i 0} {$i < 700} {incr i} { |
| 3910 |
chan puts $f $line |
| 3911 |
} |
| 3912 |
chan close $f |
| 3913 |
set f [open $path(test1) r] |
| 3914 |
chan configure $f -translation crlf |
| 3915 |
while {[chan gets $f line] >= 0} { |
| 3916 |
append c $line\n |
| 3917 |
} |
| 3918 |
chan close $f |
| 3919 |
string length $c |
| 3920 |
} -result [expr {700*15 + 1}] |
| 3921 |
test chan-io-31.32 {Tcl_Write crlf on block boundary, Tcl_Gets auto} -setup { |
| 3922 |
file delete $path(test1) |
| 3923 |
set c "" |
| 3924 |
} -body { |
| 3925 |
set f [open $path(test1) w] |
| 3926 |
chan configure $f -translation crlf |
| 3927 |
set line "123456789ABCDE" ;# 14 char plus crlf |
| 3928 |
chan puts -nonewline $f x ;# shift crlf across block boundary |
| 3929 |
for {set i 0} {$i < 700} {incr i} { |
| 3930 |
chan puts $f $line |
| 3931 |
} |
| 3932 |
chan close $f |
| 3933 |
set f [open $path(test1) r] |
| 3934 |
chan configure $f -translation auto |
| 3935 |
while {[chan gets $f line] >= 0} { |
| 3936 |
append c $line\n |
| 3937 |
} |
| 3938 |
chan close $f |
| 3939 |
string length $c |
| 3940 |
} -result [expr {700*15 + 1}] |
| 3941 |
|
| 3942 |
# Test Tcl_Read and buffering. |
| 3943 |
|
| 3944 |
test chan-io-32.1 {Tcl_Read, channel not readable} -body { |
| 3945 |
read stdout |
| 3946 |
} -returnCodes error -result {channel "stdout" wasn't opened for reading} |
| 3947 |
test chan-io-32.2 {Tcl_Read, zero byte count} { |
| 3948 |
chan read stdin 0 |
| 3949 |
} "" |
| 3950 |
test chan-io-32.3 {Tcl_Read, negative byte count} -setup { |
| 3951 |
set f [open $path(longfile) r] |
| 3952 |
} -body { |
| 3953 |
chan read $f -1 |
| 3954 |
} -returnCodes error -cleanup { |
| 3955 |
chan close $f |
| 3956 |
} -result {expected non-negative integer but got "-1"} |
| 3957 |
test chan-io-32.4 {Tcl_Read, positive byte count} -body { |
| 3958 |
set f [open $path(longfile) r] |
| 3959 |
string length [chan read $f 1024] |
| 3960 |
} -cleanup { |
| 3961 |
chan close $f |
| 3962 |
} -result 1024 |
| 3963 |
test chan-io-32.5 {Tcl_Read, multiple buffers} -body { |
| 3964 |
set f [open $path(longfile) r] |
| 3965 |
chan configure $f -buffersize 100 |
| 3966 |
string length [chan read $f 1024] |
| 3967 |
} -cleanup { |
| 3968 |
chan close $f |
| 3969 |
} -result 1024 |
| 3970 |
test chan-io-32.6 {Tcl_Read, very large read} { |
| 3971 |
set f1 [open $path(longfile) r] |
| 3972 |
set z [chan read $f1 1000000] |
| 3973 |
chan close $f1 |
| 3974 |
set l [string length $z] |
| 3975 |
set x ok |
| 3976 |
set z [file size $path(longfile)] |
| 3977 |
if {$z != $l} { |
| 3978 |
set x "$z != $l" |
| 3979 |
} |
| 3980 |
set x |
| 3981 |
} ok |
| 3982 |
test chan-io-32.7 {Tcl_Read, nonblocking, file} {nonBlockFiles} { |
| 3983 |
set f1 [open $path(longfile) r] |
| 3984 |
chan configure $f1 -blocking off |
| 3985 |
set z [chan read $f1 20] |
| 3986 |
chan close $f1 |
| 3987 |
set l [string length $z] |
| 3988 |
set x ok |
| 3989 |
if {$l != 20} { |
| 3990 |
set x "$l != 20" |
| 3991 |
} |
| 3992 |
set x |
| 3993 |
} ok |
| 3994 |
test chan-io-32.8 {Tcl_Read, nonblocking, file} {nonBlockFiles} { |
| 3995 |
set f1 [open $path(longfile) r] |
| 3996 |
chan configure $f1 -blocking off |
| 3997 |
set z [chan read $f1 1000000] |
| 3998 |
chan close $f1 |
| 3999 |
set x ok |
| 4000 |
set l [string length $z] |
| 4001 |
set z [file size $path(longfile)] |
| 4002 |
if {$z != $l} { |
| 4003 |
set x "$z != $l" |
| 4004 |
} |
| 4005 |
set x |
| 4006 |
} ok |
| 4007 |
test chan-io-32.9 {Tcl_Read, read to end of file} { |
| 4008 |
set f1 [open $path(longfile) r] |
| 4009 |
set z [chan read $f1] |
| 4010 |
chan close $f1 |
| 4011 |
set l [string length $z] |
| 4012 |
set x ok |
| 4013 |
set z [file size $path(longfile)] |
| 4014 |
if {$z != $l} { |
| 4015 |
set x "$z != $l" |
| 4016 |
} |
| 4017 |
set x |
| 4018 |
} ok |
| 4019 |
test chan-io-32.10 {Tcl_Read from a pipe} -setup { |
| 4020 |
file delete $path(pipe) |
| 4021 |
} -constraints stdio -body { |
| 4022 |
set f1 [open $path(pipe) w] |
| 4023 |
chan puts $f1 {chan puts [chan gets stdin]} |
| 4024 |
chan close $f1 |
| 4025 |
set f1 [openpipe r+ $path(pipe)] |
| 4026 |
chan puts $f1 hello |
| 4027 |
chan flush $f1 |
| 4028 |
chan read $f1 |
| 4029 |
} -cleanup { |
| 4030 |
chan close $f1 |
| 4031 |
} -result "hello\n" |
| 4032 |
test chan-io-32.11 {Tcl_Read from a pipe} -setup { |
| 4033 |
file delete $path(pipe) |
| 4034 |
set x "" |
| 4035 |
} -constraints stdio -body { |
| 4036 |
set f1 [open $path(pipe) w] |
| 4037 |
chan puts $f1 {chan puts [chan gets stdin]} |
| 4038 |
chan puts $f1 {chan puts [chan gets stdin]} |
| 4039 |
chan close $f1 |
| 4040 |
set f1 [openpipe r+ $path(pipe)] |
| 4041 |
chan puts $f1 hello |
| 4042 |
chan flush $f1 |
| 4043 |
lappend x [chan read $f1 6] |
| 4044 |
chan puts $f1 hello |
| 4045 |
chan flush $f1 |
| 4046 |
lappend x [chan read $f1] |
| 4047 |
} -cleanup { |
| 4048 |
chan close $f1 |
| 4049 |
} -result {{hello |
| 4050 |
} {hello |
| 4051 |
}} |
| 4052 |
test chan-io-32.12 {Tcl_Read, -nonewline} -setup { |
| 4053 |
file delete $path(test1) |
| 4054 |
} -body { |
| 4055 |
set f1 [open $path(test1) w] |
| 4056 |
chan puts $f1 hello |
| 4057 |
chan puts $f1 bye |
| 4058 |
chan close $f1 |
| 4059 |
set f1 [open $path(test1) r] |
| 4060 |
chan read -nonewline $f1 |
| 4061 |
} -cleanup { |
| 4062 |
chan close $f1 |
| 4063 |
} -result {hello |
| 4064 |
bye} |
| 4065 |
test chan-io-32.13 {Tcl_Read, -nonewline} -setup { |
| 4066 |
file delete $path(test1) |
| 4067 |
} -body { |
| 4068 |
set f1 [open $path(test1) w] |
| 4069 |
chan puts $f1 hello |
| 4070 |
chan puts $f1 bye |
| 4071 |
chan close $f1 |
| 4072 |
set f1 [open $path(test1) r] |
| 4073 |
set c [chan read -nonewline $f1] |
| 4074 |
list [string length $c] $c |
| 4075 |
} -cleanup { |
| 4076 |
chan close $f1 |
| 4077 |
} -result {9 {hello |
| 4078 |
bye}} |
| 4079 |
test chan-io-32.14 {Tcl_Read, reading in small chunks} -setup { |
| 4080 |
file delete $path(test1) |
| 4081 |
} -body { |
| 4082 |
set f [open $path(test1) w] |
| 4083 |
chan puts $f "Two lines: this one" |
| 4084 |
chan puts $f "and this one" |
| 4085 |
chan close $f |
| 4086 |
set f [open $path(test1)] |
| 4087 |
list [chan read $f 1] [chan read $f 2] [chan read $f] |
| 4088 |
} -cleanup { |
| 4089 |
chan close $f |
| 4090 |
} -result {T wo { lines: this one |
| 4091 |
and this one |
| 4092 |
}} |
| 4093 |
test chan-io-32.15 {Tcl_Read, asking for more input than available} -setup { |
| 4094 |
file delete $path(test1) |
| 4095 |
} -body { |
| 4096 |
set f [open $path(test1) w] |
| 4097 |
chan puts $f "Two lines: this one" |
| 4098 |
chan puts $f "and this one" |
| 4099 |
chan close $f |
| 4100 |
set f [open $path(test1)] |
| 4101 |
chan read $f 100 |
| 4102 |
} -cleanup { |
| 4103 |
chan close $f |
| 4104 |
} -result {Two lines: this one |
| 4105 |
and this one |
| 4106 |
} |
| 4107 |
test chan-io-32.16 {Tcl_Read, read to end of file with -nonewline} -setup { |
| 4108 |
file delete $path(test1) |
| 4109 |
} -body { |
| 4110 |
set f [open $path(test1) w] |
| 4111 |
chan puts $f "Two lines: this one" |
| 4112 |
chan puts $f "and this one" |
| 4113 |
chan close $f |
| 4114 |
set f [open $path(test1)] |
| 4115 |
chan read -nonewline $f |
| 4116 |
} -cleanup { |
| 4117 |
chan close $f |
| 4118 |
} -result {Two lines: this one |
| 4119 |
and this one} |
| 4120 |
|
| 4121 |
# Test Tcl_Gets. |
| 4122 |
|
| 4123 |
test chan-io-33.1 {Tcl_Gets, reading what was written} -setup { |
| 4124 |
file delete $path(test1) |
| 4125 |
} -body { |
| 4126 |
set f1 [open $path(test1) w] |
| 4127 |
chan puts $f1 "first line" |
| 4128 |
chan close $f1 |
| 4129 |
set f1 [open $path(test1) r] |
| 4130 |
chan gets $f1 |
| 4131 |
} -cleanup { |
| 4132 |
chan close $f1 |
| 4133 |
} -result {first line} |
| 4134 |
test chan-io-33.2 {Tcl_Gets into variable} { |
| 4135 |
set f1 [open $path(longfile) r] |
| 4136 |
set c [chan gets $f1 x] |
| 4137 |
set l [string length x] |
| 4138 |
set z ok |
| 4139 |
if {$l != $l} { |
| 4140 |
set z broken |
| 4141 |
} |
| 4142 |
chan close $f1 |
| 4143 |
set z |
| 4144 |
} ok |
| 4145 |
test chan-io-33.3 {Tcl_Gets from pipe} -setup { |
| 4146 |
file delete $path(pipe) |
| 4147 |
} -constraints stdio -body { |
| 4148 |
set f1 [open $path(pipe) w] |
| 4149 |
chan puts $f1 {chan puts [chan gets stdin]} |
| 4150 |
chan close $f1 |
| 4151 |
set f1 [openpipe r+ $path(pipe)] |
| 4152 |
chan puts $f1 hello |
| 4153 |
chan flush $f1 |
| 4154 |
chan gets $f1 |
| 4155 |
} -cleanup { |
| 4156 |
chan close $f1 |
| 4157 |
} -result hello |
| 4158 |
test chan-io-33.4 {Tcl_Gets with long line} -setup { |
| 4159 |
file delete $path(test3) |
| 4160 |
} -body { |
| 4161 |
set f [open $path(test3) w] |
| 4162 |
chan puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4163 |
chan puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4164 |
chan puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4165 |
chan puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4166 |
chan puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4167 |
chan close $f |
| 4168 |
set f [open $path(test3)] |
| 4169 |
chan gets $f |
| 4170 |
} -cleanup { |
| 4171 |
chan close $f |
| 4172 |
} -result {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ} |
| 4173 |
test chan-io-33.5 {Tcl_Gets with long line} -setup { |
| 4174 |
set f [open $path(test3) w] |
| 4175 |
puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4176 |
puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4177 |
puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4178 |
puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4179 |
puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4180 |
close $f |
| 4181 |
} -body { |
| 4182 |
set f [open $path(test3)] |
| 4183 |
set x [chan gets $f y] |
| 4184 |
chan close $f |
| 4185 |
list $x $y |
| 4186 |
} -result {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ} |
| 4187 |
test chan-io-33.6 {Tcl_Gets and end of file} -setup { |
| 4188 |
file delete $path(test3) |
| 4189 |
set x {} |
| 4190 |
} -body { |
| 4191 |
set f [open $path(test3) w] |
| 4192 |
chan puts -nonewline $f "Test1\nTest2" |
| 4193 |
chan close $f |
| 4194 |
set f [open $path(test3)] |
| 4195 |
set y {} |
| 4196 |
lappend x [chan gets $f y] $y |
| 4197 |
set y {} |
| 4198 |
lappend x [chan gets $f y] $y |
| 4199 |
set y {} |
| 4200 |
lappend x [chan gets $f y] $y |
| 4201 |
} -cleanup { |
| 4202 |
chan close $f |
| 4203 |
} -result {5 Test1 5 Test2 -1 {}} |
| 4204 |
test chan-io-33.7 {Tcl_Gets and bad variable} -setup { |
| 4205 |
set f [open $path(test3) w] |
| 4206 |
chan puts $f "Line 1" |
| 4207 |
chan puts $f "Line 2" |
| 4208 |
chan close $f |
| 4209 |
catch {unset x} |
| 4210 |
set f [open $path(test3) r] |
| 4211 |
} -body { |
| 4212 |
set x 24 |
| 4213 |
chan gets $f x(0) |
| 4214 |
} -returnCodes error -cleanup { |
| 4215 |
chan close $f |
| 4216 |
} -result {can't set "x(0)": variable isn't array} |
| 4217 |
test chan-io-33.8 {Tcl_Gets, exercising double buffering} { |
| 4218 |
set f [open $path(test3) w] |
| 4219 |
chan configure $f -translation lf -eofchar {} |
| 4220 |
set x "" |
| 4221 |
for {set y 0} {$y < 99} {incr y} {set x "a$x"} |
| 4222 |
for {set y 0} {$y < 100} {incr y} {chan puts $f $x} |
| 4223 |
chan close $f |
| 4224 |
set f [open $path(test3) r] |
| 4225 |
chan configure $f -translation lf |
| 4226 |
for {set y 0} {$y < 100} {incr y} {chan gets $f} |
| 4227 |
chan close $f |
| 4228 |
set y |
| 4229 |
} 100 |
| 4230 |
test chan-io-33.9 {Tcl_Gets, exercising double buffering} { |
| 4231 |
set f [open $path(test3) w] |
| 4232 |
chan configure $f -translation lf -eofchar {} |
| 4233 |
set x "" |
| 4234 |
for {set y 0} {$y < 99} {incr y} {set x "a$x"} |
| 4235 |
for {set y 0} {$y < 200} {incr y} {chan puts $f $x} |
| 4236 |
chan close $f |
| 4237 |
set f [open $path(test3) r] |
| 4238 |
chan configure $f -translation lf |
| 4239 |
for {set y 0} {$y < 200} {incr y} {chan gets $f} |
| 4240 |
chan close $f |
| 4241 |
set y |
| 4242 |
} 200 |
| 4243 |
test chan-io-33.10 {Tcl_Gets, exercising double buffering} { |
| 4244 |
set f [open $path(test3) w] |
| 4245 |
chan configure $f -translation lf -eofchar {} |
| 4246 |
set x "" |
| 4247 |
for {set y 0} {$y < 99} {incr y} {set x "a$x"} |
| 4248 |
for {set y 0} {$y < 300} {incr y} {chan puts $f $x} |
| 4249 |
chan close $f |
| 4250 |
set f [open $path(test3) r] |
| 4251 |
chan configure $f -translation lf |
| 4252 |
for {set y 0} {$y < 300} {incr y} {chan gets $f} |
| 4253 |
chan close $f |
| 4254 |
set y |
| 4255 |
} 300 |
| 4256 |
|
| 4257 |
# Test Tcl_Seek and Tcl_Tell. |
| 4258 |
|
| 4259 |
test chan-io-34.1 {Tcl_Seek to current position at start of file} -body { |
| 4260 |
set f1 [open $path(longfile) r] |
| 4261 |
chan seek $f1 0 current |
| 4262 |
chan tell $f1 |
| 4263 |
} -cleanup { |
| 4264 |
chan close $f1 |
| 4265 |
} -result 0 |
| 4266 |
test chan-io-34.2 {Tcl_Seek to offset from start} -setup { |
| 4267 |
file delete $path(test1) |
| 4268 |
} -body { |
| 4269 |
set f1 [open $path(test1) w] |
| 4270 |
chan configure $f1 -translation lf -eofchar {} |
| 4271 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4272 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4273 |
chan close $f1 |
| 4274 |
set f1 [open $path(test1) r] |
| 4275 |
chan seek $f1 10 start |
| 4276 |
chan tell $f1 |
| 4277 |
} -cleanup { |
| 4278 |
chan close $f1 |
| 4279 |
} -result 10 |
| 4280 |
test chan-io-34.3 {Tcl_Seek to end of file} -setup { |
| 4281 |
file delete $path(test1) |
| 4282 |
} -body { |
| 4283 |
set f1 [open $path(test1) w] |
| 4284 |
chan configure $f1 -translation lf -eofchar {} |
| 4285 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4286 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4287 |
chan close $f1 |
| 4288 |
set f1 [open $path(test1) r] |
| 4289 |
chan seek $f1 0 end |
| 4290 |
chan tell $f1 |
| 4291 |
} -cleanup { |
| 4292 |
chan close $f1 |
| 4293 |
} -result 54 |
| 4294 |
test chan-io-34.4 {Tcl_Seek to offset from end of file} -setup { |
| 4295 |
file delete $path(test1) |
| 4296 |
} -body { |
| 4297 |
set f1 [open $path(test1) w] |
| 4298 |
chan configure $f1 -translation lf -eofchar {} |
| 4299 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4300 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4301 |
chan close $f1 |
| 4302 |
set f1 [open $path(test1) r] |
| 4303 |
chan seek $f1 -10 end |
| 4304 |
chan tell $f1 |
| 4305 |
} -cleanup { |
| 4306 |
chan close $f1 |
| 4307 |
} -result 44 |
| 4308 |
test chan-io-34.5 {Tcl_Seek to offset from current position} -setup { |
| 4309 |
file delete $path(test1) |
| 4310 |
} -body { |
| 4311 |
set f1 [open $path(test1) w] |
| 4312 |
chan configure $f1 -translation lf -eofchar {} |
| 4313 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4314 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4315 |
chan close $f1 |
| 4316 |
set f1 [open $path(test1) r] |
| 4317 |
chan seek $f1 10 current |
| 4318 |
chan seek $f1 10 current |
| 4319 |
chan tell $f1 |
| 4320 |
} -cleanup { |
| 4321 |
chan close $f1 |
| 4322 |
} -result 20 |
| 4323 |
test chan-io-34.6 {Tcl_Seek to offset from end of file} -setup { |
| 4324 |
file delete $path(test1) |
| 4325 |
} -body { |
| 4326 |
set f1 [open $path(test1) w] |
| 4327 |
chan configure $f1 -translation lf -eofchar {} |
| 4328 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4329 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4330 |
chan close $f1 |
| 4331 |
set f1 [open $path(test1) r] |
| 4332 |
chan seek $f1 -10 end |
| 4333 |
list [chan tell $f1] [chan read $f1] |
| 4334 |
} -cleanup { |
| 4335 |
chan close $f1 |
| 4336 |
} -result {44 {rstuvwxyz |
| 4337 |
}} |
| 4338 |
test chan-io-34.7 {Tcl_Seek to offset from end of file, then to current position} -setup { |
| 4339 |
file delete $path(test1) |
| 4340 |
} -body { |
| 4341 |
set f1 [open $path(test1) w] |
| 4342 |
chan configure $f1 -translation lf -eofchar {} |
| 4343 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4344 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4345 |
chan close $f1 |
| 4346 |
set f1 [open $path(test1) r] |
| 4347 |
chan seek $f1 -10 end |
| 4348 |
set c1 [chan tell $f1] |
| 4349 |
set r1 [chan read $f1 5] |
| 4350 |
chan seek $f1 0 current |
| 4351 |
list $c1 $r1 [chan tell $f1] |
| 4352 |
} -cleanup { |
| 4353 |
chan close $f1 |
| 4354 |
} -result {44 rstuv 49} |
| 4355 |
test chan-io-34.8 {Tcl_Seek on pipes: not supported} -setup { |
| 4356 |
set pipe [openpipe] |
| 4357 |
} -constraints stdio -body { |
| 4358 |
chan seek $pipe 0 current |
| 4359 |
} -returnCodes error -cleanup { |
| 4360 |
chan close $pipe |
| 4361 |
} -match glob -result {error during seek on "*": invalid argument} |
| 4362 |
test chan-io-34.9 {Tcl_Seek, testing buffered input flushing} -setup { |
| 4363 |
file delete $path(test3) |
| 4364 |
} -body { |
| 4365 |
set f [open $path(test3) w] |
| 4366 |
chan configure $f -eofchar {} |
| 4367 |
chan puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 4368 |
chan close $f |
| 4369 |
set f [open $path(test3) RDWR] |
| 4370 |
set x [chan read $f 1] |
| 4371 |
chan seek $f 3 |
| 4372 |
lappend x [chan read $f 1] |
| 4373 |
chan seek $f 0 start |
| 4374 |
lappend x [chan read $f 1] |
| 4375 |
chan seek $f 10 current |
| 4376 |
lappend x [chan read $f 1] |
| 4377 |
chan seek $f -2 end |
| 4378 |
lappend x [chan read $f 1] |
| 4379 |
chan seek $f 50 end |
| 4380 |
lappend x [chan read $f 1] |
| 4381 |
chan seek $f 1 |
| 4382 |
lappend x [chan read $f 1] |
| 4383 |
} -cleanup { |
| 4384 |
chan close $f |
| 4385 |
} -result {a d a l Y {} b} |
| 4386 |
set path(test3) [makeFile {} test3] |
| 4387 |
test chan-io-34.10 {Tcl_Seek testing flushing of buffered input} { |
| 4388 |
set f [open $path(test3) w] |
| 4389 |
chan configure $f -translation lf |
| 4390 |
chan puts $f xyz\n123 |
| 4391 |
chan close $f |
| 4392 |
set f [open $path(test3) r+] |
| 4393 |
chan configure $f -translation lf |
| 4394 |
set x [chan gets $f] |
| 4395 |
chan seek $f 0 current |
| 4396 |
chan puts $f 456 |
| 4397 |
chan close $f |
| 4398 |
list $x [viewFile test3] |
| 4399 |
} "xyz {xyz |
| 4400 |
456}" |
| 4401 |
test chan-io-34.11 {Tcl_Seek testing flushing of buffered output} { |
| 4402 |
set f [open $path(test3) w] |
| 4403 |
chan puts $f xyz\n123 |
| 4404 |
chan close $f |
| 4405 |
set f [open $path(test3) w+] |
| 4406 |
chan puts $f xyzzy |
| 4407 |
chan seek $f 2 |
| 4408 |
set x [chan gets $f] |
| 4409 |
chan close $f |
| 4410 |
list $x [viewFile test3] |
| 4411 |
} "zzy xyzzy" |
| 4412 |
test chan-io-34.12 {Tcl_Seek testing combination of write, seek back and read} { |
| 4413 |
set f [open $path(test3) w] |
| 4414 |
chan configure $f -translation lf -eofchar {} |
| 4415 |
chan puts $f xyz\n123 |
| 4416 |
chan close $f |
| 4417 |
set f [open $path(test3) a+] |
| 4418 |
chan configure $f -translation lf -eofchar {} |
| 4419 |
chan puts $f xyzzy |
| 4420 |
chan flush $f |
| 4421 |
set x [chan tell $f] |
| 4422 |
chan seek $f -4 cur |
| 4423 |
set y [chan gets $f] |
| 4424 |
chan close $f |
| 4425 |
list $x [viewFile test3] $y |
| 4426 |
} {14 {xyz |
| 4427 |
123 |
| 4428 |
xyzzy} zzy} |
| 4429 |
test chan-io-34.13 {Tcl_Tell at start of file} -setup { |
| 4430 |
file delete $path(test1) |
| 4431 |
} -body { |
| 4432 |
set f1 [open $path(test1) w] |
| 4433 |
chan tell $f1 |
| 4434 |
} -cleanup { |
| 4435 |
chan close $f1 |
| 4436 |
} -result 0 |
| 4437 |
test chan-io-34.14 {Tcl_Tell after seek to end of file} -setup { |
| 4438 |
file delete $path(test1) |
| 4439 |
} -body { |
| 4440 |
set f1 [open $path(test1) w] |
| 4441 |
chan configure $f1 -translation lf -eofchar {} |
| 4442 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4443 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4444 |
chan close $f1 |
| 4445 |
set f1 [open $path(test1) r] |
| 4446 |
chan seek $f1 0 end |
| 4447 |
chan tell $f1 |
| 4448 |
} -cleanup { |
| 4449 |
chan close $f1 |
| 4450 |
} -result 54 |
| 4451 |
test chan-io-34.15 {Tcl_Tell combined with seeking} -setup { |
| 4452 |
file delete $path(test1) |
| 4453 |
} -body { |
| 4454 |
set f1 [open $path(test1) w] |
| 4455 |
chan configure $f1 -translation lf -eofchar {} |
| 4456 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4457 |
chan puts $f1 "abcdefghijklmnopqrstuvwxyz" |
| 4458 |
chan close $f1 |
| 4459 |
set f1 [open $path(test1) r] |
| 4460 |
chan seek $f1 10 start |
| 4461 |
set c1 [chan tell $f1] |
| 4462 |
chan seek $f1 10 current |
| 4463 |
list $c1 [chan tell $f1] |
| 4464 |
} -cleanup { |
| 4465 |
chan close $f1 |
| 4466 |
} -result {10 20} |
| 4467 |
test chan-io-34.16 {Tcl_Tell on pipe: always -1} -constraints stdio -body { |
| 4468 |
set f1 [openpipe] |
| 4469 |
chan tell $f1 |
| 4470 |
} -cleanup { |
| 4471 |
chan close $f1 |
| 4472 |
} -result -1 |
| 4473 |
test chan-io-34.17 {Tcl_Tell on pipe: always -1} stdio { |
| 4474 |
set f1 [openpipe] |
| 4475 |
chan puts $f1 {chan puts hello} |
| 4476 |
chan flush $f1 |
| 4477 |
set c [chan tell $f1] |
| 4478 |
chan gets $f1 |
| 4479 |
chan close $f1 |
| 4480 |
set c |
| 4481 |
} -1 |
| 4482 |
test chan-io-34.18 {Tcl_Tell combined with seeking and reading} -setup { |
| 4483 |
file delete $path(test2) |
| 4484 |
} -body { |
| 4485 |
set f [open $path(test2) w] |
| 4486 |
chan configure $f -translation lf -eofchar {} |
| 4487 |
chan puts -nonewline $f "line1\nline2\nline3\nline4\nline5\n" |
| 4488 |
chan close $f |
| 4489 |
set f [open $path(test2)] |
| 4490 |
chan configure $f -translation lf |
| 4491 |
set x [chan tell $f] |
| 4492 |
chan read $f 3 |
| 4493 |
lappend x [chan tell $f] |
| 4494 |
chan seek $f 2 |
| 4495 |
lappend x [chan tell $f] |
| 4496 |
chan seek $f 10 current |
| 4497 |
lappend x [chan tell $f] |
| 4498 |
chan seek $f 0 end |
| 4499 |
lappend x [chan tell $f] |
| 4500 |
} -cleanup { |
| 4501 |
chan close $f |
| 4502 |
} -result {0 3 2 12 30} |
| 4503 |
test chan-io-34.19 {Tcl_Tell combined with opening in append mode} -body { |
| 4504 |
set f [open $path(test3) w] |
| 4505 |
chan configure $f -translation lf -eofchar {} |
| 4506 |
chan puts $f "abcdefghijklmnopqrstuvwxyz" |
| 4507 |
chan puts $f "abcdefghijklmnopqrstuvwxyz" |
| 4508 |
chan close $f |
| 4509 |
set f [open $path(test3) a] |
| 4510 |
chan tell $f |
| 4511 |
} -cleanup { |
| 4512 |
chan close $f |
| 4513 |
} -result 54 |
| 4514 |
test chan-io-34.20 {Tcl_Tell combined with writing} -setup { |
| 4515 |
set l "" |
| 4516 |
} -body { |
| 4517 |
set f [open $path(test3) w] |
| 4518 |
chan seek $f 29 start |
| 4519 |
lappend l [chan tell $f] |
| 4520 |
chan puts -nonewline $f a |
| 4521 |
chan seek $f 39 start |
| 4522 |
lappend l [chan tell $f] |
| 4523 |
chan puts -nonewline $f a |
| 4524 |
lappend l [chan tell $f] |
| 4525 |
chan seek $f 407 end |
| 4526 |
lappend l [chan tell $f] |
| 4527 |
} -cleanup { |
| 4528 |
chan close $f |
| 4529 |
} -result {29 39 40 447} |
| 4530 |
test chan-io-34.21 {Tcl_Seek and Tcl_Tell on large files} -setup { |
| 4531 |
file delete $path(test3) |
| 4532 |
set l "" |
| 4533 |
} -constraints {largefileSupport extensive} -body { |
| 4534 |
set f [open $path(test3) w] |
| 4535 |
chan configure $f -encoding binary |
| 4536 |
lappend l [chan tell $f] |
| 4537 |
chan puts -nonewline $f abcdef |
| 4538 |
lappend l [chan tell $f] |
| 4539 |
chan flush $f |
| 4540 |
lappend l [chan tell $f] |
| 4541 |
# 4GB offset! |
| 4542 |
chan seek $f 0x100000000 |
| 4543 |
lappend l [chan tell $f] |
| 4544 |
chan puts -nonewline $f abcdef |
| 4545 |
lappend l [chan tell $f] |
| 4546 |
chan close $f |
| 4547 |
lappend l [file size $path(test3)] |
| 4548 |
# truncate... |
| 4549 |
chan close [open $path(test3) w] |
| 4550 |
lappend l [file size $path(test3)] |
| 4551 |
} -result {0 6 6 4294967296 4294967302 4294967302 0} |
| 4552 |
|
| 4553 |
# Test Tcl_Eof |
| 4554 |
|
| 4555 |
test chan-io-35.1 {Tcl_Eof} -setup { |
| 4556 |
file delete $path(test1) |
| 4557 |
} -body { |
| 4558 |
set f [open $path(test1) w] |
| 4559 |
chan puts $f hello |
| 4560 |
chan puts $f hello |
| 4561 |
chan close $f |
| 4562 |
set f [open $path(test1)] |
| 4563 |
set x [chan eof $f] |
| 4564 |
lappend x [chan eof $f] |
| 4565 |
chan gets $f |
| 4566 |
lappend x [chan eof $f] |
| 4567 |
chan gets $f |
| 4568 |
lappend x [chan eof $f] |
| 4569 |
chan gets $f |
| 4570 |
lappend x [chan eof $f] |
| 4571 |
lappend x [chan eof $f] |
| 4572 |
} -cleanup { |
| 4573 |
chan close $f |
| 4574 |
} -result {0 0 0 0 1 1} |
| 4575 |
test chan-io-35.2 {Tcl_Eof with pipe} -constraints stdio -setup { |
| 4576 |
file delete $path(pipe) |
| 4577 |
} -body { |
| 4578 |
set f1 [open $path(pipe) w] |
| 4579 |
chan puts $f1 {chan gets stdin} |
| 4580 |
chan puts $f1 {chan puts hello} |
| 4581 |
chan close $f1 |
| 4582 |
set f1 [openpipe r+ $path(pipe)] |
| 4583 |
chan puts $f1 hello |
| 4584 |
set x [chan eof $f1] |
| 4585 |
chan flush $f1 |
| 4586 |
lappend x [chan eof $f1] |
| 4587 |
chan gets $f1 |
| 4588 |
lappend x [chan eof $f1] |
| 4589 |
chan gets $f1 |
| 4590 |
lappend x [chan eof $f1] |
| 4591 |
} -cleanup { |
| 4592 |
chan close $f1 |
| 4593 |
} -result {0 0 0 1} |
| 4594 |
test chan-io-35.3 {Tcl_Eof with pipe} -constraints stdio -setup { |
| 4595 |
file delete $path(pipe) |
| 4596 |
} -body { |
| 4597 |
set f1 [open $path(pipe) w] |
| 4598 |
chan puts $f1 {chan gets stdin} |
| 4599 |
chan puts $f1 {chan puts hello} |
| 4600 |
chan close $f1 |
| 4601 |
set f1 [openpipe r+ $path(pipe)] |
| 4602 |
chan puts $f1 hello |
| 4603 |
set x [chan eof $f1] |
| 4604 |
chan flush $f1 |
| 4605 |
lappend x [chan eof $f1] |
| 4606 |
chan gets $f1 |
| 4607 |
lappend x [chan eof $f1] |
| 4608 |
chan gets $f1 |
| 4609 |
lappend x [chan eof $f1] |
| 4610 |
chan gets $f1 |
| 4611 |
lappend x [chan eof $f1] |
| 4612 |
chan gets $f1 |
| 4613 |
lappend x [chan eof $f1] |
| 4614 |
} -cleanup { |
| 4615 |
chan close $f1 |
| 4616 |
} -result {0 0 0 1 1 1} |
| 4617 |
test chan-io-35.4 {Tcl_Eof, eof detection on nonblocking file} -setup { |
| 4618 |
file delete $path(test1) |
| 4619 |
set l "" |
| 4620 |
} -constraints {nonBlockFiles} -body { |
| 4621 |
chan close [open $path(test1) w] |
| 4622 |
set f [open $path(test1) r] |
| 4623 |
chan configure $f -blocking off |
| 4624 |
lappend l [chan gets $f] |
| 4625 |
lappend l [chan eof $f] |
| 4626 |
} -cleanup { |
| 4627 |
chan close $f |
| 4628 |
} -result {{} 1} |
| 4629 |
test chan-io-35.5 {Tcl_Eof, eof detection on nonblocking pipe} -setup { |
| 4630 |
file delete $path(pipe) |
| 4631 |
set l "" |
| 4632 |
} -constraints stdio -body { |
| 4633 |
set f [open $path(pipe) w] |
| 4634 |
chan puts $f { |
| 4635 |
exit |
| 4636 |
} |
| 4637 |
chan close $f |
| 4638 |
set f [openpipe r $path(pipe)] |
| 4639 |
lappend l [chan gets $f] |
| 4640 |
lappend l [chan eof $f] |
| 4641 |
} -cleanup { |
| 4642 |
chan close $f |
| 4643 |
} -result {{} 1} |
| 4644 |
test chan-io-35.6 {Tcl_Eof, eof char, lf write, auto read} -setup { |
| 4645 |
file delete $path(test1) |
| 4646 |
} -body { |
| 4647 |
set f [open $path(test1) w] |
| 4648 |
chan configure $f -translation lf -eofchar \x1A |
| 4649 |
chan puts $f abc\ndef |
| 4650 |
chan close $f |
| 4651 |
set s [file size $path(test1)] |
| 4652 |
set f [open $path(test1) r] |
| 4653 |
chan configure $f -translation auto -eofchar \x1A |
| 4654 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4655 |
} -cleanup { |
| 4656 |
chan close $f |
| 4657 |
} -result {9 8 1} |
| 4658 |
test chan-io-35.7 {Tcl_Eof, eof char, lf write, lf read} -setup { |
| 4659 |
file delete $path(test1) |
| 4660 |
} -body { |
| 4661 |
set f [open $path(test1) w] |
| 4662 |
chan configure $f -translation lf -eofchar \x1A |
| 4663 |
chan puts $f abc\ndef |
| 4664 |
chan close $f |
| 4665 |
set s [file size $path(test1)] |
| 4666 |
set f [open $path(test1) r] |
| 4667 |
chan configure $f -translation lf -eofchar \x1A |
| 4668 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4669 |
} -cleanup { |
| 4670 |
chan close $f |
| 4671 |
} -result {9 8 1} |
| 4672 |
test chan-io-35.8 {Tcl_Eof, eof char, cr write, auto read} -setup { |
| 4673 |
file delete $path(test1) |
| 4674 |
} -body { |
| 4675 |
set f [open $path(test1) w] |
| 4676 |
chan configure $f -translation cr -eofchar \x1A |
| 4677 |
chan puts $f abc\ndef |
| 4678 |
chan close $f |
| 4679 |
set s [file size $path(test1)] |
| 4680 |
set f [open $path(test1) r] |
| 4681 |
chan configure $f -translation auto -eofchar \x1A |
| 4682 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4683 |
} -cleanup { |
| 4684 |
chan close $f |
| 4685 |
} -result {9 8 1} |
| 4686 |
test chan-io-35.9 {Tcl_Eof, eof char, cr write, cr read} -setup { |
| 4687 |
file delete $path(test1) |
| 4688 |
} -body { |
| 4689 |
set f [open $path(test1) w] |
| 4690 |
chan configure $f -translation cr -eofchar \x1A |
| 4691 |
chan puts $f abc\ndef |
| 4692 |
chan close $f |
| 4693 |
set s [file size $path(test1)] |
| 4694 |
set f [open $path(test1) r] |
| 4695 |
chan configure $f -translation cr -eofchar \x1A |
| 4696 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4697 |
} -cleanup { |
| 4698 |
chan close $f |
| 4699 |
} -result {9 8 1} |
| 4700 |
test chan-io-35.10 {Tcl_Eof, eof char, crlf write, auto read} -setup { |
| 4701 |
file delete $path(test1) |
| 4702 |
} -body { |
| 4703 |
set f [open $path(test1) w] |
| 4704 |
chan configure $f -translation crlf -eofchar \x1A |
| 4705 |
chan puts $f abc\ndef |
| 4706 |
chan close $f |
| 4707 |
set s [file size $path(test1)] |
| 4708 |
set f [open $path(test1) r] |
| 4709 |
chan configure $f -translation auto -eofchar \x1A |
| 4710 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4711 |
} -cleanup { |
| 4712 |
chan close $f |
| 4713 |
} -result {11 8 1} |
| 4714 |
test chan-io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} -setup { |
| 4715 |
file delete $path(test1) |
| 4716 |
} -body { |
| 4717 |
set f [open $path(test1) w] |
| 4718 |
chan configure $f -translation crlf -eofchar \x1A |
| 4719 |
chan puts $f abc\ndef |
| 4720 |
chan close $f |
| 4721 |
set s [file size $path(test1)] |
| 4722 |
set f [open $path(test1) r] |
| 4723 |
chan configure $f -translation crlf -eofchar \x1A |
| 4724 |
list $s [string length [chan read $f]] [chan eof $f] |
| 4725 |
} -cleanup { |
| 4726 |
chan close $f |
| 4727 |
} -result {11 8 1} |
| 4728 |
test chan-io-35.12 {Tcl_Eof, eof char in middle, lf write, auto read} -setup { |
| 4729 |
file delete $path(test1) |
| 4730 |
} -body { |
| 4731 |
set f [open $path(test1) w] |
| 4732 |
chan configure $f -translation lf -eofchar {} |
| 4733 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4734 |
chan close $f |
| 4735 |
set c [file size $path(test1)] |
| 4736 |
set f [open $path(test1) r] |
| 4737 |
chan configure $f -translation auto -eofchar \x1A |
| 4738 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4739 |
} -cleanup { |
| 4740 |
chan close $f |
| 4741 |
} -result {17 8 1} |
| 4742 |
test chan-io-35.13 {Tcl_Eof, eof char in middle, lf write, lf read} -setup { |
| 4743 |
file delete $path(test1) |
| 4744 |
} -body { |
| 4745 |
set f [open $path(test1) w] |
| 4746 |
chan configure $f -translation lf -eofchar {} |
| 4747 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4748 |
chan close $f |
| 4749 |
set c [file size $path(test1)] |
| 4750 |
set f [open $path(test1) r] |
| 4751 |
chan configure $f -translation lf -eofchar \x1A |
| 4752 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4753 |
} -cleanup { |
| 4754 |
chan close $f |
| 4755 |
} -result {17 8 1} |
| 4756 |
test chan-io-35.14 {Tcl_Eof, eof char in middle, cr write, auto read} -setup { |
| 4757 |
file delete $path(test1) |
| 4758 |
} -body { |
| 4759 |
set f [open $path(test1) w] |
| 4760 |
chan configure $f -translation cr -eofchar {} |
| 4761 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4762 |
chan close $f |
| 4763 |
set c [file size $path(test1)] |
| 4764 |
set f [open $path(test1) r] |
| 4765 |
chan configure $f -translation auto -eofchar \x1A |
| 4766 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4767 |
} -cleanup { |
| 4768 |
chan close $f |
| 4769 |
} -result {17 8 1} |
| 4770 |
test chan-io-35.15 {Tcl_Eof, eof char in middle, cr write, cr read} -setup { |
| 4771 |
file delete $path(test1) |
| 4772 |
} -body { |
| 4773 |
set f [open $path(test1) w] |
| 4774 |
chan configure $f -translation cr -eofchar {} |
| 4775 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4776 |
chan close $f |
| 4777 |
set c [file size $path(test1)] |
| 4778 |
set f [open $path(test1) r] |
| 4779 |
chan configure $f -translation cr -eofchar \x1A |
| 4780 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4781 |
} -cleanup { |
| 4782 |
chan close $f |
| 4783 |
} -result {17 8 1} |
| 4784 |
test chan-io-35.16 {Tcl_Eof, eof char in middle, crlf write, auto read} -setup { |
| 4785 |
file delete $path(test1) |
| 4786 |
} -body { |
| 4787 |
set f [open $path(test1) w] |
| 4788 |
chan configure $f -translation crlf -eofchar {} |
| 4789 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4790 |
chan close $f |
| 4791 |
set c [file size $path(test1)] |
| 4792 |
set f [open $path(test1) r] |
| 4793 |
chan configure $f -translation auto -eofchar \x1A |
| 4794 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4795 |
} -cleanup { |
| 4796 |
chan close $f |
| 4797 |
} -result {21 8 1} |
| 4798 |
test chan-io-35.17 {Tcl_Eof, eof char in middle, crlf write, crlf read} -setup { |
| 4799 |
file delete $path(test1) |
| 4800 |
} -body { |
| 4801 |
set f [open $path(test1) w] |
| 4802 |
chan configure $f -translation crlf -eofchar {} |
| 4803 |
chan puts $f [format abc\ndef\n%cqrs\nuvw 26] |
| 4804 |
chan close $f |
| 4805 |
set c [file size $path(test1)] |
| 4806 |
set f [open $path(test1) r] |
| 4807 |
chan configure $f -translation crlf -eofchar \x1A |
| 4808 |
list $c [string length [chan read $f]] [chan eof $f] |
| 4809 |
} -cleanup { |
| 4810 |
chan close $f |
| 4811 |
} -result {21 8 1} |
| 4812 |
|
| 4813 |
# Test Tcl_InputBlocked |
| 4814 |
|
| 4815 |
test chan-io-36.1 {Tcl_InputBlocked on nonblocking pipe} -setup { |
| 4816 |
set x "" |
| 4817 |
} -constraints stdio -body { |
| 4818 |
set f1 [openpipe] |
| 4819 |
chan puts $f1 {chan puts hello_from_pipe} |
| 4820 |
chan flush $f1 |
| 4821 |
chan gets $f1 |
| 4822 |
chan configure $f1 -blocking off -buffering full |
| 4823 |
chan puts $f1 {chan puts hello} |
| 4824 |
lappend x [chan gets $f1] |
| 4825 |
lappend x [chan blocked $f1] |
| 4826 |
chan flush $f1 |
| 4827 |
after 200 |
| 4828 |
lappend x [chan gets $f1] |
| 4829 |
lappend x [chan blocked $f1] |
| 4830 |
lappend x [chan gets $f1] |
| 4831 |
lappend x [chan blocked $f1] |
| 4832 |
} -cleanup { |
| 4833 |
chan close $f1 |
| 4834 |
} -result {{} 1 hello 0 {} 1} |
| 4835 |
test chan-io-36.2 {Tcl_InputBlocked on blocking pipe} -setup { |
| 4836 |
set x "" |
| 4837 |
} -constraints stdio -body { |
| 4838 |
set f1 [openpipe] |
| 4839 |
chan configure $f1 -buffering line |
| 4840 |
chan puts $f1 {chan puts hello_from_pipe} |
| 4841 |
lappend x [chan gets $f1] |
| 4842 |
lappend x [chan blocked $f1] |
| 4843 |
chan puts $f1 {exit} |
| 4844 |
lappend x [chan gets $f1] |
| 4845 |
lappend x [chan blocked $f1] |
| 4846 |
lappend x [chan eof $f1] |
| 4847 |
} -cleanup { |
| 4848 |
chan close $f1 |
| 4849 |
} -result {hello_from_pipe 0 {} 0 1} |
| 4850 |
test chan-io-36.3 {Tcl_InputBlocked vs files, short read} -setup { |
| 4851 |
file delete $path(test1) |
| 4852 |
set l "" |
| 4853 |
} -body { |
| 4854 |
set f [open $path(test1) w] |
| 4855 |
chan puts $f abcdefghijklmnop |
| 4856 |
chan close $f |
| 4857 |
set f [open $path(test1) r] |
| 4858 |
lappend l [chan blocked $f] |
| 4859 |
lappend l [chan read $f 3] |
| 4860 |
lappend l [chan blocked $f] |
| 4861 |
lappend l [chan read -nonewline $f] |
| 4862 |
lappend l [chan blocked $f] |
| 4863 |
lappend l [chan eof $f] |
| 4864 |
} -cleanup { |
| 4865 |
chan close $f |
| 4866 |
} -result {0 abc 0 defghijklmnop 0 1} |
| 4867 |
test chan-io-36.4 {Tcl_InputBlocked vs files, event driven read} -setup { |
| 4868 |
file delete $path(test1) |
| 4869 |
set l "" |
| 4870 |
variable x |
| 4871 |
} -constraints {fileevent} -body { |
| 4872 |
set f [open $path(test1) w] |
| 4873 |
chan puts $f abcdefghijklmnop |
| 4874 |
chan close $f |
| 4875 |
set f [open $path(test1) r] |
| 4876 |
chan event $f readable [namespace code { |
| 4877 |
lappend l [chan read $f 3] |
| 4878 |
if {[chan eof $f]} {lappend l eof; chan close $f; set x done} |
| 4879 |
}] |
| 4880 |
vwait [namespace which -variable x] |
| 4881 |
return $l |
| 4882 |
} -result {abc def ghi jkl mno {p |
| 4883 |
} eof} |
| 4884 |
test chan-io-36.5 {Tcl_InputBlocked vs files, short read, nonblocking} -setup { |
| 4885 |
file delete $path(test1) |
| 4886 |
set l "" |
| 4887 |
} -constraints {nonBlockFiles} -body { |
| 4888 |
set f [open $path(test1) w] |
| 4889 |
chan puts $f abcdefghijklmnop |
| 4890 |
chan close $f |
| 4891 |
set f [open $path(test1) r] |
| 4892 |
chan configure $f -blocking off |
| 4893 |
lappend l [chan blocked $f] |
| 4894 |
lappend l [chan read $f 3] |
| 4895 |
lappend l [chan blocked $f] |
| 4896 |
lappend l [chan read -nonewline $f] |
| 4897 |
lappend l [chan blocked $f] |
| 4898 |
lappend l [chan eof $f] |
| 4899 |
} -cleanup { |
| 4900 |
chan close $f |
| 4901 |
} -result {0 abc 0 defghijklmnop 0 1} |
| 4902 |
test chan-io-36.6 {Tcl_InputBlocked vs files, event driven read} -setup { |
| 4903 |
file delete $path(test1) |
| 4904 |
set l "" |
| 4905 |
variable x |
| 4906 |
} -constraints {nonBlockFiles fileevent} -body { |
| 4907 |
set f [open $path(test1) w] |
| 4908 |
chan puts $f abcdefghijklmnop |
| 4909 |
chan close $f |
| 4910 |
set f [open $path(test1) r] |
| 4911 |
chan configure $f -blocking off |
| 4912 |
chan event $f readable [namespace code { |
| 4913 |
lappend l [chan read $f 3] |
| 4914 |
if {[chan eof $f]} {lappend l eof; chan close $f; set x done} |
| 4915 |
}] |
| 4916 |
vwait [namespace which -variable x] |
| 4917 |
return $l |
| 4918 |
} -result {abc def ghi jkl mno {p |
| 4919 |
} eof} |
| 4920 |
|
| 4921 |
# Test Tcl_InputBuffered |
| 4922 |
|
| 4923 |
test chan-io-37.1 {Tcl_InputBuffered} -setup { |
| 4924 |
set l "" |
| 4925 |
} -constraints {testchannel} -body { |
| 4926 |
set f [open $path(longfile) r] |
| 4927 |
chan configure $f -buffersize 4096 |
| 4928 |
chan read $f 3 |
| 4929 |
lappend l [testchannel inputbuffered $f] |
| 4930 |
lappend l [chan tell $f] |
| 4931 |
} -cleanup { |
| 4932 |
chan close $f |
| 4933 |
} -result {4093 3} |
| 4934 |
test chan-io-37.2 {Tcl_InputBuffered, test input flushing on seek} -setup { |
| 4935 |
set l "" |
| 4936 |
} -constraints {testchannel} -body { |
| 4937 |
set f [open $path(longfile) r] |
| 4938 |
chan configure $f -buffersize 4096 |
| 4939 |
chan read $f 3 |
| 4940 |
lappend l [testchannel inputbuffered $f] |
| 4941 |
lappend l [chan tell $f] |
| 4942 |
chan seek $f 0 current |
| 4943 |
lappend l [testchannel inputbuffered $f] |
| 4944 |
lappend l [chan tell $f] |
| 4945 |
} -cleanup { |
| 4946 |
chan close $f |
| 4947 |
} -result {4093 3 0 3} |
| 4948 |
|
| 4949 |
# Test Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize |
| 4950 |
|
| 4951 |
test chan-io-38.1 {Tcl_GetChannelBufferSize, default buffer size} -body { |
| 4952 |
set f [open $path(longfile) r] |
| 4953 |
chan configure $f -buffersize |
| 4954 |
} -cleanup { |
| 4955 |
chan close $f |
| 4956 |
} -result 4096 |
| 4957 |
test chan-io-38.2 {Tcl_SetChannelBufferSize, Tcl_GetChannelBufferSize} -setup { |
| 4958 |
set l "" |
| 4959 |
} -body { |
| 4960 |
set f [open $path(longfile) r] |
| 4961 |
lappend l [chan configure $f -buffersize] |
| 4962 |
chan configure $f -buffersize 10000 |
| 4963 |
lappend l [chan configure $f -buffersize] |
| 4964 |
chan configure $f -buffersize 1 |
| 4965 |
lappend l [chan configure $f -buffersize] |
| 4966 |
chan configure $f -buffersize -1 |
| 4967 |
lappend l [chan configure $f -buffersize] |
| 4968 |
chan configure $f -buffersize 0 |
| 4969 |
lappend l [chan configure $f -buffersize] |
| 4970 |
chan configure $f -buffersize 100000 |
| 4971 |
lappend l [chan configure $f -buffersize] |
| 4972 |
chan configure $f -buffersize 10000000 |
| 4973 |
lappend l [chan configure $f -buffersize] |
| 4974 |
} -cleanup { |
| 4975 |
chan close $f |
| 4976 |
} -result {4096 10000 1 1 1 100000 1048576} |
| 4977 |
test chan-io-38.3 {Tcl_SetChannelBufferSize, changing buffersize between reads} { |
| 4978 |
# This test crashes the interp if Bug #427196 is not fixed |
| 4979 |
set chan [open [info script] r] |
| 4980 |
chan configure $chan -buffersize 10 |
| 4981 |
set var [chan read $chan 2] |
| 4982 |
chan configure $chan -buffersize 32 |
| 4983 |
append var [chan read $chan] |
| 4984 |
chan close $chan |
| 4985 |
} {} |
| 4986 |
|
| 4987 |
# Test Tcl_SetChannelOption, Tcl_GetChannelOption |
| 4988 |
|
| 4989 |
test chan-io-39.1 {Tcl_GetChannelOption} -setup { |
| 4990 |
file delete $path(test1) |
| 4991 |
} -body { |
| 4992 |
set f1 [open $path(test1) w] |
| 4993 |
chan configure $f1 -blocking |
| 4994 |
} -cleanup { |
| 4995 |
chan close $f1 |
| 4996 |
} -result 1 |
| 4997 |
# |
| 4998 |
# Test 17.2 was removed. |
| 4999 |
# |
| 5000 |
test chan-io-39.2 {Tcl_GetChannelOption} -setup { |
| 5001 |
file delete $path(test1) |
| 5002 |
} -body { |
| 5003 |
set f1 [open $path(test1) w] |
| 5004 |
chan configure $f1 -buffering |
| 5005 |
} -cleanup { |
| 5006 |
chan close $f1 |
| 5007 |
} -result full |
| 5008 |
test chan-io-39.3 {Tcl_GetChannelOption} -setup { |
| 5009 |
file delete $path(test1) |
| 5010 |
} -body { |
| 5011 |
set f1 [open $path(test1) w] |
| 5012 |
chan configure $f1 -buffering line |
| 5013 |
chan configure $f1 -buffering |
| 5014 |
} -cleanup { |
| 5015 |
chan close $f1 |
| 5016 |
} -result line |
| 5017 |
test chan-io-39.4 {Tcl_GetChannelOption, Tcl_SetChannelOption} -setup { |
| 5018 |
file delete $path(test1) |
| 5019 |
set l "" |
| 5020 |
} -body { |
| 5021 |
set f1 [open $path(test1) w] |
| 5022 |
lappend l [chan configure $f1 -buffering] |
| 5023 |
chan configure $f1 -buffering line |
| 5024 |
lappend l [chan configure $f1 -buffering] |
| 5025 |
chan configure $f1 -buffering none |
| 5026 |
lappend l [chan configure $f1 -buffering] |
| 5027 |
chan configure $f1 -buffering line |
| 5028 |
lappend l [chan configure $f1 -buffering] |
| 5029 |
chan configure $f1 -buffering full |
| 5030 |
lappend l [chan configure $f1 -buffering] |
| 5031 |
} -cleanup { |
| 5032 |
chan close $f1 |
| 5033 |
} -result {full line none line full} |
| 5034 |
test chan-io-39.5 {Tcl_GetChannelOption, invariance} -setup { |
| 5035 |
file delete $path(test1) |
| 5036 |
set l "" |
| 5037 |
} -body { |
| 5038 |
set f1 [open $path(test1) w] |
| 5039 |
lappend l [chan configure $f1 -buffering] |
| 5040 |
lappend l [list [catch {chan configure $f1 -buffering green} msg] $msg] |
| 5041 |
lappend l [chan configure $f1 -buffering] |
| 5042 |
} -cleanup { |
| 5043 |
chan close $f1 |
| 5044 |
} -result {full {1 {bad value for -buffering: must be one of full, line, or none}} full} |
| 5045 |
test chan-io-39.6 {Tcl_SetChannelOption, multiple options} -setup { |
| 5046 |
file delete $path(test1) |
| 5047 |
} -body { |
| 5048 |
set f1 [open $path(test1) w] |
| 5049 |
chan configure $f1 -translation lf -buffering line |
| 5050 |
chan puts $f1 hello |
| 5051 |
chan puts $f1 bye |
| 5052 |
file size $path(test1) |
| 5053 |
} -cleanup { |
| 5054 |
chan close $f1 |
| 5055 |
} -result 10 |
| 5056 |
test chan-io-39.7 {Tcl_SetChannelOption, buffering, translation} -setup { |
| 5057 |
file delete $path(test1) |
| 5058 |
set x "" |
| 5059 |
} -body { |
| 5060 |
set f1 [open $path(test1) w] |
| 5061 |
chan configure $f1 -translation lf |
| 5062 |
chan puts $f1 hello |
| 5063 |
chan puts $f1 bye |
| 5064 |
chan configure $f1 -buffering line |
| 5065 |
lappend x [file size $path(test1)] |
| 5066 |
chan puts $f1 really_bye |
| 5067 |
lappend x [file size $path(test1)] |
| 5068 |
} -cleanup { |
| 5069 |
chan close $f1 |
| 5070 |
} -result {0 21} |
| 5071 |
test chan-io-39.8 {Tcl_SetChannelOption, different buffering options} -setup { |
| 5072 |
file delete $path(test1) |
| 5073 |
set l "" |
| 5074 |
} -body { |
| 5075 |
set f1 [open $path(test1) w] |
| 5076 |
chan configure $f1 -translation lf -buffering none -eofchar {} |
| 5077 |
chan puts -nonewline $f1 hello |
| 5078 |
lappend l [file size $path(test1)] |
| 5079 |
chan puts -nonewline $f1 hello |
| 5080 |
lappend l [file size $path(test1)] |
| 5081 |
chan configure $f1 -buffering full |
| 5082 |
chan puts -nonewline $f1 hello |
| 5083 |
lappend l [file size $path(test1)] |
| 5084 |
chan configure $f1 -buffering none |
| 5085 |
lappend l [file size $path(test1)] |
| 5086 |
chan puts -nonewline $f1 hello |
| 5087 |
lappend l [file size $path(test1)] |
| 5088 |
chan close $f1 |
| 5089 |
lappend l [file size $path(test1)] |
| 5090 |
} -result {5 10 10 10 20 20} |
| 5091 |
test chan-io-39.9 {Tcl_SetChannelOption, blocking mode} -setup { |
| 5092 |
file delete $path(test1) |
| 5093 |
set x "" |
| 5094 |
} -constraints {nonBlockFiles} -body { |
| 5095 |
set f1 [open $path(test1) w] |
| 5096 |
chan close $f1 |
| 5097 |
set f1 [open $path(test1) r] |
| 5098 |
lappend x [chan configure $f1 -blocking] |
| 5099 |
chan configure $f1 -blocking off |
| 5100 |
lappend x [chan configure $f1 -blocking] |
| 5101 |
lappend x [chan gets $f1] |
| 5102 |
lappend x [chan read $f1 1000] |
| 5103 |
lappend x [chan blocked $f1] |
| 5104 |
lappend x [chan eof $f1] |
| 5105 |
} -cleanup { |
| 5106 |
chan close $f1 |
| 5107 |
} -result {1 0 {} {} 0 1} |
| 5108 |
test chan-io-39.10 {Tcl_SetChannelOption, blocking mode} -setup { |
| 5109 |
file delete $path(pipe) |
| 5110 |
set x "" |
| 5111 |
} -constraints stdio -body { |
| 5112 |
set f1 [open $path(pipe) w] |
| 5113 |
chan puts $f1 { |
| 5114 |
chan gets stdin |
| 5115 |
after 100 |
| 5116 |
chan puts hi |
| 5117 |
chan gets stdin |
| 5118 |
} |
| 5119 |
chan close $f1 |
| 5120 |
set f1 [openpipe r+ $path(pipe)] |
| 5121 |
chan configure $f1 -blocking off -buffering line |
| 5122 |
lappend x [chan configure $f1 -blocking] |
| 5123 |
lappend x [chan gets $f1] |
| 5124 |
lappend x [chan blocked $f1] |
| 5125 |
chan configure $f1 -blocking on |
| 5126 |
chan puts $f1 hello |
| 5127 |
chan configure $f1 -blocking off |
| 5128 |
lappend x [chan gets $f1] |
| 5129 |
lappend x [chan blocked $f1] |
| 5130 |
chan configure $f1 -blocking on |
| 5131 |
chan puts $f1 bye |
| 5132 |
chan configure $f1 -blocking off |
| 5133 |
lappend x [chan gets $f1] |
| 5134 |
lappend x [chan blocked $f1] |
| 5135 |
chan configure $f1 -blocking on |
| 5136 |
lappend x [chan configure $f1 -blocking] |
| 5137 |
lappend x [chan gets $f1] |
| 5138 |
lappend x [chan blocked $f1] |
| 5139 |
lappend x [chan eof $f1] |
| 5140 |
lappend x [chan gets $f1] |
| 5141 |
lappend x [chan eof $f1] |
| 5142 |
} -cleanup { |
| 5143 |
chan close $f1 |
| 5144 |
} -result {0 {} 1 {} 1 {} 1 1 hi 0 0 {} 1} |
| 5145 |
test chan-io-39.11 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size clipped to lower bound} -setup { |
| 5146 |
file delete $path(test1) |
| 5147 |
} -body { |
| 5148 |
set f [open $path(test1) w] |
| 5149 |
chan configure $f -buffersize -10 |
| 5150 |
chan configure $f -buffersize |
| 5151 |
} -cleanup { |
| 5152 |
chan close $f |
| 5153 |
} -result 1 |
| 5154 |
test chan-io-39.12 {Tcl_SetChannelOption, Tcl_GetChannelOption buffer size clipped to upper bound} -setup { |
| 5155 |
file delete $path(test1) |
| 5156 |
} -body { |
| 5157 |
set f [open $path(test1) w] |
| 5158 |
chan configure $f -buffersize 10000000 |
| 5159 |
chan configure $f -buffersize |
| 5160 |
} -cleanup { |
| 5161 |
chan close $f |
| 5162 |
} -result 1048576 |
| 5163 |
test chan-io-39.13 {Tcl_SetChannelOption, Tcl_GetChannelOption, buffer size} -setup { |
| 5164 |
file delete $path(test1) |
| 5165 |
} -body { |
| 5166 |
set f [open $path(test1) w] |
| 5167 |
chan configure $f -buffersize 40000 |
| 5168 |
chan configure $f -buffersize |
| 5169 |
} -cleanup { |
| 5170 |
chan close $f |
| 5171 |
} -result 40000 |
| 5172 |
test chan-io-39.14 {Tcl_SetChannelOption: -encoding, binary & utf-8} -setup { |
| 5173 |
file delete $path(test1) |
| 5174 |
} -body { |
| 5175 |
set f [open $path(test1) w] |
| 5176 |
chan configure $f -encoding {} |
| 5177 |
chan puts -nonewline $f \xE7\x89\xA6 |
| 5178 |
chan close $f |
| 5179 |
set f [open $path(test1) r] |
| 5180 |
chan configure $f -encoding utf-8 |
| 5181 |
chan read $f |
| 5182 |
} -cleanup { |
| 5183 |
chan close $f |
| 5184 |
} -result \u7266 |
| 5185 |
test chan-io-39.15 {Tcl_SetChannelOption: -encoding, binary & utf-8} -setup { |
| 5186 |
file delete $path(test1) |
| 5187 |
} -body { |
| 5188 |
set f [open $path(test1) w] |
| 5189 |
chan configure $f -encoding binary |
| 5190 |
chan puts -nonewline $f \xE7\x89\xA6 |
| 5191 |
chan close $f |
| 5192 |
set f [open $path(test1) r] |
| 5193 |
chan configure $f -encoding utf-8 |
| 5194 |
chan read $f |
| 5195 |
} -cleanup { |
| 5196 |
chan close $f |
| 5197 |
} -result \u7266 |
| 5198 |
test chan-io-39.16 {Tcl_SetChannelOption: -encoding, errors} -setup { |
| 5199 |
file delete $path(test1) |
| 5200 |
set f [open $path(test1) w] |
| 5201 |
} -body { |
| 5202 |
chan configure $f -encoding foobar |
| 5203 |
} -returnCodes error -cleanup { |
| 5204 |
chan close $f |
| 5205 |
} -result {unknown encoding "foobar"} |
| 5206 |
test chan-io-39.17 {Tcl_SetChannelOption: -encoding, clearing CHANNEL_NEED_MORE_DATA} -setup { |
| 5207 |
variable x {} |
| 5208 |
} -constraints {stdio fileevent} -body { |
| 5209 |
set f [openpipe r+ $path(cat)] |
| 5210 |
chan configure $f -encoding binary |
| 5211 |
chan puts -nonewline $f \xE7 |
| 5212 |
chan flush $f |
| 5213 |
chan configure $f -encoding utf-8 -blocking 0 |
| 5214 |
chan event $f readable [namespace code { lappend x [chan read $f] }] |
| 5215 |
vwait [namespace which -variable x] |
| 5216 |
after 300 [namespace code { lappend x timeout }] |
| 5217 |
vwait [namespace which -variable x] |
| 5218 |
chan configure $f -encoding utf-8 |
| 5219 |
vwait [namespace which -variable x] |
| 5220 |
after 300 [namespace code { lappend x timeout }] |
| 5221 |
vwait [namespace which -variable x] |
| 5222 |
chan configure $f -encoding binary |
| 5223 |
vwait [namespace which -variable x] |
| 5224 |
after 300 [namespace code { lappend x timeout }] |
| 5225 |
vwait [namespace which -variable x] |
| 5226 |
return $x |
| 5227 |
} -cleanup { |
| 5228 |
chan close $f |
| 5229 |
} -result "{} timeout {} timeout \xE7 timeout" |
| 5230 |
test chan-io-39.18 {Tcl_SetChannelOption, setting read mode independently} \ |
| 5231 |
-constraints {socket} -body { |
| 5232 |
proc accept {s a p} {chan close $s} |
| 5233 |
set s1 [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5234 |
set port [lindex [chan configure $s1 -sockname] 2] |
| 5235 |
set s2 [socket 127.0.0.1 $port] |
| 5236 |
update |
| 5237 |
chan configure $s2 -translation {auto lf} |
| 5238 |
chan configure $s2 -translation |
| 5239 |
} -cleanup { |
| 5240 |
chan close $s1 |
| 5241 |
chan close $s2 |
| 5242 |
} -result {auto lf} |
| 5243 |
test chan-io-39.19 {Tcl_SetChannelOption, setting read mode independently} \ |
| 5244 |
-constraints {socket} -body { |
| 5245 |
proc accept {s a p} {chan close $s} |
| 5246 |
set s1 [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5247 |
set port [lindex [chan configure $s1 -sockname] 2] |
| 5248 |
set s2 [socket 127.0.0.1 $port] |
| 5249 |
update |
| 5250 |
chan configure $s2 -translation {auto crlf} |
| 5251 |
chan configure $s2 -translation |
| 5252 |
} -cleanup { |
| 5253 |
chan close $s1 |
| 5254 |
chan close $s2 |
| 5255 |
} -result {auto crlf} |
| 5256 |
test chan-io-39.20 {Tcl_SetChannelOption, setting read mode independently} \ |
| 5257 |
-constraints {socket} -body { |
| 5258 |
proc accept {s a p} {chan close $s} |
| 5259 |
set s1 [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5260 |
set port [lindex [chan configure $s1 -sockname] 2] |
| 5261 |
set s2 [socket 127.0.0.1 $port] |
| 5262 |
update |
| 5263 |
chan configure $s2 -translation {auto cr} |
| 5264 |
chan configure $s2 -translation |
| 5265 |
} -cleanup { |
| 5266 |
chan close $s1 |
| 5267 |
chan close $s2 |
| 5268 |
} -result {auto cr} |
| 5269 |
test chan-io-39.21 {Tcl_SetChannelOption, setting read mode independently} \ |
| 5270 |
-constraints {socket} -body { |
| 5271 |
proc accept {s a p} {chan close $s} |
| 5272 |
set s1 [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5273 |
set port [lindex [chan configure $s1 -sockname] 2] |
| 5274 |
set s2 [socket 127.0.0.1 $port] |
| 5275 |
update |
| 5276 |
chan configure $s2 -translation {auto auto} |
| 5277 |
chan configure $s2 -translation |
| 5278 |
} -cleanup { |
| 5279 |
chan close $s1 |
| 5280 |
chan close $s2 |
| 5281 |
} -result {auto crlf} |
| 5282 |
test chan-io-39.22 {Tcl_SetChannelOption, invariance} -setup { |
| 5283 |
file delete $path(test1) |
| 5284 |
set l "" |
| 5285 |
} -constraints {unix} -body { |
| 5286 |
set f1 [open $path(test1) w+] |
| 5287 |
lappend l [chan configure $f1 -eofchar] |
| 5288 |
chan configure $f1 -eofchar {ON GO} |
| 5289 |
lappend l [chan configure $f1 -eofchar] |
| 5290 |
chan configure $f1 -eofchar D |
| 5291 |
lappend l [chan configure $f1 -eofchar] |
| 5292 |
} -cleanup { |
| 5293 |
chan close $f1 |
| 5294 |
} -result {{{} {}} {O G} {D D}} |
| 5295 |
test chan-io-39.22a {Tcl_SetChannelOption, invariance} -setup { |
| 5296 |
file delete $path(test1) |
| 5297 |
set l [list] |
| 5298 |
} -body { |
| 5299 |
set f1 [open $path(test1) w+] |
| 5300 |
chan configure $f1 -eofchar {ON GO} |
| 5301 |
lappend l [chan configure $f1 -eofchar] |
| 5302 |
chan configure $f1 -eofchar D |
| 5303 |
lappend l [chan configure $f1 -eofchar] |
| 5304 |
lappend l [list [catch {chan configure $f1 -eofchar {1 2 3}} msg] $msg] |
| 5305 |
} -cleanup { |
| 5306 |
chan close $f1 |
| 5307 |
} -result {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}} |
| 5308 |
test chan-io-39.23 { |
| 5309 |
Tcl_GetChannelOption, server socket is not readable or writable, but should |
| 5310 |
still have valid -eofchar and -translation options. |
| 5311 |
} -setup { |
| 5312 |
set l [list] |
| 5313 |
} -body { |
| 5314 |
set sock [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5315 |
lappend l [chan configure $sock -eofchar] \ |
| 5316 |
[chan configure $sock -translation] |
| 5317 |
} -cleanup { |
| 5318 |
chan close $sock |
| 5319 |
} -result {{{}} auto} |
| 5320 |
test chan-io-39.24 {Tcl_SetChannelOption, server socket is not readable or\ |
| 5321 |
writable so we can't change -eofchar or -translation} -setup { |
| 5322 |
set l [list] |
| 5323 |
} -body { |
| 5324 |
set sock [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 5325 |
chan configure $sock -eofchar D -translation lf |
| 5326 |
lappend l [chan configure $sock -eofchar] \ |
| 5327 |
[chan configure $sock -translation] |
| 5328 |
} -cleanup { |
| 5329 |
chan close $sock |
| 5330 |
} -result {{{}} auto} |
| 5331 |
|
| 5332 |
test chan-io-40.1 {POSIX open access modes: RDWR} -setup { |
| 5333 |
file delete $path(test3) |
| 5334 |
} -body { |
| 5335 |
set f [open $path(test3) w] |
| 5336 |
chan puts $f xyzzy |
| 5337 |
chan close $f |
| 5338 |
set f [open $path(test3) RDWR] |
| 5339 |
chan puts -nonewline $f "ab" |
| 5340 |
chan seek $f 0 current |
| 5341 |
set x [chan gets $f] |
| 5342 |
chan close $f |
| 5343 |
set f [open $path(test3) r] |
| 5344 |
lappend x [chan gets $f] |
| 5345 |
} -cleanup { |
| 5346 |
chan close $f |
| 5347 |
} -result {zzy abzzy} |
| 5348 |
test chan-io-40.2 {POSIX open access modes: CREAT} -setup { |
| 5349 |
file delete $path(test3) |
| 5350 |
} -constraints {unix notWsl} -body { |
| 5351 |
set f [open $path(test3) {WRONLY CREAT} 0o600] |
| 5352 |
file stat $path(test3) stats |
| 5353 |
set x [format 0o%03o [expr {$stats(mode) & 0o777}]] |
| 5354 |
chan puts $f "line 1" |
| 5355 |
chan close $f |
| 5356 |
set f [open $path(test3) r] |
| 5357 |
lappend x [chan gets $f] |
| 5358 |
} -cleanup { |
| 5359 |
chan close $f |
| 5360 |
} -result {0o600 {line 1}} |
| 5361 |
test chan-io-40.3 {POSIX open access modes: CREAT} -setup { |
| 5362 |
file delete $path(test3) |
| 5363 |
} -constraints {unix umask notWsl} -body { |
| 5364 |
# This test only works if your umask is 2, like ouster's. |
| 5365 |
chan close [open $path(test3) {WRONLY CREAT}] |
| 5366 |
file stat $path(test3) stats |
| 5367 |
format 0o%03o [expr {$stats(mode) & 0o777}] |
| 5368 |
} -result [format 0o%03o [expr {0o666 & ~ $umaskValue}]] |
| 5369 |
test chan-io-40.4 {POSIX open access modes: CREAT} -setup { |
| 5370 |
file delete $path(test3) |
| 5371 |
} -body { |
| 5372 |
set f [open $path(test3) w] |
| 5373 |
chan configure $f -eofchar {} |
| 5374 |
chan puts $f xyzzy |
| 5375 |
chan close $f |
| 5376 |
set f [open $path(test3) {WRONLY CREAT}] |
| 5377 |
chan configure $f -eofchar {} |
| 5378 |
chan puts -nonewline $f "ab" |
| 5379 |
chan close $f |
| 5380 |
set f [open $path(test3) r] |
| 5381 |
chan gets $f |
| 5382 |
} -cleanup { |
| 5383 |
chan close $f |
| 5384 |
} -result abzzy |
| 5385 |
test chan-io-40.5 {POSIX open access modes: APPEND} -setup { |
| 5386 |
file delete $path(test3) |
| 5387 |
set x "" |
| 5388 |
} -body { |
| 5389 |
set f [open $path(test3) w] |
| 5390 |
chan configure $f -translation lf -eofchar {} |
| 5391 |
chan puts $f xyzzy |
| 5392 |
chan close $f |
| 5393 |
set f [open $path(test3) {WRONLY APPEND}] |
| 5394 |
chan configure $f -translation lf |
| 5395 |
chan puts $f "new line" |
| 5396 |
chan seek $f 0 |
| 5397 |
chan puts $f "abc" |
| 5398 |
chan close $f |
| 5399 |
set f [open $path(test3) r] |
| 5400 |
chan configure $f -translation lf |
| 5401 |
chan seek $f 6 current |
| 5402 |
lappend x [chan gets $f] |
| 5403 |
lappend x [chan gets $f] |
| 5404 |
} -cleanup { |
| 5405 |
chan close $f |
| 5406 |
} -result {{new line} abc} |
| 5407 |
test chan-io-40.6 {POSIX open access modes: EXCL} -match regexp -setup { |
| 5408 |
file delete $path(test3) |
| 5409 |
} -body { |
| 5410 |
set f [open $path(test3) w] |
| 5411 |
chan puts $f xyzzy |
| 5412 |
chan close $f |
| 5413 |
open $path(test3) {WRONLY CREAT EXCL} |
| 5414 |
} -returnCodes error -result {(?i)couldn't open ".*test3": file (already )?exists} |
| 5415 |
test chan-io-40.7 {POSIX open access modes: EXCL} -setup { |
| 5416 |
file delete $path(test3) |
| 5417 |
} -body { |
| 5418 |
set f [open $path(test3) {WRONLY CREAT EXCL}] |
| 5419 |
chan configure $f -eofchar {} |
| 5420 |
chan puts $f "A test line" |
| 5421 |
chan close $f |
| 5422 |
viewFile test3 |
| 5423 |
} -result {A test line} |
| 5424 |
test chan-io-40.8 {POSIX open access modes: TRUNC} -setup { |
| 5425 |
file delete $path(test3) |
| 5426 |
} -body { |
| 5427 |
set f [open $path(test3) w] |
| 5428 |
chan puts $f xyzzy |
| 5429 |
chan close $f |
| 5430 |
set f [open $path(test3) {WRONLY TRUNC}] |
| 5431 |
chan puts $f abc |
| 5432 |
chan close $f |
| 5433 |
set f [open $path(test3) r] |
| 5434 |
chan gets $f |
| 5435 |
} -cleanup { |
| 5436 |
chan close $f |
| 5437 |
} -result abc |
| 5438 |
test chan-io-40.9 {POSIX open access modes: NONBLOCK} -setup { |
| 5439 |
file delete $path(test3) |
| 5440 |
} -constraints {nonPortable unix} -body { |
| 5441 |
set f [open $path(test3) {WRONLY NONBLOCK CREAT}] |
| 5442 |
chan puts $f "NONBLOCK test" |
| 5443 |
chan close $f |
| 5444 |
set f [open $path(test3) r] |
| 5445 |
chan gets $f |
| 5446 |
} -cleanup { |
| 5447 |
chan close $f |
| 5448 |
} -result {NONBLOCK test} |
| 5449 |
test chan-io-40.10 {POSIX open access modes: RDONLY} -body { |
| 5450 |
set f [open $path(test1) w] |
| 5451 |
chan puts $f "two lines: this one" |
| 5452 |
chan puts $f "and this" |
| 5453 |
chan close $f |
| 5454 |
set f [open $path(test1) RDONLY] |
| 5455 |
list [chan gets $f] [catch {chan puts $f Test} msg] $msg |
| 5456 |
} -cleanup { |
| 5457 |
chan close $f |
| 5458 |
} -match glob -result {{two lines: this one} 1 {channel "*" wasn't opened for writing}} |
| 5459 |
test chan-io-40.11 {POSIX open access modes: RDONLY} -match regexp -body { |
| 5460 |
file delete $path(test3) |
| 5461 |
open $path(test3) RDONLY |
| 5462 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} |
| 5463 |
test chan-io-40.12 {POSIX open access modes: WRONLY} -match regexp -body { |
| 5464 |
file delete $path(test3) |
| 5465 |
open $path(test3) WRONLY |
| 5466 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} |
| 5467 |
test chan-io-40.13 {POSIX open access modes: WRONLY} -body { |
| 5468 |
makeFile xyzzy test3 |
| 5469 |
set f [open $path(test3) WRONLY] |
| 5470 |
chan configure $f -eofchar {} |
| 5471 |
chan puts -nonewline $f "ab" |
| 5472 |
chan seek $f 0 current |
| 5473 |
set x [list [catch {chan gets $f} msg] $msg] |
| 5474 |
chan close $f |
| 5475 |
lappend x [viewFile test3] |
| 5476 |
} -match glob -result {1 {channel "*" wasn't opened for reading} abzzy} |
| 5477 |
test chan-io-40.14 {POSIX open access modes: RDWR} -match regexp -body { |
| 5478 |
file delete $path(test3) |
| 5479 |
open $path(test3) RDWR |
| 5480 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} |
| 5481 |
test chan-io-40.15 {POSIX open access modes: RDWR} { |
| 5482 |
makeFile xyzzy test3 |
| 5483 |
set f [open $path(test3) RDWR] |
| 5484 |
chan puts -nonewline $f "ab" |
| 5485 |
chan seek $f 0 current |
| 5486 |
set x [chan gets $f] |
| 5487 |
chan close $f |
| 5488 |
lappend x [viewFile test3] |
| 5489 |
} {zzy abzzy} |
| 5490 |
test chan-io-40.16 {tilde substitution in open} -constraints makeFileInHome -setup { |
| 5491 |
makeFile {Some text} _test_ ~ |
| 5492 |
} -body { |
| 5493 |
file exists [file join $::env(HOME) _test_] |
| 5494 |
} -cleanup { |
| 5495 |
removeFile _test_ ~ |
| 5496 |
} -result 1 |
| 5497 |
test chan-io-40.17 {tilde substitution in open} -setup { |
| 5498 |
set home $::env(HOME) |
| 5499 |
} -body { |
| 5500 |
unset ::env(HOME) |
| 5501 |
open ~/foo |
| 5502 |
} -returnCodes error -cleanup { |
| 5503 |
set ::env(HOME) $home |
| 5504 |
} -result {couldn't find HOME environment variable to expand path} |
| 5505 |
|
| 5506 |
test chan-io-41.1 {Tcl_FileeventCmd: errors} -constraints fileevent -body { |
| 5507 |
chan event foo |
| 5508 |
} -returnCodes error -result {wrong # args: should be "chan event channelId event ?script?"} |
| 5509 |
test chan-io-41.2 {Tcl_FileeventCmd: errors} -constraints fileevent -body { |
| 5510 |
chan event foo bar baz q |
| 5511 |
} -returnCodes error -result {wrong # args: should be "chan event channelId event ?script?"} |
| 5512 |
test chan-io-41.3 {Tcl_FileeventCmd: errors} -constraints fileevent -body { |
| 5513 |
chan event gorp readable |
| 5514 |
} -returnCodes error -result {can not find channel named "gorp"} |
| 5515 |
test chan-io-41.4 {Tcl_FileeventCmd: errors} -constraints fileevent -body { |
| 5516 |
chan event gorp writable |
| 5517 |
} -returnCodes error -result {can not find channel named "gorp"} |
| 5518 |
test chan-io-41.5 {Tcl_FileeventCmd: errors} -constraints fileevent -body { |
| 5519 |
chan event gorp who-knows |
| 5520 |
} -returnCodes error -result {bad event name "who-knows": must be readable or writable} |
| 5521 |
|
| 5522 |
# |
| 5523 |
# Test chan event on a file |
| 5524 |
# |
| 5525 |
|
| 5526 |
set path(foo) [makeFile {} foo] |
| 5527 |
set f [open $path(foo) w+] |
| 5528 |
|
| 5529 |
test chan-io-42.1 {Tcl_FileeventCmd: creating, deleting, querying} {fileevent} { |
| 5530 |
list [chan event $f readable] [chan event $f writable] |
| 5531 |
} {{} {}} |
| 5532 |
test chan-io-42.2 {Tcl_FileeventCmd: replacing} {fileevent} { |
| 5533 |
set result {} |
| 5534 |
chan event $f r "first script" |
| 5535 |
lappend result [chan event $f readable] |
| 5536 |
chan event $f r "new script" |
| 5537 |
lappend result [chan event $f readable] |
| 5538 |
chan event $f r "yet another" |
| 5539 |
lappend result [chan event $f readable] |
| 5540 |
chan event $f r "" |
| 5541 |
lappend result [chan event $f readable] |
| 5542 |
} {{first script} {new script} {yet another} {}} |
| 5543 |
test chan-io-42.3 {Tcl_FileeventCmd: replacing, with NULL chars in script} {fileevent} { |
| 5544 |
set result {} |
| 5545 |
chan event $f r "first scr\x00ipt" |
| 5546 |
lappend result [string length [chan event $f readable]] |
| 5547 |
chan event $f r "new scr\x00ipt" |
| 5548 |
lappend result [string length [chan event $f readable]] |
| 5549 |
chan event $f r "yet ano\x00ther" |
| 5550 |
lappend result [string length [chan event $f readable]] |
| 5551 |
chan event $f r "" |
| 5552 |
lappend result [chan event $f readable] |
| 5553 |
} {13 11 12 {}} |
| 5554 |
|
| 5555 |
test chan-io-43.1 {Tcl_FileeventCmd: creating, deleting, querying} {stdio unixExecs fileevent} { |
| 5556 |
set result {} |
| 5557 |
chan event $f readable "script 1" |
| 5558 |
lappend result [chan event $f readable] [chan event $f writable] |
| 5559 |
chan event $f writable "write script" |
| 5560 |
lappend result [chan event $f readable] [chan event $f writable] |
| 5561 |
chan event $f readable {} |
| 5562 |
lappend result [chan event $f readable] [chan event $f writable] |
| 5563 |
chan event $f writable {} |
| 5564 |
lappend result [chan event $f readable] [chan event $f writable] |
| 5565 |
} {{script 1} {} {script 1} {write script} {} {write script} {} {}} |
| 5566 |
test chan-io-43.2 {Tcl_FileeventCmd: deleting when many present} -setup { |
| 5567 |
set f2 [open "|[list cat -u]" r+] |
| 5568 |
set f3 [open "|[list cat -u]" r+] |
| 5569 |
set result {} |
| 5570 |
} -constraints {stdio unixExecs fileevent} -body { |
| 5571 |
lappend result [chan event $f r] [chan event $f2 r] [chan event $f3 r] |
| 5572 |
chan event $f r "chan read f" |
| 5573 |
chan event $f2 r "chan read f2" |
| 5574 |
chan event $f3 r "chan read f3" |
| 5575 |
lappend result [chan event $f r] [chan event $f2 r] [chan event $f3 r] |
| 5576 |
chan event $f2 r {} |
| 5577 |
lappend result [chan event $f r] [chan event $f2 r] [chan event $f3 r] |
| 5578 |
chan event $f3 r {} |
| 5579 |
lappend result [chan event $f r] [chan event $f2 r] [chan event $f3 r] |
| 5580 |
chan event $f r {} |
| 5581 |
lappend result [chan event $f r] [chan event $f2 r] [chan event $f3 r] |
| 5582 |
} -cleanup { |
| 5583 |
catch {chan close $f2} |
| 5584 |
catch {chan close $f3} |
| 5585 |
} -result {{} {} {} {chan read f} {chan read f2} {chan read f3} {chan read f} {} {chan read f3} {chan read f} {} {} {} {} {}} |
| 5586 |
|
| 5587 |
test chan-io-44.1 {FileEventProc procedure: normal read event} -setup { |
| 5588 |
set f2 [open "|[list cat -u]" r+] |
| 5589 |
set f3 [open "|[list cat -u]" r+] |
| 5590 |
} -constraints {stdio unixExecs fileevent} -body { |
| 5591 |
chan event $f2 readable [namespace code { |
| 5592 |
set x [chan gets $f2]; chan event $f2 readable {} |
| 5593 |
}] |
| 5594 |
chan puts $f2 text; chan flush $f2 |
| 5595 |
variable x initial |
| 5596 |
vwait [namespace which -variable x] |
| 5597 |
return $x |
| 5598 |
} -cleanup { |
| 5599 |
catch {chan close $f2} |
| 5600 |
catch {chan close $f3} |
| 5601 |
} -result {text} |
| 5602 |
test chan-io-44.2 {FileEventProc procedure: error in read event} -setup { |
| 5603 |
set f2 [open "|[list cat -u]" r+] |
| 5604 |
set f3 [open "|[list cat -u]" r+] |
| 5605 |
proc myHandler {msg options} { |
| 5606 |
variable x $msg |
| 5607 |
} |
| 5608 |
set handler [interp bgerror {}] |
| 5609 |
interp bgerror {} [namespace which myHandler] |
| 5610 |
} -constraints {stdio unixExecs fileevent} -body { |
| 5611 |
chan event $f2 readable {error bogus} |
| 5612 |
chan puts $f2 text; chan flush $f2 |
| 5613 |
variable x initial |
| 5614 |
vwait [namespace which -variable x] |
| 5615 |
list $x [chan event $f2 readable] |
| 5616 |
} -cleanup { |
| 5617 |
interp bgerror {} $handler |
| 5618 |
catch {chan close $f2} |
| 5619 |
catch {chan close $f3} |
| 5620 |
} -result {bogus {}} |
| 5621 |
test chan-io-44.3 {FileEventProc procedure: normal write event} -setup { |
| 5622 |
set f2 [open "|[list cat -u]" r+] |
| 5623 |
set f3 [open "|[list cat -u]" r+] |
| 5624 |
} -constraints {stdio unixExecs fileevent} -body { |
| 5625 |
chan event $f2 writable [namespace code { |
| 5626 |
lappend x "triggered" |
| 5627 |
incr count -1 |
| 5628 |
if {$count <= 0} { |
| 5629 |
chan event $f2 writable {} |
| 5630 |
} |
| 5631 |
}] |
| 5632 |
variable x initial |
| 5633 |
set count 3 |
| 5634 |
vwait [namespace which -variable x] |
| 5635 |
vwait [namespace which -variable x] |
| 5636 |
vwait [namespace which -variable x] |
| 5637 |
return $x |
| 5638 |
} -cleanup { |
| 5639 |
catch {chan close $f2} |
| 5640 |
catch {chan close $f3} |
| 5641 |
} -result {initial triggered triggered triggered} |
| 5642 |
test chan-io-44.4 {FileEventProc procedure: eror in write event} -setup { |
| 5643 |
set f2 [open "|[list cat -u]" r+] |
| 5644 |
set f3 [open "|[list cat -u]" r+] |
| 5645 |
proc myHandler {msg options} { |
| 5646 |
variable x $msg |
| 5647 |
} |
| 5648 |
set handler [interp bgerror {}] |
| 5649 |
interp bgerror {} [namespace which myHandler] |
| 5650 |
} -constraints {stdio unixExecs fileevent} -body { |
| 5651 |
chan event $f2 writable {error bad-write} |
| 5652 |
variable x initial |
| 5653 |
vwait [namespace which -variable x] |
| 5654 |
list $x [chan event $f2 writable] |
| 5655 |
} -cleanup { |
| 5656 |
interp bgerror {} $handler |
| 5657 |
catch {chan close $f2} |
| 5658 |
catch {chan close $f3} |
| 5659 |
} -result {bad-write {}} |
| 5660 |
test chan-io-44.5 {FileEventProc procedure: end of file} -constraints { |
| 5661 |
stdio unixExecs fileevent |
| 5662 |
} -body { |
| 5663 |
set f4 [openpipe r $path(cat) << foo] |
| 5664 |
chan event $f4 readable [namespace code { |
| 5665 |
if {[chan gets $f4 line] < 0} { |
| 5666 |
lappend x eof |
| 5667 |
chan event $f4 readable {} |
| 5668 |
} else { |
| 5669 |
lappend x $line |
| 5670 |
} |
| 5671 |
}] |
| 5672 |
variable x initial |
| 5673 |
vwait [namespace which -variable x] |
| 5674 |
vwait [namespace which -variable x] |
| 5675 |
set x |
| 5676 |
} -cleanup { |
| 5677 |
chan close $f4 |
| 5678 |
} -result {initial foo eof} |
| 5679 |
|
| 5680 |
chan close $f |
| 5681 |
makeFile "foo bar" foo |
| 5682 |
|
| 5683 |
test chan-io-45.1 {DeleteFileEvent, cleanup on chan close} {fileevent} { |
| 5684 |
set f [open $path(foo) r] |
| 5685 |
chan event $f readable [namespace code { |
| 5686 |
lappend x "binding triggered: \"[chan gets $f]\"" |
| 5687 |
chan event $f readable {} |
| 5688 |
}] |
| 5689 |
chan close $f |
| 5690 |
set x initial |
| 5691 |
after 100 [namespace code { |
| 5692 |
set y done |
| 5693 |
}] |
| 5694 |
variable y |
| 5695 |
vwait [namespace which -variable y] |
| 5696 |
set x |
| 5697 |
} {initial} |
| 5698 |
test chan-io-45.2 {DeleteFileEvent, cleanup on chan close} {fileevent} { |
| 5699 |
set f [open $path(foo) r] |
| 5700 |
set f2 [open $path(foo) r] |
| 5701 |
chan event $f readable [namespace code { |
| 5702 |
lappend x "f triggered: \"[chan gets $f]\"" |
| 5703 |
chan event $f readable {} |
| 5704 |
}] |
| 5705 |
chan event $f2 readable [namespace code { |
| 5706 |
lappend x "f2 triggered: \"[chan gets $f2]\"" |
| 5707 |
chan event $f2 readable {} |
| 5708 |
}] |
| 5709 |
chan close $f |
| 5710 |
variable x initial |
| 5711 |
vwait [namespace which -variable x] |
| 5712 |
chan close $f2 |
| 5713 |
set x |
| 5714 |
} {initial {f2 triggered: "foo bar"}} |
| 5715 |
test chan-io-45.3 {DeleteFileEvent, cleanup on chan close} {fileevent} { |
| 5716 |
set f [open $path(foo) r] |
| 5717 |
set f2 [open $path(foo) r] |
| 5718 |
set f3 [open $path(foo) r] |
| 5719 |
chan event $f readable {f script} |
| 5720 |
chan event $f2 readable {f2 script} |
| 5721 |
chan event $f3 readable {f3 script} |
| 5722 |
set x {} |
| 5723 |
chan close $f2 |
| 5724 |
lappend x [catch {chan event $f readable} msg] $msg \ |
| 5725 |
[catch {chan event $f2 readable}] \ |
| 5726 |
[catch {chan event $f3 readable} msg] $msg |
| 5727 |
chan close $f3 |
| 5728 |
lappend x [catch {chan event $f readable} msg] $msg \ |
| 5729 |
[catch {chan event $f2 readable}] \ |
| 5730 |
[catch {chan event $f3 readable}] |
| 5731 |
chan close $f |
| 5732 |
lappend x [catch {chan event $f readable}] \ |
| 5733 |
[catch {chan event $f2 readable}] \ |
| 5734 |
[catch {chan event $f3 readable}] |
| 5735 |
} {0 {f script} 1 0 {f3 script} 0 {f script} 1 1 1 1 1} |
| 5736 |
|
| 5737 |
# Execute these tests only if the "testfevent" command is present. |
| 5738 |
|
| 5739 |
test chan-io-46.1 {Tcl event loop vs multiple interpreters} {testfevent fileevent notOSX} { |
| 5740 |
testfevent create |
| 5741 |
set script "set f \[[list open $path(foo) r]]\n" |
| 5742 |
append script { |
| 5743 |
set x "no event" |
| 5744 |
chan event $f readable [namespace code { |
| 5745 |
set x "f triggered: [chan gets $f]" |
| 5746 |
chan event $f readable {} |
| 5747 |
}] |
| 5748 |
} |
| 5749 |
set timer [after 10 lappend x timeout] |
| 5750 |
testfevent cmd $script |
| 5751 |
vwait x |
| 5752 |
after cancel $timer |
| 5753 |
testfevent cmd {chan close $f} |
| 5754 |
list [testfevent cmd {set x}] [testfevent cmd {info commands after}] |
| 5755 |
} {{f triggered: foo bar} after} |
| 5756 |
test chan-io-46.2 {Tcl event loop vs multiple interpreters} testfevent { |
| 5757 |
testfevent create |
| 5758 |
testfevent cmd { |
| 5759 |
variable x 0 |
| 5760 |
after 100 {set x triggered} |
| 5761 |
vwait [namespace which -variable x] |
| 5762 |
set x |
| 5763 |
} |
| 5764 |
} {triggered} |
| 5765 |
test chan-io-46.3 {Tcl event loop vs multiple interpreters} testfevent { |
| 5766 |
testfevent create |
| 5767 |
testfevent cmd { |
| 5768 |
set x 0 |
| 5769 |
after 10 {lappend x timer} |
| 5770 |
after 30 |
| 5771 |
set result $x |
| 5772 |
update idletasks |
| 5773 |
lappend result $x |
| 5774 |
update |
| 5775 |
lappend result $x |
| 5776 |
} |
| 5777 |
} {0 0 {0 timer}} |
| 5778 |
|
| 5779 |
test chan-io-47.1 {chan event vs multiple interpreters} -setup { |
| 5780 |
set f [open $path(foo) r] |
| 5781 |
set f2 [open $path(foo) r] |
| 5782 |
set f3 [open $path(foo) r] |
| 5783 |
set x {} |
| 5784 |
} -constraints {testfevent fileevent} -body { |
| 5785 |
chan event $f readable {script 1} |
| 5786 |
testfevent create |
| 5787 |
testfevent share $f2 |
| 5788 |
testfevent cmd "chan event $f2 readable {script 2}" |
| 5789 |
chan event $f3 readable {sript 3} |
| 5790 |
lappend x [chan event $f2 readable] |
| 5791 |
testfevent delete |
| 5792 |
lappend x [chan event $f readable] [chan event $f2 readable] \ |
| 5793 |
[chan event $f3 readable] |
| 5794 |
} -cleanup { |
| 5795 |
chan close $f |
| 5796 |
chan close $f2 |
| 5797 |
chan close $f3 |
| 5798 |
} -result {{} {script 1} {} {sript 3}} |
| 5799 |
test chan-io-47.2 {deleting chan event on interpreter delete} -setup { |
| 5800 |
set f [open $path(foo) r] |
| 5801 |
set f2 [open $path(foo) r] |
| 5802 |
set f3 [open $path(foo) r] |
| 5803 |
set f4 [open $path(foo) r] |
| 5804 |
} -constraints {testfevent fileevent} -body { |
| 5805 |
chan event $f readable {script 1} |
| 5806 |
testfevent create |
| 5807 |
testfevent share $f2 |
| 5808 |
testfevent share $f3 |
| 5809 |
testfevent cmd "chan event $f2 readable {script 2} |
| 5810 |
chan event $f3 readable {script 3}" |
| 5811 |
chan event $f4 readable {script 4} |
| 5812 |
testfevent delete |
| 5813 |
list [chan event $f readable] [chan event $f2 readable] \ |
| 5814 |
[chan event $f3 readable] [chan event $f4 readable] |
| 5815 |
} -cleanup { |
| 5816 |
chan close $f |
| 5817 |
chan close $f2 |
| 5818 |
chan close $f3 |
| 5819 |
chan close $f4 |
| 5820 |
} -result {{script 1} {} {} {script 4}} |
| 5821 |
test chan-io-47.3 {deleting chan event on interpreter delete} -setup { |
| 5822 |
set f [open $path(foo) r] |
| 5823 |
set f2 [open $path(foo) r] |
| 5824 |
set f3 [open $path(foo) r] |
| 5825 |
set f4 [open $path(foo) r] |
| 5826 |
} -constraints {testfevent fileevent} -body { |
| 5827 |
testfevent create |
| 5828 |
testfevent share $f3 |
| 5829 |
testfevent share $f4 |
| 5830 |
chan event $f readable {script 1} |
| 5831 |
chan event $f2 readable {script 2} |
| 5832 |
testfevent cmd "chan event $f3 readable {script 3} |
| 5833 |
chan event $f4 readable {script 4}" |
| 5834 |
testfevent delete |
| 5835 |
list [chan event $f readable] [chan event $f2 readable] \ |
| 5836 |
[chan event $f3 readable] [chan event $f4 readable] |
| 5837 |
} -cleanup { |
| 5838 |
chan close $f |
| 5839 |
chan close $f2 |
| 5840 |
chan close $f3 |
| 5841 |
chan close $f4 |
| 5842 |
} -result {{script 1} {script 2} {} {}} |
| 5843 |
test chan-io-47.4 {file events on shared files and multiple interpreters} -setup { |
| 5844 |
set f [open $path(foo) r] |
| 5845 |
set f2 [open $path(foo) r] |
| 5846 |
} -constraints {testfevent fileevent} -body { |
| 5847 |
testfevent create |
| 5848 |
testfevent share $f |
| 5849 |
testfevent cmd "chan event $f readable {script 1}" |
| 5850 |
chan event $f readable {script 2} |
| 5851 |
chan event $f2 readable {script 3} |
| 5852 |
list [chan event $f2 readable] [testfevent cmd "chan event $f readable"] \ |
| 5853 |
[chan event $f readable] |
| 5854 |
} -cleanup { |
| 5855 |
testfevent delete |
| 5856 |
chan close $f |
| 5857 |
chan close $f2 |
| 5858 |
} -result {{script 3} {script 1} {script 2}} |
| 5859 |
test chan-io-47.5 {file events on shared files, deleting file events} -setup { |
| 5860 |
set f [open $path(foo) r] |
| 5861 |
} -body { |
| 5862 |
testfevent create |
| 5863 |
testfevent share $f |
| 5864 |
testfevent cmd "chan event $f readable {script 1}" |
| 5865 |
chan event $f readable {script 2} |
| 5866 |
testfevent cmd "chan event $f readable {}" |
| 5867 |
list [testfevent cmd "chan event $f readable"] [chan event $f readable] |
| 5868 |
} -constraints {testfevent fileevent} -cleanup { |
| 5869 |
testfevent delete |
| 5870 |
chan close $f |
| 5871 |
} -result {{} {script 2}} |
| 5872 |
test chan-io-47.6 {file events on shared files, deleting file events} -setup { |
| 5873 |
set f [open $path(foo) r] |
| 5874 |
} -body { |
| 5875 |
testfevent create |
| 5876 |
testfevent share $f |
| 5877 |
testfevent cmd "chan event $f readable {script 1}" |
| 5878 |
chan event $f readable {script 2} |
| 5879 |
chan event $f readable {} |
| 5880 |
list [testfevent cmd "chan event $f readable"] [chan event $f readable] |
| 5881 |
} -constraints {testfevent fileevent} -cleanup { |
| 5882 |
testfevent delete |
| 5883 |
chan close $f |
| 5884 |
} -result {{script 1} {}} |
| 5885 |
unset path(foo) |
| 5886 |
removeFile foo |
| 5887 |
|
| 5888 |
set path(bar) [makeFile {} bar] |
| 5889 |
|
| 5890 |
test chan-io-48.1 {testing readability conditions} {fileevent} { |
| 5891 |
set f [open $path(bar) w] |
| 5892 |
chan puts $f abcdefg |
| 5893 |
chan puts $f abcdefg |
| 5894 |
chan puts $f abcdefg |
| 5895 |
chan puts $f abcdefg |
| 5896 |
chan puts $f abcdefg |
| 5897 |
chan close $f |
| 5898 |
set f [open $path(bar) r] |
| 5899 |
chan event $f readable [namespace code { |
| 5900 |
lappend l called |
| 5901 |
if {[chan eof $f]} { |
| 5902 |
chan close $f |
| 5903 |
set x done |
| 5904 |
} else { |
| 5905 |
chan gets $f |
| 5906 |
} |
| 5907 |
}] |
| 5908 |
set l "" |
| 5909 |
variable x not_done |
| 5910 |
vwait [namespace which -variable x] |
| 5911 |
list $x $l |
| 5912 |
} {done {called called called called called called called}} |
| 5913 |
test chan-io-48.2 {testing readability conditions} {nonBlockFiles fileevent} { |
| 5914 |
set f [open $path(bar) w] |
| 5915 |
chan puts $f abcdefg |
| 5916 |
chan puts $f abcdefg |
| 5917 |
chan puts $f abcdefg |
| 5918 |
chan puts $f abcdefg |
| 5919 |
chan puts $f abcdefg |
| 5920 |
chan close $f |
| 5921 |
set f [open $path(bar) r] |
| 5922 |
chan event $f readable [namespace code { |
| 5923 |
lappend l called |
| 5924 |
if {[chan eof $f]} { |
| 5925 |
chan close $f |
| 5926 |
set x done |
| 5927 |
} else { |
| 5928 |
chan gets $f |
| 5929 |
} |
| 5930 |
}] |
| 5931 |
chan configure $f -blocking off |
| 5932 |
set l "" |
| 5933 |
variable x not_done |
| 5934 |
vwait [namespace which -variable x] |
| 5935 |
list $x $l |
| 5936 |
} {done {called called called called called called called}} |
| 5937 |
set path(my_script) [makeFile {} my_script] |
| 5938 |
test chan-io-48.3 {testing readability conditions} -setup { |
| 5939 |
set l "" |
| 5940 |
} -constraints {stdio unix nonBlockFiles fileevent} -body { |
| 5941 |
set f [open $path(bar) w] |
| 5942 |
chan puts $f abcdefg |
| 5943 |
chan puts $f abcdefg |
| 5944 |
chan puts $f abcdefg |
| 5945 |
chan puts $f abcdefg |
| 5946 |
chan puts $f abcdefg |
| 5947 |
chan close $f |
| 5948 |
set f [open $path(my_script) w] |
| 5949 |
chan puts $f { |
| 5950 |
proc copy_slowly {f} { |
| 5951 |
while {![chan eof $f]} { |
| 5952 |
chan puts [chan gets $f] |
| 5953 |
after 200 |
| 5954 |
} |
| 5955 |
chan close $f |
| 5956 |
} |
| 5957 |
} |
| 5958 |
chan close $f |
| 5959 |
set f [openpipe] |
| 5960 |
chan event $f readable [namespace code { |
| 5961 |
if {[chan eof $f]} { |
| 5962 |
set x done |
| 5963 |
} else { |
| 5964 |
chan gets $f |
| 5965 |
lappend l [chan blocked $f] |
| 5966 |
chan gets $f |
| 5967 |
lappend l [chan blocked $f] |
| 5968 |
} |
| 5969 |
}] |
| 5970 |
chan configure $f -buffering line |
| 5971 |
chan configure $f -blocking off |
| 5972 |
variable x not_done |
| 5973 |
chan puts $f [list source $path(my_script)] |
| 5974 |
chan puts $f "set f \[[list open $path(bar) r]]" |
| 5975 |
chan puts $f {copy_slowly $f} |
| 5976 |
chan puts $f {exit} |
| 5977 |
vwait [namespace which -variable x] |
| 5978 |
list $x $l |
| 5979 |
} -cleanup { |
| 5980 |
chan close $f |
| 5981 |
} -result {done {0 1 0 1 0 1 0 1 0 1 0 1 0 0}} |
| 5982 |
unset path(bar) |
| 5983 |
removeFile bar |
| 5984 |
|
| 5985 |
test chan-io-48.4 {lf write, testing readability, ^Z termination, auto read mode} -setup { |
| 5986 |
file delete $path(test1) |
| 5987 |
set c 0 |
| 5988 |
set l "" |
| 5989 |
} -constraints {fileevent} -body { |
| 5990 |
set f [open $path(test1) w] |
| 5991 |
chan configure $f -translation lf |
| 5992 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 5993 |
chan close $f |
| 5994 |
set f [open $path(test1) r] |
| 5995 |
chan configure $f -translation auto -eofchar \x1A |
| 5996 |
chan event $f readable [namespace code { |
| 5997 |
if {[chan eof $f]} { |
| 5998 |
set x done |
| 5999 |
chan close $f |
| 6000 |
} else { |
| 6001 |
lappend l [chan gets $f] |
| 6002 |
incr c |
| 6003 |
} |
| 6004 |
}] |
| 6005 |
variable x |
| 6006 |
vwait [namespace which -variable x] |
| 6007 |
list $c $l |
| 6008 |
} -result {3 {abc def {}}} |
| 6009 |
test chan-io-48.5 {lf write, testing readability, ^Z in middle, auto read mode} -setup { |
| 6010 |
file delete $path(test1) |
| 6011 |
set c 0 |
| 6012 |
set l "" |
| 6013 |
} -constraints {fileevent} -body { |
| 6014 |
set f [open $path(test1) w] |
| 6015 |
chan configure $f -translation lf |
| 6016 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6017 |
chan close $f |
| 6018 |
set f [open $path(test1) r] |
| 6019 |
chan configure $f -translation auto -eofchar \x1A |
| 6020 |
chan event $f readable [namespace code { |
| 6021 |
if {[chan eof $f]} { |
| 6022 |
set x done |
| 6023 |
chan close $f |
| 6024 |
} else { |
| 6025 |
lappend l [chan gets $f] |
| 6026 |
incr c |
| 6027 |
} |
| 6028 |
}] |
| 6029 |
variable x |
| 6030 |
vwait [namespace which -variable x] |
| 6031 |
list $c $l |
| 6032 |
} -result {3 {abc def {}}} |
| 6033 |
test chan-io-48.6 {cr write, testing readability, ^Z termination, auto read mode} -setup { |
| 6034 |
file delete $path(test1) |
| 6035 |
set c 0 |
| 6036 |
set l "" |
| 6037 |
} -constraints {fileevent} -body { |
| 6038 |
set f [open $path(test1) w] |
| 6039 |
chan configure $f -translation cr |
| 6040 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 6041 |
chan close $f |
| 6042 |
set f [open $path(test1) r] |
| 6043 |
chan configure $f -translation auto -eofchar \x1A |
| 6044 |
chan event $f readable [namespace code { |
| 6045 |
if {[chan eof $f]} { |
| 6046 |
set x done |
| 6047 |
chan close $f |
| 6048 |
} else { |
| 6049 |
lappend l [chan gets $f] |
| 6050 |
incr c |
| 6051 |
} |
| 6052 |
}] |
| 6053 |
variable x |
| 6054 |
vwait [namespace which -variable x] |
| 6055 |
list $c $l |
| 6056 |
} -result {3 {abc def {}}} |
| 6057 |
test chan-io-48.7 {cr write, testing readability, ^Z in middle, auto read mode} -setup { |
| 6058 |
file delete $path(test1) |
| 6059 |
set c 0 |
| 6060 |
set l "" |
| 6061 |
} -constraints {fileevent} -body { |
| 6062 |
set f [open $path(test1) w] |
| 6063 |
chan configure $f -translation cr |
| 6064 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6065 |
chan close $f |
| 6066 |
set f [open $path(test1) r] |
| 6067 |
chan configure $f -translation auto -eofchar \x1A |
| 6068 |
chan event $f readable [namespace code { |
| 6069 |
if {[chan eof $f]} { |
| 6070 |
set x done |
| 6071 |
chan close $f |
| 6072 |
} else { |
| 6073 |
lappend l [chan gets $f] |
| 6074 |
incr c |
| 6075 |
} |
| 6076 |
}] |
| 6077 |
variable x |
| 6078 |
vwait [namespace which -variable x] |
| 6079 |
list $c $l |
| 6080 |
} -result {3 {abc def {}}} |
| 6081 |
test chan-io-48.8 {crlf write, testing readability, ^Z termination, auto read mode} -setup { |
| 6082 |
file delete $path(test1) |
| 6083 |
set c 0 |
| 6084 |
set l "" |
| 6085 |
} -constraints {fileevent} -body { |
| 6086 |
set f [open $path(test1) w] |
| 6087 |
chan configure $f -translation crlf |
| 6088 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 6089 |
chan close $f |
| 6090 |
set f [open $path(test1) r] |
| 6091 |
chan configure $f -translation auto -eofchar \x1A |
| 6092 |
chan event $f readable [namespace code { |
| 6093 |
if {[chan eof $f]} { |
| 6094 |
set x done |
| 6095 |
chan close $f |
| 6096 |
} else { |
| 6097 |
lappend l [chan gets $f] |
| 6098 |
incr c |
| 6099 |
} |
| 6100 |
}] |
| 6101 |
variable x |
| 6102 |
vwait [namespace which -variable x] |
| 6103 |
list $c $l |
| 6104 |
} -result {3 {abc def {}}} |
| 6105 |
test chan-io-48.9 {crlf write, testing readability, ^Z in middle, auto read mode} -setup { |
| 6106 |
file delete $path(test1) |
| 6107 |
set c 0 |
| 6108 |
set l "" |
| 6109 |
} -constraints {fileevent} -body { |
| 6110 |
set f [open $path(test1) w] |
| 6111 |
chan configure $f -translation crlf |
| 6112 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6113 |
chan close $f |
| 6114 |
set f [open $path(test1) r] |
| 6115 |
chan configure $f -translation auto -eofchar \x1A |
| 6116 |
chan event $f readable [namespace code { |
| 6117 |
if {[chan eof $f]} { |
| 6118 |
set x done |
| 6119 |
chan close $f |
| 6120 |
} else { |
| 6121 |
lappend l [chan gets $f] |
| 6122 |
incr c |
| 6123 |
} |
| 6124 |
}] |
| 6125 |
variable x |
| 6126 |
vwait [namespace which -variable x] |
| 6127 |
list $c $l |
| 6128 |
} -result {3 {abc def {}}} |
| 6129 |
test chan-io-48.10 {lf write, testing readability, ^Z in middle, lf read mode} -setup { |
| 6130 |
file delete $path(test1) |
| 6131 |
set c 0 |
| 6132 |
set l "" |
| 6133 |
} -constraints {fileevent} -body { |
| 6134 |
set f [open $path(test1) w] |
| 6135 |
chan configure $f -translation lf |
| 6136 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6137 |
chan close $f |
| 6138 |
set f [open $path(test1) r] |
| 6139 |
chan configure $f -translation lf -eofchar \x1A |
| 6140 |
chan event $f readable [namespace code { |
| 6141 |
if {[chan eof $f]} { |
| 6142 |
set x done |
| 6143 |
chan close $f |
| 6144 |
} else { |
| 6145 |
lappend l [chan gets $f] |
| 6146 |
incr c |
| 6147 |
} |
| 6148 |
}] |
| 6149 |
variable x |
| 6150 |
vwait [namespace which -variable x] |
| 6151 |
list $c $l |
| 6152 |
} -result {3 {abc def {}}} |
| 6153 |
test chan-io-48.11 {lf write, testing readability, ^Z termination, lf read mode} -setup { |
| 6154 |
file delete $path(test1) |
| 6155 |
set c 0 |
| 6156 |
set l "" |
| 6157 |
} -constraints {fileevent} -body { |
| 6158 |
set f [open $path(test1) w] |
| 6159 |
chan configure $f -translation lf |
| 6160 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 6161 |
chan close $f |
| 6162 |
set f [open $path(test1) r] |
| 6163 |
chan configure $f -translation lf -eofchar \x1A |
| 6164 |
chan event $f readable [namespace code { |
| 6165 |
if {[chan eof $f]} { |
| 6166 |
set x done |
| 6167 |
chan close $f |
| 6168 |
} else { |
| 6169 |
lappend l [chan gets $f] |
| 6170 |
incr c |
| 6171 |
} |
| 6172 |
}] |
| 6173 |
variable x |
| 6174 |
vwait [namespace which -variable x] |
| 6175 |
list $c $l |
| 6176 |
} -result {3 {abc def {}}} |
| 6177 |
test chan-io-48.12 {cr write, testing readability, ^Z in middle, cr read mode} -setup { |
| 6178 |
file delete $path(test1) |
| 6179 |
set c 0 |
| 6180 |
set l "" |
| 6181 |
} -constraints {fileevent} -body { |
| 6182 |
set f [open $path(test1) w] |
| 6183 |
chan configure $f -translation cr |
| 6184 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6185 |
chan close $f |
| 6186 |
set f [open $path(test1) r] |
| 6187 |
chan configure $f -translation cr -eofchar \x1A |
| 6188 |
chan event $f readable [namespace code { |
| 6189 |
if {[chan eof $f]} { |
| 6190 |
set x done |
| 6191 |
chan close $f |
| 6192 |
} else { |
| 6193 |
lappend l [chan gets $f] |
| 6194 |
incr c |
| 6195 |
} |
| 6196 |
}] |
| 6197 |
variable x |
| 6198 |
vwait [namespace which -variable x] |
| 6199 |
list $c $l |
| 6200 |
} -result {3 {abc def {}}} |
| 6201 |
test chan-io-48.13 {cr write, testing readability, ^Z termination, cr read mode} -setup { |
| 6202 |
file delete $path(test1) |
| 6203 |
set c 0 |
| 6204 |
set l "" |
| 6205 |
} -constraints {fileevent} -body { |
| 6206 |
set f [open $path(test1) w] |
| 6207 |
chan configure $f -translation cr |
| 6208 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 6209 |
chan close $f |
| 6210 |
set f [open $path(test1) r] |
| 6211 |
chan configure $f -translation cr -eofchar \x1A |
| 6212 |
chan event $f readable [namespace code { |
| 6213 |
if {[chan eof $f]} { |
| 6214 |
set x done |
| 6215 |
chan close $f |
| 6216 |
} else { |
| 6217 |
lappend l [chan gets $f] |
| 6218 |
incr c |
| 6219 |
} |
| 6220 |
}] |
| 6221 |
variable x |
| 6222 |
vwait [namespace which -variable x] |
| 6223 |
list $c $l |
| 6224 |
} -result {3 {abc def {}}} |
| 6225 |
test chan-io-48.14 {crlf write, testing readability, ^Z in middle, crlf read mode} -setup { |
| 6226 |
file delete $path(test1) |
| 6227 |
set c 0 |
| 6228 |
set l "" |
| 6229 |
} -constraints {fileevent} -body { |
| 6230 |
set f [open $path(test1) w] |
| 6231 |
chan configure $f -translation crlf |
| 6232 |
chan puts -nonewline $f [format "abc\ndef\n%cfoo\nbar\n" 26] |
| 6233 |
chan close $f |
| 6234 |
set f [open $path(test1) r] |
| 6235 |
chan configure $f -translation crlf -eofchar \x1A |
| 6236 |
chan event $f readable [namespace code { |
| 6237 |
if {[chan eof $f]} { |
| 6238 |
set x done |
| 6239 |
chan close $f |
| 6240 |
} else { |
| 6241 |
lappend l [chan gets $f] |
| 6242 |
incr c |
| 6243 |
} |
| 6244 |
}] |
| 6245 |
variable x |
| 6246 |
vwait [namespace which -variable x] |
| 6247 |
list $c $l |
| 6248 |
} -result {3 {abc def {}}} |
| 6249 |
test chan-io-48.15 {crlf write, testing readability, ^Z termi, crlf read mode} -setup { |
| 6250 |
file delete $path(test1) |
| 6251 |
set c 0 |
| 6252 |
set l "" |
| 6253 |
} -constraints {fileevent} -body { |
| 6254 |
set f [open $path(test1) w] |
| 6255 |
chan configure $f -translation crlf |
| 6256 |
chan puts -nonewline $f [format "abc\ndef\n%c" 26] |
| 6257 |
chan close $f |
| 6258 |
set f [open $path(test1) r] |
| 6259 |
chan configure $f -translation crlf -eofchar \x1A |
| 6260 |
chan event $f readable [namespace code { |
| 6261 |
if {[chan eof $f]} { |
| 6262 |
set x done |
| 6263 |
chan close $f |
| 6264 |
} else { |
| 6265 |
lappend l [chan gets $f] |
| 6266 |
incr c |
| 6267 |
} |
| 6268 |
}] |
| 6269 |
variable x |
| 6270 |
vwait [namespace which -variable x] |
| 6271 |
list $c $l |
| 6272 |
} -result {3 {abc def {}}} |
| 6273 |
|
| 6274 |
test chan-io-49.1 {testing crlf reading, leftover cr disgorgment} -setup { |
| 6275 |
file delete $path(test1) |
| 6276 |
set l "" |
| 6277 |
} -body { |
| 6278 |
set f [open $path(test1) w] |
| 6279 |
chan configure $f -translation lf |
| 6280 |
chan puts -nonewline $f "a\rb\rc\r\n" |
| 6281 |
chan close $f |
| 6282 |
set f [open $path(test1) r] |
| 6283 |
lappend l [file size $path(test1)] |
| 6284 |
chan configure $f -translation crlf |
| 6285 |
lappend l [chan read $f 1] |
| 6286 |
lappend l [chan tell $f] |
| 6287 |
lappend l [chan read $f 1] |
| 6288 |
lappend l [chan tell $f] |
| 6289 |
lappend l [chan read $f 1] |
| 6290 |
lappend l [chan tell $f] |
| 6291 |
lappend l [chan read $f 1] |
| 6292 |
lappend l [chan tell $f] |
| 6293 |
lappend l [chan read $f 1] |
| 6294 |
lappend l [chan tell $f] |
| 6295 |
lappend l [chan read $f 1] |
| 6296 |
lappend l [chan tell $f] |
| 6297 |
lappend l [chan eof $f] |
| 6298 |
lappend l [chan read $f 1] |
| 6299 |
lappend l [chan eof $f] |
| 6300 |
} -cleanup { |
| 6301 |
chan close $f |
| 6302 |
} -result "7 a 1 [list \r] 2 b 3 [list \r] 4 c 5 { |
| 6303 |
} 7 0 {} 1" |
| 6304 |
test chan-io-49.2 {testing crlf reading, leftover cr disgorgment} -setup { |
| 6305 |
file delete $path(test1) |
| 6306 |
set l "" |
| 6307 |
} -body { |
| 6308 |
set f [open $path(test1) w] |
| 6309 |
chan configure $f -translation lf |
| 6310 |
chan puts -nonewline $f "a\rb\rc\r\n" |
| 6311 |
chan close $f |
| 6312 |
set f [open $path(test1) r] |
| 6313 |
lappend l [file size $path(test1)] |
| 6314 |
chan configure $f -translation crlf |
| 6315 |
lappend l [chan read $f 2] |
| 6316 |
lappend l [chan tell $f] |
| 6317 |
lappend l [chan read $f 2] |
| 6318 |
lappend l [chan tell $f] |
| 6319 |
lappend l [chan read $f 2] |
| 6320 |
lappend l [chan tell $f] |
| 6321 |
lappend l [chan eof $f] |
| 6322 |
lappend l [chan read $f 2] |
| 6323 |
lappend l [chan tell $f] |
| 6324 |
lappend l [chan eof $f] |
| 6325 |
} -cleanup { |
| 6326 |
chan close $f |
| 6327 |
} -result "7 [list a\r] 2 [list b\r] 4 [list c\n] 7 0 {} 7 1" |
| 6328 |
test chan-io-49.3 {testing crlf reading, leftover cr disgorgment} -setup { |
| 6329 |
file delete $path(test1) |
| 6330 |
set l "" |
| 6331 |
} -body { |
| 6332 |
set f [open $path(test1) w] |
| 6333 |
chan configure $f -translation lf |
| 6334 |
chan puts -nonewline $f "a\rb\rc\r\n" |
| 6335 |
chan close $f |
| 6336 |
set f [open $path(test1) r] |
| 6337 |
lappend l [file size $path(test1)] |
| 6338 |
chan configure $f -translation crlf |
| 6339 |
lappend l [chan read $f 3] |
| 6340 |
lappend l [chan tell $f] |
| 6341 |
lappend l [chan read $f 3] |
| 6342 |
lappend l [chan tell $f] |
| 6343 |
lappend l [chan eof $f] |
| 6344 |
lappend l [chan read $f 3] |
| 6345 |
lappend l [chan tell $f] |
| 6346 |
lappend l [chan eof $f] |
| 6347 |
} -cleanup { |
| 6348 |
chan close $f |
| 6349 |
} -result "7 [list a\rb] 3 [list \rc\n] 7 0 {} 7 1" |
| 6350 |
test chan-io-49.4 {testing crlf reading, leftover cr disgorgment} -setup { |
| 6351 |
file delete $path(test1) |
| 6352 |
set l "" |
| 6353 |
} -body { |
| 6354 |
set f [open $path(test1) w] |
| 6355 |
chan configure $f -translation lf |
| 6356 |
chan puts -nonewline $f "a\rb\rc\r\n" |
| 6357 |
chan close $f |
| 6358 |
set f [open $path(test1) r] |
| 6359 |
lappend l [file size $path(test1)] |
| 6360 |
chan configure $f -translation crlf |
| 6361 |
lappend l [chan read $f 3] |
| 6362 |
lappend l [chan tell $f] |
| 6363 |
lappend l [chan gets $f] |
| 6364 |
lappend l [chan tell $f] |
| 6365 |
lappend l [chan eof $f] |
| 6366 |
lappend l [chan gets $f] |
| 6367 |
lappend l [chan tell $f] |
| 6368 |
lappend l [chan eof $f] |
| 6369 |
} -cleanup { |
| 6370 |
chan close $f |
| 6371 |
} -result "7 [list a\rb] 3 [list \rc] 7 0 {} 7 1" |
| 6372 |
test chan-io-49.5 {testing crlf reading, leftover cr disgorgment} -setup { |
| 6373 |
file delete $path(test1) |
| 6374 |
set l "" |
| 6375 |
} -body { |
| 6376 |
set f [open $path(test1) w] |
| 6377 |
chan configure $f -translation lf |
| 6378 |
chan puts -nonewline $f "a\rb\rc\r\n" |
| 6379 |
chan close $f |
| 6380 |
set f [open $path(test1) r] |
| 6381 |
lappend l [file size $path(test1)] |
| 6382 |
chan configure $f -translation crlf |
| 6383 |
lappend l [set x [chan gets $f]] |
| 6384 |
lappend l [chan tell $f] |
| 6385 |
lappend l [chan gets $f] |
| 6386 |
lappend l [chan tell $f] |
| 6387 |
lappend l [chan eof $f] |
| 6388 |
} -cleanup { |
| 6389 |
chan close $f |
| 6390 |
} -result [list 7 a\rb\rc 7 {} 7 1] |
| 6391 |
|
| 6392 |
test chan-io-50.1 {testing handler deletion} -setup { |
| 6393 |
file delete $path(test1) |
| 6394 |
} -constraints testchannelevent -body { |
| 6395 |
set f [open $path(test1) w] |
| 6396 |
chan close $f |
| 6397 |
set f [open $path(test1) r] |
| 6398 |
variable z not_called |
| 6399 |
set timer [after 50 lappend z timeout] |
| 6400 |
testservicemode 0 |
| 6401 |
testchannelevent $f add readable [namespace code { |
| 6402 |
variable z called |
| 6403 |
testchannelevent $f delete 0 |
| 6404 |
}] |
| 6405 |
testservicemode 1 |
| 6406 |
vwait z |
| 6407 |
after cancel $timer |
| 6408 |
set z |
| 6409 |
} -cleanup { |
| 6410 |
chan close $f |
| 6411 |
} -result called |
| 6412 |
test chan-io-50.2 {testing handler deletion with multiple handlers} -setup { |
| 6413 |
file delete $path(test1) |
| 6414 |
chan close [open $path(test1) w] |
| 6415 |
set z "" |
| 6416 |
} -constraints {testchannelevent testservicemode} -body { |
| 6417 |
proc delhandler {f i} { |
| 6418 |
variable z |
| 6419 |
lappend z "called delhandler $f $i" |
| 6420 |
testchannelevent $f delete 0 |
| 6421 |
} |
| 6422 |
set z "" |
| 6423 |
set timer [after 50 lappend z timeout] |
| 6424 |
testservicemode 0 |
| 6425 |
set f [open $path(test1) r] |
| 6426 |
testchannelevent $f add readable [namespace code [list delhandler $f 1]] |
| 6427 |
testchannelevent $f add readable [namespace code [list delhandler $f 0]] |
| 6428 |
testservicemode 1 |
| 6429 |
vwait z |
| 6430 |
after cancel $timer |
| 6431 |
string equal $z \ |
| 6432 |
[list [list called delhandler $f 0] [list called delhandler $f 1]] |
| 6433 |
} -cleanup { |
| 6434 |
chan close $f |
| 6435 |
} -result 1 |
| 6436 |
test chan-io-50.3 {testing handler deletion with multiple handlers} -setup { |
| 6437 |
file delete $path(test1) |
| 6438 |
chan close [open $path(test1) w] |
| 6439 |
} -constraints {testchannelevent testservicemode} -body { |
| 6440 |
proc notcalled {f i} { |
| 6441 |
variable z |
| 6442 |
lappend z "notcalled was called!! $f $i" |
| 6443 |
} |
| 6444 |
proc delhandler {f i} { |
| 6445 |
variable z |
| 6446 |
testchannelevent $f delete 1 |
| 6447 |
lappend z "delhandler $f $i called" |
| 6448 |
testchannelevent $f delete 0 |
| 6449 |
lappend z "delhandler $f $i deleted myself" |
| 6450 |
} |
| 6451 |
set z "" |
| 6452 |
set timer [after 50 lappend z timeout] |
| 6453 |
testservicemode 0 |
| 6454 |
set f [open $path(test1) r] |
| 6455 |
testchannelevent $f add readable [namespace code [list notcalled $f 1]] |
| 6456 |
testchannelevent $f add readable [namespace code [list delhandler $f 0]] |
| 6457 |
testservicemode 1 |
| 6458 |
vwait z |
| 6459 |
after cancel $timer |
| 6460 |
string equal $z \ |
| 6461 |
[list [list delhandler $f 0 called] \ |
| 6462 |
[list delhandler $f 0 deleted myself]] |
| 6463 |
} -cleanup { |
| 6464 |
chan close $f |
| 6465 |
} -result 1 |
| 6466 |
test chan-io-50.4 {testing handler deletion vs reentrant calls} -setup { |
| 6467 |
file delete $path(test1) |
| 6468 |
set f [open $path(test1) w] |
| 6469 |
chan close $f |
| 6470 |
} -constraints testchannelevent -body { |
| 6471 |
set f [open $path(test1) r] |
| 6472 |
testchannelevent $f add readable [namespace code { |
| 6473 |
if {$u eq "recursive"} { |
| 6474 |
testchannelevent $f delete 0 |
| 6475 |
lappend z "delrecursive deleting recursive" |
| 6476 |
} else { |
| 6477 |
lappend z "delrecursive calling recursive" |
| 6478 |
set u recursive |
| 6479 |
update |
| 6480 |
} |
| 6481 |
}] |
| 6482 |
variable u toplevel |
| 6483 |
variable z "" |
| 6484 |
set timer [after 50 lappend z timeout] |
| 6485 |
vwait z |
| 6486 |
after cancel $timer |
| 6487 |
set z |
| 6488 |
} -cleanup { |
| 6489 |
chan close $f |
| 6490 |
update |
| 6491 |
} -result {{delrecursive calling recursive} {delrecursive deleting recursive}} |
| 6492 |
test chan-io-50.5 {testing handler deletion vs reentrant calls} -setup { |
| 6493 |
file delete $path(test1) |
| 6494 |
set f [open $path(test1) w] |
| 6495 |
chan close $f |
| 6496 |
update |
| 6497 |
} -constraints {testchannelevent testservicemode notOSX} -body { |
| 6498 |
proc notcalled {f} { |
| 6499 |
variable z |
| 6500 |
lappend z "notcalled was called!! $f" |
| 6501 |
} |
| 6502 |
proc del {f} { |
| 6503 |
variable u |
| 6504 |
variable z |
| 6505 |
if {$u eq "recursive"} { |
| 6506 |
testchannelevent $f delete 1 |
| 6507 |
testchannelevent $f delete 0 |
| 6508 |
lappend z "del deleted notcalled" |
| 6509 |
lappend z "del deleted myself" |
| 6510 |
} else { |
| 6511 |
set u recursive |
| 6512 |
lappend z "del calling recursive" |
| 6513 |
set timer [after 50 lappend z timeout] |
| 6514 |
set mode [testservicemode 1] |
| 6515 |
vwait z |
| 6516 |
after cancel $timer |
| 6517 |
testservicemode $mode |
| 6518 |
lappend z "del after update" |
| 6519 |
} |
| 6520 |
} |
| 6521 |
set z "" |
| 6522 |
set u toplevel |
| 6523 |
set timer [after 50 lappend z timeout] |
| 6524 |
testservicemode 0 |
| 6525 |
set f [open $path(test1) r] |
| 6526 |
testchannelevent $f add readable [namespace code [list notcalled $f]] |
| 6527 |
testchannelevent $f add readable [namespace code [list del $f]] |
| 6528 |
testservicemode 1 |
| 6529 |
vwait z |
| 6530 |
after cancel $timer |
| 6531 |
set z |
| 6532 |
} -cleanup { |
| 6533 |
chan close $f |
| 6534 |
update |
| 6535 |
} -result [list {del calling recursive} {del deleted notcalled} \ |
| 6536 |
{del deleted myself} {del after update}] |
| 6537 |
test chan-io-50.6 {testing handler deletion vs reentrant calls} -setup { |
| 6538 |
file delete $path(test1) |
| 6539 |
set f [open $path(test1) w] |
| 6540 |
chan close $f |
| 6541 |
} -constraints {testchannelevent testservicemode} -body { |
| 6542 |
proc first {f} { |
| 6543 |
variable u |
| 6544 |
variable z |
| 6545 |
if {$u eq "toplevel"} { |
| 6546 |
lappend z "first called" |
| 6547 |
set mode [testservicemode 1] |
| 6548 |
set timer [after 50 lappend z timeout] |
| 6549 |
set u first |
| 6550 |
vwait z |
| 6551 |
after cancel $timer |
| 6552 |
testservicemode $mode |
| 6553 |
lappend z "first after update" |
| 6554 |
} else { |
| 6555 |
lappend z "first called not toplevel" |
| 6556 |
} |
| 6557 |
} |
| 6558 |
proc second {f} { |
| 6559 |
variable u |
| 6560 |
variable z |
| 6561 |
if {$u eq "first"} { |
| 6562 |
lappend z "second called, first time" |
| 6563 |
set u second |
| 6564 |
testchannelevent $f delete 0 |
| 6565 |
} elseif {$u eq "second"} { |
| 6566 |
lappend z "second called, second time" |
| 6567 |
testchannelevent $f delete 0 |
| 6568 |
} else { |
| 6569 |
lappend z "second called, cannot happen!" |
| 6570 |
testchannelevent $f removeall |
| 6571 |
} |
| 6572 |
} |
| 6573 |
set z "" |
| 6574 |
set u toplevel |
| 6575 |
set timer [after 50 lappend z timeout] |
| 6576 |
testservicemode 0 |
| 6577 |
set f [open $path(test1) r] |
| 6578 |
testchannelevent $f add readable [namespace code [list second $f]] |
| 6579 |
testchannelevent $f add readable [namespace code [list first $f]] |
| 6580 |
testservicemode 1 |
| 6581 |
vwait z |
| 6582 |
after cancel $timer |
| 6583 |
set z |
| 6584 |
} -cleanup { |
| 6585 |
chan close $f |
| 6586 |
} -result [list {first called} {first called not toplevel} \ |
| 6587 |
{second called, first time} {second called, second time} \ |
| 6588 |
{first after update}] |
| 6589 |
|
| 6590 |
test chan-io-51.1 {Test old socket deletion on Macintosh} -setup { |
| 6591 |
set x 0 |
| 6592 |
set result "" |
| 6593 |
variable wait "" |
| 6594 |
} -constraints {socket} -body { |
| 6595 |
proc accept {s a p} { |
| 6596 |
variable x |
| 6597 |
chan configure $s -blocking off |
| 6598 |
chan puts $s "sock[incr x]" |
| 6599 |
chan close $s |
| 6600 |
variable wait done |
| 6601 |
} |
| 6602 |
set ss [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 6603 |
set port [lindex [chan configure $ss -sockname] 2] |
| 6604 |
set cs [socket 127.0.0.1 $port] |
| 6605 |
vwait [namespace which -variable wait] |
| 6606 |
lappend result [chan gets $cs] |
| 6607 |
chan close $cs |
| 6608 |
set cs [socket 127.0.0.1 $port] |
| 6609 |
vwait [namespace which -variable wait] |
| 6610 |
lappend result [chan gets $cs] |
| 6611 |
chan close $cs |
| 6612 |
set cs [socket 127.0.0.1 $port] |
| 6613 |
vwait [namespace which -variable wait] |
| 6614 |
lappend result [chan gets $cs] |
| 6615 |
chan close $cs |
| 6616 |
set cs [socket 127.0.0.1 $port] |
| 6617 |
vwait [namespace which -variable wait] |
| 6618 |
lappend result [chan gets $cs] |
| 6619 |
} -cleanup { |
| 6620 |
chan close $cs |
| 6621 |
chan close $ss |
| 6622 |
} -result {sock1 sock2 sock3 sock4} |
| 6623 |
|
| 6624 |
test chan-io-52.1 {TclCopyChannel} -constraints {fcopy} -setup { |
| 6625 |
file delete $path(test1) |
| 6626 |
} -body { |
| 6627 |
set f1 [open $thisScript] |
| 6628 |
set f2 [open $path(test1) w] |
| 6629 |
chan copy $f1 $f2 -command " # " |
| 6630 |
chan copy $f1 $f2 |
| 6631 |
} -returnCodes error -cleanup { |
| 6632 |
chan close $f1 |
| 6633 |
chan close $f2 |
| 6634 |
} -match glob -result {channel "*" is busy} |
| 6635 |
test chan-io-52.2 {TclCopyChannel} -constraints {fcopy} -setup { |
| 6636 |
file delete $path(test1) |
| 6637 |
} -body { |
| 6638 |
set f1 [open $thisScript] |
| 6639 |
set f2 [open $path(test1) w] |
| 6640 |
set f3 [open $thisScript] |
| 6641 |
chan copy $f1 $f2 -command " # " |
| 6642 |
chan copy $f3 $f2 |
| 6643 |
} -returnCodes error -cleanup { |
| 6644 |
chan close $f1 |
| 6645 |
chan close $f2 |
| 6646 |
chan close $f3 |
| 6647 |
} -match glob -result {channel "*" is busy} |
| 6648 |
test chan-io-52.3 {TclCopyChannel} -constraints {fcopy} -setup { |
| 6649 |
file delete $path(test1) |
| 6650 |
} -body { |
| 6651 |
set f1 [open $thisScript] |
| 6652 |
set f2 [open $path(test1) w] |
| 6653 |
chan configure $f1 -translation binary -blocking 0 |
| 6654 |
chan configure $f2 -translation cr -encoding iso8859-1 -blocking 0 |
| 6655 |
set s0 [chan copy $f1 $f2] |
| 6656 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6657 |
chan close $f1 |
| 6658 |
chan close $f2 |
| 6659 |
set s1 [file size $thisScript] |
| 6660 |
set s2 [file size $path(test1)] |
| 6661 |
if {($s1 == $s2) && ($s0 == $s1)} { |
| 6662 |
lappend result ok |
| 6663 |
} |
| 6664 |
return $result |
| 6665 |
} -result {0 0 ok} |
| 6666 |
test chan-io-52.4 {TclCopyChannel} -constraints {fcopy} -setup { |
| 6667 |
file delete $path(test1) |
| 6668 |
} -body { |
| 6669 |
set f1 [open $thisScript] |
| 6670 |
set f2 [open $path(test1) w] |
| 6671 |
chan configure $f1 -translation lf -blocking 0 |
| 6672 |
chan configure $f2 -translation cr -blocking 0 |
| 6673 |
chan copy $f1 $f2 -size 40 |
| 6674 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6675 |
chan close $f1 |
| 6676 |
chan close $f2 |
| 6677 |
lappend result [file size $path(test1)] |
| 6678 |
} -result {0 0 40} |
| 6679 |
test chan-io-52.5 {TclCopyChannel, all} -constraints {fcopy} -setup { |
| 6680 |
file delete $path(test1) |
| 6681 |
} -body { |
| 6682 |
set f1 [open $thisScript] |
| 6683 |
set f2 [open $path(test1) w] |
| 6684 |
chan configure $f1 -translation binary -blocking 0 |
| 6685 |
chan configure $f2 -translation binary -blocking 0 |
| 6686 |
chan copy $f1 $f2 -size -1 ;# -1 means 'copy all', same as if no -size specified. |
| 6687 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6688 |
chan close $f1 |
| 6689 |
chan close $f2 |
| 6690 |
if {[file size $thisScript] == [file size $path(test1)]} { |
| 6691 |
lappend result ok |
| 6692 |
} |
| 6693 |
return $result |
| 6694 |
} -result {0 0 ok} |
| 6695 |
test chan-io-52.5a {TclCopyChannel, all, other negative value} -setup { |
| 6696 |
file delete $path(test1) |
| 6697 |
} -constraints {fcopy} -body { |
| 6698 |
set f1 [open $thisScript] |
| 6699 |
set f2 [open $path(test1) w] |
| 6700 |
chan configure $f1 -translation binary -blocking 0 |
| 6701 |
chan configure $f2 -translation binary -blocking 0 |
| 6702 |
chan copy $f1 $f2 -size -2 ;# < 0 behaves like -1, copy all |
| 6703 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6704 |
chan close $f1 |
| 6705 |
chan close $f2 |
| 6706 |
if {[file size $thisScript] == [file size $path(test1)]} { |
| 6707 |
lappend result ok |
| 6708 |
} |
| 6709 |
return $result |
| 6710 |
} -result {0 0 ok} |
| 6711 |
test chan-io-52.5b {TclCopyChannel, all, wrap to negative value} -setup { |
| 6712 |
file delete $path(test1) |
| 6713 |
} -constraints {fcopy} -body { |
| 6714 |
set f1 [open $thisScript] |
| 6715 |
set f2 [open $path(test1) w] |
| 6716 |
chan configure $f1 -translation binary -blocking 0 |
| 6717 |
chan configure $f2 -translation binary -blocking 0 |
| 6718 |
chan copy $f1 $f2 -size 3221176172 ;# Wrapped to < 0, behaves like -1, copy all |
| 6719 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6720 |
chan close $f1 |
| 6721 |
chan close $f2 |
| 6722 |
if {[file size $thisScript] == [file size $path(test1)]} { |
| 6723 |
lappend result ok |
| 6724 |
} |
| 6725 |
return $result |
| 6726 |
} -result {0 0 ok} |
| 6727 |
test chan-io-52.6 {TclCopyChannel} -setup { |
| 6728 |
file delete $path(test1) |
| 6729 |
} -constraints {fcopy} -body { |
| 6730 |
set f1 [open $thisScript] |
| 6731 |
set f2 [open $path(test1) w] |
| 6732 |
chan configure $f1 -translation binary -blocking 0 |
| 6733 |
chan configure $f2 -translation binary -blocking 0 |
| 6734 |
set s0 [chan copy $f1 $f2 -size [expr {[file size $thisScript] + 5}]] |
| 6735 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6736 |
chan close $f1 |
| 6737 |
chan close $f2 |
| 6738 |
set s1 [file size $thisScript] |
| 6739 |
set s2 [file size $path(test1)] |
| 6740 |
if {($s1 == $s2) && ($s0 == $s1)} { |
| 6741 |
lappend result ok |
| 6742 |
} |
| 6743 |
return $result |
| 6744 |
} -result {0 0 ok} |
| 6745 |
test chan-io-52.7 {TclCopyChannel} -constraints {fcopy} -setup { |
| 6746 |
file delete $path(test1) |
| 6747 |
} -body { |
| 6748 |
set f1 [open $thisScript] |
| 6749 |
set f2 [open $path(test1) w] |
| 6750 |
chan configure $f1 -translation binary -blocking 0 |
| 6751 |
chan configure $f2 -translation binary -blocking 0 |
| 6752 |
chan copy $f1 $f2 |
| 6753 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6754 |
if {[file size $thisScript] == [file size $path(test1)]} { |
| 6755 |
lappend result ok |
| 6756 |
} |
| 6757 |
return $result |
| 6758 |
} -cleanup { |
| 6759 |
chan close $f1 |
| 6760 |
chan close $f2 |
| 6761 |
} -result {0 0 ok} |
| 6762 |
test chan-io-52.8 {TclCopyChannel} -setup { |
| 6763 |
file delete $path(test1) |
| 6764 |
file delete $path(pipe) |
| 6765 |
} -constraints {stdio fcopy} -body { |
| 6766 |
set f1 [open $path(pipe) w] |
| 6767 |
chan configure $f1 -translation lf |
| 6768 |
chan puts $f1 " |
| 6769 |
chan puts ready |
| 6770 |
chan gets stdin |
| 6771 |
set f1 \[open [list $thisScript] r\] |
| 6772 |
chan configure \$f1 -translation lf |
| 6773 |
chan puts \[chan read \$f1 100\] |
| 6774 |
chan close \$f1 |
| 6775 |
" |
| 6776 |
chan close $f1 |
| 6777 |
set f1 [openpipe r+ $path(pipe)] |
| 6778 |
chan configure $f1 -translation lf |
| 6779 |
chan gets $f1 |
| 6780 |
chan puts $f1 ready |
| 6781 |
chan flush $f1 |
| 6782 |
set f2 [open $path(test1) w] |
| 6783 |
chan configure $f2 -translation lf |
| 6784 |
set s0 [chan copy $f1 $f2 -size 40] |
| 6785 |
catch {chan close $f1} |
| 6786 |
chan close $f2 |
| 6787 |
list $s0 [file size $path(test1)] |
| 6788 |
} -result {40 40} |
| 6789 |
# Empty files, to register them with the test facility |
| 6790 |
set path(kyrillic.txt) [makeFile {} kyrillic.txt] |
| 6791 |
set path(utf8-fcopy.txt) [makeFile {} utf8-fcopy.txt] |
| 6792 |
set path(utf8-rp.txt) [makeFile {} utf8-rp.txt] |
| 6793 |
# Create kyrillic file, use lf translation to avoid os eol issues |
| 6794 |
set out [open $path(kyrillic.txt) w] |
| 6795 |
chan configure $out -encoding koi8-r -translation lf |
| 6796 |
chan puts $out \u0410\u0410 |
| 6797 |
chan close $out |
| 6798 |
test chan-io-52.9 {TclCopyChannel & encodings} {fcopy} { |
| 6799 |
# Copy kyrillic to UTF-8, using chan copy. |
| 6800 |
set in [open $path(kyrillic.txt) r] |
| 6801 |
set out [open $path(utf8-fcopy.txt) w] |
| 6802 |
chan configure $in -encoding koi8-r -translation lf |
| 6803 |
chan configure $out -encoding utf-8 -translation lf |
| 6804 |
chan copy $in $out |
| 6805 |
chan close $in |
| 6806 |
chan close $out |
| 6807 |
# Do the same again, but differently (read/chan puts). |
| 6808 |
set in [open $path(kyrillic.txt) r] |
| 6809 |
set out [open $path(utf8-rp.txt) w] |
| 6810 |
chan configure $in -encoding koi8-r -translation lf |
| 6811 |
chan configure $out -encoding utf-8 -translation lf |
| 6812 |
chan puts -nonewline $out [chan read $in] |
| 6813 |
chan close $in |
| 6814 |
chan close $out |
| 6815 |
list [file size $path(kyrillic.txt)] \ |
| 6816 |
[file size $path(utf8-fcopy.txt)] \ |
| 6817 |
[file size $path(utf8-rp.txt)] |
| 6818 |
} {3 5 5} |
| 6819 |
test chan-io-52.10 {TclCopyChannel & encodings} {fcopy} { |
| 6820 |
# encoding to binary (=> implies that the internal utf-8 is written) |
| 6821 |
set in [open $path(kyrillic.txt) r] |
| 6822 |
set out [open $path(utf8-fcopy.txt) w] |
| 6823 |
chan configure $in -encoding koi8-r -translation lf |
| 6824 |
# -translation binary is also -encoding binary |
| 6825 |
chan configure $out -translation binary |
| 6826 |
chan copy $in $out |
| 6827 |
chan close $in |
| 6828 |
chan close $out |
| 6829 |
file size $path(utf8-fcopy.txt) |
| 6830 |
} 5 |
| 6831 |
test chan-io-52.11 {TclCopyChannel & encodings} -setup { |
| 6832 |
set f [open $path(utf8-fcopy.txt) w] |
| 6833 |
fconfigure $f -encoding utf-8 -translation lf |
| 6834 |
puts $f \u0410\u0410 |
| 6835 |
close $f |
| 6836 |
} -constraints {fcopy} -body { |
| 6837 |
# binary to encoding => the input has to be in utf-8 to make sense to the |
| 6838 |
# encoder |
| 6839 |
set in [open $path(utf8-fcopy.txt) r] |
| 6840 |
set out [open $path(kyrillic.txt) w] |
| 6841 |
# -translation binary is also -encoding binary |
| 6842 |
chan configure $in -translation binary |
| 6843 |
chan configure $out -encoding koi8-r -translation lf |
| 6844 |
chan copy $in $out |
| 6845 |
chan close $in |
| 6846 |
chan close $out |
| 6847 |
file size $path(kyrillic.txt) |
| 6848 |
} -result 3 |
| 6849 |
|
| 6850 |
test chan-io-53.1 {CopyData} -setup { |
| 6851 |
file delete $path(test1) |
| 6852 |
} -constraints {fcopy} -body { |
| 6853 |
set f1 [open $thisScript] |
| 6854 |
set f2 [open $path(test1) w] |
| 6855 |
chan configure $f1 -translation lf -blocking 0 |
| 6856 |
chan configure $f2 -translation cr -blocking 0 |
| 6857 |
chan copy $f1 $f2 -size 0 |
| 6858 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6859 |
chan close $f1 |
| 6860 |
chan close $f2 |
| 6861 |
lappend result [file size $path(test1)] |
| 6862 |
} -result {0 0 0} |
| 6863 |
test chan-io-53.2 {CopyData} -setup { |
| 6864 |
file delete $path(test1) |
| 6865 |
} -constraints {fcopy} -body { |
| 6866 |
set f1 [open $thisScript] |
| 6867 |
set f2 [open $path(test1) w] |
| 6868 |
chan configure $f1 -translation binary -blocking 0 |
| 6869 |
chan configure $f2 -translation cr -encoding iso8859-1 -blocking 0 |
| 6870 |
chan copy $f1 $f2 -command [namespace code {set s0}] |
| 6871 |
set result [list [chan configure $f1 -blocking] [chan configure $f2 -blocking]] |
| 6872 |
variable s0 |
| 6873 |
vwait [namespace which -variable s0] |
| 6874 |
chan close $f1 |
| 6875 |
chan close $f2 |
| 6876 |
set s1 [file size $thisScript] |
| 6877 |
set s2 [file size $path(test1)] |
| 6878 |
if {($s1 == $s2) && ($s0 == $s1)} { |
| 6879 |
lappend result ok |
| 6880 |
} |
| 6881 |
return $result |
| 6882 |
} -result {0 0 ok} |
| 6883 |
test chan-io-53.3 {CopyData: background read underflow} -setup { |
| 6884 |
file delete $path(test1) |
| 6885 |
file delete $path(pipe) |
| 6886 |
} -constraints {stdio unix fcopy} -body { |
| 6887 |
set f1 [open $path(pipe) w] |
| 6888 |
chan puts -nonewline $f1 { |
| 6889 |
chan puts ready |
| 6890 |
chan flush stdout ;# Don't assume line buffered! |
| 6891 |
chan copy stdin stdout -command { set x } |
| 6892 |
vwait x |
| 6893 |
set f [} |
| 6894 |
chan puts $f1 [list open $path(test1) w]] |
| 6895 |
chan puts $f1 { |
| 6896 |
chan configure $f -translation lf |
| 6897 |
chan puts $f "done" |
| 6898 |
chan close $f |
| 6899 |
} |
| 6900 |
chan close $f1 |
| 6901 |
set f1 [openpipe r+ $path(pipe)] |
| 6902 |
set result [chan gets $f1] |
| 6903 |
chan puts $f1 line1 |
| 6904 |
chan flush $f1 |
| 6905 |
lappend result [chan gets $f1] |
| 6906 |
chan puts $f1 line2 |
| 6907 |
chan flush $f1 |
| 6908 |
lappend result [chan gets $f1] |
| 6909 |
chan close $f1 |
| 6910 |
after 500 |
| 6911 |
set f [open $path(test1)] |
| 6912 |
lappend result [chan read $f] |
| 6913 |
} -cleanup { |
| 6914 |
chan close $f |
| 6915 |
} -result "ready line1 line2 {done\n}" |
| 6916 |
test chan-io-53.4 {CopyData: background write overflow} -setup { |
| 6917 |
set big bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n |
| 6918 |
variable x |
| 6919 |
for {set x 0} {$x < 12} {incr x} { |
| 6920 |
append big $big |
| 6921 |
} |
| 6922 |
file delete $path(test1) |
| 6923 |
file delete $path(pipe) |
| 6924 |
} -constraints {stdio unix fileevent fcopy} -body { |
| 6925 |
set f1 [open $path(pipe) w] |
| 6926 |
chan puts $f1 { |
| 6927 |
chan puts ready |
| 6928 |
chan copy stdin stdout -command { set x } |
| 6929 |
vwait x |
| 6930 |
set f [open $path(test1) w] |
| 6931 |
chan configure $f -translation lf |
| 6932 |
chan puts $f "done" |
| 6933 |
chan close $f |
| 6934 |
} |
| 6935 |
chan close $f1 |
| 6936 |
set f1 [openpipe r+ $path(pipe)] |
| 6937 |
set result [chan gets $f1] |
| 6938 |
chan configure $f1 -blocking 0 |
| 6939 |
chan puts $f1 $big |
| 6940 |
chan flush $f1 |
| 6941 |
after 500 |
| 6942 |
set result "" |
| 6943 |
chan event $f1 read [namespace code { |
| 6944 |
append result [chan read $f1 1024] |
| 6945 |
if {[string length $result] >= [string length $big]} { |
| 6946 |
set x done |
| 6947 |
} |
| 6948 |
}] |
| 6949 |
vwait [namespace which -variable x] |
| 6950 |
return $x |
| 6951 |
} -cleanup { |
| 6952 |
set big {} |
| 6953 |
chan close $f1 |
| 6954 |
} -result done |
| 6955 |
set result {} |
| 6956 |
proc FcopyTestAccept {sock args} { |
| 6957 |
after 1000 "chan close $sock" |
| 6958 |
} |
| 6959 |
proc FcopyTestDone {bytes {error {}}} { |
| 6960 |
variable fcopyTestDone |
| 6961 |
if {[string length $error]} { |
| 6962 |
set fcopyTestDone 1 |
| 6963 |
} else { |
| 6964 |
set fcopyTestDone 0 |
| 6965 |
} |
| 6966 |
} |
| 6967 |
test chan-io-53.5 {CopyData: error during chan copy} {socket fcopy} { |
| 6968 |
variable fcopyTestDone |
| 6969 |
set listen [socket -server [namespace code FcopyTestAccept] -myaddr 127.0.0.1 0] |
| 6970 |
set in [open $thisScript] ;# 126 K |
| 6971 |
set out [socket 127.0.0.1 [lindex [chan configure $listen -sockname] 2]] |
| 6972 |
catch {unset fcopyTestDone} |
| 6973 |
chan close $listen ;# This means the socket open never really succeeds |
| 6974 |
chan copy $in $out -command [namespace code FcopyTestDone] |
| 6975 |
variable fcopyTestDone |
| 6976 |
if {![info exists fcopyTestDone]} { |
| 6977 |
vwait [namespace which -variable fcopyTestDone] ;# The error occurs here in the b.g. |
| 6978 |
} |
| 6979 |
chan close $in |
| 6980 |
chan close $out |
| 6981 |
set fcopyTestDone ;# 1 for error condition |
| 6982 |
} 1 |
| 6983 |
test chan-io-53.6 {CopyData: error during chan copy} -setup { |
| 6984 |
variable fcopyTestDone |
| 6985 |
file delete $path(pipe) |
| 6986 |
file delete $path(test1) |
| 6987 |
catch {unset fcopyTestDone} |
| 6988 |
} -constraints {stdio fcopy} -body { |
| 6989 |
set f1 [open $path(pipe) w] |
| 6990 |
chan puts $f1 "exit 1" |
| 6991 |
chan close $f1 |
| 6992 |
set in [openpipe r+ $path(pipe)] |
| 6993 |
set out [open $path(test1) w] |
| 6994 |
chan copy $in $out -command [namespace code FcopyTestDone] |
| 6995 |
variable fcopyTestDone |
| 6996 |
if {![info exists fcopyTestDone]} { |
| 6997 |
vwait [namespace which -variable fcopyTestDone] |
| 6998 |
} |
| 6999 |
return $fcopyTestDone ;# 0 for plain end of file |
| 7000 |
} -cleanup { |
| 7001 |
catch {chan close $in} |
| 7002 |
chan close $out |
| 7003 |
} -result 0 |
| 7004 |
proc doFcopy {in out {bytes 0} {error {}}} { |
| 7005 |
variable fcopyTestDone |
| 7006 |
variable fcopyTestCount |
| 7007 |
incr fcopyTestCount $bytes |
| 7008 |
if {[string length $error]} { |
| 7009 |
set fcopyTestDone 1 |
| 7010 |
} elseif {[chan eof $in]} { |
| 7011 |
set fcopyTestDone 0 |
| 7012 |
} else { |
| 7013 |
# Delay next chan copy to wait for size>0 input bytes |
| 7014 |
after 100 [list chan copy $in $out -size 1000 \ |
| 7015 |
-command [namespace code [list doFcopy $in $out]]] |
| 7016 |
} |
| 7017 |
} |
| 7018 |
test chan-io-53.7 {CopyData: Flooding chan copy from pipe} -setup { |
| 7019 |
variable fcopyTestDone |
| 7020 |
file delete $path(pipe) |
| 7021 |
catch {unset fcopyTestDone} |
| 7022 |
} -constraints {stdio fcopy} -body { |
| 7023 |
set fcopyTestCount 0 |
| 7024 |
set f1 [open $path(pipe) w] |
| 7025 |
chan puts $f1 { |
| 7026 |
# Write 10 bytes / 10 msec |
| 7027 |
proc Write {count} { |
| 7028 |
chan puts -nonewline "1234567890" |
| 7029 |
if {[incr count -1]} { |
| 7030 |
after 10 [list Write $count] |
| 7031 |
} else { |
| 7032 |
set ::ready 1 |
| 7033 |
} |
| 7034 |
} |
| 7035 |
chan configure stdout -buffering none |
| 7036 |
Write 345 ;# 3450 bytes ~3.45 sec |
| 7037 |
vwait ready |
| 7038 |
exit 0 |
| 7039 |
} |
| 7040 |
chan close $f1 |
| 7041 |
set in [openpipe r+ $path(pipe) &] |
| 7042 |
set out [open $path(test1) w] |
| 7043 |
doFcopy $in $out |
| 7044 |
variable fcopyTestDone |
| 7045 |
if {![info exists fcopyTestDone]} { |
| 7046 |
vwait [namespace which -variable fcopyTestDone] |
| 7047 |
} |
| 7048 |
# -1=error 0=script error N=number of bytes |
| 7049 |
expr {($fcopyTestDone == 0) ? $fcopyTestCount : -1} |
| 7050 |
} -cleanup { |
| 7051 |
catch {chan close $in} |
| 7052 |
chan close $out |
| 7053 |
} -result {3450} |
| 7054 |
test chan-io-53.8 {CopyData: async callback and error handling, Bug 1932639} -setup { |
| 7055 |
# copy progress callback. errors out intentionally |
| 7056 |
proc cmd args { |
| 7057 |
lappend ::RES "CMD $args" |
| 7058 |
error !STOP |
| 7059 |
} |
| 7060 |
# capture callback error here |
| 7061 |
proc ::bgerror args { |
| 7062 |
lappend ::RES "bgerror/OK $args" |
| 7063 |
set ::forever has-been-reached |
| 7064 |
return |
| 7065 |
} |
| 7066 |
# Files we use for our channels |
| 7067 |
set foo [makeFile ashgdfashdgfasdhgfasdhgf foo] |
| 7068 |
set bar [makeFile {} bar] |
| 7069 |
# Channels to copy between |
| 7070 |
set f [open $foo r] ; fconfigure $f -translation binary |
| 7071 |
set g [open $bar w] ; fconfigure $g -translation binary -buffering none |
| 7072 |
} -constraints {stdio fcopy} -body { |
| 7073 |
# Record input size, so that result is always defined |
| 7074 |
lappend ::RES [file size $bar] |
| 7075 |
# Run the copy. Should not invoke -command now. |
| 7076 |
chan copy $f $g -size 2 -command [namespace code cmd] |
| 7077 |
# Check that -command was not called synchronously |
| 7078 |
set sbs [file size $bar] |
| 7079 |
lappend ::RES [expr {($sbs > 0) ? "sync/FAIL" : "sync/OK"}] $sbs |
| 7080 |
# Now let the async part happen. Should capture the error in cmd via |
| 7081 |
# bgerror. If not break the event loop via timer. |
| 7082 |
set token [after 1000 { |
| 7083 |
lappend ::RES {bgerror/FAIL timeout} |
| 7084 |
set ::forever has-been-reached |
| 7085 |
}] |
| 7086 |
vwait ::forever |
| 7087 |
catch {after cancel $token} |
| 7088 |
# Report |
| 7089 |
set ::RES |
| 7090 |
} -cleanup { |
| 7091 |
chan close $f |
| 7092 |
chan close $g |
| 7093 |
catch {unset ::RES} |
| 7094 |
catch {unset ::forever} |
| 7095 |
rename ::bgerror {} |
| 7096 |
removeFile foo |
| 7097 |
removeFile bar |
| 7098 |
} -result {0 sync/OK 0 {CMD 2} {bgerror/OK !STOP}} |
| 7099 |
test chan-io-53.8a {CopyData: async callback and error handling, Bug 1932639, at eof} -setup { |
| 7100 |
# copy progress callback. |
| 7101 |
proc cmd args { |
| 7102 |
lappend ::RES "CMD $args" |
| 7103 |
set ::forever has-been-reached |
| 7104 |
return |
| 7105 |
} |
| 7106 |
# Files we use for our channels |
| 7107 |
set foo [makeFile ashgdfashdgfasdhgfasdhgf foo] |
| 7108 |
set bar [makeFile {} bar] |
| 7109 |
# Channels to copy between |
| 7110 |
set f [open $foo r] ; chan configure $f -translation binary |
| 7111 |
set g [open $bar w] ; chan configure $g -translation binary -buffering none |
| 7112 |
} -constraints {stdio fcopy} -body { |
| 7113 |
# Initialize and force eof on the input. |
| 7114 |
chan seek $f 0 end ; chan read $f 1 |
| 7115 |
set ::RES [chan eof $f] |
| 7116 |
# Run the copy. Should not invoke -command now. |
| 7117 |
chan copy $f $g -size 2 -command [namespace code cmd] |
| 7118 |
# Check that -command was not called synchronously |
| 7119 |
lappend ::RES [expr {([llength $::RES] > 1) ? "sync/FAIL" : "sync/OK"}] |
| 7120 |
# Now let the async part happen. Should capture the eof in cmd |
| 7121 |
# If not break the event loop via timer. |
| 7122 |
set token [after 1000 { |
| 7123 |
lappend ::RES {cmd/FAIL timeout} |
| 7124 |
set ::forever has-been-reached |
| 7125 |
}] |
| 7126 |
vwait ::forever |
| 7127 |
catch {after cancel $token} |
| 7128 |
# Report |
| 7129 |
return $::RES |
| 7130 |
} -cleanup { |
| 7131 |
chan close $f |
| 7132 |
chan close $g |
| 7133 |
catch {unset ::RES} |
| 7134 |
catch {unset ::forever} |
| 7135 |
removeFile foo |
| 7136 |
removeFile bar |
| 7137 |
} -result {1 sync/OK {CMD 0}} |
| 7138 |
test chan-io-53.9 {CopyData: -size and event interaction, Bug 780533} -setup { |
| 7139 |
set out [makeFile {} out] |
| 7140 |
set err [makeFile {} err] |
| 7141 |
set pipe [open "|[list [info nameofexecutable] 2> $err]" r+] |
| 7142 |
chan configure $pipe -translation binary -buffering line |
| 7143 |
chan puts $pipe { |
| 7144 |
chan configure stdout -translation binary -buffering line |
| 7145 |
chan puts stderr Waiting... |
| 7146 |
after 1000 |
| 7147 |
foreach x {a b c} { |
| 7148 |
chan puts stderr Looping... |
| 7149 |
chan puts $x |
| 7150 |
after 500 |
| 7151 |
} |
| 7152 |
proc bye args { |
| 7153 |
if {[chan gets stdin line]<0} { |
| 7154 |
chan puts stderr "CHILD: EOF detected, exiting" |
| 7155 |
exit |
| 7156 |
} else { |
| 7157 |
chan puts stderr "CHILD: ignoring line: $line" |
| 7158 |
} |
| 7159 |
} |
| 7160 |
chan puts stderr Now-sleeping-forever |
| 7161 |
chan event stdin readable bye |
| 7162 |
vwait forever |
| 7163 |
} |
| 7164 |
proc ::done args { |
| 7165 |
set ::forever OK |
| 7166 |
return |
| 7167 |
} |
| 7168 |
set ::forever {} |
| 7169 |
set out [open $out w] |
| 7170 |
} -constraints {stdio fcopy} -body { |
| 7171 |
chan copy $pipe $out -size 6 -command ::done |
| 7172 |
set token [after 5000 { |
| 7173 |
set ::forever {fcopy hangs} |
| 7174 |
}] |
| 7175 |
vwait ::forever |
| 7176 |
catch {after cancel $token} |
| 7177 |
set ::forever |
| 7178 |
} -cleanup { |
| 7179 |
chan close $pipe |
| 7180 |
rename ::done {} |
| 7181 |
if {[testConstraint win]} { |
| 7182 |
after 1000; # Allow Windows time to figure out that the |
| 7183 |
# process is gone |
| 7184 |
} |
| 7185 |
catch {close $out} |
| 7186 |
catch {removeFile out} |
| 7187 |
catch {removeFile err} |
| 7188 |
catch {unset ::forever} |
| 7189 |
} -result OK |
| 7190 |
test chan-io-53.10 {Bug 1350564, multi-directional fcopy} -setup { |
| 7191 |
set err [makeFile {} err] |
| 7192 |
set pipe [open "|[list [info nameofexecutable] 2> $err]" r+] |
| 7193 |
chan configure $pipe -translation binary -buffering line |
| 7194 |
chan puts $pipe { |
| 7195 |
chan configure stderr -buffering line |
| 7196 |
# Kill server when pipe closed by invoker. |
| 7197 |
proc bye args { |
| 7198 |
if {![chan eof stdin]} { chan gets stdin ; return } |
| 7199 |
chan puts stderr BYE |
| 7200 |
exit |
| 7201 |
} |
| 7202 |
# Server code. Bi-directional copy between 2 sockets. |
| 7203 |
proc geof {sok} { |
| 7204 |
chan puts stderr DONE/$sok |
| 7205 |
chan close $sok |
| 7206 |
} |
| 7207 |
proc new {sok args} { |
| 7208 |
chan puts stderr NEW/$sok |
| 7209 |
global l srv |
| 7210 |
chan configure $sok -translation binary -buffering none |
| 7211 |
lappend l $sok |
| 7212 |
if {[llength $l] == 2} { |
| 7213 |
chan close $srv |
| 7214 |
foreach {a b} $l break |
| 7215 |
chan copy $a $b -command [list geof $a] |
| 7216 |
chan copy $b $a -command [list geof $b] |
| 7217 |
chan puts stderr 2COPY |
| 7218 |
} |
| 7219 |
chan puts stderr ... |
| 7220 |
} |
| 7221 |
chan puts stderr SRV |
| 7222 |
set l {} |
| 7223 |
set srv [socket -server new -myaddr 127.0.0.1 0] |
| 7224 |
set port [lindex [chan configure $srv -sockname] 2] |
| 7225 |
chan puts stderr WAITING |
| 7226 |
chan event stdin readable bye |
| 7227 |
puts "OK $port" |
| 7228 |
vwait forever |
| 7229 |
} |
| 7230 |
# wait for OK from server. |
| 7231 |
lassign [chan gets $pipe] ok port |
| 7232 |
# Now the two clients. |
| 7233 |
proc done {sock} { |
| 7234 |
if {[chan eof $sock]} { chan close $sock ; return } |
| 7235 |
lappend ::forever [chan gets $sock] |
| 7236 |
return |
| 7237 |
} |
| 7238 |
set a [socket 127.0.0.1 $port] |
| 7239 |
set b [socket 127.0.0.1 $port] |
| 7240 |
chan configure $a -translation binary -buffering none |
| 7241 |
chan configure $b -translation binary -buffering none |
| 7242 |
chan event $a readable [namespace code "done $a"] |
| 7243 |
chan event $b readable [namespace code "done $b"] |
| 7244 |
} -constraints {stdio fcopy} -body { |
| 7245 |
# Now pass data through the server in both directions. |
| 7246 |
set ::forever {} |
| 7247 |
chan puts $a AB |
| 7248 |
vwait ::forever |
| 7249 |
chan puts $b BA |
| 7250 |
vwait ::forever |
| 7251 |
set ::forever |
| 7252 |
} -cleanup { |
| 7253 |
catch {chan close $a} |
| 7254 |
catch {chan close $b} |
| 7255 |
chan close $pipe |
| 7256 |
if {[testConstraint win]} { |
| 7257 |
after 1000 ;# Give Windows time to kill the process |
| 7258 |
} |
| 7259 |
removeFile err |
| 7260 |
catch {unset ::forever} |
| 7261 |
} -result {AB BA} |
| 7262 |
|
| 7263 |
test chan-io-54.1 {Recursive channel events} {socket fileevent} { |
| 7264 |
# This test checks to see if file events are delivered during recursive |
| 7265 |
# event loops when there is buffered data on the channel. |
| 7266 |
proc accept {s a p} { |
| 7267 |
variable as |
| 7268 |
chan configure $s -translation lf |
| 7269 |
chan puts $s "line 1\nline2\nline3" |
| 7270 |
chan flush $s |
| 7271 |
set as $s |
| 7272 |
} |
| 7273 |
proc readit {s next} { |
| 7274 |
variable x |
| 7275 |
variable result |
| 7276 |
lappend result $next |
| 7277 |
if {$next == 1} { |
| 7278 |
chan event $s readable [namespace code [list readit $s 2]] |
| 7279 |
vwait [namespace which -variable x] |
| 7280 |
} |
| 7281 |
incr x |
| 7282 |
} |
| 7283 |
set ss [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 7284 |
# We need to delay on some systems until the creation of the server socket |
| 7285 |
# completes. |
| 7286 |
set done 0 |
| 7287 |
for {set i 0} {$i < 10} {incr i} { |
| 7288 |
if {![catch { |
| 7289 |
set cs [socket 127.0.0.1 [lindex [chan configure $ss -sockname] 2]] |
| 7290 |
}]} { |
| 7291 |
set done 1 |
| 7292 |
break |
| 7293 |
} |
| 7294 |
after 100 |
| 7295 |
} |
| 7296 |
if {$done == 0} { |
| 7297 |
chan close $ss |
| 7298 |
error "failed to connect to server" |
| 7299 |
} |
| 7300 |
variable result {} |
| 7301 |
variable x 0 |
| 7302 |
variable as |
| 7303 |
vwait [namespace which -variable as] |
| 7304 |
chan configure $cs -translation lf |
| 7305 |
lappend result [chan gets $cs] |
| 7306 |
chan configure $cs -blocking off |
| 7307 |
chan event $cs readable [namespace code [list readit $cs 1]] |
| 7308 |
set a [after 2000 [namespace code { set x failure }]] |
| 7309 |
vwait [namespace which -variable x] |
| 7310 |
after cancel $a |
| 7311 |
chan close $as |
| 7312 |
chan close $ss |
| 7313 |
chan close $cs |
| 7314 |
list $result $x |
| 7315 |
} {{{line 1} 1 2} 2} |
| 7316 |
test chan-io-54.2 {Testing for busy-wait in recursive channel events} -setup { |
| 7317 |
set accept {} |
| 7318 |
set after {} |
| 7319 |
variable done 0 |
| 7320 |
} -constraints {socket fileevent} -body { |
| 7321 |
variable s [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 7322 |
proc accept {s a p} { |
| 7323 |
variable counter 0 |
| 7324 |
variable accept $s |
| 7325 |
chan configure $s -blocking off -buffering line -translation lf |
| 7326 |
chan event $s readable [namespace code "doit $s"] |
| 7327 |
} |
| 7328 |
proc doit {s} { |
| 7329 |
variable counter |
| 7330 |
variable after |
| 7331 |
incr counter |
| 7332 |
if {[chan gets $s] eq ""} { |
| 7333 |
chan event $s readable [namespace code "doit1 $s"] |
| 7334 |
set after [after 1000 [namespace code { |
| 7335 |
chan puts $writer hello |
| 7336 |
chan flush $writer |
| 7337 |
set done 1 |
| 7338 |
}]] |
| 7339 |
} |
| 7340 |
} |
| 7341 |
proc doit1 {s} { |
| 7342 |
variable counter |
| 7343 |
variable accept |
| 7344 |
incr counter |
| 7345 |
chan gets $s |
| 7346 |
chan close $s |
| 7347 |
set accept {} |
| 7348 |
} |
| 7349 |
proc producer {} { |
| 7350 |
variable s |
| 7351 |
variable writer |
| 7352 |
set writer [socket 127.0.0.1 [lindex [chan configure $s -sockname] 2]] |
| 7353 |
chan configure $writer -buffering line |
| 7354 |
chan puts -nonewline $writer hello |
| 7355 |
chan flush $writer |
| 7356 |
} |
| 7357 |
producer |
| 7358 |
vwait [namespace which -variable done] |
| 7359 |
chan close $writer |
| 7360 |
chan close $s |
| 7361 |
after cancel $after |
| 7362 |
set counter |
| 7363 |
} -cleanup { |
| 7364 |
if {$accept ne {}} {chan close $accept} |
| 7365 |
} -result 1 |
| 7366 |
|
| 7367 |
set path(fooBar) [makeFile {} fooBar] |
| 7368 |
|
| 7369 |
test chan-io-55.1 {ChannelEventScriptInvoker: deletion} -constraints { |
| 7370 |
fileevent |
| 7371 |
} -setup { |
| 7372 |
variable x |
| 7373 |
proc eventScript {fd} { |
| 7374 |
variable x |
| 7375 |
chan close $fd |
| 7376 |
error "planned error" |
| 7377 |
set x whoops |
| 7378 |
} |
| 7379 |
proc myHandler args { |
| 7380 |
variable x got_error |
| 7381 |
} |
| 7382 |
set handler [interp bgerror {}] |
| 7383 |
interp bgerror {} [namespace which myHandler] |
| 7384 |
} -body { |
| 7385 |
set f [open $path(fooBar) w] |
| 7386 |
chan event $f writable [namespace code [list eventScript $f]] |
| 7387 |
variable x not_done |
| 7388 |
vwait [namespace which -variable x] |
| 7389 |
set x |
| 7390 |
} -cleanup { |
| 7391 |
interp bgerror {} $handler |
| 7392 |
} -result {got_error} |
| 7393 |
|
| 7394 |
test chan-io-56.1 {ChannelTimerProc} {testchannelevent} { |
| 7395 |
set f [open $path(fooBar) w] |
| 7396 |
chan puts $f "this is a test" |
| 7397 |
chan close $f |
| 7398 |
set f [open $path(fooBar) r] |
| 7399 |
testchannelevent $f add readable [namespace code { |
| 7400 |
chan read $f 1 |
| 7401 |
incr x |
| 7402 |
}] |
| 7403 |
variable x 0 |
| 7404 |
vwait [namespace which -variable x] |
| 7405 |
vwait [namespace which -variable x] |
| 7406 |
set result $x |
| 7407 |
testchannelevent $f set 0 none |
| 7408 |
after idle [namespace code {set y done}] |
| 7409 |
variable y |
| 7410 |
vwait [namespace which -variable y] |
| 7411 |
chan close $f |
| 7412 |
lappend result $y |
| 7413 |
} {2 done} |
| 7414 |
|
| 7415 |
test chan-io-57.1 {buffered data and file events, gets} -setup { |
| 7416 |
variable s2 |
| 7417 |
} -constraints {fileevent} -body { |
| 7418 |
proc accept {sock args} { |
| 7419 |
variable s2 |
| 7420 |
set s2 $sock |
| 7421 |
} |
| 7422 |
set server [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 7423 |
set s [socket 127.0.0.1 [lindex [chan configure $server -sockname] 2]] |
| 7424 |
vwait [namespace which -variable s2] |
| 7425 |
update |
| 7426 |
chan event $s2 readable [namespace code {lappend result readable}] |
| 7427 |
chan puts $s "12\n34567890" |
| 7428 |
chan flush $s |
| 7429 |
variable result [chan gets $s2] |
| 7430 |
after 1000 [namespace code {lappend result timer}] |
| 7431 |
vwait [namespace which -variable result] |
| 7432 |
lappend result [chan gets $s2] |
| 7433 |
vwait [namespace which -variable result] |
| 7434 |
set result |
| 7435 |
} -cleanup { |
| 7436 |
chan close $s |
| 7437 |
chan close $s2 |
| 7438 |
chan close $server |
| 7439 |
} -result {12 readable 34567890 timer} |
| 7440 |
test chan-io-57.2 {buffered data and file events, read} -setup { |
| 7441 |
variable s2 |
| 7442 |
} -constraints {fileevent} -body { |
| 7443 |
proc accept {sock args} { |
| 7444 |
variable s2 |
| 7445 |
set s2 $sock |
| 7446 |
} |
| 7447 |
set server [socket -server [namespace code accept] -myaddr 127.0.0.1 0] |
| 7448 |
set s [socket 127.0.0.1 [lindex [chan configure $server -sockname] 2]] |
| 7449 |
vwait [namespace which -variable s2] |
| 7450 |
update |
| 7451 |
chan event $s2 readable [namespace code {lappend result readable}] |
| 7452 |
chan puts -nonewline $s "1234567890" |
| 7453 |
chan flush $s |
| 7454 |
variable result [chan read $s2 1] |
| 7455 |
after 1000 [namespace code {lappend result timer}] |
| 7456 |
vwait [namespace which -variable result] |
| 7457 |
lappend result [chan read $s2 9] |
| 7458 |
vwait [namespace which -variable result] |
| 7459 |
set result |
| 7460 |
} -cleanup { |
| 7461 |
chan close $s |
| 7462 |
chan close $s2 |
| 7463 |
chan close $server |
| 7464 |
} -result {1 readable 234567890 timer} |
| 7465 |
|
| 7466 |
test chan-io-58.1 {Tcl_NotifyChannel and error when closing} {stdio unixOrWin fileevent} { |
| 7467 |
set out [open $path(script) w] |
| 7468 |
chan puts $out { |
| 7469 |
chan puts "normal message from pipe" |
| 7470 |
chan puts stderr "error message from pipe" |
| 7471 |
exit 1 |
| 7472 |
} |
| 7473 |
proc readit {pipe} { |
| 7474 |
variable x |
| 7475 |
variable result |
| 7476 |
if {[chan eof $pipe]} { |
| 7477 |
set x [catch {chan close $pipe} line] |
| 7478 |
lappend result catch $line |
| 7479 |
} else { |
| 7480 |
chan gets $pipe line |
| 7481 |
lappend result chan gets $line |
| 7482 |
} |
| 7483 |
} |
| 7484 |
chan close $out |
| 7485 |
set pipe [openpipe r $path(script)] |
| 7486 |
chan event $pipe readable [namespace code [list readit $pipe]] |
| 7487 |
variable x "" |
| 7488 |
set result "" |
| 7489 |
vwait [namespace which -variable x] |
| 7490 |
list $x $result |
| 7491 |
} {1 {chan gets {normal message from pipe} chan gets {} catch {error message from pipe}}} |
| 7492 |
|
| 7493 |
test chan-io-59.1 {Thread reference of channels} {testmainthread testchannel} { |
| 7494 |
# TIP #10 |
| 7495 |
# More complicated tests (like that the reference changes as a channel is |
| 7496 |
# moved from thread to thread) can be done only in the extension which |
| 7497 |
# fully implements the moving of channels between threads, i.e. 'Threads'. |
| 7498 |
set f [open $path(longfile) r] |
| 7499 |
set result [testchannel mthread $f] |
| 7500 |
chan close $f |
| 7501 |
string equal $result [testmainthread] |
| 7502 |
} {1} |
| 7503 |
|
| 7504 |
test chan-io-60.1 {writing illegal utf sequences} {fileevent testbytestring} { |
| 7505 |
# This test will hang in older revisions of the core. |
| 7506 |
set out [open $path(script) w] |
| 7507 |
chan puts $out "catch {load $::tcltestlib Tcltest}" |
| 7508 |
chan puts $out { |
| 7509 |
chan puts [testbytestring \xE2] |
| 7510 |
exit 1 |
| 7511 |
} |
| 7512 |
proc readit {pipe} { |
| 7513 |
variable x |
| 7514 |
variable result |
| 7515 |
if {[chan eof $pipe]} { |
| 7516 |
set x [catch {chan close $pipe} line] |
| 7517 |
lappend result catch $line |
| 7518 |
} else { |
| 7519 |
chan gets $pipe line |
| 7520 |
lappend result gets $line |
| 7521 |
} |
| 7522 |
} |
| 7523 |
chan close $out |
| 7524 |
set pipe [openpipe r $path(script)] |
| 7525 |
chan event $pipe readable [namespace code [list readit $pipe]] |
| 7526 |
variable x "" |
| 7527 |
set result "" |
| 7528 |
vwait [namespace which -variable x] |
| 7529 |
# cut of the remainder of the error stack, especially the filename |
| 7530 |
set result [lreplace $result 3 3 [lindex [split [lindex $result 3] \n] 0]] |
| 7531 |
list $x $result |
| 7532 |
} {1 {gets {} catch {error writing "stdout": invalid argument}}} |
| 7533 |
|
| 7534 |
test chan-io-61.1 {Reset eof state after changing the eof char} -setup { |
| 7535 |
set datafile [makeFile {} eofchar] |
| 7536 |
set f [open $datafile w] |
| 7537 |
chan configure $f -translation binary |
| 7538 |
chan puts -nonewline $f [string repeat "Ho hum\n" 11] |
| 7539 |
chan puts $f = |
| 7540 |
set line [string repeat "Ge gla " 4] |
| 7541 |
chan puts -nonewline $f [string repeat [string trimright $line]\n 834] |
| 7542 |
chan close $f |
| 7543 |
} -body { |
| 7544 |
set f [open $datafile r] |
| 7545 |
chan configure $f -eofchar = |
| 7546 |
set res {} |
| 7547 |
lappend res [chan read $f; chan tell $f] |
| 7548 |
chan configure $f -eofchar {} |
| 7549 |
lappend res [chan read $f 1] |
| 7550 |
lappend res [chan read $f; chan tell $f] |
| 7551 |
# Any seek zaps the internals into a good state. |
| 7552 |
#chan seek $f 0 start |
| 7553 |
#chan seek $f 0 current |
| 7554 |
#lappend res [chan read $f; chan tell $f] |
| 7555 |
} -cleanup { |
| 7556 |
chan close $f |
| 7557 |
removeFile eofchar |
| 7558 |
} -result {77 = 23431} |
| 7559 |
|
| 7560 |
# Test the cutting and splicing of channels, this is incidentally the |
| 7561 |
# attach/detach facility of package Thread, but __without any safeguards__. It |
| 7562 |
# can also be used to emulate transfer of channels between threads, and is |
| 7563 |
# used for that here. |
| 7564 |
|
| 7565 |
test chan-io-70.0 {Cutting & Splicing channels} -setup { |
| 7566 |
set f [makeFile {... dummy ...} cutsplice] |
| 7567 |
set res {} |
| 7568 |
} -constraints {testchannel} -body { |
| 7569 |
set c [open $f r] |
| 7570 |
lappend res [catch {chan seek $c 0 start}] |
| 7571 |
testchannel cut $c |
| 7572 |
lappend res [catch {chan seek $c 0 start}] |
| 7573 |
testchannel splice $c |
| 7574 |
lappend res [catch {chan seek $c 0 start}] |
| 7575 |
} -cleanup { |
| 7576 |
chan close $c |
| 7577 |
removeFile cutsplice |
| 7578 |
} -result {0 1 0} |
| 7579 |
|
| 7580 |
test chan-io-70.1 {Transfer channel} -setup { |
| 7581 |
set f [makeFile {... dummy ...} cutsplice] |
| 7582 |
set res {} |
| 7583 |
} -constraints {testchannel thread} -body { |
| 7584 |
set c [open $f r] |
| 7585 |
lappend res [catch {chan seek $c 0 start}] |
| 7586 |
testchannel cut $c |
| 7587 |
lappend res [catch {chan seek $c 0 start}] |
| 7588 |
set tid [thread::create -preserved] |
| 7589 |
thread::send $tid [list set c $c] |
| 7590 |
thread::send $tid {load {} Tcltest} |
| 7591 |
lappend res [thread::send $tid { |
| 7592 |
testchannel splice $c |
| 7593 |
set res [catch {chan seek $c 0 start}] |
| 7594 |
chan close $c |
| 7595 |
set res |
| 7596 |
}] |
| 7597 |
} -cleanup { |
| 7598 |
thread::release $tid |
| 7599 |
removeFile cutsplice |
| 7600 |
} -result {0 1 0} |
| 7601 |
|
| 7602 |
# ### ### ### ######### ######### ######### |
| 7603 |
|
| 7604 |
foreach {n msg expected} { |
| 7605 |
0 {} {} |
| 7606 |
1 {{message only}} {{message only}} |
| 7607 |
2 {-options x} {-options x} |
| 7608 |
3 {-options {x y} {the message}} {-options {x y} {the message}} |
| 7609 |
|
| 7610 |
4 {-code 1 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7611 |
5 {-code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7612 |
6 {-code 1 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7613 |
7 {-code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7614 |
8 {-code error -level 0 -f ba snarf} {-code error -level 0 -f ba snarf} |
| 7615 |
9 {-code ok -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7616 |
10 {-code error -level 5 -f ba snarf} {-code error -level 0 -f ba snarf} |
| 7617 |
11 {-code ok -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7618 |
12 {-code boss -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7619 |
13 {-code boss -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7620 |
14 {-code 1 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7621 |
15 {-code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7622 |
16 {-code 1 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7623 |
17 {-code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7624 |
18 {-code error -level 0 -f ba} {-code error -level 0 -f ba} |
| 7625 |
19 {-code ok -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7626 |
20 {-code error -level 5 -f ba} {-code error -level 0 -f ba} |
| 7627 |
21 {-code ok -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7628 |
22 {-code boss -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7629 |
23 {-code boss -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7630 |
24 {-code 1 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7631 |
25 {-code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7632 |
26 {-code error -level X -f ba snarf} {-code error -level 0 -f ba snarf} |
| 7633 |
27 {-code ok -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7634 |
28 {-code boss -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7635 |
29 {-code 1 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7636 |
30 {-code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7637 |
31 {-code error -level X -f ba} {-code error -level 0 -f ba} |
| 7638 |
32 {-code ok -level X -f ba} {-code 1 -level 0 -f ba} |
| 7639 |
33 {-code boss -level X -f ba} {-code 1 -level 0 -f ba} |
| 7640 |
|
| 7641 |
34 {-code 1 -code 1 -level 0 -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7642 |
35 {-code 1 -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7643 |
36 {-code 1 -code 1 -level 5 -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7644 |
37 {-code 1 -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7645 |
38 {-code 1 -code error -level 0 -f ba snarf} {-code 1 -code error -level 0 -f ba snarf} |
| 7646 |
39 {-code 1 -code ok -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7647 |
40 {-code 1 -code error -level 5 -f ba snarf} {-code 1 -code error -level 0 -f ba snarf} |
| 7648 |
41 {-code 1 -code ok -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7649 |
42 {-code 1 -code boss -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7650 |
43 {-code 1 -code boss -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7651 |
44 {-code 1 -code 1 -level 0 -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7652 |
45 {-code 1 -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7653 |
46 {-code 1 -code 1 -level 5 -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7654 |
47 {-code 1 -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7655 |
48 {-code 1 -code error -level 0 -f ba} {-code 1 -code error -level 0 -f ba} |
| 7656 |
49 {-code 1 -code ok -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7657 |
50 {-code 1 -code error -level 5 -f ba} {-code 1 -code error -level 0 -f ba} |
| 7658 |
51 {-code 1 -code ok -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7659 |
52 {-code 1 -code boss -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7660 |
53 {-code 1 -code boss -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7661 |
54 {-code 1 -code 1 -level X -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7662 |
55 {-code 1 -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7663 |
56 {-code 1 -code error -level X -f ba snarf} {-code 1 -code error -level 0 -f ba snarf} |
| 7664 |
57 {-code 1 -code ok -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7665 |
58 {-code 1 -code boss -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7666 |
59 {-code 1 -code 1 -level X -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7667 |
60 {-code 1 -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7668 |
61 {-code 1 -code error -level X -f ba} {-code 1 -code error -level 0 -f ba} |
| 7669 |
62 {-code 1 -code ok -level X -f ba} {-code 1 -level 0 -f ba} |
| 7670 |
63 {-code 1 -code boss -level X -f ba} {-code 1 -level 0 -f ba} |
| 7671 |
|
| 7672 |
64 {-code 0 -code 1 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7673 |
65 {-code 0 -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7674 |
66 {-code 0 -code 1 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7675 |
67 {-code 0 -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7676 |
68 {-code 0 -code error -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7677 |
69 {-code 0 -code ok -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7678 |
70 {-code 0 -code error -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7679 |
71 {-code 0 -code ok -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7680 |
72 {-code 0 -code boss -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7681 |
73 {-code 0 -code boss -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7682 |
74 {-code 0 -code 1 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7683 |
75 {-code 0 -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7684 |
76 {-code 0 -code 1 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7685 |
77 {-code 0 -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7686 |
78 {-code 0 -code error -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7687 |
79 {-code 0 -code ok -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7688 |
80 {-code 0 -code error -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7689 |
81 {-code 0 -code ok -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7690 |
82 {-code 0 -code boss -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7691 |
83 {-code 0 -code boss -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7692 |
84 {-code 0 -code 1 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7693 |
85 {-code 0 -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7694 |
86 {-code 0 -code error -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7695 |
87 {-code 0 -code ok -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7696 |
88 {-code 0 -code boss -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7697 |
89 {-code 0 -code 1 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7698 |
90 {-code 0 -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7699 |
91 {-code 0 -code error -level X -f ba} {-code 1 -level 0 -f ba} |
| 7700 |
92 {-code 0 -code ok -level X -f ba} {-code 1 -level 0 -f ba} |
| 7701 |
93 {-code 0 -code boss -level X -f ba} {-code 1 -level 0 -f ba} |
| 7702 |
|
| 7703 |
94 {-code 1 -code 1 -level 0 -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7704 |
95 {-code 0 -code 1 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7705 |
96 {-code 1 -code 1 -level 5 -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7706 |
97 {-code 0 -code 1 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7707 |
98 {-code error -code 1 -level 0 -f ba snarf} {-code error -code 1 -level 0 -f ba snarf} |
| 7708 |
99 {-code ok -code 1 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7709 |
a0 {-code error -code 1 -level 5 -f ba snarf} {-code error -code 1 -level 0 -f ba snarf} |
| 7710 |
a1 {-code ok -code 1 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7711 |
a2 {-code boss -code 1 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7712 |
a3 {-code boss -code 1 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7713 |
a4 {-code 1 -code 1 -level 0 -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7714 |
a5 {-code 0 -code 1 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7715 |
a6 {-code 1 -code 1 -level 5 -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7716 |
a7 {-code 0 -code 1 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7717 |
a8 {-code error -code 1 -level 0 -f ba} {-code error -code 1 -level 0 -f ba} |
| 7718 |
a9 {-code ok -code 1 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7719 |
b0 {-code error -code 1 -level 5 -f ba} {-code error -code 1 -level 0 -f ba} |
| 7720 |
b1 {-code ok -code 1 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7721 |
b2 {-code boss -code 1 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7722 |
b3 {-code boss -code 1 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7723 |
b4 {-code 1 -code 1 -level X -f ba snarf} {-code 1 -code 1 -level 0 -f ba snarf} |
| 7724 |
b5 {-code 0 -code 1 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7725 |
b6 {-code error -code 1 -level X -f ba snarf} {-code error -code 1 -level 0 -f ba snarf} |
| 7726 |
b7 {-code ok -code 1 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7727 |
b8 {-code boss -code 1 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7728 |
b9 {-code 1 -code 1 -level X -f ba} {-code 1 -code 1 -level 0 -f ba} |
| 7729 |
c0 {-code 0 -code 1 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7730 |
c1 {-code error -code 1 -level X -f ba} {-code error -code 1 -level 0 -f ba} |
| 7731 |
c2 {-code ok -code 1 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7732 |
c3 {-code boss -code 1 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7733 |
|
| 7734 |
c4 {-code 1 -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7735 |
c5 {-code 0 -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7736 |
c6 {-code 1 -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7737 |
c7 {-code 0 -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7738 |
c8 {-code error -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7739 |
c9 {-code ok -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7740 |
d0 {-code error -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7741 |
d1 {-code ok -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7742 |
d2 {-code boss -code 0 -level 0 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7743 |
d3 {-code boss -code 0 -level 5 -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7744 |
d4 {-code 1 -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7745 |
d5 {-code 0 -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7746 |
d6 {-code 1 -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7747 |
d7 {-code 0 -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7748 |
d8 {-code error -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7749 |
d9 {-code ok -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7750 |
e0 {-code error -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7751 |
e1 {-code ok -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7752 |
e2 {-code boss -code 0 -level 0 -f ba} {-code 1 -level 0 -f ba} |
| 7753 |
e3 {-code boss -code 0 -level 5 -f ba} {-code 1 -level 0 -f ba} |
| 7754 |
e4 {-code 1 -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7755 |
e5 {-code 0 -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7756 |
e6 {-code error -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7757 |
e7 {-code ok -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7758 |
e8 {-code boss -code 0 -level X -f ba snarf} {-code 1 -level 0 -f ba snarf} |
| 7759 |
e9 {-code 1 -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7760 |
f0 {-code 0 -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7761 |
f1 {-code error -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7762 |
f2 {-code ok -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7763 |
f3 {-code boss -code 0 -level X -f ba} {-code 1 -level 0 -f ba} |
| 7764 |
} { |
| 7765 |
test chan-io-71.$n {Tcl_SetChannelError} -setup { |
| 7766 |
set f [makeFile {... dummy ...} cutsplice] |
| 7767 |
} -constraints {testchannel} -body { |
| 7768 |
set c [open $f r] |
| 7769 |
testchannel setchannelerror $c [lrange $msg 0 end] |
| 7770 |
} -cleanup { |
| 7771 |
chan close $c |
| 7772 |
removeFile cutsplice |
| 7773 |
} -result [lrange $expected 0 end] |
| 7774 |
test chan-io-72.$n {Tcl_SetChannelErrorInterp} -setup { |
| 7775 |
set f [makeFile {... dummy ...} cutsplice] |
| 7776 |
} -constraints {testchannel} -body { |
| 7777 |
set c [open $f r] |
| 7778 |
testchannel setchannelerrorinterp $c [lrange $msg 0 end] |
| 7779 |
} -cleanup { |
| 7780 |
chan close $c |
| 7781 |
removeFile cutsplice |
| 7782 |
} -result [lrange $expected 0 end] |
| 7783 |
} |
| 7784 |
|
| 7785 |
test chan-io-73.1 {channel Tcl_Obj SetChannelFromAny} -body { |
| 7786 |
# Test for Bug 1847044 - don't spoil type unless we have a valid channel |
| 7787 |
chan close [lreplace [list a] 0 end] |
| 7788 |
} -returnCodes error -match glob -result * |
| 7789 |
|
| 7790 |
# ### ### ### ######### ######### ######### |
| 7791 |
|
| 7792 |
# cleanup |
| 7793 |
foreach file [list fooBar longfile script output test1 pipe my_script \ |
| 7794 |
test2 test3 cat kyrillic.txt utf8-fcopy.txt utf8-rp.txt] { |
| 7795 |
removeFile $file |
| 7796 |
} |
| 7797 |
cleanupTests |
| 7798 |
} |
| 7799 |
namespace delete ::tcl::test::io |