From c13ce2985c35b4c6a4b65779c7b30648c6a6e3b8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 17 Nov 2022 17:38:20 +0100 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- src/io/fs/walk_test.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/io/fs/walk_test.go b/src/io/fs/walk_test.go index 04358beb24..40f4e1ab9d 100644 --- a/src/io/fs/walk_test.go +++ b/src/io/fs/walk_test.go @@ -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) { -- 2.50.0