From c5cd9430779e9d1fb77da7b0f1fe24f05f86370c Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 26 Sep 2022 12:16:58 -0400 Subject: [PATCH] gopls: fix the reset_golden.sh script and regenerate golden files Update the reset_golden.sh script to run the ./test and ./internal/lsp directories, following the deprecation of ./internal/lsp/cmd and ./internal/lsp/source tests. Also, fix it to generate golden data for tests that only run at 1.17 and earlier. Use the newly fixed script to sync the golden data. For golang/go#54845 Change-Id: I2b42dac91cf1c7e2e8e25fd2aa8ab23c91e05c6c Reviewed-on: https://go-review.googlesource.com/c/tools/+/434635 Reviewed-by: Alan Donovan gopls-CI: kokoro Run-TryBot: Robert Findley TryBot-Result: Gopher Robot --- gopls/internal/lsp/reset_golden.sh | 24 +++++++-- .../internal/lsp/testdata/godef/a/a.go.golden | 50 +++++++++---------- .../internal/lsp/testdata/godef/a/d.go.golden | 24 ++++----- .../godef/hover_generics/hover.go.golden | 8 --- 4 files changed, 57 insertions(+), 49 deletions(-) diff --git a/gopls/internal/lsp/reset_golden.sh b/gopls/internal/lsp/reset_golden.sh index ef9dacf2dc1..ff7f4d08208 100755 --- a/gopls/internal/lsp/reset_golden.sh +++ b/gopls/internal/lsp/reset_golden.sh @@ -4,11 +4,27 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # -# Regenerates the *.golden files in the ./internal/lsp/testdata directory. +# Updates the *.golden files ... to match the tests' current behavior. set -eu +GO117BIN="go1.17.9" + +command -v $GO117BIN >/dev/null 2>&1 || { + go install golang.org/dl/$GO117BIN@latest + $GO117BIN download +} + find ./internal/lsp/testdata -name *.golden ! -name summary*.txt.golden -delete -go test ./internal/lsp/source -golden -go test ./internal/lsp/ -golden -go test ./internal/lsp/cmd -golden +# Here we intentionally do not run the ./internal/lsp/source tests with +# -golden. Eventually these tests will be deleted, and in the meantime they are +# redundant with the ./internal/lsp tests. +# +# Note: go1.17.9 tests must be run *before* go tests, as by convention the +# golden output should match the output of gopls built with the most recent +# version of Go. If output differs at 1.17, tests must be tolerant of the 1.17 +# output. +$GO117BIN test ./internal/lsp -golden +go test ./internal/lsp -golden +$GO117BIN test ./test -golden +go test ./test -golden diff --git a/gopls/internal/lsp/testdata/godef/a/a.go.golden b/gopls/internal/lsp/testdata/godef/a/a.go.golden index 3363100ce0d..470396d068c 100644 --- a/gopls/internal/lsp/testdata/godef/a/a.go.golden +++ b/gopls/internal/lsp/testdata/godef/a/a.go.golden @@ -1,3 +1,28 @@ +-- H-hoverdef -- +```go +type H interface { + Goodbye() //@mark(AGoodbye, "Goodbye") +} +``` + +[`a.H` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#H) +-- I-hoverdef -- +```go +type I interface { + B() //@mark(AB, "B") + J +} +``` + +[`a.I` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#I) +-- J-hoverdef -- +```go +type J interface { + Hello() //@mark(AHello, "Hello") +} +``` + +[`a.J` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#J) -- Lock-hoverdef -- ```go func (*sync.Mutex).Lock() @@ -165,31 +190,6 @@ const h untyped int = 2 Constant block. --- H-hoverdef -- -```go -type H interface { - Goodbye() //@mark(AGoodbye, "Goodbye") -} -``` - -[`a.H` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#H) --- I-hoverdef -- -```go -type I interface { - B() //@mark(AB, "B") - J -} -``` - -[`a.I` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#I) --- J-hoverdef -- -```go -type J interface { - Hello() //@mark(AHello, "Hello") -} -``` - -[`a.J` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#J) -- make-hoverdef -- ```go func make(t Type, size ...int) Type diff --git a/gopls/internal/lsp/testdata/godef/a/d.go.golden b/gopls/internal/lsp/testdata/godef/a/d.go.golden index 840dbaf60ac..ee687750c3e 100644 --- a/gopls/internal/lsp/testdata/godef/a/d.go.golden +++ b/gopls/internal/lsp/testdata/godef/a/d.go.golden @@ -64,6 +64,18 @@ func (Thing).Method(i int) string ``` [`(a.Thing).Method` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#Thing.Method) +-- NextThing-hoverdef -- +```go +type NextThing struct { + Thing + Value int +} + +func (*NextThing).Method3() int +func (NextThing).another() string +``` + +[`a.NextThing` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#NextThing) -- Other-definition -- godef/a/d.go:9:5-10: defined here as ```go var Other Thing @@ -177,15 +189,3 @@ func Things(val []string) []Thing -- a-hoverdef -- Package a is a package for testing go to definition. --- NextThing-hoverdef -- -```go -type NextThing struct { - Thing - Value int -} - -func (*NextThing).Method3() int -func (NextThing).another() string -``` - -[`a.NextThing` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/godef/a#NextThing) diff --git a/gopls/internal/lsp/testdata/godef/hover_generics/hover.go.golden b/gopls/internal/lsp/testdata/godef/hover_generics/hover.go.golden index 7f302ab6865..fb03865bf8b 100644 --- a/gopls/internal/lsp/testdata/godef/hover_generics/hover.go.golden +++ b/gopls/internal/lsp/testdata/godef/hover_generics/hover.go.golden @@ -1,11 +1,3 @@ --- Pparam-hoverdef -- -```go -type parameter P interface{~int|string} -``` --- Pvar-hoverdef -- -```go -type parameter P interface{~int|string} -``` -- ValueQfield-hoverdef -- ```go field Q int