aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/path/filepath/path_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-09-07 15:19:53 -0700
committerRobert Griesemer <gri@golang.org>2011-09-07 15:19:53 -0700
commit49bcc88f793050d128f0f0df447ff2e2783cc145 (patch)
tree7cd14d94ac22229537966325bca45c7dfb7f2e64 /src/pkg/path/filepath/path_test.go
parente5c20dc270c3471bddee57f470bff6481ed12234 (diff)
downloadgo-49bcc88f793050d128f0f0df447ff2e2783cc145.tar.xz
undo CL 4964067 / 661cb84cc6f0
API change. Needs further reflection. ««« original CL description path/filepath: Simplify Walk interface The last argument of filepath.Walk was removed, and the Visitor interface now contains an Error method that is called on errors. Fixes #2237. R=golang-dev, gri, r CC=golang-dev https://golang.org/cl/4964067 »»» R=r CC=golang-dev https://golang.org/cl/4974065
Diffstat (limited to 'src/pkg/path/filepath/path_test.go')
-rw-r--r--src/pkg/path/filepath/path_test.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go
index 8c566c7002..395b12775a 100644
--- a/src/pkg/path/filepath/path_test.go
+++ b/src/pkg/path/filepath/path_test.go
@@ -299,30 +299,30 @@ func mark(name string) {
})
}
-type TestVisitor chan os.Error
+type TestVisitor struct{}
-func (v TestVisitor) VisitDir(path string, f *os.FileInfo) bool {
+func (v *TestVisitor) VisitDir(path string, f *os.FileInfo) bool {
mark(f.Name)
return true
}
-func (v TestVisitor) VisitFile(path string, f *os.FileInfo) {
+func (v *TestVisitor) VisitFile(path string, f *os.FileInfo) {
mark(f.Name)
}
-func (v TestVisitor) Error(path string, err os.Error) {
- v <- err
-}
-
func TestWalk(t *testing.T) {
makeTree(t)
- v := make(TestVisitor, 64)
+ // 1) ignore error handling, expect none
+ v := &TestVisitor{}
+ filepath.Walk(tree.name, v, nil)
+ checkMarks(t)
- // 1) no errors expected.
- filepath.Walk(tree.name, v)
+ // 2) handle errors, expect none
+ errors := make(chan os.Error, 64)
+ filepath.Walk(tree.name, v, errors)
select {
- case err := <-v:
+ case err := <-errors:
t.Errorf("no error expected, found: %s", err)
default:
// ok
@@ -343,13 +343,14 @@ func TestWalk(t *testing.T) {
tree.entries[1].mark--
tree.entries[3].mark--
- // 2) expect two errors
+ // 3) handle errors, expect two
+ errors = make(chan os.Error, 64)
os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0)
- filepath.Walk(tree.name, v)
+ filepath.Walk(tree.name, v, errors)
Loop:
for i := 1; i <= 2; i++ {
select {
- case <-v:
+ case <-errors:
// ok
default:
t.Errorf("%d. error expected, none found", i)
@@ -357,7 +358,7 @@ func TestWalk(t *testing.T) {
}
}
select {
- case err := <-v:
+ case err := <-errors:
t.Errorf("only two errors expected, found 3rd: %v", err)
default:
// ok