go/packages, internal/lsp: modify tests to expose overlays bug

https://golang.org/issue/33157 explains the issues with overlays. The
gopls tests caught this bug, but the go/packages tests didn't, so modify
the go/packages tests correspondingly.

Change-Id: I8ea8e06e145aa2420655cbe4884e60f36acfad7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-07-16 01:58:38 -04:00
parent 7caf8110c9
commit c81b74871b
5 changed files with 15 additions and 5 deletions

View File

@ -930,6 +930,12 @@ func testNewPackagesInOverlay(t *testing.T, exporter packagestest.Exporter) {
"b/b.go": `package b; import "golang.org/fake/c"; const B = "b" + c.C`,
"c/c.go": `package c; const C = "c"`,
"d/d.go": `package d; const D = "d"`,
// TODO: Remove these temporary files when golang.org/issue/33157 is resolved.
filepath.Join("e/e_temp.go"): ``,
filepath.Join("f/f_temp.go"): ``,
filepath.Join("g/g_temp.go"): ``,
filepath.Join("h/h_temp.go"): ``,
}}})
defer exported.Cleanup()
@ -986,7 +992,11 @@ func testNewPackagesInOverlay(t *testing.T, exporter packagestest.Exporter) {
} {
exported.Config.Overlay = test.overlay
exported.Config.Mode = packages.LoadAllSyntax
initial, err := packages.Load(exported.Config, "golang.org/fake/e")
exported.Config.Logf = t.Logf
// With an overlay, we don't know the expected import path,
// so load with the absolute path of the directory.
initial, err := packages.Load(exported.Config, filepath.Join(dir, "e"))
if err != nil {
t.Error(err)
continue

View File

@ -1 +1 @@
an empty file so that the directory exists
an empty file so that this directory exists

View File

@ -0,0 +1 @@
TODO: Remove this file when golang.org/issue/33157 is resolved.

View File

@ -1,3 +0,0 @@
package nodisk
//TODO: remove this file when https://github.com/golang/go/issues/33125 is fixed.

View File

@ -195,10 +195,12 @@ func Load(t testing.TB, exporter packagestest.Exporter, dir string) *Data {
filename := data.Exported.File(testModule, fragment)
data.fragments[filename] = fragment
}
data.Exported.Config.Logf = t.Logf
// Merge the exported.Config with the view.Config.
data.Config = *data.Exported.Config
data.Config.Fset = token.NewFileSet()
data.Config.Logf = t.Logf
data.Config.Context = Context(nil)
data.Config.ParseFile = func(fset *token.FileSet, filename string, src []byte) (*ast.File, error) {
panic("ParseFile should not be called")