1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

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 (
"go/token"
"path/filepath"
"reflect"
"sort"
"strings"
@ -29,6 +30,7 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
exported := packagestest.Export(t, exporter, modules)
defer exported.Cleanup()
dirs := make(map[string]bool)
wants := make(map[string][]protocol.Diagnostic)
for _, module := range modules {
for fragment := range module.Files {
@ -37,6 +39,7 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
}
filename := exporter.Filename(exported, module.Name, fragment)
wants[filename] = []protocol.Diagnostic{}
dirs[filepath.Dir(filename)] = true
}
}
err := exported.Expect(map[string]interface{}{
@ -68,10 +71,20 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
if err != nil {
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.config = exported.Config
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))
if err != nil {
t.Fatal(err)
@ -80,8 +93,10 @@ func testDiagnostics(t *testing.T, exporter packagestest.Exporter) {
sort.Slice(got, func(i int, j int) bool {
return got[i].Range.Start.Line < got[j].Range.Start.Line
})
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
func stuff() {

View File

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