Attachment "chan.test.patch" to
ticket [1586860fff]
added by
cleverly
2006-11-01 11:01:43.
--- tests/chan.test.orig 2006-10-29 13:59:35.000000000 -0700
+++ tests/chan.test 2006-10-31 20:55:42.000000000 -0700
@@ -24,7 +24,7 @@
} -returnCodes error -result "wrong # args: should be \"chan subcommand ?argument ...?\""
test chan-1.2 {chan command general syntax} -body {
chan FOOBAR
-} -returnCodes error -result "unknown or ambiguous subcommand \"FOOBAR\": must be blocked, close, configure, copy, create, eof, event, flush, gets, names, postevent, puts, read, seek, tell, or truncate"
+} -returnCodes error -result "unknown or ambiguous subcommand \"FOOBAR\": must be available, blocked, close, configure, copy, create, eof, event, flush, gets, names, postevent, puts, read, seek, tell, or truncate"
test chan-2.1 {chan command: blocked subcommand} -body {
chan blocked foo bar
@@ -96,6 +96,83 @@
catch {removeFile $file}
}
+# TIP 287: chan available
+test chan-16.1 {chan command: available subcommand} -body {
+ chan available foo bar
+} -returnCodes error -result "wrong # args: should be \"chan available channelId\""
+test chan-16.2 {chan command: available subcommand} -body {
+ chan available stdout
+} -returnCodes error -result "channel \"stdout\" wasn't opened for reading"
+test chan-16.3 {chan command: available subcommand} -body {
+ chan available stdin
+} -result 0
+test chan-16.4 {chan command: available subcommand} -body {
+ chan available FOOBAR
+} -returnCodes error -result "can not find channel named \"FOOBAR\""
+test chan-16.5 {chan command: available subcommand} -setup {
+ set file [makeFile {} testAvailable]
+ set f [open $file w+]
+ chan configure $f -translation lf -buffering line
+} -body {
+ chan puts $f foo
+ chan puts $f bar
+ chan puts $f baz
+ chan seek $f 0
+ chan gets $f
+ chan available $f
+} -result 8 -cleanup {
+ catch {chan close $f}
+ catch {removeFile $file}
+}
+test chan-16.6 {chan command: available subcommand} -setup {
+ proc chan-16.6-accept {sock addr port} {
+ chan configure $sock -blocking 0 -buffering line -buffersize 32
+ chan event $sock readable [list chan-16.6-readable $sock]
+ }
+
+ proc chan-16.6-readable {sock} {
+ set r [chan gets $sock line]
+ set l [string length $line]
+ set e [chan eof $sock]
+ set b [chan blocked $sock]
+ set a [chan available $sock]
+
+ lappend ::chan-16.6-data $r $l $e $b $a
+
+ if {$r != -1 || $e || $l || !$b || $a > 128} {
+ set data [read $sock $a]
+ lappend ::chan-16.6-data [string range $data 0 2]
+ lappend ::chan-16.6-data [string range $data end-2 end]
+ set ::chan-16.6-done 1
+ }
+ }
+
+ proc chan-16.6-client {} {
+ chan puts -nonewline $::client ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
+ chan flush $::client
+ after 100 chan-16.6-client
+ }
+
+ set ::server [socket -server chan-16.6-accept -myaddr 127.0.0.1 0]
+ set ::client [socket 127.0.0.1 [lindex [fconfigure $::server -sockname] 2]]
+ set ::chan-16.6-data [list]
+ set ::chan-16.6-done 0
+} -body {
+ after idle chan-16.6-client
+ vwait ::chan-16.6-done
+ set ::chan-16.6-data
+} -result {-1 0 0 1 36 -1 0 0 1 72 -1 0 0 1 108 -1 0 0 1 144 ABC 890} -cleanup {
+ catch {chan close $client}
+ catch {chan close $server}
+ rename chan-16.6-accept {}
+ rename chan-16.6-readable {}
+ rename chan-16.6-client {}
+ unset -nocomplain ::chan-16.6-data
+ unset -nocomplain ::chan-16.6-done
+ unset -nocomplain ::server
+ unset -nocomplain ::client
+}
+
cleanupTests
return