sl@0: # -*- tcl -*- sl@0: # Commands covered: open, close, gets, read, puts, seek, tell, eof, flush, sl@0: # fblocked, fconfigure, open, channel, fcopy sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1994 The Regents of the University of California. sl@0: # Copyright (c) 1994-1996 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: ioCmd.test,v 1.16.2.3 2006/03/16 18:23:24 andreas_kupries Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: testConstraint fcopy [llength [info commands fcopy]] sl@0: sl@0: test iocmd-1.1 {puts command} { sl@0: list [catch {puts} msg] $msg sl@0: } {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}} sl@0: test iocmd-1.2 {puts command} { sl@0: list [catch {puts a b c d e f g} msg] $msg sl@0: } {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}} sl@0: test iocmd-1.3 {puts command} { sl@0: list [catch {puts froboz -nonewline kablooie} msg] $msg sl@0: } {1 {bad argument "kablooie": should be "nonewline"}} sl@0: test iocmd-1.4 {puts command} { sl@0: list [catch {puts froboz hello} msg] $msg sl@0: } {1 {can not find channel named "froboz"}} sl@0: test iocmd-1.5 {puts command} { sl@0: list [catch {puts stdin hello} msg] $msg sl@0: } {1 {channel "stdin" wasn't opened for writing}} sl@0: sl@0: set path(test1) [makeFile {} test1] sl@0: sl@0: test iocmd-1.6 {puts command} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts -nonewline $f foobar sl@0: close $f sl@0: file size $path(test1) sl@0: } 6 sl@0: test iocmd-1.7 {puts command} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} sl@0: puts $f foobar sl@0: close $f sl@0: file size $path(test1) sl@0: } 7 sl@0: test iocmd-1.8 {puts command} { sl@0: set f [open $path(test1) w] sl@0: fconfigure $f -translation lf -eofchar {} -encoding iso8859-1 sl@0: puts -nonewline $f [binary format a4a5 foo bar] sl@0: close $f sl@0: file size $path(test1) sl@0: } 9 sl@0: sl@0: sl@0: test iocmd-2.1 {flush command} { sl@0: list [catch {flush} msg] $msg sl@0: } {1 {wrong # args: should be "flush channelId"}} sl@0: test iocmd-2.2 {flush command} { sl@0: list [catch {flush a b c d e} msg] $msg sl@0: } {1 {wrong # args: should be "flush channelId"}} sl@0: test iocmd-2.3 {flush command} { sl@0: list [catch {flush foo} msg] $msg sl@0: } {1 {can not find channel named "foo"}} sl@0: test iocmd-2.4 {flush command} { sl@0: list [catch {flush stdin} msg] $msg sl@0: } {1 {channel "stdin" wasn't opened for writing}} sl@0: sl@0: test iocmd-3.1 {gets command} { sl@0: list [catch {gets} msg] $msg sl@0: } {1 {wrong # args: should be "gets channelId ?varName?"}} sl@0: test iocmd-3.2 {gets command} { sl@0: list [catch {gets a b c d e f g} msg] $msg sl@0: } {1 {wrong # args: should be "gets channelId ?varName?"}} sl@0: test iocmd-3.3 {gets command} { sl@0: list [catch {gets aaa} msg] $msg sl@0: } {1 {can not find channel named "aaa"}} sl@0: test iocmd-3.4 {gets command} { sl@0: list [catch {gets stdout} msg] $msg sl@0: } {1 {channel "stdout" wasn't opened for reading}} sl@0: test iocmd-3.5 {gets command} { sl@0: set f [open $path(test1) w] sl@0: puts $f [binary format a4a5 foo bar] sl@0: close $f sl@0: set f [open $path(test1) r] sl@0: set result [gets $f] sl@0: close $f sl@0: set x foo\x00 sl@0: set x "${x}bar\x00\x00" sl@0: string compare $x $result sl@0: } 0 sl@0: sl@0: test iocmd-4.1 {read command} { sl@0: list [catch {read} msg] $msg sl@0: } {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}} sl@0: test iocmd-4.2 {read command} { sl@0: list [catch {read a b c d e f g h} msg] $msg sl@0: } {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}} sl@0: test iocmd-4.3 {read command} { sl@0: list [catch {read aaa} msg] $msg sl@0: } {1 {can not find channel named "aaa"}} sl@0: test iocmd-4.4 {read command} { sl@0: list [catch {read -nonewline} msg] $msg sl@0: } {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}} sl@0: test iocmd-4.5 {read command} { sl@0: list [catch {read -nonew file4} msg] $msg $errorCode sl@0: } {1 {can not find channel named "-nonew"} NONE} sl@0: test iocmd-4.6 {read command} { sl@0: list [catch {read stdout} msg] $msg sl@0: } {1 {channel "stdout" wasn't opened for reading}} sl@0: test iocmd-4.7 {read command} { sl@0: list [catch {read -nonewline stdout} msg] $msg sl@0: } {1 {channel "stdout" wasn't opened for reading}} sl@0: test iocmd-4.8 {read command with incorrect combination of arguments} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f "Two lines: this one" sl@0: puts $f "and this one" sl@0: close $f sl@0: set f [open $path(test1)] sl@0: set x [list [catch {read -nonewline $f 20 z} msg] $msg $errorCode] sl@0: close $f sl@0: set x sl@0: } {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"} NONE} sl@0: test iocmd-4.9 {read command} { sl@0: list [catch {read stdin foo} msg] $msg $errorCode sl@0: } {1 {bad argument "foo": should be "nonewline"} NONE} sl@0: test iocmd-4.10 {read command} { sl@0: list [catch {read file107} msg] $msg $errorCode sl@0: } {1 {can not find channel named "file107"} NONE} sl@0: sl@0: set path(test3) [makeFile {} test3] sl@0: sl@0: test iocmd-4.11 {read command} { sl@0: set f [open $path(test3) w] sl@0: set x [list [catch {read $f} msg] $msg $errorCode] sl@0: close $f sl@0: string compare [string tolower $x] \ sl@0: [list 1 [format "channel \"%s\" wasn't opened for reading" $f] none] sl@0: } 0 sl@0: test iocmd-4.12 {read command} { sl@0: set f [open $path(test1)] sl@0: set x [list [catch {read $f 12z} msg] $msg $errorCode] sl@0: close $f sl@0: set x sl@0: } {1 {expected integer but got "12z"} NONE} sl@0: sl@0: test iocmd-5.1 {seek command} { sl@0: list [catch {seek} msg] $msg sl@0: } {1 {wrong # args: should be "seek channelId offset ?origin?"}} sl@0: test iocmd-5.2 {seek command} { sl@0: list [catch {seek a b c d e f g} msg] $msg sl@0: } {1 {wrong # args: should be "seek channelId offset ?origin?"}} sl@0: test iocmd-5.3 {seek command} { sl@0: list [catch {seek stdin gugu} msg] $msg sl@0: } {1 {expected integer but got "gugu"}} sl@0: test iocmd-5.4 {seek command} { sl@0: list [catch {seek stdin 100 gugu} msg] $msg sl@0: } {1 {bad origin "gugu": must be start, current, or end}} sl@0: sl@0: test iocmd-6.1 {tell command} { sl@0: list [catch {tell} msg] $msg sl@0: } {1 {wrong # args: should be "tell channelId"}} sl@0: test iocmd-6.2 {tell command} { sl@0: list [catch {tell a b c d e} msg] $msg sl@0: } {1 {wrong # args: should be "tell channelId"}} sl@0: test iocmd-6.3 {tell command} { sl@0: list [catch {tell aaa} msg] $msg sl@0: } {1 {can not find channel named "aaa"}} sl@0: sl@0: test iocmd-7.1 {close command} { sl@0: list [catch {close} msg] $msg sl@0: } {1 {wrong # args: should be "close channelId"}} sl@0: test iocmd-7.2 {close command} { sl@0: list [catch {close a b c d e} msg] $msg sl@0: } {1 {wrong # args: should be "close channelId"}} sl@0: test iocmd-7.3 {close command} { sl@0: list [catch {close aaa} msg] $msg sl@0: } {1 {can not find channel named "aaa"}} sl@0: sl@0: test iocmd-8.1 {fconfigure command} { sl@0: list [catch {fconfigure} msg] $msg sl@0: } {1 {wrong # args: should be "fconfigure channelId ?optionName? ?value? ?optionName value?..."}} sl@0: test iocmd-8.2 {fconfigure command} { sl@0: list [catch {fconfigure a b c d e f} msg] $msg sl@0: } {1 {wrong # args: should be "fconfigure channelId ?optionName? ?value? ?optionName value?..."}} sl@0: test iocmd-8.3 {fconfigure command} { sl@0: list [catch {fconfigure a b} msg] $msg sl@0: } {1 {can not find channel named "a"}} sl@0: test iocmd-8.4 {fconfigure command} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: set x [list [catch {fconfigure $f1 froboz} msg] $msg] sl@0: close $f1 sl@0: set x sl@0: } {1 {bad option "froboz": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}} sl@0: test iocmd-8.5 {fconfigure command} { sl@0: list [catch {fconfigure stdin -buffering froboz} msg] $msg sl@0: } {1 {bad value for -buffering: must be one of full, line, or none}} sl@0: test iocmd-8.6 {fconfigure command} { sl@0: list [catch {fconfigure stdin -translation froboz} msg] $msg sl@0: } {1 {bad value for -translation: must be one of auto, binary, cr, lf, crlf, or platform}} sl@0: test iocmd-8.7 {fconfigure command} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -eofchar {} -encoding unicode sl@0: set x [fconfigure $f1] sl@0: close $f1 sl@0: set x sl@0: } {-blocking 1 -buffering full -buffersize 4096 -encoding unicode -eofchar {} -translation lf} sl@0: test iocmd-8.8 {fconfigure command} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation lf -buffering line -buffersize 3030 \ sl@0: -eofchar {} -encoding unicode sl@0: set x "" sl@0: lappend x [fconfigure $f1 -buffering] sl@0: lappend x [fconfigure $f1] sl@0: close $f1 sl@0: set x sl@0: } {line {-blocking 1 -buffering line -buffersize 3030 -encoding unicode -eofchar {} -translation lf}} sl@0: test iocmd-8.9 {fconfigure command} { sl@0: file delete $path(test1) sl@0: set f1 [open $path(test1) w] sl@0: fconfigure $f1 -translation binary -buffering none -buffersize 4040 \ sl@0: -eofchar {} -encoding binary sl@0: set x [fconfigure $f1] sl@0: close $f1 sl@0: set x sl@0: } {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -translation lf} sl@0: test iocmd-8.10 {fconfigure command} { sl@0: list [catch {fconfigure a b} msg] $msg sl@0: } {1 {can not find channel named "a"}} sl@0: sl@0: set path(fconfigure.dummy) [makeFile {} fconfigure.dummy] sl@0: sl@0: test iocmd-8.11 {fconfigure command} { sl@0: set chan [open $path(fconfigure.dummy) r] sl@0: set res [list [catch {fconfigure $chan -froboz blarfo} msg] $msg] sl@0: close $chan sl@0: set res sl@0: } {1 {bad option "-froboz": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}} sl@0: sl@0: test iocmd-8.12 {fconfigure command} { sl@0: set chan [open $path(fconfigure.dummy) r] sl@0: set res [list [catch {fconfigure $chan -b blarfo} msg] $msg] sl@0: close $chan sl@0: set res sl@0: } {1 {bad option "-b": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}} sl@0: sl@0: test iocmd-8.13 {fconfigure command} { sl@0: set chan [open $path(fconfigure.dummy) r] sl@0: set res [list [catch {fconfigure $chan -buffer blarfo} msg] $msg] sl@0: close $chan sl@0: set res sl@0: } {1 {bad option "-buffer": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}} sl@0: sl@0: removeFile fconfigure.dummy sl@0: sl@0: test iocmd-8.14 {fconfigure command} { sl@0: fconfigure stdin -buffers sl@0: } 4096 sl@0: sl@0: proc iocmdSSETUP {} { sl@0: uplevel { sl@0: set srv [socket -server iocmdSRV 0] sl@0: set port [lindex [fconfigure $srv -sockname] 2] sl@0: proc iocmdSRV {sock ip port} {close $sock} sl@0: set cli [socket 127.0.0.1 $port] sl@0: } sl@0: } sl@0: proc iocmdSSHTDWN {} { sl@0: uplevel { sl@0: close $cli sl@0: close $srv sl@0: unset cli srv port sl@0: rename iocmdSRV {} sl@0: } sl@0: } sl@0: sl@0: test iocmd-8.15.0 {fconfigure command / tcp channel} {socket macOnly} { sl@0: iocmdSSETUP sl@0: set r [list [catch {fconfigure $cli -blah} msg] $msg] sl@0: iocmdSSHTDWN sl@0: set r sl@0: } {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -error, -peername, or -sockname}} sl@0: test iocmd-8.15.1 {fconfigure command / tcp channel} {socket unixOrPc} { sl@0: iocmdSSETUP sl@0: set r [list [catch {fconfigure $cli -blah} msg] $msg] sl@0: iocmdSSHTDWN sl@0: set r sl@0: } {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -peername, or -sockname}} sl@0: test iocmd-8.16 {fconfigure command / tcp channel} {socket} { sl@0: iocmdSSETUP sl@0: set r [expr [lindex [fconfigure $cli -peername] 2]==$port] sl@0: iocmdSSHTDWN sl@0: set r sl@0: } 1 sl@0: test iocmd-8.17 {fconfigure command / tcp channel} {nonPortable} { sl@0: # It is possible that you don't get the connection reset by peer sl@0: # error but rather a valid answer. depends of the tcp implementation sl@0: iocmdSSETUP sl@0: update; sl@0: puts $cli "blah"; flush $cli; # that flush could/should fail too sl@0: update; sl@0: set r [catch {fconfigure $cli -peername} msg] sl@0: iocmdSSHTDWN sl@0: regsub -all {can([^:])+: } $r {} r; sl@0: set r sl@0: } 1 sl@0: test iocmd-8.18 {fconfigure command / unix tty channel} {nonPortable unixOnly} { sl@0: # might fail if /dev/ttya is unavailable sl@0: set tty [open /dev/ttya] sl@0: set r [list [catch {fconfigure $tty -blah blih} msg] $msg]; sl@0: close $tty; sl@0: set r; sl@0: } {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, or -mode}} sl@0: test iocmd-8.19 {fconfigure command / win tty channel} {nonPortable pcOnly} { sl@0: # might fail if com1 is unavailable sl@0: set tty [open com1] sl@0: set r [list [catch {fconfigure $tty -blah blih} msg] $msg]; sl@0: close $tty; sl@0: set r; sl@0: } {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -mode, or -pollinterval}} sl@0: sl@0: test iocmd-9.1 {eof command} { sl@0: list [catch {eof} msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "eof channelId"} NONE} sl@0: test iocmd-9.2 {eof command} { sl@0: list [catch {eof a b} msg] $msg $errorCode sl@0: } {1 {wrong # args: should be "eof channelId"} NONE} sl@0: test iocmd-9.3 {eof command} { sl@0: catch {close file100} sl@0: list [catch {eof file100} msg] $msg $errorCode sl@0: } {1 {can not find channel named "file100"} NONE} sl@0: sl@0: # The tests for Tcl_ExecObjCmd are in exec.test sl@0: sl@0: test iocmd-10.1 {fblocked command} { sl@0: list [catch {fblocked} msg] $msg sl@0: } {1 {wrong # args: should be "fblocked channelId"}} sl@0: test iocmd-10.2 {fblocked command} { sl@0: list [catch {fblocked a b c d e f g} msg] $msg sl@0: } {1 {wrong # args: should be "fblocked channelId"}} sl@0: test iocmd-10.3 {fblocked command} { sl@0: list [catch {fblocked file1000} msg] $msg sl@0: } {1 {can not find channel named "file1000"}} sl@0: test iocmd-10.4 {fblocked command} { sl@0: list [catch {fblocked stdout} msg] $msg sl@0: } {1 {channel "stdout" wasn't opened for reading}} sl@0: test iocmd-10.5 {fblocked command} { sl@0: fblocked stdin sl@0: } 0 sl@0: sl@0: set path(test4) [makeFile {} test4] sl@0: set path(test5) [makeFile {} test5] sl@0: sl@0: file delete $path(test5) sl@0: test iocmd-11.1 {I/O to command pipelines} {unixOrPc unixExecs} { sl@0: set f [open $path(test4) w] sl@0: close $f sl@0: list [catch {open "| cat < $path(test4) > $path(test5)" w} msg] $msg $errorCode sl@0: } {1 {can't write input to command: standard input was redirected} NONE} sl@0: test iocmd-11.2 {I/O to command pipelines} {unixOrPc unixExecs} { sl@0: list [catch {open "| echo > $path(test5)" r} msg] $msg $errorCode sl@0: } {1 {can't read output from command: standard output was redirected} NONE} sl@0: test iocmd-11.3 {I/O to command pipelines} {unixOrPc unixExecs} { sl@0: list [catch {open "| echo > $path(test5)" r+} msg] $msg $errorCode sl@0: } {1 {can't read output from command: standard output was redirected} NONE} sl@0: sl@0: test iocmd-12.1 {POSIX open access modes: RDONLY} { sl@0: file delete $path(test1) sl@0: set f [open $path(test1) w] sl@0: puts $f "Two lines: this one" sl@0: puts $f "and this one" sl@0: close $f sl@0: set f [open $path(test1) RDONLY] sl@0: set x [list [gets $f] [catch {puts $f Test} msg] $msg] sl@0: close $f sl@0: string compare $x \ sl@0: "{Two lines: this one} 1 [list [format "channel \"%s\" wasn't opened for writing" $f]]" sl@0: } 0 sl@0: test iocmd-12.2 {POSIX open access modes: RDONLY} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) RDONLY sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: test iocmd-12.3 {POSIX open access modes: WRONLY} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) WRONLY sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: # sl@0: # Test 13.4 relies on assigning the same channel name twice. sl@0: # sl@0: test iocmd-12.4 {POSIX open access modes: WRONLY} {unixOnly} { sl@0: file delete $path(test3) sl@0: set f [open $path(test3) w] sl@0: fconfigure $f -eofchar {} sl@0: puts $f xyzzy sl@0: close $f sl@0: set f [open $path(test3) WRONLY] sl@0: fconfigure $f -eofchar {} sl@0: puts -nonewline $f "ab" sl@0: seek $f 0 current sl@0: set x [list [catch {gets $f} msg] $msg] sl@0: close $f sl@0: set f [open $path(test3) r] sl@0: fconfigure $f -eofchar {} sl@0: lappend x [gets $f] sl@0: close $f sl@0: set y [list 1 [format "channel \"%s\" wasn't opened for reading" $f] abzzy] sl@0: string compare $x $y sl@0: } 0 sl@0: test iocmd-12.5 {POSIX open access modes: RDWR} -match regexp -body { sl@0: file delete $path(test3) sl@0: open $path(test3) RDWR sl@0: } -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory} sl@0: test iocmd-12.6 {POSIX open access modes: errors} { sl@0: concat [catch {open $path(test3) "FOO \{BAR BAZ"} msg] $msg\n$errorInfo sl@0: } "1 unmatched open brace in list sl@0: unmatched open brace in list sl@0: while processing open access modes \"FOO {BAR BAZ\" sl@0: invoked from within sl@0: \"open \$path(test3) \"FOO \\{BAR BAZ\"\"" sl@0: test iocmd-12.7 {POSIX open access modes: errors} { sl@0: list [catch {open $path(test3) {FOO BAR BAZ}} msg] $msg sl@0: } {1 {invalid access mode "FOO": must be RDONLY, WRONLY, RDWR, APPEND, CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC}} sl@0: test iocmd-12.8 {POSIX open access modes: errors} { sl@0: list [catch {open $path(test3) {TRUNC CREAT}} msg] $msg sl@0: } {1 {access mode must include either RDONLY, WRONLY, or RDWR}} sl@0: close [open $path(test3) w] sl@0: sl@0: test iocmd-13.1 {errors in open command} { sl@0: list [catch {open} msg] $msg sl@0: } {1 {wrong # args: should be "open fileName ?access? ?permissions?"}} sl@0: test iocmd-13.2 {errors in open command} { sl@0: list [catch {open a b c d} msg] $msg sl@0: } {1 {wrong # args: should be "open fileName ?access? ?permissions?"}} sl@0: test iocmd-13.3 {errors in open command} { sl@0: list [catch {open $path(test1) x} msg] $msg sl@0: } {1 {illegal access mode "x"}} sl@0: test iocmd-13.4 {errors in open command} { sl@0: list [catch {open $path(test1) rw} msg] $msg sl@0: } {1 {illegal access mode "rw"}} sl@0: test iocmd-13.5 {errors in open command} { sl@0: list [catch {open $path(test1) r+1} msg] $msg sl@0: } {1 {illegal access mode "r+1"}} sl@0: test iocmd-13.6 {errors in open command} { sl@0: set msg [list [catch {open _non_existent_} msg] $msg $errorCode] sl@0: regsub [file join {} _non_existent_] $msg "_non_existent_" msg sl@0: string tolower $msg sl@0: } {1 {couldn't open "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}} sl@0: sl@0: sl@0: test iocmd-13.7.1 {open for append, a mode} -setup { sl@0: set log [makeFile {} out] sl@0: set chans {} sl@0: } -body { sl@0: foreach i { 0 1 2 3 4 5 6 7 8 9 } { sl@0: puts [set ch [open $log a]] $i sl@0: lappend chans $ch sl@0: } sl@0: foreach ch $chans {catch {close $ch}} sl@0: lsort [split [string trim [viewFile out]] \n] sl@0: } -cleanup { sl@0: removeFile out sl@0: # Ensure that channels are gone, even if body failed to do so sl@0: foreach ch $chans {catch {close $ch}} sl@0: } -result {0 1 2 3 4 5 6 7 8 9} sl@0: sl@0: test iocmd-13.7.2 {open for append, O_APPEND} -setup { sl@0: set log [makeFile {} out] sl@0: set chans {} sl@0: } -body { sl@0: foreach i { 0 1 2 3 4 5 6 7 8 9 } { sl@0: puts [set ch [open $log {WRONLY CREAT APPEND}]] $i sl@0: lappend chans $ch sl@0: } sl@0: foreach ch $chans {catch {close $ch}} sl@0: lsort [split [string trim [viewFile out]] \n] sl@0: } -cleanup { sl@0: removeFile out sl@0: # Ensure that channels are gone, even if body failed to do so sl@0: foreach ch $chans {catch {close $ch}} sl@0: } -result {0 1 2 3 4 5 6 7 8 9} sl@0: sl@0: sl@0: sl@0: sl@0: test iocmd-14.1 {file id parsing errors} { sl@0: list [catch {eof gorp} msg] $msg $errorCode sl@0: } {1 {can not find channel named "gorp"} NONE} sl@0: test iocmd-14.2 {file id parsing errors} { sl@0: list [catch {eof filex} msg] $msg sl@0: } {1 {can not find channel named "filex"}} sl@0: test iocmd-14.3 {file id parsing errors} { sl@0: list [catch {eof file12a} msg] $msg sl@0: } {1 {can not find channel named "file12a"}} sl@0: test iocmd-14.4 {file id parsing errors} { sl@0: list [catch {eof file123} msg] $msg sl@0: } {1 {can not find channel named "file123"}} sl@0: test iocmd-14.5 {file id parsing errors} { sl@0: list [catch {eof stdout} msg] $msg sl@0: } {0 0} sl@0: test iocmd-14.6 {file id parsing errors} { sl@0: list [catch {eof stdin} msg] $msg sl@0: } {0 0} sl@0: test iocmd-14.7 {file id parsing errors} { sl@0: list [catch {eof stdout} msg] $msg sl@0: } {0 0} sl@0: test iocmd-14.8 {file id parsing errors} { sl@0: list [catch {eof stderr} msg] $msg sl@0: } {0 0} sl@0: test iocmd-14.9 {file id parsing errors} { sl@0: list [catch {eof stderr1} msg] $msg sl@0: } {1 {can not find channel named "stderr1"}} sl@0: sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: sl@0: set expect "1 {can not find channel named \"$f\"}" sl@0: test iocmd-14.10 {file id parsing errors} { sl@0: list [catch {eof $f} msg] $msg sl@0: } $expect sl@0: sl@0: test iocmd-15.1 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy} msg] $msg sl@0: } {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}} sl@0: test iocmd-15.2 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy 1} msg] $msg sl@0: } {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}} sl@0: test iocmd-15.3 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy 1 2 3 4 5 6 7} msg] $msg sl@0: } {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}} sl@0: test iocmd-15.4 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy 1 2 3} msg] $msg sl@0: } {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}} sl@0: test iocmd-15.5 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy 1 2 3 4 5} msg] $msg sl@0: } {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}} sl@0: sl@0: set path(test2) [makeFile {} test2] sl@0: sl@0: set f [open $path(test1) w] sl@0: close $f sl@0: sl@0: set rfile [open $path(test1) r] sl@0: set wfile [open $path(test2) w] sl@0: sl@0: test iocmd-15.6 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy foo $wfile} msg] $msg sl@0: } {1 {can not find channel named "foo"}} sl@0: test iocmd-15.7 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $rfile foo} msg] $msg sl@0: } {1 {can not find channel named "foo"}} sl@0: test iocmd-15.8 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $wfile $wfile} msg] $msg sl@0: } "1 {channel \"$wfile\" wasn't opened for reading}" sl@0: test iocmd-15.9 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $rfile $rfile} msg] $msg sl@0: } "1 {channel \"$rfile\" wasn't opened for writing}" sl@0: test iocmd-15.10 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $rfile $wfile foo bar} msg] $msg sl@0: } {1 {bad switch "foo": must be -size or -command}} sl@0: test iocmd-15.11 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $rfile $wfile -size foo} msg] $msg sl@0: } {1 {expected integer but got "foo"}} sl@0: test iocmd-15.12 {Tcl_FcopyObjCmd} {fcopy} { sl@0: list [catch {fcopy $rfile $wfile -command bar -size foo} msg] $msg sl@0: } {1 {expected integer but got "foo"}} sl@0: sl@0: close $rfile sl@0: close $wfile sl@0: sl@0: # cleanup sl@0: foreach file [list test1 test2 test3 test4] { sl@0: removeFile $file sl@0: } sl@0: # delay long enough for background processes to finish sl@0: after 500 sl@0: foreach file [list test5] { sl@0: removeFile $file sl@0: } sl@0: cleanupTests sl@0: return