Skip to content

Commit

Permalink
cmd/go: run 'go help documentation' through gofmt in TestDocsUpToDate
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
rsc committed Mar 18, 2022
1 parent 7747c33 commit 0a49f70
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cmd/go/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package main_test

import (
"bytes"
"go/format"
diffpkg "internal/diff"
"os"
"testing"

Expand All @@ -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))
}
}

0 comments on commit 0a49f70

Please sign in to comment.