diff options
Diffstat (limited to 'internal/lsp/cmd/test')
-rw-r--r-- | internal/lsp/cmd/test/call_hierarchy.go | 85 | ||||
-rw-r--r-- | internal/lsp/cmd/test/check.go | 63 | ||||
-rw-r--r-- | internal/lsp/cmd/test/cmdtest.go | 169 | ||||
-rw-r--r-- | internal/lsp/cmd/test/definition.go | 61 | ||||
-rw-r--r-- | internal/lsp/cmd/test/folding_range.go | 25 | ||||
-rw-r--r-- | internal/lsp/cmd/test/format.go | 86 | ||||
-rw-r--r-- | internal/lsp/cmd/test/highlight.go | 29 | ||||
-rw-r--r-- | internal/lsp/cmd/test/implementation.go | 37 | ||||
-rw-r--r-- | internal/lsp/cmd/test/imports.go | 29 | ||||
-rw-r--r-- | internal/lsp/cmd/test/links.go | 30 | ||||
-rw-r--r-- | internal/lsp/cmd/test/prepare_rename.go | 46 | ||||
-rw-r--r-- | internal/lsp/cmd/test/references.go | 49 | ||||
-rw-r--r-- | internal/lsp/cmd/test/rename.go | 29 | ||||
-rw-r--r-- | internal/lsp/cmd/test/semanticdriver.go | 34 | ||||
-rw-r--r-- | internal/lsp/cmd/test/signature.go | 34 | ||||
-rw-r--r-- | internal/lsp/cmd/test/suggested_fix.go | 35 | ||||
-rw-r--r-- | internal/lsp/cmd/test/symbols.go | 23 | ||||
-rw-r--r-- | internal/lsp/cmd/test/workspace_symbol.go | 53 |
18 files changed, 0 insertions, 917 deletions
diff --git a/internal/lsp/cmd/test/call_hierarchy.go b/internal/lsp/cmd/test/call_hierarchy.go deleted file mode 100644 index 38f8ed707..000000000 --- a/internal/lsp/cmd/test/call_hierarchy.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "sort" - "strings" - "testing" - - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -func (r *runner) CallHierarchy(t *testing.T, spn span.Span, expectedCalls *tests.CallHierarchyResult) { - collectCallSpansString := func(callItems []protocol.CallHierarchyItem) string { - var callSpans []string - for _, call := range callItems { - mapper, err := r.data.Mapper(call.URI.SpanURI()) - if err != nil { - t.Fatal(err) - } - callSpan, err := mapper.Span(protocol.Location{URI: call.URI, Range: call.Range}) - if err != nil { - t.Fatal(err) - } - callSpans = append(callSpans, fmt.Sprint(callSpan)) - } - // to make tests deterministic - sort.Strings(callSpans) - return r.Normalize(strings.Join(callSpans, "\n")) - } - - expectIn, expectOut := collectCallSpansString(expectedCalls.IncomingCalls), collectCallSpansString(expectedCalls.OutgoingCalls) - expectIdent := r.Normalize(fmt.Sprint(spn)) - - uri := spn.URI() - filename := uri.Filename() - target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column()) - - got, stderr := r.NormalizeGoplsCmd(t, "call_hierarchy", target) - if stderr != "" { - t.Fatalf("call_hierarchy failed for %s: %s", target, stderr) - } - - gotIn, gotIdent, gotOut := cleanCallHierarchyCmdResult(got) - if expectIn != gotIn { - t.Errorf("incoming calls call_hierarchy failed for %s expected:\n%s\ngot:\n%s", target, expectIn, gotIn) - } - if expectIdent != gotIdent { - t.Errorf("call_hierarchy failed for %s expected:\n%s\ngot:\n%s", target, expectIdent, gotIdent) - } - if expectOut != gotOut { - t.Errorf("outgoing calls call_hierarchy failed for %s expected:\n%s\ngot:\n%s", target, expectOut, gotOut) - } - -} - -// parses function URI and Range from call hierarchy cmd output to -// incoming, identifier and outgoing calls (returned in that order) -// ex: "identifier: function d at .../callhierarchy/callhierarchy.go:19:6-7" -> ".../callhierarchy/callhierarchy.go:19:6-7" -func cleanCallHierarchyCmdResult(output string) (incoming, ident, outgoing string) { - var incomingCalls, outgoingCalls []string - for _, out := range strings.Split(output, "\n") { - if out == "" { - continue - } - - callLocation := out[strings.LastIndex(out, " ")+1:] - if strings.HasPrefix(out, "caller") { - incomingCalls = append(incomingCalls, callLocation) - } else if strings.HasPrefix(out, "callee") { - outgoingCalls = append(outgoingCalls, callLocation) - } else { - ident = callLocation - } - } - sort.Strings(incomingCalls) - sort.Strings(outgoingCalls) - incoming, outgoing = strings.Join(incomingCalls, "\n"), strings.Join(outgoingCalls, "\n") - return -} diff --git a/internal/lsp/cmd/test/check.go b/internal/lsp/cmd/test/check.go deleted file mode 100644 index f0e6d8fef..000000000 --- a/internal/lsp/cmd/test/check.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "io/ioutil" - "strings" - "testing" - - "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/span" -) - -func (r *runner) Diagnostics(t *testing.T, uri span.URI, want []*source.Diagnostic) { - if len(want) == 1 && want[0].Message == "" { - return - } - fname := uri.Filename() - out, _ := r.runGoplsCmd(t, "check", fname) - // parse got into a collection of reports - got := map[string]struct{}{} - for _, l := range strings.Split(out, "\n") { - if len(l) == 0 { - continue - } - // parse and reprint to normalize the span - bits := strings.SplitN(l, ": ", 2) - if len(bits) == 2 { - spn := span.Parse(strings.TrimSpace(bits[0])) - spn = span.New(spn.URI(), spn.Start(), span.Point{}) - data, err := ioutil.ReadFile(fname) - if err != nil { - t.Fatal(err) - } - converter := span.NewContentConverter(fname, data) - s, err := spn.WithPosition(converter) - if err != nil { - t.Fatal(err) - } - l = fmt.Sprintf("%s: %s", s, strings.TrimSpace(bits[1])) - } - got[r.NormalizePrefix(l)] = struct{}{} - } - for _, diag := range want { - expect := fmt.Sprintf("%v:%v:%v: %v", uri.Filename(), diag.Range.Start.Line+1, diag.Range.Start.Character+1, diag.Message) - if diag.Range.Start.Character == 0 { - expect = fmt.Sprintf("%v:%v: %v", uri.Filename(), diag.Range.Start.Line+1, diag.Message) - } - expect = r.NormalizePrefix(expect) - _, found := got[expect] - if !found { - t.Errorf("missing diagnostic %q, %v", expect, got) - } else { - delete(got, expect) - } - } - for extra := range got { - t.Errorf("extra diagnostic %q", extra) - } -} diff --git a/internal/lsp/cmd/test/cmdtest.go b/internal/lsp/cmd/test/cmdtest.go deleted file mode 100644 index 312f7b8b4..000000000 --- a/internal/lsp/cmd/test/cmdtest.go +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package cmdtest contains the test suite for the command line behavior of gopls. -package cmdtest - -import ( - "bytes" - "context" - "flag" - "fmt" - "io" - "os" - "sync" - "testing" - - "golang.org/x/tools/internal/jsonrpc2/servertest" - "golang.org/x/tools/internal/lsp/cache" - "golang.org/x/tools/internal/lsp/cmd" - "golang.org/x/tools/internal/lsp/debug" - "golang.org/x/tools/internal/lsp/lsprpc" - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/tool" -) - -type runner struct { - data *tests.Data - ctx context.Context - options func(*source.Options) - normalizers []tests.Normalizer - remote string -} - -func TestCommandLine(t *testing.T, testdata string, options func(*source.Options)) { - // On Android, the testdata directory is not copied to the runner. - if stat, err := os.Stat(testdata); err != nil || !stat.IsDir() { - t.Skip("testdata directory not present") - } - tests.RunTests(t, testdata, false, func(t *testing.T, datum *tests.Data) { - ctx := tests.Context(t) - ts := NewTestServer(ctx, options) - tests.Run(t, NewRunner(datum, ctx, ts.Addr, options), datum) - cmd.CloseTestConnections(ctx) - }) -} - -func NewTestServer(ctx context.Context, options func(*source.Options)) *servertest.TCPServer { - ctx = debug.WithInstance(ctx, "", "") - cache := cache.New(options) - ss := lsprpc.NewStreamServer(cache, false) - return servertest.NewTCPServer(ctx, ss, nil) -} - -func NewRunner(data *tests.Data, ctx context.Context, remote string, options func(*source.Options)) *runner { - return &runner{ - data: data, - ctx: ctx, - options: options, - normalizers: tests.CollectNormalizers(data.Exported), - remote: remote, - } -} - -func (r *runner) CodeLens(t *testing.T, uri span.URI, want []protocol.CodeLens) { - //TODO: add command line completions tests when it works -} - -func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.CompletionSnippet, placeholders bool, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) CaseSensitiveCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { - //TODO: add command line completions tests when it works -} - -func (r *runner) FunctionExtraction(t *testing.T, start span.Span, end span.Span) { - //TODO: function extraction not supported on command line -} - -func (r *runner) MethodExtraction(t *testing.T, start span.Span, end span.Span) { - //TODO: function extraction not supported on command line -} - -func (r *runner) AddImport(t *testing.T, uri span.URI, expectedImport string) { - //TODO: import addition not supported on command line -} - -func (r *runner) Hover(t *testing.T, spn span.Span, info string) { - //TODO: hovering not supported on command line -} - -func (r *runner) runGoplsCmd(t testing.TB, args ...string) (string, string) { - rStdout, wStdout, err := os.Pipe() - if err != nil { - t.Fatal(err) - } - oldStdout := os.Stdout - rStderr, wStderr, err := os.Pipe() - if err != nil { - t.Fatal(err) - } - oldStderr := os.Stderr - stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{} - var wg sync.WaitGroup - wg.Add(2) - go func() { - io.Copy(stdout, rStdout) - wg.Done() - }() - go func() { - io.Copy(stderr, rStderr) - wg.Done() - }() - os.Stdout, os.Stderr = wStdout, wStderr - app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Exported.Config.Env, r.options) - remote := r.remote - s := flag.NewFlagSet(app.Name(), flag.ExitOnError) - err = tool.Run(tests.Context(t), s, - app, - append([]string{fmt.Sprintf("-remote=internal@%s", remote)}, args...)) - if err != nil { - fmt.Fprint(os.Stderr, err) - } - wStdout.Close() - wStderr.Close() - wg.Wait() - os.Stdout, os.Stderr = oldStdout, oldStderr - rStdout.Close() - rStderr.Close() - return stdout.String(), stderr.String() -} - -// NormalizeGoplsCmd runs the gopls command and normalizes its output. -func (r *runner) NormalizeGoplsCmd(t testing.TB, args ...string) (string, string) { - stdout, stderr := r.runGoplsCmd(t, args...) - return r.Normalize(stdout), r.Normalize(stderr) -} - -func (r *runner) Normalize(s string) string { - return tests.Normalize(s, r.normalizers) -} - -func (r *runner) NormalizePrefix(s string) string { - return tests.NormalizePrefix(s, r.normalizers) -} diff --git a/internal/lsp/cmd/test/definition.go b/internal/lsp/cmd/test/definition.go deleted file mode 100644 index c82d9a6c1..000000000 --- a/internal/lsp/cmd/test/definition.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "runtime" - "strings" - "testing" - - "golang.org/x/tools/internal/lsp/diff" - "golang.org/x/tools/internal/lsp/diff/myers" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -type godefMode int - -const ( - plainGodef = godefMode(1 << iota) - jsonGoDef -) - -var godefModes = []godefMode{ - plainGodef, - jsonGoDef, -} - -func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) { - if d.IsType || d.OnlyHover { - // TODO: support type definition, hover queries - return - } - d.Src = span.New(d.Src.URI(), span.NewPoint(0, 0, d.Src.Start().Offset()), span.Point{}) - for _, mode := range godefModes { - args := []string{"definition", "-markdown"} - tag := d.Name + "-definition" - if mode&jsonGoDef != 0 { - tag += "-json" - args = append(args, "-json") - } - uri := d.Src.URI() - args = append(args, fmt.Sprint(d.Src)) - got, _ := r.NormalizeGoplsCmd(t, args...) - if mode&jsonGoDef != 0 && runtime.GOOS == "windows" { - got = strings.Replace(got, "file:///", "file://", -1) - } - expect := strings.TrimSpace(string(r.data.Golden(tag, uri.Filename(), func() ([]byte, error) { - return []byte(got), nil - }))) - if expect != "" && !strings.HasPrefix(got, expect) { - d, err := myers.ComputeEdits("", expect, got) - if err != nil { - t.Fatal(err) - } - t.Errorf("definition %v failed with %#v\n%s", tag, args, diff.ToUnified("expect", "got", expect, d)) - } - } -} diff --git a/internal/lsp/cmd/test/folding_range.go b/internal/lsp/cmd/test/folding_range.go deleted file mode 100644 index 4478687b5..000000000 --- a/internal/lsp/cmd/test/folding_range.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "testing" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) FoldingRanges(t *testing.T, spn span.Span) { - goldenTag := "foldingRange-cmd" - uri := spn.URI() - filename := uri.Filename() - got, _ := r.NormalizeGoplsCmd(t, "folding_ranges", filename) - expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) { - return []byte(got), nil - })) - - if expect != got { - t.Errorf("folding_ranges failed failed for %s expected:\n%s\ngot:\n%s", filename, expect, got) - } -} diff --git a/internal/lsp/cmd/test/format.go b/internal/lsp/cmd/test/format.go deleted file mode 100644 index 77eedd440..000000000 --- a/internal/lsp/cmd/test/format.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "bytes" - exec "golang.org/x/sys/execabs" - "io/ioutil" - "os" - "regexp" - "strings" - "testing" - - "golang.org/x/tools/internal/span" - "golang.org/x/tools/internal/testenv" -) - -func (r *runner) Format(t *testing.T, spn span.Span) { - tag := "gofmt" - uri := spn.URI() - filename := uri.Filename() - expect := string(r.data.Golden(tag, filename, func() ([]byte, error) { - cmd := exec.Command("gofmt", filename) - contents, _ := cmd.Output() // ignore error, sometimes we have intentionally ungofmt-able files - contents = []byte(r.Normalize(fixFileHeader(string(contents)))) - return contents, nil - })) - if expect == "" { - //TODO: our error handling differs, for now just skip unformattable files - t.Skip("Unformattable file") - } - got, _ := r.NormalizeGoplsCmd(t, "format", filename) - if expect != got { - t.Errorf("format failed for %s expected:\n%s\ngot:\n%s", filename, expect, got) - } - // now check we can build a valid unified diff - unified, _ := r.NormalizeGoplsCmd(t, "format", "-d", filename) - checkUnified(t, filename, expect, unified) -} - -var unifiedHeader = regexp.MustCompile(`^diff -u.*\n(---\s+\S+\.go\.orig)\s+[\d-:. ]+(\n\+\+\+\s+\S+\.go)\s+[\d-:. ]+(\n@@)`) - -func fixFileHeader(s string) string { - match := unifiedHeader.FindStringSubmatch(s) - if match == nil { - return s - } - return strings.Join(append(match[1:], s[len(match[0]):]), "") -} - -func checkUnified(t *testing.T, filename string, expect string, patch string) { - testenv.NeedsTool(t, "patch") - if strings.Count(patch, "\n+++ ") > 1 { - // TODO(golang/go/#34580) - t.Skip("multi-file patch tests not supported yet") - } - applied := "" - if patch == "" { - applied = expect - } else { - temp, err := ioutil.TempFile("", "applied") - if err != nil { - t.Fatal(err) - } - temp.Close() - defer os.Remove(temp.Name()) - cmd := exec.Command("patch", "-u", "-p0", "-o", temp.Name(), filename) - cmd.Stdin = bytes.NewBuffer([]byte(patch)) - msg, err := cmd.CombinedOutput() - if err != nil { - t.Errorf("failed applying patch to %s: %v\ngot:\n%s\npatch:\n%s", filename, err, msg, patch) - return - } - out, err := ioutil.ReadFile(temp.Name()) - if err != nil { - t.Errorf("failed reading patched output for %s: %v\n", filename, err) - return - } - applied = string(out) - } - if expect != applied { - t.Errorf("apply unified gave wrong result for %s expected:\n%s\ngot:\n%s\npatch:\n%s", filename, expect, applied, patch) - } -} diff --git a/internal/lsp/cmd/test/highlight.go b/internal/lsp/cmd/test/highlight.go deleted file mode 100644 index 99e8b2c3f..000000000 --- a/internal/lsp/cmd/test/highlight.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "testing" - - "fmt" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) Highlight(t *testing.T, spn span.Span, spans []span.Span) { - var expect string - for _, l := range spans { - expect += fmt.Sprintln(l) - } - expect = r.Normalize(expect) - - uri := spn.URI() - filename := uri.Filename() - target := filename + ":" + fmt.Sprint(spn.Start().Line()) + ":" + fmt.Sprint(spn.Start().Column()) - got, _ := r.NormalizeGoplsCmd(t, "highlight", target) - if expect != got { - t.Errorf("highlight failed for %s expected:\n%s\ngot:\n%s", target, expect, got) - } -} diff --git a/internal/lsp/cmd/test/implementation.go b/internal/lsp/cmd/test/implementation.go deleted file mode 100644 index 189452466..000000000 --- a/internal/lsp/cmd/test/implementation.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "sort" - "testing" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) Implementation(t *testing.T, spn span.Span, imps []span.Span) { - var itemStrings []string - for _, i := range imps { - itemStrings = append(itemStrings, fmt.Sprint(i)) - } - sort.Strings(itemStrings) - var expect string - for _, i := range itemStrings { - expect += i + "\n" - } - expect = r.Normalize(expect) - - uri := spn.URI() - filename := uri.Filename() - target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column()) - - got, stderr := r.NormalizeGoplsCmd(t, "implementation", target) - if stderr != "" { - t.Errorf("implementation failed for %s: %s", target, stderr) - } else if expect != got { - t.Errorf("implementation failed for %s expected:\n%s\ngot:\n%s", target, expect, got) - } -} diff --git a/internal/lsp/cmd/test/imports.go b/internal/lsp/cmd/test/imports.go deleted file mode 100644 index ce8aee55d..000000000 --- a/internal/lsp/cmd/test/imports.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "testing" - - "golang.org/x/tools/internal/lsp/diff" - "golang.org/x/tools/internal/lsp/diff/myers" - "golang.org/x/tools/internal/span" -) - -func (r *runner) Import(t *testing.T, spn span.Span) { - uri := spn.URI() - filename := uri.Filename() - got, _ := r.NormalizeGoplsCmd(t, "imports", filename) - want := string(r.data.Golden("goimports", filename, func() ([]byte, error) { - return []byte(got), nil - })) - if want != got { - d, err := myers.ComputeEdits(uri, want, got) - if err != nil { - t.Fatal(err) - } - t.Errorf("imports failed for %s, expected:\n%s", filename, diff.ToUnified("want", "got", want, d)) - } -} diff --git a/internal/lsp/cmd/test/links.go b/internal/lsp/cmd/test/links.go deleted file mode 100644 index 88df76832..000000000 --- a/internal/lsp/cmd/test/links.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "encoding/json" - "testing" - - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -func (r *runner) Link(t *testing.T, uri span.URI, wantLinks []tests.Link) { - m, err := r.data.Mapper(uri) - if err != nil { - t.Fatal(err) - } - out, _ := r.NormalizeGoplsCmd(t, "links", "-json", uri.Filename()) - var got []protocol.DocumentLink - err = json.Unmarshal([]byte(out), &got) - if err != nil { - t.Fatal(err) - } - if diff := tests.DiffLinks(m, wantLinks, got); diff != "" { - t.Error(diff) - } -} diff --git a/internal/lsp/cmd/test/prepare_rename.go b/internal/lsp/cmd/test/prepare_rename.go deleted file mode 100644 index b5359e57b..000000000 --- a/internal/lsp/cmd/test/prepare_rename.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "testing" - - "golang.org/x/tools/internal/lsp/cmd" - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/span" -) - -func (r *runner) PrepareRename(t *testing.T, src span.Span, want *source.PrepareItem) { - m, err := r.data.Mapper(src.URI()) - if err != nil { - t.Errorf("prepare_rename failed: %v", err) - } - - var ( - target = fmt.Sprintf("%v", src) - args = []string{"prepare_rename", target} - stdOut, stdErr = r.NormalizeGoplsCmd(t, args...) - expect string - ) - - if want.Text == "" { - if stdErr != "" && stdErr != cmd.ErrInvalidRenamePosition.Error() { - t.Errorf("prepare_rename failed for %s,\nexpected:\n`%v`\ngot:\n`%v`", target, expect, stdErr) - } - return - } - - ws, err := m.Span(protocol.Location{Range: want.Range}) - if err != nil { - t.Errorf("prepare_rename failed: %v", err) - } - - expect = r.Normalize(fmt.Sprintln(ws)) - if expect != stdOut { - t.Errorf("prepare_rename failed for %s expected:\n`%s`\ngot:\n`%s`\n", target, expect, stdOut) - } -} diff --git a/internal/lsp/cmd/test/references.go b/internal/lsp/cmd/test/references.go deleted file mode 100644 index 66d0d0662..000000000 --- a/internal/lsp/cmd/test/references.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "sort" - "testing" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) References(t *testing.T, spn span.Span, itemList []span.Span) { - for _, includeDeclaration := range []bool{true, false} { - t.Run(fmt.Sprintf("refs-declaration-%v", includeDeclaration), func(t *testing.T) { - var itemStrings []string - for i, s := range itemList { - // We don't want the first result if we aren't including the declaration. - if i == 0 && !includeDeclaration { - continue - } - itemStrings = append(itemStrings, fmt.Sprint(s)) - } - sort.Strings(itemStrings) - var expect string - for _, s := range itemStrings { - expect += s + "\n" - } - expect = r.Normalize(expect) - - uri := spn.URI() - filename := uri.Filename() - target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column()) - args := []string{"references"} - if includeDeclaration { - args = append(args, "-d") - } - args = append(args, target) - got, stderr := r.NormalizeGoplsCmd(t, args...) - if stderr != "" { - t.Errorf("references failed for %s: %s", target, stderr) - } else if expect != got { - t.Errorf("references failed for %s expected:\n%s\ngot:\n%s", target, expect, got) - } - }) - } -} diff --git a/internal/lsp/cmd/test/rename.go b/internal/lsp/cmd/test/rename.go deleted file mode 100644 index 0fe2d1e18..000000000 --- a/internal/lsp/cmd/test/rename.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "testing" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) Rename(t *testing.T, spn span.Span, newText string) { - filename := spn.URI().Filename() - goldenTag := newText + "-rename" - loc := fmt.Sprintf("%v", spn) - got, err := r.NormalizeGoplsCmd(t, "rename", loc, newText) - got += err - expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) { - return []byte(got), nil - })) - if expect != got { - t.Errorf("rename failed with %v %v\nexpected:\n%s\ngot:\n%s", loc, newText, expect, got) - } - // now check we can build a valid unified diff - unified, _ := r.NormalizeGoplsCmd(t, "rename", "-d", loc, newText) - checkUnified(t, filename, expect, unified) -} diff --git a/internal/lsp/cmd/test/semanticdriver.go b/internal/lsp/cmd/test/semanticdriver.go deleted file mode 100644 index 80dc61e3d..000000000 --- a/internal/lsp/cmd/test/semanticdriver.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "strings" - "testing" - - "golang.org/x/tools/internal/span" -) - -func (r *runner) SemanticTokens(t *testing.T, spn span.Span) { - uri := spn.URI() - filename := uri.Filename() - got, stderr := r.NormalizeGoplsCmd(t, "semtok", filename) - if stderr != "" { - t.Fatalf("%s: %q", filename, stderr) - } - want := string(r.data.Golden("semantic", filename, func() ([]byte, error) { - return []byte(got), nil - })) - if want != got { - lwant := strings.Split(want, "\n") - lgot := strings.Split(got, "\n") - t.Errorf("want(%d-%d) != got(%d-%d) for %s", len(want), len(lwant), len(got), len(lgot), r.Normalize(filename)) - for i := 0; i < len(lwant) && i < len(lgot); i++ { - if lwant[i] != lgot[i] { - t.Errorf("line %d:\nwant%q\ngot %q\n", i, lwant[i], lgot[i]) - } - } - } -} diff --git a/internal/lsp/cmd/test/signature.go b/internal/lsp/cmd/test/signature.go deleted file mode 100644 index f6bdaebf3..000000000 --- a/internal/lsp/cmd/test/signature.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "testing" - - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -func (r *runner) SignatureHelp(t *testing.T, spn span.Span, want *protocol.SignatureHelp) { - uri := spn.URI() - filename := uri.Filename() - target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column()) - got, _ := r.NormalizeGoplsCmd(t, "signature", target) - if want == nil { - if got != "" { - t.Fatalf("want nil, but got %s", got) - } - return - } - goldenTag := want.Signatures[0].Label + "-signature" - expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) { - return []byte(got), nil - })) - if tests.NormalizeAny(expect) != tests.NormalizeAny(got) { - t.Errorf("signature failed for %s expected:\n%q\ngot:\n%q'", filename, expect, got) - } -} diff --git a/internal/lsp/cmd/test/suggested_fix.go b/internal/lsp/cmd/test/suggested_fix.go deleted file mode 100644 index c819e0517..000000000 --- a/internal/lsp/cmd/test/suggested_fix.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "testing" - - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -func (r *runner) SuggestedFix(t *testing.T, spn span.Span, actionKinds []string, expectedActions int) { - uri := spn.URI() - filename := uri.Filename() - args := []string{"fix", "-a", fmt.Sprintf("%s", spn)} - for _, kind := range actionKinds { - if kind == "refactor.rewrite" { - t.Skip("refactor.rewrite is not yet supported on the command line") - } - } - args = append(args, actionKinds...) - got, stderr := r.NormalizeGoplsCmd(t, args...) - if stderr == "ExecuteCommand is not yet supported on the command line" { - return // don't skip to keep the summary counts correct - } - want := string(r.data.Golden("suggestedfix_"+tests.SpanName(spn), filename, func() ([]byte, error) { - return []byte(got), nil - })) - if want != got { - t.Errorf("suggested fixes failed for %s:\n%s", filename, tests.Diff(t, want, got)) - } -} diff --git a/internal/lsp/cmd/test/symbols.go b/internal/lsp/cmd/test/symbols.go deleted file mode 100644 index 055be0308..000000000 --- a/internal/lsp/cmd/test/symbols.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "testing" - - "golang.org/x/tools/internal/lsp/protocol" - "golang.org/x/tools/internal/span" -) - -func (r *runner) Symbols(t *testing.T, uri span.URI, expectedSymbols []protocol.DocumentSymbol) { - filename := uri.Filename() - got, _ := r.NormalizeGoplsCmd(t, "symbols", filename) - expect := string(r.data.Golden("symbols", filename, func() ([]byte, error) { - return []byte(got), nil - })) - if expect != got { - t.Errorf("symbols failed for %s expected:\n%s\ngot:\n%s", filename, expect, got) - } -} diff --git a/internal/lsp/cmd/test/workspace_symbol.go b/internal/lsp/cmd/test/workspace_symbol.go deleted file mode 100644 index ce965f03a..000000000 --- a/internal/lsp/cmd/test/workspace_symbol.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmdtest - -import ( - "fmt" - "path/filepath" - "sort" - "strings" - "testing" - - "golang.org/x/tools/internal/lsp/source" - "golang.org/x/tools/internal/lsp/tests" - "golang.org/x/tools/internal/span" -) - -func (r *runner) WorkspaceSymbols(t *testing.T, uri span.URI, query string, typ tests.WorkspaceSymbolsTestType) { - var matcher string - switch typ { - case tests.WorkspaceSymbolsFuzzy: - matcher = "fuzzy" - case tests.WorkspaceSymbolsCaseSensitive: - matcher = "caseSensitive" - case tests.WorkspaceSymbolsDefault: - matcher = "caseInsensitive" - } - r.runWorkspaceSymbols(t, uri, matcher, query) -} - -func (r *runner) runWorkspaceSymbols(t *testing.T, uri span.URI, matcher, query string) { - t.Helper() - - out, _ := r.runGoplsCmd(t, "workspace_symbol", "-matcher", matcher, query) - var filtered []string - dir := filepath.Dir(uri.Filename()) - for _, line := range strings.Split(out, "\n") { - if source.InDir(dir, line) { - filtered = append(filtered, filepath.ToSlash(line)) - } - } - sort.Strings(filtered) - got := r.Normalize(strings.Join(filtered, "\n") + "\n") - - expect := string(r.data.Golden(fmt.Sprintf("workspace_symbol-%s-%s", strings.ToLower(string(matcher)), query), uri.Filename(), func() ([]byte, error) { - return []byte(got), nil - })) - - if expect != got { - t.Errorf("workspace_symbol failed for %s:\n%s", query, tests.Diff(t, expect, got)) - } -} |