diff --git a/internal/lsp/diagnostics_test.go b/internal/lsp/diagnostics_test.go index 9f585844..07478bcf 100644 --- a/internal/lsp/diagnostics_test.go +++ b/internal/lsp/diagnostics_test.go @@ -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,20 +71,32 @@ 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 { - diagnostics, err := v.diagnostics(filenameToURI(filename)) - if err != nil { - t.Fatal(err) - } - got := diagnostics[filename] - 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) + for _, pkg := range pkgs { + for _, filename := range pkg.GoFiles { + diagnostics, err := v.diagnostics(filenameToURI(filename)) + if err != nil { + t.Fatal(err) + } + got := diagnostics[filename] + 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) + } } } } diff --git a/internal/lsp/testdata/diagnostics/bad/bad.go b/internal/lsp/testdata/diagnostics/bad/bad.go index abbf57e7..8500d069 100644 --- a/internal/lsp/testdata/diagnostics/bad/bad.go +++ b/internal/lsp/testdata/diagnostics/bad/bad.go @@ -1,3 +1,5 @@ +// +build go1.11 + package bad func stuff() { diff --git a/internal/lsp/testdata/diagnostics/bad/bad_util.go b/internal/lsp/testdata/diagnostics/bad/bad_util.go index 9ab8a73e..f6a0e7d9 100644 --- a/internal/lsp/testdata/diagnostics/bad/bad_util.go +++ b/internal/lsp/testdata/diagnostics/bad/bad_util.go @@ -1,3 +1,5 @@ +// +build go1.11 + package bad func random2(y int) int {