File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ func (p *Pipe) First(lines int) *Pipe {
154
154
output .WriteString (scanner .Text ())
155
155
output .WriteRune ('\n' )
156
156
}
157
+ p .Close ()
157
158
err := scanner .Err ()
158
159
if err != nil {
159
160
p .SetError (err )
Original file line number Diff line number Diff line change @@ -226,23 +226,30 @@ func TestFirst(t *testing.T) {
226
226
if err != nil {
227
227
t .Fatal (err )
228
228
}
229
- got , err := File ("testdata/first.input.txt" ).First (10 ).Bytes ()
229
+ input := File ("testdata/first.input.txt" )
230
+ got , err := input .First (10 ).Bytes ()
230
231
if err != nil {
231
232
t .Error (err )
232
233
}
233
234
if ! bytes .Equal (got , want ) {
234
235
t .Errorf ("want %q, got %q" , want , got )
235
236
}
236
- // First(0) should return zero lines
237
- zero := File ("testdata/first.input.txt" ).First (0 )
238
- gotZero , err := zero .CountLines ()
237
+ _ , err = ioutil .ReadAll (input .Reader )
238
+ if err == nil {
239
+ t .Error ("input not closed after reading" )
240
+ }
241
+ input = File ("testdata/first.input.txt" )
242
+ gotZero , err := input .First (0 ).CountLines ()
239
243
if err != nil {
240
244
t .Fatal (err )
241
245
}
242
246
if gotZero != 0 {
243
247
t .Errorf ("want 0 lines, got %d lines" , gotZero )
244
248
}
245
- // First(N) where the input has less than N lines, should just return the input.
249
+ _ , err = ioutil .ReadAll (input .Reader )
250
+ if err == nil {
251
+ t .Error ("input not closed after reading" )
252
+ }
246
253
want , err = File ("testdata/first.input.txt" ).Bytes ()
247
254
if err != nil {
248
255
t .Fatal (err )
You can’t perform that action at this time.
0 commit comments