mirror of https://github.com/golang/go.git
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:
parent
69111344d4
commit
addffd168b
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue