sl@0
|
1 |
# -*- tcl -*-
|
sl@0
|
2 |
# Commands covered: open, close, gets, read, puts, seek, tell, eof, flush,
|
sl@0
|
3 |
# fblocked, fconfigure, open, channel, fcopy
|
sl@0
|
4 |
#
|
sl@0
|
5 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
6 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
7 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
8 |
#
|
sl@0
|
9 |
# Copyright (c) 1991-1994 The Regents of the University of California.
|
sl@0
|
10 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
sl@0
|
11 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
14 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# RCS: @(#) $Id: ioCmd.test,v 1.16.2.3 2006/03/16 18:23:24 andreas_kupries Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
19 |
package require tcltest
|
sl@0
|
20 |
namespace import -force ::tcltest::*
|
sl@0
|
21 |
}
|
sl@0
|
22 |
|
sl@0
|
23 |
testConstraint fcopy [llength [info commands fcopy]]
|
sl@0
|
24 |
|
sl@0
|
25 |
test iocmd-1.1 {puts command} {
|
sl@0
|
26 |
list [catch {puts} msg] $msg
|
sl@0
|
27 |
} {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}}
|
sl@0
|
28 |
test iocmd-1.2 {puts command} {
|
sl@0
|
29 |
list [catch {puts a b c d e f g} msg] $msg
|
sl@0
|
30 |
} {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"}}
|
sl@0
|
31 |
test iocmd-1.3 {puts command} {
|
sl@0
|
32 |
list [catch {puts froboz -nonewline kablooie} msg] $msg
|
sl@0
|
33 |
} {1 {bad argument "kablooie": should be "nonewline"}}
|
sl@0
|
34 |
test iocmd-1.4 {puts command} {
|
sl@0
|
35 |
list [catch {puts froboz hello} msg] $msg
|
sl@0
|
36 |
} {1 {can not find channel named "froboz"}}
|
sl@0
|
37 |
test iocmd-1.5 {puts command} {
|
sl@0
|
38 |
list [catch {puts stdin hello} msg] $msg
|
sl@0
|
39 |
} {1 {channel "stdin" wasn't opened for writing}}
|
sl@0
|
40 |
|
sl@0
|
41 |
set path(test1) [makeFile {} test1]
|
sl@0
|
42 |
|
sl@0
|
43 |
test iocmd-1.6 {puts command} {
|
sl@0
|
44 |
set f [open $path(test1) w]
|
sl@0
|
45 |
fconfigure $f -translation lf -eofchar {}
|
sl@0
|
46 |
puts -nonewline $f foobar
|
sl@0
|
47 |
close $f
|
sl@0
|
48 |
file size $path(test1)
|
sl@0
|
49 |
} 6
|
sl@0
|
50 |
test iocmd-1.7 {puts command} {
|
sl@0
|
51 |
set f [open $path(test1) w]
|
sl@0
|
52 |
fconfigure $f -translation lf -eofchar {}
|
sl@0
|
53 |
puts $f foobar
|
sl@0
|
54 |
close $f
|
sl@0
|
55 |
file size $path(test1)
|
sl@0
|
56 |
} 7
|
sl@0
|
57 |
test iocmd-1.8 {puts command} {
|
sl@0
|
58 |
set f [open $path(test1) w]
|
sl@0
|
59 |
fconfigure $f -translation lf -eofchar {} -encoding iso8859-1
|
sl@0
|
60 |
puts -nonewline $f [binary format a4a5 foo bar]
|
sl@0
|
61 |
close $f
|
sl@0
|
62 |
file size $path(test1)
|
sl@0
|
63 |
} 9
|
sl@0
|
64 |
|
sl@0
|
65 |
|
sl@0
|
66 |
test iocmd-2.1 {flush command} {
|
sl@0
|
67 |
list [catch {flush} msg] $msg
|
sl@0
|
68 |
} {1 {wrong # args: should be "flush channelId"}}
|
sl@0
|
69 |
test iocmd-2.2 {flush command} {
|
sl@0
|
70 |
list [catch {flush a b c d e} msg] $msg
|
sl@0
|
71 |
} {1 {wrong # args: should be "flush channelId"}}
|
sl@0
|
72 |
test iocmd-2.3 {flush command} {
|
sl@0
|
73 |
list [catch {flush foo} msg] $msg
|
sl@0
|
74 |
} {1 {can not find channel named "foo"}}
|
sl@0
|
75 |
test iocmd-2.4 {flush command} {
|
sl@0
|
76 |
list [catch {flush stdin} msg] $msg
|
sl@0
|
77 |
} {1 {channel "stdin" wasn't opened for writing}}
|
sl@0
|
78 |
|
sl@0
|
79 |
test iocmd-3.1 {gets command} {
|
sl@0
|
80 |
list [catch {gets} msg] $msg
|
sl@0
|
81 |
} {1 {wrong # args: should be "gets channelId ?varName?"}}
|
sl@0
|
82 |
test iocmd-3.2 {gets command} {
|
sl@0
|
83 |
list [catch {gets a b c d e f g} msg] $msg
|
sl@0
|
84 |
} {1 {wrong # args: should be "gets channelId ?varName?"}}
|
sl@0
|
85 |
test iocmd-3.3 {gets command} {
|
sl@0
|
86 |
list [catch {gets aaa} msg] $msg
|
sl@0
|
87 |
} {1 {can not find channel named "aaa"}}
|
sl@0
|
88 |
test iocmd-3.4 {gets command} {
|
sl@0
|
89 |
list [catch {gets stdout} msg] $msg
|
sl@0
|
90 |
} {1 {channel "stdout" wasn't opened for reading}}
|
sl@0
|
91 |
test iocmd-3.5 {gets command} {
|
sl@0
|
92 |
set f [open $path(test1) w]
|
sl@0
|
93 |
puts $f [binary format a4a5 foo bar]
|
sl@0
|
94 |
close $f
|
sl@0
|
95 |
set f [open $path(test1) r]
|
sl@0
|
96 |
set result [gets $f]
|
sl@0
|
97 |
close $f
|
sl@0
|
98 |
set x foo\x00
|
sl@0
|
99 |
set x "${x}bar\x00\x00"
|
sl@0
|
100 |
string compare $x $result
|
sl@0
|
101 |
} 0
|
sl@0
|
102 |
|
sl@0
|
103 |
test iocmd-4.1 {read command} {
|
sl@0
|
104 |
list [catch {read} msg] $msg
|
sl@0
|
105 |
} {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}}
|
sl@0
|
106 |
test iocmd-4.2 {read command} {
|
sl@0
|
107 |
list [catch {read a b c d e f g h} msg] $msg
|
sl@0
|
108 |
} {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}}
|
sl@0
|
109 |
test iocmd-4.3 {read command} {
|
sl@0
|
110 |
list [catch {read aaa} msg] $msg
|
sl@0
|
111 |
} {1 {can not find channel named "aaa"}}
|
sl@0
|
112 |
test iocmd-4.4 {read command} {
|
sl@0
|
113 |
list [catch {read -nonewline} msg] $msg
|
sl@0
|
114 |
} {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"}}
|
sl@0
|
115 |
test iocmd-4.5 {read command} {
|
sl@0
|
116 |
list [catch {read -nonew file4} msg] $msg $errorCode
|
sl@0
|
117 |
} {1 {can not find channel named "-nonew"} NONE}
|
sl@0
|
118 |
test iocmd-4.6 {read command} {
|
sl@0
|
119 |
list [catch {read stdout} msg] $msg
|
sl@0
|
120 |
} {1 {channel "stdout" wasn't opened for reading}}
|
sl@0
|
121 |
test iocmd-4.7 {read command} {
|
sl@0
|
122 |
list [catch {read -nonewline stdout} msg] $msg
|
sl@0
|
123 |
} {1 {channel "stdout" wasn't opened for reading}}
|
sl@0
|
124 |
test iocmd-4.8 {read command with incorrect combination of arguments} {
|
sl@0
|
125 |
file delete $path(test1)
|
sl@0
|
126 |
set f [open $path(test1) w]
|
sl@0
|
127 |
puts $f "Two lines: this one"
|
sl@0
|
128 |
puts $f "and this one"
|
sl@0
|
129 |
close $f
|
sl@0
|
130 |
set f [open $path(test1)]
|
sl@0
|
131 |
set x [list [catch {read -nonewline $f 20 z} msg] $msg $errorCode]
|
sl@0
|
132 |
close $f
|
sl@0
|
133 |
set x
|
sl@0
|
134 |
} {1 {wrong # args: should be "read channelId ?numChars?" or "read ?-nonewline? channelId"} NONE}
|
sl@0
|
135 |
test iocmd-4.9 {read command} {
|
sl@0
|
136 |
list [catch {read stdin foo} msg] $msg $errorCode
|
sl@0
|
137 |
} {1 {bad argument "foo": should be "nonewline"} NONE}
|
sl@0
|
138 |
test iocmd-4.10 {read command} {
|
sl@0
|
139 |
list [catch {read file107} msg] $msg $errorCode
|
sl@0
|
140 |
} {1 {can not find channel named "file107"} NONE}
|
sl@0
|
141 |
|
sl@0
|
142 |
set path(test3) [makeFile {} test3]
|
sl@0
|
143 |
|
sl@0
|
144 |
test iocmd-4.11 {read command} {
|
sl@0
|
145 |
set f [open $path(test3) w]
|
sl@0
|
146 |
set x [list [catch {read $f} msg] $msg $errorCode]
|
sl@0
|
147 |
close $f
|
sl@0
|
148 |
string compare [string tolower $x] \
|
sl@0
|
149 |
[list 1 [format "channel \"%s\" wasn't opened for reading" $f] none]
|
sl@0
|
150 |
} 0
|
sl@0
|
151 |
test iocmd-4.12 {read command} {
|
sl@0
|
152 |
set f [open $path(test1)]
|
sl@0
|
153 |
set x [list [catch {read $f 12z} msg] $msg $errorCode]
|
sl@0
|
154 |
close $f
|
sl@0
|
155 |
set x
|
sl@0
|
156 |
} {1 {expected integer but got "12z"} NONE}
|
sl@0
|
157 |
|
sl@0
|
158 |
test iocmd-5.1 {seek command} {
|
sl@0
|
159 |
list [catch {seek} msg] $msg
|
sl@0
|
160 |
} {1 {wrong # args: should be "seek channelId offset ?origin?"}}
|
sl@0
|
161 |
test iocmd-5.2 {seek command} {
|
sl@0
|
162 |
list [catch {seek a b c d e f g} msg] $msg
|
sl@0
|
163 |
} {1 {wrong # args: should be "seek channelId offset ?origin?"}}
|
sl@0
|
164 |
test iocmd-5.3 {seek command} {
|
sl@0
|
165 |
list [catch {seek stdin gugu} msg] $msg
|
sl@0
|
166 |
} {1 {expected integer but got "gugu"}}
|
sl@0
|
167 |
test iocmd-5.4 {seek command} {
|
sl@0
|
168 |
list [catch {seek stdin 100 gugu} msg] $msg
|
sl@0
|
169 |
} {1 {bad origin "gugu": must be start, current, or end}}
|
sl@0
|
170 |
|
sl@0
|
171 |
test iocmd-6.1 {tell command} {
|
sl@0
|
172 |
list [catch {tell} msg] $msg
|
sl@0
|
173 |
} {1 {wrong # args: should be "tell channelId"}}
|
sl@0
|
174 |
test iocmd-6.2 {tell command} {
|
sl@0
|
175 |
list [catch {tell a b c d e} msg] $msg
|
sl@0
|
176 |
} {1 {wrong # args: should be "tell channelId"}}
|
sl@0
|
177 |
test iocmd-6.3 {tell command} {
|
sl@0
|
178 |
list [catch {tell aaa} msg] $msg
|
sl@0
|
179 |
} {1 {can not find channel named "aaa"}}
|
sl@0
|
180 |
|
sl@0
|
181 |
test iocmd-7.1 {close command} {
|
sl@0
|
182 |
list [catch {close} msg] $msg
|
sl@0
|
183 |
} {1 {wrong # args: should be "close channelId"}}
|
sl@0
|
184 |
test iocmd-7.2 {close command} {
|
sl@0
|
185 |
list [catch {close a b c d e} msg] $msg
|
sl@0
|
186 |
} {1 {wrong # args: should be "close channelId"}}
|
sl@0
|
187 |
test iocmd-7.3 {close command} {
|
sl@0
|
188 |
list [catch {close aaa} msg] $msg
|
sl@0
|
189 |
} {1 {can not find channel named "aaa"}}
|
sl@0
|
190 |
|
sl@0
|
191 |
test iocmd-8.1 {fconfigure command} {
|
sl@0
|
192 |
list [catch {fconfigure} msg] $msg
|
sl@0
|
193 |
} {1 {wrong # args: should be "fconfigure channelId ?optionName? ?value? ?optionName value?..."}}
|
sl@0
|
194 |
test iocmd-8.2 {fconfigure command} {
|
sl@0
|
195 |
list [catch {fconfigure a b c d e f} msg] $msg
|
sl@0
|
196 |
} {1 {wrong # args: should be "fconfigure channelId ?optionName? ?value? ?optionName value?..."}}
|
sl@0
|
197 |
test iocmd-8.3 {fconfigure command} {
|
sl@0
|
198 |
list [catch {fconfigure a b} msg] $msg
|
sl@0
|
199 |
} {1 {can not find channel named "a"}}
|
sl@0
|
200 |
test iocmd-8.4 {fconfigure command} {
|
sl@0
|
201 |
file delete $path(test1)
|
sl@0
|
202 |
set f1 [open $path(test1) w]
|
sl@0
|
203 |
set x [list [catch {fconfigure $f1 froboz} msg] $msg]
|
sl@0
|
204 |
close $f1
|
sl@0
|
205 |
set x
|
sl@0
|
206 |
} {1 {bad option "froboz": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}}
|
sl@0
|
207 |
test iocmd-8.5 {fconfigure command} {
|
sl@0
|
208 |
list [catch {fconfigure stdin -buffering froboz} msg] $msg
|
sl@0
|
209 |
} {1 {bad value for -buffering: must be one of full, line, or none}}
|
sl@0
|
210 |
test iocmd-8.6 {fconfigure command} {
|
sl@0
|
211 |
list [catch {fconfigure stdin -translation froboz} msg] $msg
|
sl@0
|
212 |
} {1 {bad value for -translation: must be one of auto, binary, cr, lf, crlf, or platform}}
|
sl@0
|
213 |
test iocmd-8.7 {fconfigure command} {
|
sl@0
|
214 |
file delete $path(test1)
|
sl@0
|
215 |
set f1 [open $path(test1) w]
|
sl@0
|
216 |
fconfigure $f1 -translation lf -eofchar {} -encoding unicode
|
sl@0
|
217 |
set x [fconfigure $f1]
|
sl@0
|
218 |
close $f1
|
sl@0
|
219 |
set x
|
sl@0
|
220 |
} {-blocking 1 -buffering full -buffersize 4096 -encoding unicode -eofchar {} -translation lf}
|
sl@0
|
221 |
test iocmd-8.8 {fconfigure command} {
|
sl@0
|
222 |
file delete $path(test1)
|
sl@0
|
223 |
set f1 [open $path(test1) w]
|
sl@0
|
224 |
fconfigure $f1 -translation lf -buffering line -buffersize 3030 \
|
sl@0
|
225 |
-eofchar {} -encoding unicode
|
sl@0
|
226 |
set x ""
|
sl@0
|
227 |
lappend x [fconfigure $f1 -buffering]
|
sl@0
|
228 |
lappend x [fconfigure $f1]
|
sl@0
|
229 |
close $f1
|
sl@0
|
230 |
set x
|
sl@0
|
231 |
} {line {-blocking 1 -buffering line -buffersize 3030 -encoding unicode -eofchar {} -translation lf}}
|
sl@0
|
232 |
test iocmd-8.9 {fconfigure command} {
|
sl@0
|
233 |
file delete $path(test1)
|
sl@0
|
234 |
set f1 [open $path(test1) w]
|
sl@0
|
235 |
fconfigure $f1 -translation binary -buffering none -buffersize 4040 \
|
sl@0
|
236 |
-eofchar {} -encoding binary
|
sl@0
|
237 |
set x [fconfigure $f1]
|
sl@0
|
238 |
close $f1
|
sl@0
|
239 |
set x
|
sl@0
|
240 |
} {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -translation lf}
|
sl@0
|
241 |
test iocmd-8.10 {fconfigure command} {
|
sl@0
|
242 |
list [catch {fconfigure a b} msg] $msg
|
sl@0
|
243 |
} {1 {can not find channel named "a"}}
|
sl@0
|
244 |
|
sl@0
|
245 |
set path(fconfigure.dummy) [makeFile {} fconfigure.dummy]
|
sl@0
|
246 |
|
sl@0
|
247 |
test iocmd-8.11 {fconfigure command} {
|
sl@0
|
248 |
set chan [open $path(fconfigure.dummy) r]
|
sl@0
|
249 |
set res [list [catch {fconfigure $chan -froboz blarfo} msg] $msg]
|
sl@0
|
250 |
close $chan
|
sl@0
|
251 |
set res
|
sl@0
|
252 |
} {1 {bad option "-froboz": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}}
|
sl@0
|
253 |
|
sl@0
|
254 |
test iocmd-8.12 {fconfigure command} {
|
sl@0
|
255 |
set chan [open $path(fconfigure.dummy) r]
|
sl@0
|
256 |
set res [list [catch {fconfigure $chan -b blarfo} msg] $msg]
|
sl@0
|
257 |
close $chan
|
sl@0
|
258 |
set res
|
sl@0
|
259 |
} {1 {bad option "-b": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}}
|
sl@0
|
260 |
|
sl@0
|
261 |
test iocmd-8.13 {fconfigure command} {
|
sl@0
|
262 |
set chan [open $path(fconfigure.dummy) r]
|
sl@0
|
263 |
set res [list [catch {fconfigure $chan -buffer blarfo} msg] $msg]
|
sl@0
|
264 |
close $chan
|
sl@0
|
265 |
set res
|
sl@0
|
266 |
} {1 {bad option "-buffer": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation}}
|
sl@0
|
267 |
|
sl@0
|
268 |
removeFile fconfigure.dummy
|
sl@0
|
269 |
|
sl@0
|
270 |
test iocmd-8.14 {fconfigure command} {
|
sl@0
|
271 |
fconfigure stdin -buffers
|
sl@0
|
272 |
} 4096
|
sl@0
|
273 |
|
sl@0
|
274 |
proc iocmdSSETUP {} {
|
sl@0
|
275 |
uplevel {
|
sl@0
|
276 |
set srv [socket -server iocmdSRV 0]
|
sl@0
|
277 |
set port [lindex [fconfigure $srv -sockname] 2]
|
sl@0
|
278 |
proc iocmdSRV {sock ip port} {close $sock}
|
sl@0
|
279 |
set cli [socket 127.0.0.1 $port]
|
sl@0
|
280 |
}
|
sl@0
|
281 |
}
|
sl@0
|
282 |
proc iocmdSSHTDWN {} {
|
sl@0
|
283 |
uplevel {
|
sl@0
|
284 |
close $cli
|
sl@0
|
285 |
close $srv
|
sl@0
|
286 |
unset cli srv port
|
sl@0
|
287 |
rename iocmdSRV {}
|
sl@0
|
288 |
}
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
test iocmd-8.15.0 {fconfigure command / tcp channel} {socket macOnly} {
|
sl@0
|
292 |
iocmdSSETUP
|
sl@0
|
293 |
set r [list [catch {fconfigure $cli -blah} msg] $msg]
|
sl@0
|
294 |
iocmdSSHTDWN
|
sl@0
|
295 |
set r
|
sl@0
|
296 |
} {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -error, -peername, or -sockname}}
|
sl@0
|
297 |
test iocmd-8.15.1 {fconfigure command / tcp channel} {socket unixOrPc} {
|
sl@0
|
298 |
iocmdSSETUP
|
sl@0
|
299 |
set r [list [catch {fconfigure $cli -blah} msg] $msg]
|
sl@0
|
300 |
iocmdSSHTDWN
|
sl@0
|
301 |
set r
|
sl@0
|
302 |
} {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -peername, or -sockname}}
|
sl@0
|
303 |
test iocmd-8.16 {fconfigure command / tcp channel} {socket} {
|
sl@0
|
304 |
iocmdSSETUP
|
sl@0
|
305 |
set r [expr [lindex [fconfigure $cli -peername] 2]==$port]
|
sl@0
|
306 |
iocmdSSHTDWN
|
sl@0
|
307 |
set r
|
sl@0
|
308 |
} 1
|
sl@0
|
309 |
test iocmd-8.17 {fconfigure command / tcp channel} {nonPortable} {
|
sl@0
|
310 |
# It is possible that you don't get the connection reset by peer
|
sl@0
|
311 |
# error but rather a valid answer. depends of the tcp implementation
|
sl@0
|
312 |
iocmdSSETUP
|
sl@0
|
313 |
update;
|
sl@0
|
314 |
puts $cli "blah"; flush $cli; # that flush could/should fail too
|
sl@0
|
315 |
update;
|
sl@0
|
316 |
set r [catch {fconfigure $cli -peername} msg]
|
sl@0
|
317 |
iocmdSSHTDWN
|
sl@0
|
318 |
regsub -all {can([^:])+: } $r {} r;
|
sl@0
|
319 |
set r
|
sl@0
|
320 |
} 1
|
sl@0
|
321 |
test iocmd-8.18 {fconfigure command / unix tty channel} {nonPortable unixOnly} {
|
sl@0
|
322 |
# might fail if /dev/ttya is unavailable
|
sl@0
|
323 |
set tty [open /dev/ttya]
|
sl@0
|
324 |
set r [list [catch {fconfigure $tty -blah blih} msg] $msg];
|
sl@0
|
325 |
close $tty;
|
sl@0
|
326 |
set r;
|
sl@0
|
327 |
} {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, or -mode}}
|
sl@0
|
328 |
test iocmd-8.19 {fconfigure command / win tty channel} {nonPortable pcOnly} {
|
sl@0
|
329 |
# might fail if com1 is unavailable
|
sl@0
|
330 |
set tty [open com1]
|
sl@0
|
331 |
set r [list [catch {fconfigure $tty -blah blih} msg] $msg];
|
sl@0
|
332 |
close $tty;
|
sl@0
|
333 |
set r;
|
sl@0
|
334 |
} {1 {bad option "-blah": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation, -mode, or -pollinterval}}
|
sl@0
|
335 |
|
sl@0
|
336 |
test iocmd-9.1 {eof command} {
|
sl@0
|
337 |
list [catch {eof} msg] $msg $errorCode
|
sl@0
|
338 |
} {1 {wrong # args: should be "eof channelId"} NONE}
|
sl@0
|
339 |
test iocmd-9.2 {eof command} {
|
sl@0
|
340 |
list [catch {eof a b} msg] $msg $errorCode
|
sl@0
|
341 |
} {1 {wrong # args: should be "eof channelId"} NONE}
|
sl@0
|
342 |
test iocmd-9.3 {eof command} {
|
sl@0
|
343 |
catch {close file100}
|
sl@0
|
344 |
list [catch {eof file100} msg] $msg $errorCode
|
sl@0
|
345 |
} {1 {can not find channel named "file100"} NONE}
|
sl@0
|
346 |
|
sl@0
|
347 |
# The tests for Tcl_ExecObjCmd are in exec.test
|
sl@0
|
348 |
|
sl@0
|
349 |
test iocmd-10.1 {fblocked command} {
|
sl@0
|
350 |
list [catch {fblocked} msg] $msg
|
sl@0
|
351 |
} {1 {wrong # args: should be "fblocked channelId"}}
|
sl@0
|
352 |
test iocmd-10.2 {fblocked command} {
|
sl@0
|
353 |
list [catch {fblocked a b c d e f g} msg] $msg
|
sl@0
|
354 |
} {1 {wrong # args: should be "fblocked channelId"}}
|
sl@0
|
355 |
test iocmd-10.3 {fblocked command} {
|
sl@0
|
356 |
list [catch {fblocked file1000} msg] $msg
|
sl@0
|
357 |
} {1 {can not find channel named "file1000"}}
|
sl@0
|
358 |
test iocmd-10.4 {fblocked command} {
|
sl@0
|
359 |
list [catch {fblocked stdout} msg] $msg
|
sl@0
|
360 |
} {1 {channel "stdout" wasn't opened for reading}}
|
sl@0
|
361 |
test iocmd-10.5 {fblocked command} {
|
sl@0
|
362 |
fblocked stdin
|
sl@0
|
363 |
} 0
|
sl@0
|
364 |
|
sl@0
|
365 |
set path(test4) [makeFile {} test4]
|
sl@0
|
366 |
set path(test5) [makeFile {} test5]
|
sl@0
|
367 |
|
sl@0
|
368 |
file delete $path(test5)
|
sl@0
|
369 |
test iocmd-11.1 {I/O to command pipelines} {unixOrPc unixExecs} {
|
sl@0
|
370 |
set f [open $path(test4) w]
|
sl@0
|
371 |
close $f
|
sl@0
|
372 |
list [catch {open "| cat < $path(test4) > $path(test5)" w} msg] $msg $errorCode
|
sl@0
|
373 |
} {1 {can't write input to command: standard input was redirected} NONE}
|
sl@0
|
374 |
test iocmd-11.2 {I/O to command pipelines} {unixOrPc unixExecs} {
|
sl@0
|
375 |
list [catch {open "| echo > $path(test5)" r} msg] $msg $errorCode
|
sl@0
|
376 |
} {1 {can't read output from command: standard output was redirected} NONE}
|
sl@0
|
377 |
test iocmd-11.3 {I/O to command pipelines} {unixOrPc unixExecs} {
|
sl@0
|
378 |
list [catch {open "| echo > $path(test5)" r+} msg] $msg $errorCode
|
sl@0
|
379 |
} {1 {can't read output from command: standard output was redirected} NONE}
|
sl@0
|
380 |
|
sl@0
|
381 |
test iocmd-12.1 {POSIX open access modes: RDONLY} {
|
sl@0
|
382 |
file delete $path(test1)
|
sl@0
|
383 |
set f [open $path(test1) w]
|
sl@0
|
384 |
puts $f "Two lines: this one"
|
sl@0
|
385 |
puts $f "and this one"
|
sl@0
|
386 |
close $f
|
sl@0
|
387 |
set f [open $path(test1) RDONLY]
|
sl@0
|
388 |
set x [list [gets $f] [catch {puts $f Test} msg] $msg]
|
sl@0
|
389 |
close $f
|
sl@0
|
390 |
string compare $x \
|
sl@0
|
391 |
"{Two lines: this one} 1 [list [format "channel \"%s\" wasn't opened for writing" $f]]"
|
sl@0
|
392 |
} 0
|
sl@0
|
393 |
test iocmd-12.2 {POSIX open access modes: RDONLY} -match regexp -body {
|
sl@0
|
394 |
file delete $path(test3)
|
sl@0
|
395 |
open $path(test3) RDONLY
|
sl@0
|
396 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
|
sl@0
|
397 |
test iocmd-12.3 {POSIX open access modes: WRONLY} -match regexp -body {
|
sl@0
|
398 |
file delete $path(test3)
|
sl@0
|
399 |
open $path(test3) WRONLY
|
sl@0
|
400 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
|
sl@0
|
401 |
#
|
sl@0
|
402 |
# Test 13.4 relies on assigning the same channel name twice.
|
sl@0
|
403 |
#
|
sl@0
|
404 |
test iocmd-12.4 {POSIX open access modes: WRONLY} {unixOnly} {
|
sl@0
|
405 |
file delete $path(test3)
|
sl@0
|
406 |
set f [open $path(test3) w]
|
sl@0
|
407 |
fconfigure $f -eofchar {}
|
sl@0
|
408 |
puts $f xyzzy
|
sl@0
|
409 |
close $f
|
sl@0
|
410 |
set f [open $path(test3) WRONLY]
|
sl@0
|
411 |
fconfigure $f -eofchar {}
|
sl@0
|
412 |
puts -nonewline $f "ab"
|
sl@0
|
413 |
seek $f 0 current
|
sl@0
|
414 |
set x [list [catch {gets $f} msg] $msg]
|
sl@0
|
415 |
close $f
|
sl@0
|
416 |
set f [open $path(test3) r]
|
sl@0
|
417 |
fconfigure $f -eofchar {}
|
sl@0
|
418 |
lappend x [gets $f]
|
sl@0
|
419 |
close $f
|
sl@0
|
420 |
set y [list 1 [format "channel \"%s\" wasn't opened for reading" $f] abzzy]
|
sl@0
|
421 |
string compare $x $y
|
sl@0
|
422 |
} 0
|
sl@0
|
423 |
test iocmd-12.5 {POSIX open access modes: RDWR} -match regexp -body {
|
sl@0
|
424 |
file delete $path(test3)
|
sl@0
|
425 |
open $path(test3) RDWR
|
sl@0
|
426 |
} -returnCodes error -result {(?i)couldn't open ".*test3": no such file or directory}
|
sl@0
|
427 |
test iocmd-12.6 {POSIX open access modes: errors} {
|
sl@0
|
428 |
concat [catch {open $path(test3) "FOO \{BAR BAZ"} msg] $msg\n$errorInfo
|
sl@0
|
429 |
} "1 unmatched open brace in list
|
sl@0
|
430 |
unmatched open brace in list
|
sl@0
|
431 |
while processing open access modes \"FOO {BAR BAZ\"
|
sl@0
|
432 |
invoked from within
|
sl@0
|
433 |
\"open \$path(test3) \"FOO \\{BAR BAZ\"\""
|
sl@0
|
434 |
test iocmd-12.7 {POSIX open access modes: errors} {
|
sl@0
|
435 |
list [catch {open $path(test3) {FOO BAR BAZ}} msg] $msg
|
sl@0
|
436 |
} {1 {invalid access mode "FOO": must be RDONLY, WRONLY, RDWR, APPEND, CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC}}
|
sl@0
|
437 |
test iocmd-12.8 {POSIX open access modes: errors} {
|
sl@0
|
438 |
list [catch {open $path(test3) {TRUNC CREAT}} msg] $msg
|
sl@0
|
439 |
} {1 {access mode must include either RDONLY, WRONLY, or RDWR}}
|
sl@0
|
440 |
close [open $path(test3) w]
|
sl@0
|
441 |
|
sl@0
|
442 |
test iocmd-13.1 {errors in open command} {
|
sl@0
|
443 |
list [catch {open} msg] $msg
|
sl@0
|
444 |
} {1 {wrong # args: should be "open fileName ?access? ?permissions?"}}
|
sl@0
|
445 |
test iocmd-13.2 {errors in open command} {
|
sl@0
|
446 |
list [catch {open a b c d} msg] $msg
|
sl@0
|
447 |
} {1 {wrong # args: should be "open fileName ?access? ?permissions?"}}
|
sl@0
|
448 |
test iocmd-13.3 {errors in open command} {
|
sl@0
|
449 |
list [catch {open $path(test1) x} msg] $msg
|
sl@0
|
450 |
} {1 {illegal access mode "x"}}
|
sl@0
|
451 |
test iocmd-13.4 {errors in open command} {
|
sl@0
|
452 |
list [catch {open $path(test1) rw} msg] $msg
|
sl@0
|
453 |
} {1 {illegal access mode "rw"}}
|
sl@0
|
454 |
test iocmd-13.5 {errors in open command} {
|
sl@0
|
455 |
list [catch {open $path(test1) r+1} msg] $msg
|
sl@0
|
456 |
} {1 {illegal access mode "r+1"}}
|
sl@0
|
457 |
test iocmd-13.6 {errors in open command} {
|
sl@0
|
458 |
set msg [list [catch {open _non_existent_} msg] $msg $errorCode]
|
sl@0
|
459 |
regsub [file join {} _non_existent_] $msg "_non_existent_" msg
|
sl@0
|
460 |
string tolower $msg
|
sl@0
|
461 |
} {1 {couldn't open "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
|
sl@0
|
462 |
|
sl@0
|
463 |
|
sl@0
|
464 |
test iocmd-13.7.1 {open for append, a mode} -setup {
|
sl@0
|
465 |
set log [makeFile {} out]
|
sl@0
|
466 |
set chans {}
|
sl@0
|
467 |
} -body {
|
sl@0
|
468 |
foreach i { 0 1 2 3 4 5 6 7 8 9 } {
|
sl@0
|
469 |
puts [set ch [open $log a]] $i
|
sl@0
|
470 |
lappend chans $ch
|
sl@0
|
471 |
}
|
sl@0
|
472 |
foreach ch $chans {catch {close $ch}}
|
sl@0
|
473 |
lsort [split [string trim [viewFile out]] \n]
|
sl@0
|
474 |
} -cleanup {
|
sl@0
|
475 |
removeFile out
|
sl@0
|
476 |
# Ensure that channels are gone, even if body failed to do so
|
sl@0
|
477 |
foreach ch $chans {catch {close $ch}}
|
sl@0
|
478 |
} -result {0 1 2 3 4 5 6 7 8 9}
|
sl@0
|
479 |
|
sl@0
|
480 |
test iocmd-13.7.2 {open for append, O_APPEND} -setup {
|
sl@0
|
481 |
set log [makeFile {} out]
|
sl@0
|
482 |
set chans {}
|
sl@0
|
483 |
} -body {
|
sl@0
|
484 |
foreach i { 0 1 2 3 4 5 6 7 8 9 } {
|
sl@0
|
485 |
puts [set ch [open $log {WRONLY CREAT APPEND}]] $i
|
sl@0
|
486 |
lappend chans $ch
|
sl@0
|
487 |
}
|
sl@0
|
488 |
foreach ch $chans {catch {close $ch}}
|
sl@0
|
489 |
lsort [split [string trim [viewFile out]] \n]
|
sl@0
|
490 |
} -cleanup {
|
sl@0
|
491 |
removeFile out
|
sl@0
|
492 |
# Ensure that channels are gone, even if body failed to do so
|
sl@0
|
493 |
foreach ch $chans {catch {close $ch}}
|
sl@0
|
494 |
} -result {0 1 2 3 4 5 6 7 8 9}
|
sl@0
|
495 |
|
sl@0
|
496 |
|
sl@0
|
497 |
|
sl@0
|
498 |
|
sl@0
|
499 |
test iocmd-14.1 {file id parsing errors} {
|
sl@0
|
500 |
list [catch {eof gorp} msg] $msg $errorCode
|
sl@0
|
501 |
} {1 {can not find channel named "gorp"} NONE}
|
sl@0
|
502 |
test iocmd-14.2 {file id parsing errors} {
|
sl@0
|
503 |
list [catch {eof filex} msg] $msg
|
sl@0
|
504 |
} {1 {can not find channel named "filex"}}
|
sl@0
|
505 |
test iocmd-14.3 {file id parsing errors} {
|
sl@0
|
506 |
list [catch {eof file12a} msg] $msg
|
sl@0
|
507 |
} {1 {can not find channel named "file12a"}}
|
sl@0
|
508 |
test iocmd-14.4 {file id parsing errors} {
|
sl@0
|
509 |
list [catch {eof file123} msg] $msg
|
sl@0
|
510 |
} {1 {can not find channel named "file123"}}
|
sl@0
|
511 |
test iocmd-14.5 {file id parsing errors} {
|
sl@0
|
512 |
list [catch {eof stdout} msg] $msg
|
sl@0
|
513 |
} {0 0}
|
sl@0
|
514 |
test iocmd-14.6 {file id parsing errors} {
|
sl@0
|
515 |
list [catch {eof stdin} msg] $msg
|
sl@0
|
516 |
} {0 0}
|
sl@0
|
517 |
test iocmd-14.7 {file id parsing errors} {
|
sl@0
|
518 |
list [catch {eof stdout} msg] $msg
|
sl@0
|
519 |
} {0 0}
|
sl@0
|
520 |
test iocmd-14.8 {file id parsing errors} {
|
sl@0
|
521 |
list [catch {eof stderr} msg] $msg
|
sl@0
|
522 |
} {0 0}
|
sl@0
|
523 |
test iocmd-14.9 {file id parsing errors} {
|
sl@0
|
524 |
list [catch {eof stderr1} msg] $msg
|
sl@0
|
525 |
} {1 {can not find channel named "stderr1"}}
|
sl@0
|
526 |
|
sl@0
|
527 |
set f [open $path(test1) w]
|
sl@0
|
528 |
close $f
|
sl@0
|
529 |
|
sl@0
|
530 |
set expect "1 {can not find channel named \"$f\"}"
|
sl@0
|
531 |
test iocmd-14.10 {file id parsing errors} {
|
sl@0
|
532 |
list [catch {eof $f} msg] $msg
|
sl@0
|
533 |
} $expect
|
sl@0
|
534 |
|
sl@0
|
535 |
test iocmd-15.1 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
536 |
list [catch {fcopy} msg] $msg
|
sl@0
|
537 |
} {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}}
|
sl@0
|
538 |
test iocmd-15.2 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
539 |
list [catch {fcopy 1} msg] $msg
|
sl@0
|
540 |
} {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}}
|
sl@0
|
541 |
test iocmd-15.3 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
542 |
list [catch {fcopy 1 2 3 4 5 6 7} msg] $msg
|
sl@0
|
543 |
} {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}}
|
sl@0
|
544 |
test iocmd-15.4 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
545 |
list [catch {fcopy 1 2 3} msg] $msg
|
sl@0
|
546 |
} {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}}
|
sl@0
|
547 |
test iocmd-15.5 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
548 |
list [catch {fcopy 1 2 3 4 5} msg] $msg
|
sl@0
|
549 |
} {1 {wrong # args: should be "fcopy input output ?-size size? ?-command callback?"}}
|
sl@0
|
550 |
|
sl@0
|
551 |
set path(test2) [makeFile {} test2]
|
sl@0
|
552 |
|
sl@0
|
553 |
set f [open $path(test1) w]
|
sl@0
|
554 |
close $f
|
sl@0
|
555 |
|
sl@0
|
556 |
set rfile [open $path(test1) r]
|
sl@0
|
557 |
set wfile [open $path(test2) w]
|
sl@0
|
558 |
|
sl@0
|
559 |
test iocmd-15.6 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
560 |
list [catch {fcopy foo $wfile} msg] $msg
|
sl@0
|
561 |
} {1 {can not find channel named "foo"}}
|
sl@0
|
562 |
test iocmd-15.7 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
563 |
list [catch {fcopy $rfile foo} msg] $msg
|
sl@0
|
564 |
} {1 {can not find channel named "foo"}}
|
sl@0
|
565 |
test iocmd-15.8 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
566 |
list [catch {fcopy $wfile $wfile} msg] $msg
|
sl@0
|
567 |
} "1 {channel \"$wfile\" wasn't opened for reading}"
|
sl@0
|
568 |
test iocmd-15.9 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
569 |
list [catch {fcopy $rfile $rfile} msg] $msg
|
sl@0
|
570 |
} "1 {channel \"$rfile\" wasn't opened for writing}"
|
sl@0
|
571 |
test iocmd-15.10 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
572 |
list [catch {fcopy $rfile $wfile foo bar} msg] $msg
|
sl@0
|
573 |
} {1 {bad switch "foo": must be -size or -command}}
|
sl@0
|
574 |
test iocmd-15.11 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
575 |
list [catch {fcopy $rfile $wfile -size foo} msg] $msg
|
sl@0
|
576 |
} {1 {expected integer but got "foo"}}
|
sl@0
|
577 |
test iocmd-15.12 {Tcl_FcopyObjCmd} {fcopy} {
|
sl@0
|
578 |
list [catch {fcopy $rfile $wfile -command bar -size foo} msg] $msg
|
sl@0
|
579 |
} {1 {expected integer but got "foo"}}
|
sl@0
|
580 |
|
sl@0
|
581 |
close $rfile
|
sl@0
|
582 |
close $wfile
|
sl@0
|
583 |
|
sl@0
|
584 |
# cleanup
|
sl@0
|
585 |
foreach file [list test1 test2 test3 test4] {
|
sl@0
|
586 |
removeFile $file
|
sl@0
|
587 |
}
|
sl@0
|
588 |
# delay long enough for background processes to finish
|
sl@0
|
589 |
after 500
|
sl@0
|
590 |
foreach file [list test5] {
|
sl@0
|
591 |
removeFile $file
|
sl@0
|
592 |
}
|
sl@0
|
593 |
cleanupTests
|
sl@0
|
594 |
return
|