@@ -11,9 +11,9 @@ $f puts test-data
1111$f close
1212# create a test file file with several lines
1313set f [open copy.in wb]
14- $f puts line1
15- $f puts line2
16- $f puts line3
14+ $f puts line1xy
15+ $f puts line2xy
16+ $f puts line3xy
1717$f close
1818
1919set f [open testdata.in rb]
@@ -94,10 +94,82 @@ test aio-3.2 {copy bad length} -body {
9494
9595set badvar a
9696
97- test aio-4.1 {gets invalid var} -body {
97+ test aio-4.1 {gets usage} -body {
98+ $f gets abc def
99+ } -returnCodes error -match glob -result {wrong # args: should be "* gets ?-eol <str>? ?-keep 0|1? ?var?"}
100+
101+ test aio-4.2 {gets invalid option} -body {
102+ $f gets -xyz 3 def
103+ } -returnCodes error -result {bad option "-xyz": must be -eol, or -keep}
104+
105+ test aio-4.3 {gets invalid var} -body {
98106 $f gets badvar(abc)
99107} -returnCodes error -result {can't set "badvar(abc)": variable isn't array}
100108
109+ test aio-4.4 {gets -eol} -body {
110+ set ff [open copy.in]
111+ set rc [$ff gets -eol y\n buf]
112+ $ff close
113+ list $rc $buf
114+ } -result {6 line1x}
115+
116+ test aio-4.5 {gets -eol} -body {
117+ set ff [open copy.in]
118+ set rc [$ff gets -eol 2xy\n buf]
119+ $ff close
120+ list $rc $buf
121+ } -result {12 {line1xy
122+ line}}
123+
124+ test aio-4.6 {gets -keep} -body {
125+ set ff [open copy.in]
126+ set rc [$ff gets -keep 1 buf]
127+ $ff close
128+ list $rc $buf
129+ } -result {8 {line1xy
130+ }}
131+
132+ test aio-4.7 {gets -eol -keep} -body {
133+ set ff [open copy.in]
134+ set rc [$ff gets -keep 1 -eol 2xy\n buf]
135+ $ff close
136+ list $rc $buf
137+ } -result {16 {line1xy
138+ line2xy
139+ }}
140+
141+ test aio-4.8 {gets -eol no var} -body {
142+ set ff [open copy.in]
143+ set buf [$ff gets -eol xy -keep 1]
144+ $ff close
145+ set buf
146+ } -result line1xy
147+
148+ test aio-4.9 {gets -keep 0 count} -body {
149+ set ff [open copy.in]
150+ set count [$ff gets -keep 0 buf]
151+ $ff close
152+ list $count $buf
153+ } -result {7 line1xy}
154+
155+ test aio-4.10 {gets -keep 1 count} -body {
156+ set ff [open copy.in]
157+ set count [$ff gets -keep 1 buf]
158+ $ff close
159+ list $count $buf
160+ } -result {8 {line1xy
161+ }}
162+
163+ test aio-4.11 {gets -eol multiple calls} -body {
164+ set ff [open copy.in]
165+ set lines {}
166+ lappend lines [$ff gets -eol xy\n]
167+ lappend lines [$ff gets -eol xy\n]
168+ lappend lines [$ff gets -eol xy\n]
169+ $ff close
170+ set lines
171+ } -result {line1 line2 line3}
172+
101173test aio-5.1 {puts usage} -body {
102174 stdout puts -badopt abc
103175} -returnCodes error -result {wrong # args: should be "stdout puts ?-nonewline? str"}
@@ -188,19 +260,19 @@ test copyto-1.1 {basic copyto} {
188260 set result [list [$ff gets] [$ff gets] [$ff gets]]
189261 $ff close
190262 set result
191- } {line1 line2 line3 }
263+ } {line1xy line2xy line3xy }
192264
193265test copyto-1.2 {copyto with limit} {
194266 set in [open copy.in]
195267 set out [open copy.out w]
196- $in copyto $out 8
268+ $in copyto $out 10
197269 $in close
198270 $out close
199271 set ff [open copy.out]
200272 set result [list [$ff gets] [$ff gets] [$ff gets]]
201273 $ff close
202274 set result
203- } {line1 li {}}
275+ } {line1xy li {}}
204276
205277test copyto-1.3 {copyto after gets} {
206278 set in [open copy.in]
@@ -213,7 +285,7 @@ test copyto-1.3 {copyto after gets} {
213285 set result [list [$ff gets] [$ff gets] [$ff gets]]
214286 $ff close
215287 set result
216- } {line2 line3 {}}
288+ } {line2xy line3xy {}}
217289
218290test copyto-1.4 {copyto after read} {
219291 set in [open copy.in]
@@ -226,7 +298,7 @@ test copyto-1.4 {copyto after read} {
226298 set result [list [$ff gets] [$ff gets] [$ff gets]]
227299 $ff close
228300 set result
229- } {e1 line2 line3 }
301+ } {e1xy line2xy line3xy }
230302
231303test copyto-1.5 {copyto after gets, seek} {
232304 set in [open copy.in]
@@ -240,7 +312,7 @@ test copyto-1.5 {copyto after gets, seek} {
240312 set result [list [$ff gets] [$ff gets] [$ff gets]]
241313 $ff close
242314 set result
243- } {ne1 line2 line3 }
315+ } {ne1xy line2xy line3xy }
244316
245317test copyto-1.6 {copyto from pipe} {
246318 set in [open "|cat copy.in"]
@@ -252,7 +324,7 @@ test copyto-1.6 {copyto from pipe} {
252324 set result [list [$ff gets] [$ff gets] [$ff gets]]
253325 $ff close
254326 set result
255- } {line1 line2 line3 }
327+ } {line1xy line2xy line3xy }
256328
257329test copyto-1.6 {copyto to pipe} {
258330 set out [open "|cat >copy.out" w]
@@ -264,7 +336,7 @@ test copyto-1.6 {copyto to pipe} {
264336 set result [list [$ff gets] [$ff gets] [$ff gets]]
265337 $ff close
266338 set result
267- } {line1 line2 line3 }
339+ } {line1xy line2xy line3xy }
268340
269341# Creates a child process and returns {pid writehandle}
270342# The child expects to read $numlines lines of input and exits with a return
0 commit comments