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