internal/lsp: fix LSP tests to be compatible with Go 1.10

Change golang/go#145697 added tests for diagnostics in the LSP implementation,
but these test did not work with Go 1.10. This change skips tests that
require Go 1.11.

Change-Id: I52bd2df484b5786395edac2c1c8592c83ac1aaa4
Reviewed-on: https://go-review.googlesource.com/c/147439
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2018-11-05 12:47:03 -05:00
parent 96e9e165b7
commit ebdbadb46e
3 changed files with 30 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package lsp
import ( import (
"go/token" "go/token"
"path/filepath"
"reflect" "reflect"
"sort" "sort"
"strings" "strings"
@ -29,6 +30,7 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
exported := packagestest.Export(t, exporter, modules) exported := packagestest.Export(t, exporter, modules)
defer exported.Cleanup() defer exported.Cleanup()
dirs := make(map[string]bool)
wants := make(map[string][]protocol.Diagnostic) wants := make(map[string][]protocol.Diagnostic)
for _, module := range modules { for _, module := range modules {
for fragment := range module.Files { for fragment := range module.Files {
@ -37,6 +39,7 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
} }
filename := exporter.Filename(exported, module.Name, fragment) filename := exporter.Filename(exported, module.Name, fragment)
wants[filename] = []protocol.Diagnostic{} wants[filename] = []protocol.Diagnostic{}
dirs[filepath.Dir(filename)] = true
} }
} }
err := exported.Expect(map[string]interface{}{ err := exported.Expect(map[string]interface{}{
@ -68,20 +71,32 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
var dirList []string
for dir := range dirs {
dirList = append(dirList, dir)
}
exported.Config.Mode = packages.LoadFiles
pkgs, err := packages.Load(exported.Config, dirList...)
if err != nil {
t.Fatal(err)
}
v := newView() v := newView()
v.config = exported.Config v.config = exported.Config
v.config.Mode = packages.LoadSyntax v.config.Mode = packages.LoadSyntax
for filename, want := range wants { for _, pkg := range pkgs {
diagnostics, err := v.diagnostics(filenameToURI(filename)) for _, filename := range pkg.GoFiles {
if err != nil { diagnostics, err := v.diagnostics(filenameToURI(filename))
t.Fatal(err) if err != nil {
} t.Fatal(err)
got := diagnostics[filename] }
sort.Slice(got, func(i int, j int) bool { got := diagnostics[filename]
return got[i].Range.Start.Line < got[j].Range.Start.Line sort.Slice(got, func(i int, j int) bool {
}) return got[i].Range.Start.Line < got[j].Range.Start.Line
if equal := reflect.DeepEqual(want, got); !equal { })
t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filename, want, got) want := wants[filename]
if equal := reflect.DeepEqual(want, got); !equal {
t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filename, want, got)
}
} }
} }
} }

View File

@ -1,3 +1,5 @@
// +build go1.11
package bad package bad
func stuff() { func stuff() {

View File

@ -1,3 +1,5 @@
// +build go1.11
package bad package bad
func random2(y int) int { func random2(y int) int {