1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00

go/packages: add a test for ad-hoc packages in overlays

Updates golang/go#33482

Change-Id: Ib24a0b955694455ddf1fc31011d57a7d797519ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-08-06 17:37:06 -04:00
parent 9fb8e5c879
commit 88ddfcebc7

View File

@ -1010,6 +1010,47 @@ func testNewPackagesInOverlay(t *testing.T, exporter packagestest.Exporter) {
}
}
func TestAdHocOverlays(t *testing.T) {
// Enable this test when https://golang.org/issue/33482 is resolved.
t.Skip()
// This test doesn't use packagestest because we are testing ad-hoc packages,
// which are outside of $GOPATH and outside of a module.
tmp, err := ioutil.TempDir("", "a")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmp)
filename := filepath.Join(tmp, "a.go")
content := []byte(`package a
const A = 1
`)
config := &packages.Config{
Dir: tmp,
Mode: packages.LoadAllSyntax,
Overlay: map[string][]byte{
filename: content,
},
}
initial, err := packages.Load(config, fmt.Sprintf("file=%s", filename))
if err != nil {
t.Error(err)
}
// Check value of a.A.
a := initial[0]
aA := constant(a, "A")
if aA == nil {
t.Errorf("a.A: got nil")
return
}
got := aA.Val().String()
if want := "1"; got != want {
t.Errorf("a.A: got %s, want %s", got, want)
}
}
func TestLoadAllSyntaxImportErrors(t *testing.T) {
packagestest.TestAll(t, testLoadAllSyntaxImportErrors)
}