diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-09-10 13:14:00 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-09-10 13:14:00 +0000 |
commit | af4b8a523322d6100b52d41ad12d7b602d01331b (patch) | |
tree | 948949901cdcd5af947a3db9a68f59e5c4b415bd /libgo/go/io | |
parent | 337fa50b7b0d2964b6ebe2373224b5c1bbb61efb (diff) | |
download | gcc-af4b8a523322d6100b52d41ad12d7b602d01331b.zip gcc-af4b8a523322d6100b52d41ad12d7b602d01331b.tar.gz gcc-af4b8a523322d6100b52d41ad12d7b602d01331b.tar.bz2 |
libgo: update to Go 1.7.1 release
Reviewed-on: https://go-review.googlesource.com/29012
From-SVN: r240071
Diffstat (limited to 'libgo/go/io')
-rw-r--r-- | libgo/go/io/multi.go | 9 | ||||
-rw-r--r-- | libgo/go/io/multi_test.go | 38 |
2 files changed, 43 insertions, 4 deletions
diff --git a/libgo/go/io/multi.go b/libgo/go/io/multi.go index ed05cac..3a9d036 100644 --- a/libgo/go/io/multi.go +++ b/libgo/go/io/multi.go @@ -18,15 +18,16 @@ func (mr *multiReader) Read(p []byte) (n int, err error) { } } n, err = mr.readers[0].Read(p) + if err == EOF { + mr.readers = mr.readers[1:] + } if n > 0 || err != EOF { - if err == EOF { - // Don't return EOF yet. There may be more bytes - // in the remaining readers. + if err == EOF && len(mr.readers) > 0 { + // Don't return EOF yet. More readers remain. err = nil } return } - mr.readers = mr.readers[1:] } return 0, EOF } diff --git a/libgo/go/io/multi_test.go b/libgo/go/io/multi_test.go index a434453..447e7f5 100644 --- a/libgo/go/io/multi_test.go +++ b/libgo/go/io/multi_test.go @@ -197,3 +197,41 @@ func TestMultiReaderFlatten(t *testing.T) { myDepth+2, readDepth) } } + +// byteAndEOFReader is a Reader which reads one byte (the underlying +// byte) and io.EOF at once in its Read call. +type byteAndEOFReader byte + +func (b byteAndEOFReader) Read(p []byte) (n int, err error) { + if len(p) == 0 { + // Read(0 bytes) is useless. We expect no such useless + // calls in this test. + panic("unexpected call") + } + p[0] = byte(b) + return 1, EOF +} + +// In Go 1.7, this yielded bytes forever. +func TestMultiReaderSingleByteWithEOF(t *testing.T) { + got, err := ioutil.ReadAll(LimitReader(MultiReader(byteAndEOFReader('a'), byteAndEOFReader('b')), 10)) + if err != nil { + t.Fatal(err) + } + const want = "ab" + if string(got) != want { + t.Errorf("got %q; want %q", got, want) + } +} + +// Test that a reader returning (n, EOF) at the end of an MultiReader +// chain continues to return EOF on its final read, rather than +// yielding a (0, EOF). +func TestMultiReaderFinalEOF(t *testing.T) { + r := MultiReader(bytes.NewReader(nil), byteAndEOFReader('a')) + buf := make([]byte, 2) + n, err := r.Read(buf) + if n != 1 || err != EOF { + t.Errorf("got %v, %v; want 1, EOF", n, err) + } +} |