diff options
| author | Russ Cox <rsc@golang.org> | 2015-06-29 11:53:51 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-06-29 21:16:35 +0000 |
| commit | 4df6b1ec2f27d0dded28ecc7cde5d12f57e144d9 (patch) | |
| tree | d06697f49b4d9f00564ba36820a1eae269186ca1 /src/path/filepath/path_test.go | |
| parent | 69f0d4c6bebc775cfbc50e9562b5533ba86b90c9 (diff) | |
| download | go-4df6b1ec2f27d0dded28ecc7cde5d12f57e144d9.tar.xz | |
path/filepath: document and test behavior of SkipDir on files
This behavior is not what we might have designed from the start,
but it has been present since Go 1. Rather than make a visible
behavioral change that might cause programs to work differently
in Go ≤1.4 vs Go ≥1.5, document what SkipDir on a non-directory
has always meant. If code doesn't want this meaning, it is easy
enough not to return SkipDir on non-directories.
Fixes #10533.
Change-Id: Ic0612f032044bc7c69bf62583a02037e4b47530b
Reviewed-on: https://go-review.googlesource.com/11690
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/path/filepath/path_test.go')
| -rw-r--r-- | src/path/filepath/path_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 4ecaada983..91b6493c51 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -510,6 +510,35 @@ func touch(t *testing.T, name string) { } } +func TestWalkSkipDirOnFile(t *testing.T) { + td, err := ioutil.TempDir("", "walktest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(td) + + if err := os.MkdirAll(filepath.Join(td, "dir"), 0755); err != nil { + t.Fatal(err) + } + touch(t, filepath.Join(td, "dir/foo1")) + touch(t, filepath.Join(td, "dir/foo2")) + + sawFoo2 := false + filepath.Walk(td, func(path string, info os.FileInfo, err error) error { + if strings.HasSuffix(path, "foo2") { + sawFoo2 = true + } + if strings.HasSuffix(path, "foo1") { + return filepath.SkipDir + } + return nil + }) + + if sawFoo2 { + t.Errorf("SkipDir on file foo1 did not block processing of foo2") + } +} + func TestWalkFileError(t *testing.T) { td, err := ioutil.TempDir("", "walktest") if err != nil { |
