Skip to content

Commit c13ce29

Browse files
tklausergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 1ed636d commit c13ce29

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/io/fs/walk_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func walkTree(n *Node, path string, f func(path string, n *Node)) {
5353
}
5454
}
5555

56-
func makeTree(t *testing.T) FS {
56+
func makeTree() FS {
5757
fsys := fstest.MapFS{}
5858
walkTree(tree, tree.name, func(path string, n *Node) {
5959
if n.entries == nil {
@@ -65,17 +65,6 @@ func makeTree(t *testing.T) FS {
6565
return fsys
6666
}
6767

68-
func markTree(n *Node) { walkTree(n, "", func(path string, n *Node) { n.mark++ }) }
69-
70-
func checkMarks(t *testing.T, report bool) {
71-
walkTree(tree, tree.name, func(path string, n *Node) {
72-
if n.mark != 1 && report {
73-
t.Errorf("node %s mark = %d; expected 1", path, n.mark)
74-
}
75-
n.mark = 0
76-
})
77-
}
78-
7968
// Assumes that each node name is unique. Good enough for a test.
8069
// If clear is true, any incoming error is cleared before return. The errors
8170
// are always accumulated, though.
@@ -108,7 +97,7 @@ func TestWalkDir(t *testing.T) {
10897
}
10998
defer os.Chdir(origDir)
11099

111-
fsys := makeTree(t)
100+
fsys := makeTree()
112101
errors := make([]error, 0, 10)
113102
clear := true
114103
markFn := func(path string, entry DirEntry, err error) error {
@@ -122,7 +111,12 @@ func TestWalkDir(t *testing.T) {
122111
if len(errors) != 0 {
123112
t.Fatalf("unexpected errors: %s", errors)
124113
}
125-
checkMarks(t, true)
114+
walkTree(tree, tree.name, func(path string, n *Node) {
115+
if n.mark != 1 {
116+
t.Errorf("node %s mark = %d; expected 1", path, n.mark)
117+
}
118+
n.mark = 0
119+
})
126120
}
127121

128122
func TestIssue51617(t *testing.T) {

0 commit comments

Comments
 (0)