mirror of
https://github.com/golang/go
synced 2024-11-19 00:04:40 -07:00
go/packages: make TestOverlayDeps deterministic
It had a 50/50 chance of checking the test package for the import instead of the non-test package. Find the right package before checking it now. Fixes golang/go#36908 Change-Id: I3a044d83f55093961cf5221b315a54028fdd540d Reviewed-on: https://go-review.googlesource.com/c/tools/+/217084 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
449c356b79
commit
9090804516
@ -983,10 +983,19 @@ func testOverlayDeps(t *testing.T, exporter packagestest.Exporter) {
|
|||||||
packages.NeedImports |
|
packages.NeedImports |
|
||||||
packages.NeedDeps |
|
packages.NeedDeps |
|
||||||
packages.NeedTypesSizes
|
packages.NeedTypesSizes
|
||||||
initial, err := packages.Load(exported.Config, fmt.Sprintf("file=%s", exported.File("golang.org/fake", "c/c.go")))
|
pkgs, err := packages.Load(exported.Config, fmt.Sprintf("file=%s", exported.File("golang.org/fake", "c/c.go")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find package golang.org/fake/c
|
||||||
|
sort.Slice(pkgs, func(i, j int) bool { return pkgs[i].ID < pkgs[j].ID })
|
||||||
|
pkgc := pkgs[0]
|
||||||
|
if pkgc.ID != "golang.org/fake/c" {
|
||||||
|
t.Errorf("expected first package in sorted list to be \"golang.org/fake/c\", got %v", pkgc.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure golang.org/fake/c imports net/http, as per the overlay.
|
||||||
contains := func(imports map[string]*packages.Package, wantImport string) bool {
|
contains := func(imports map[string]*packages.Package, wantImport string) bool {
|
||||||
for imp := range imports {
|
for imp := range imports {
|
||||||
if imp == wantImport {
|
if imp == wantImport {
|
||||||
@ -995,11 +1004,11 @@ func testOverlayDeps(t *testing.T, exporter packagestest.Exporter) {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, pkg := range initial {
|
if !contains(pkgc.Imports, "net/http") {
|
||||||
if !contains(pkg.Imports, "net/http") {
|
t.Errorf("expected import of %s in package %s, got the following imports: %v",
|
||||||
t.Errorf("expected %s import in %s", "net/http", pkg.ID)
|
"net/http", pkgc.ID, pkgc.Imports)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewPackagesInOverlay(t *testing.T) { packagestest.TestAll(t, testNewPackagesInOverlay) }
|
func TestNewPackagesInOverlay(t *testing.T) { packagestest.TestAll(t, testNewPackagesInOverlay) }
|
||||||
|
Loading…
Reference in New Issue
Block a user