diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index a736d1e2a5..83852302ae 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -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) }