os: add a few upstream tests for Read and ReadAt, fix problems they exposed.

There are more upstream tests to pull in, but this is plenty for today.
This commit is contained in:
Dan Kegel
2021-12-29 09:36:01 -08:00
committed by Ron Evans
parent 1e2791b216
commit 61be9189f1
4 changed files with 148 additions and 4 deletions
+6 -2
View File
@@ -101,6 +101,7 @@ func Create(name string) (*File, error) {
// read and any error encountered. At end of file, Read returns 0, io.EOF.
func (f *File) Read(b []byte) (n int, err error) {
n, err = f.handle.Read(b)
// TODO: want to always wrap, like upstream, but ReadFile() compares against exactly io.EOF?
if err != nil && err != io.EOF {
err = &PathError{"read", f.name, err}
}
@@ -120,8 +121,11 @@ func (f *File) ReadAt(b []byte, offset int64) (n int, err error) {
for len(b) > 0 {
m, e := f.handle.ReadAt(b, offset)
if e != nil {
if err != io.EOF {
err = &PathError{"readat", f.name, err}
// TODO: want to always wrap, like upstream, but TestReadAtEOF compares against exactly io.EOF?
if e != io.EOF {
err = &PathError{"readat", f.name, e}
} else {
err = e
}
break
}