Commit 685a8157 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

os: yet more Readdir tests and fix earlier regression

R=golang-dev, fshahriar
CC=golang-dev
https://golang.org/cl/4548068
parent 0e865ab8
......@@ -32,11 +32,11 @@ func (f *File) Readdirnames(n int) (names []string, err Error) {
f.dirinfo.buf = make([]byte, blockSize)
}
d := f.dirinfo
wantAll := n <= 0
size := n
if size < 0 {
if size <= 0 {
size = 100
n = -1
}
names = make([]string, 0, size) // Empty with room to grow.
......@@ -60,7 +60,7 @@ func (f *File) Readdirnames(n int) (names []string, err Error) {
d.bufp += nb
n -= nc
}
if !wantAll && len(names) == 0 {
if n >= 0 && len(names) == 0 {
return names, EOF
}
return names, nil
......
......@@ -296,7 +296,7 @@ func TestReaddirNValues(t *testing.T) {
t.Fatalf("TempDir: %v", err)
}
defer RemoveAll(dir)
for i := 1; i <= 20; i++ {
for i := 1; i <= 105; i++ {
f, err := Create(filepath.Join(dir, fmt.Sprintf("%d", i)))
if err != nil {
t.Fatalf("Create: %v", err)
......@@ -335,18 +335,25 @@ func TestReaddirNValues(t *testing.T) {
}
for _, fn := range []func(int, int, Error){readDirExpect, readDirNamesExpect} {
// Test the -1 case
// Test the slurp case
openDir()
fn(-1, 20, nil)
fn(0, 105, nil)
fn(0, 0, nil)
d.Close()
// Slurp with -1 instead
openDir()
fn(-1, 105, nil)
fn(-2, 0, nil)
fn(0, 0, nil)
d.Close()
// Test the bounded case
openDir()
fn(19, 19, nil)
fn(18, 1, nil)
fn(17, 0, EOF)
fn(1, 1, nil)
fn(2, 2, nil)
fn(105, 102, nil) // and tests buffer >100 case
fn(3, 0, EOF)
d.Close()
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment