Skip to content

Commit

Permalink
gopls/internal/lsp/tests: remove AddImport support
Browse files Browse the repository at this point in the history
I went to translate the one 'addimport' marker test to the new
framework, only to decide that it would be better as a one-off
regression test in ./internal/regtest/misc, only to discover that there
was already a regression test misc.TestAddImport doing exactly what we
want. So this coverage was completely redundant -- just remove it.

For golang/go#54845

Change-Id: I1412990a9027b97b2b76c56462fe17c43c5a0c6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/541126
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr committed Nov 9, 2023
1 parent 72be087 commit bbf8bf8
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 81 deletions.
52 changes: 0 additions & 52 deletions gopls/internal/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"golang.org/x/tools/gopls/internal/bug"
"golang.org/x/tools/gopls/internal/lsp/cache"
"golang.org/x/tools/gopls/internal/lsp/command"
"golang.org/x/tools/gopls/internal/lsp/debug"
"golang.org/x/tools/gopls/internal/lsp/protocol"
"golang.org/x/tools/gopls/internal/lsp/source"
Expand Down Expand Up @@ -238,57 +237,6 @@ func applyTextDocumentEdits(r *runner, edits []protocol.DocumentChanges) (map[sp
return res, nil
}

func (r *runner) AddImport(t *testing.T, uri span.URI, expectedImport string) {
cmd, err := command.NewListKnownPackagesCommand("List Known Packages", command.URIArg{
URI: protocol.URIFromSpanURI(uri),
})
if err != nil {
t.Fatal(err)
}
resp, err := r.server.executeCommand(r.ctx, &protocol.ExecuteCommandParams{
Command: cmd.Command,
Arguments: cmd.Arguments,
})
if err != nil {
t.Fatal(err)
}
res := resp.(command.ListKnownPackagesResult)
var hasPkg bool
for _, p := range res.Packages {
if p == expectedImport {
hasPkg = true
break
}
}
if !hasPkg {
t.Fatalf("%s: got %v packages\nwant contains %q", command.ListKnownPackages, res.Packages, expectedImport)
}
cmd, err = command.NewAddImportCommand("Add Imports", command.AddImportArgs{
URI: protocol.URIFromSpanURI(uri),
ImportPath: expectedImport,
})
if err != nil {
t.Fatal(err)
}
_, err = r.server.executeCommand(r.ctx, &protocol.ExecuteCommandParams{
Command: cmd.Command,
Arguments: cmd.Arguments,
})
if err != nil {
t.Fatal(err)
}
got := (<-r.editRecv)[uri]
want := r.data.Golden(t, "addimport", uri.Filename(), func() ([]byte, error) {
return []byte(got), nil
})
if want == nil {
t.Fatalf("golden file %q not found", uri.Filename())
}
if diff := compare.Bytes(want, got); diff != "" {
t.Errorf("%s mismatch\n%s", command.AddImport, diff)
}
}

func (r *runner) SelectionRanges(t *testing.T, spn span.Span) {
uri := spn.URI()
sm, err := r.data.Mapper(uri)
Expand Down
1 change: 0 additions & 1 deletion gopls/internal/lsp/regtest/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ var update = flag.Bool("update", false, "if set, update test data during marker
// suggestedfix be consolidated?
//
// Existing marker tests (in ../testdata) to port:
// - AddImport
// - CallHierarchy
// - InlayHints
// - SelectionRanges
Expand Down
7 changes: 0 additions & 7 deletions gopls/internal/lsp/testdata/addimport/addimport.go.golden

This file was deleted.

3 changes: 0 additions & 3 deletions gopls/internal/lsp/testdata/addimport/addimport.go.in

This file was deleted.

18 changes: 0 additions & 18 deletions gopls/internal/lsp/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ var UpdateGolden = flag.Bool("golden", false, "Update golden files")
// These type names apparently avoid the need to repeat the
// type in the field name and the make() expression.
type CallHierarchy = map[span.Span]*CallHierarchyResult
type AddImport = map[span.URI]string
type SelectionRanges = []span.Span

type Data struct {
Config packages.Config
Exported *packagestest.Exported
CallHierarchy CallHierarchy
AddImport AddImport
SelectionRanges SelectionRanges

fragments map[string]string
Expand All @@ -78,7 +76,6 @@ type Data struct {
// we can abolish the interface now.
type Tests interface {
CallHierarchy(*testing.T, span.Span, *CallHierarchyResult)
AddImport(*testing.T, span.URI, string)
SelectionRanges(*testing.T, span.Span)
}

Expand Down Expand Up @@ -166,7 +163,6 @@ func RunTests(t *testing.T, dataDir string, includeMultiModule bool, f func(*tes
func load(t testing.TB, mode string, dir string) *Data {
datum := &Data{
CallHierarchy: make(CallHierarchy),
AddImport: make(AddImport),

dir: dir,
fragments: map[string]string{},
Expand Down Expand Up @@ -301,7 +297,6 @@ func load(t testing.TB, mode string, dir string) *Data {
if err := datum.Exported.Expect(map[string]interface{}{
"incomingcalls": datum.collectIncomingCalls,
"outgoingcalls": datum.collectOutgoingCalls,
"addimport": datum.collectAddImports,
"selectionrange": datum.collectSelectionRanges,
}); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -367,15 +362,6 @@ func Run(t *testing.T, tests Tests, data *Data) {
}
})

t.Run("AddImport", func(t *testing.T) {
t.Helper()
for uri, exp := range data.AddImport {
t.Run(uriName(uri), func(t *testing.T) {
tests.AddImport(t, uri, exp)
})
}
})

t.Run("SelectionRanges", func(t *testing.T) {
t.Helper()
for _, span := range data.SelectionRanges {
Expand Down Expand Up @@ -485,10 +471,6 @@ func (data *Data) Golden(t *testing.T, tag, target string, update func() ([]byte
return file.Data[:len(file.Data)-1] // drop the trailing \n
}

func (data *Data) collectAddImports(spn span.Span, imp string) {
data.AddImport[spn.URI()] = imp
}

func (data *Data) collectSelectionRanges(spn span.Span) {
data.SelectionRanges = append(data.SelectionRanges, spn)
}
Expand Down

0 comments on commit bbf8bf8

Please sign in to comment.