io/fs: clean up test helper functions

Inline the only use of checkMarks which also allows to drop the
always-true report argument. This also ensures the correct line gets
reported in case of an error.

Also remove the unused markTree function and drop the unused testing.T
argument from makeTree.

Change-Id: I4033d3e5ecd929d08ce03c563aa99444e102d931
Reviewed-on: https://go-review.googlesource.com/c/go/+/451615
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Tobias Klauser 2022-11-17 17:38:20 +01:00 committed by Gopher Robot
parent 1ed636dc97
commit c13ce2985c

View file

@ -53,7 +53,7 @@ func walkTree(n *Node, path string, f func(path string, n *Node)) {
}
}
func makeTree(t *testing.T) FS {
func makeTree() FS {
fsys := fstest.MapFS{}
walkTree(tree, tree.name, func(path string, n *Node) {
if n.entries == nil {
@ -65,17 +65,6 @@ func makeTree(t *testing.T) FS {
return fsys
}
func markTree(n *Node) { walkTree(n, "", func(path string, n *Node) { n.mark++ }) }
func checkMarks(t *testing.T, report bool) {
walkTree(tree, tree.name, func(path string, n *Node) {
if n.mark != 1 && report {
t.Errorf("node %s mark = %d; expected 1", path, n.mark)
}
n.mark = 0
})
}
// Assumes that each node name is unique. Good enough for a test.
// If clear is true, any incoming error is cleared before return. The errors
// are always accumulated, though.
@ -108,7 +97,7 @@ func TestWalkDir(t *testing.T) {
}
defer os.Chdir(origDir)
fsys := makeTree(t)
fsys := makeTree()
errors := make([]error, 0, 10)
clear := true
markFn := func(path string, entry DirEntry, err error) error {
@ -122,7 +111,12 @@ func TestWalkDir(t *testing.T) {
if len(errors) != 0 {
t.Fatalf("unexpected errors: %s", errors)
}
checkMarks(t, true)
walkTree(tree, tree.name, func(path string, n *Node) {
if n.mark != 1 {
t.Errorf("node %s mark = %d; expected 1", path, n.mark)
}
n.mark = 0
})
}
func TestIssue51617(t *testing.T) {