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:
parent
96e9e165b7
commit
ebdbadb46e
|
@ -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,10 +71,20 @@ 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 {
|
||||||
|
for _, filename := range pkg.GoFiles {
|
||||||
diagnostics, err := v.diagnostics(filenameToURI(filename))
|
diagnostics, err := v.diagnostics(filenameToURI(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -80,8 +93,10 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
|
||||||
sort.Slice(got, func(i int, j int) bool {
|
sort.Slice(got, func(i int, j int) bool {
|
||||||
return got[i].Range.Start.Line < got[j].Range.Start.Line
|
return got[i].Range.Start.Line < got[j].Range.Start.Line
|
||||||
})
|
})
|
||||||
|
want := wants[filename]
|
||||||
if equal := reflect.DeepEqual(want, got); !equal {
|
if equal := reflect.DeepEqual(want, got); !equal {
|
||||||
t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filename, want, got)
|
t.Errorf("diagnostics failed for %s: (expected: %v), (got: %v)", filename, want, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build go1.11
|
||||||
|
|
||||||
package bad
|
package bad
|
||||||
|
|
||||||
func stuff() {
|
func stuff() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build go1.11
|
||||||
|
|
||||||
package bad
|
package bad
|
||||||
|
|
||||||
func random2(y int) int {
|
func random2(y int) int {
|
||||||
|
|
Loading…
Reference in New Issue