internal/lsp: fix golden generation for import tests

A long time ago I only fixed golden generation for lsp/source. Get lsp/
and lsp/cmd too.

We have import tests that aren't formatted correctly, so we can't use
goimports to generate goldens. Just trust got.

Change-Id: If924503c0c0f6c60cd31fce194a8c1216001035b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/209981
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Heschi Kreinick 2019-12-04 20:39:06 -05:00
parent 69111344d4
commit addffd168b
2 changed files with 7 additions and 16 deletions

View File

@ -5,7 +5,6 @@
package cmdtest
import (
"os/exec"
"testing"
"golang.org/x/tools/internal/span"
@ -16,9 +15,7 @@ func (r *runner) Import(t *testing.T, spn span.Span) {
filename := uri.Filename()
got, _ := r.NormalizeGoplsCmd(t, "imports", filename)
want := string(r.data.Golden("goimports", filename, func() ([]byte, error) {
cmd := exec.Command("goimports", filename)
out, _ := cmd.Output() // ignore error, sometimes we have intentionally ungofmt-able files
return out, nil
return []byte(got), nil
}))
if want != got {
t.Errorf("imports failed for %s, expected:\n%q\ngot:\n%q", filename, want, got)

View File

@ -291,22 +291,13 @@ func (r *runner) Format(t *testing.T, spn span.Span) {
func (r *runner) Import(t *testing.T, spn span.Span) {
uri := spn.URI()
filename := uri.Filename()
goimported := string(r.data.Golden("goimports", filename, func() ([]byte, error) {
cmd := exec.Command("goimports", filename)
out, _ := cmd.Output() // ignore error, sometimes we have intentionally ungofmt-able files
return out, nil
}))
actions, err := r.server.CodeAction(r.ctx, &protocol.CodeActionParams{
TextDocument: protocol.TextDocumentIdentifier{
URI: protocol.NewURI(uri),
},
})
if err != nil {
if goimported != "" {
t.Error(err)
}
return
t.Fatal(err)
}
m, err := r.data.Mapper(uri)
if err != nil {
@ -320,8 +311,11 @@ func (r *runner) Import(t *testing.T, spn span.Span) {
}
got = res[uri]
}
if goimported != got {
t.Errorf("import failed for %s, expected:\n%v\ngot:\n%v", filename, goimported, got)
want := string(r.data.Golden("goimports", filename, func() ([]byte, error) {
return []byte(got), nil
}))
if want != got {
t.Errorf("import failed for %s, expected:\n%v\ngot:\n%v", filename, want, got)
}
}