diff options
| author | Russ Cox <rsc@golang.org> | 2022-02-04 11:55:33 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2022-03-18 16:57:07 +0000 |
| commit | 0a49f706e172443d817cfb3d44e5b366da1cc72a (patch) | |
| tree | 887bc7751297aa923b74226e2620df897234f762 /src/cmd | |
| parent | 7747c33a41491be74da65b116718f4df7a2f8337 (diff) | |
| download | go-0a49f706e172443d817cfb3d44e5b366da1cc72a.tar.xz | |
cmd/go: run 'go help documentation' through gofmt in TestDocsUpToDate
mkalldocs.sh runs gofmt on the output, but the test does not.
If go help documentation and gofmt disagree, the test will fail.
Fix that.
Change-Id: I837374a2d36cb5d71278ecefe2a7b6544622c576
Reviewed-on: https://go-review.googlesource.com/c/go/+/384256
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/go/help_test.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cmd/go/help_test.go b/src/cmd/go/help_test.go index abfc3db993..3e1d817ca5 100644 --- a/src/cmd/go/help_test.go +++ b/src/cmd/go/help_test.go @@ -6,6 +6,8 @@ package main_test import ( "bytes" + "go/format" + diffpkg "internal/diff" "os" "testing" @@ -23,11 +25,17 @@ func TestDocsUpToDate(t *testing.T) { buf := new(bytes.Buffer) // Match the command in mkalldocs.sh that generates alldocs.go. help.Help(buf, []string{"documentation"}) - data, err := os.ReadFile("alldocs.go") + internal := buf.Bytes() + internal, err := format.Source(internal) + if err != nil { + t.Fatalf("gofmt docs: %v", err) + } + alldocs, err := os.ReadFile("alldocs.go") if err != nil { t.Fatalf("error reading alldocs.go: %v", err) } - if !bytes.Equal(data, buf.Bytes()) { - t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it") + if !bytes.Equal(internal, alldocs) { + t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it\n%s", + diffpkg.Diff("go help documentation | gofmt", internal, "alldocs.go", alldocs)) } } |
