]> Cypherpunks repositories - gostls13.git/commitdiff
io/fs: clean up test helper functions
authorTobias Klauser <tklauser@distanz.ch>
Thu, 17 Nov 2022 16:38:20 +0000 (17:38 +0100)
committerGopher Robot <gobot@golang.org>
Fri, 18 Nov 2022 15:21:18 +0000 (15:21 +0000)
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>

src/io/fs/walk_test.go

index 04358beb240da6ced6fcea970e21077f08cf298d..40f4e1ab9d6139950884d60551fc8cdf730b4f93 100644 (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) {