diff --git a/internal/lsp/cmd/test/imports.go b/internal/lsp/cmd/test/imports.go index 03d7ecc956..04c700b96c 100644 --- a/internal/lsp/cmd/test/imports.go +++ b/internal/lsp/cmd/test/imports.go @@ -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) diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 0fd2258357..b2414ad857 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -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) } }