mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
go/packages: fix flaky TestJSON and reenable it on Go 1.10
The fallback driver wasn't returning the roots in a deterministic order because it was using sticking them in a map and then iterating over that map to get each element. Put them into a slice instead (and make a few small associated changes) to preserve behavior. Fixes golang/go#28040 Fixes golang/go#28609 Change-Id: Ib8f8c88d65b7a48b2b04ca91e2d3c316d5bb5803 Reviewed-on: https://go-review.googlesource.com/c/148880 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
6d71ab8aad
commit
680468b755
@ -46,7 +46,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
|
||||
var response driverResponse
|
||||
allPkgs := make(map[string]bool)
|
||||
addPackage := func(p *jsonPackage) {
|
||||
addPackage := func(p *jsonPackage, isRoot bool) {
|
||||
id := p.ImportPath
|
||||
|
||||
if allPkgs[id] {
|
||||
@ -54,7 +54,6 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
}
|
||||
allPkgs[id] = true
|
||||
|
||||
isRoot := original[id] != nil
|
||||
pkgpath := id
|
||||
|
||||
if pkgpath == "unsafe" {
|
||||
@ -221,7 +220,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
}
|
||||
|
||||
for _, pkg := range original {
|
||||
addPackage(pkg)
|
||||
addPackage(pkg, true)
|
||||
}
|
||||
if cfg.Mode < LoadImports || len(deps) == 0 {
|
||||
return &response, nil
|
||||
@ -239,7 +238,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
return nil, fmt.Errorf("JSON decoding failed: %v", err)
|
||||
}
|
||||
|
||||
addPackage(p)
|
||||
addPackage(p, false)
|
||||
}
|
||||
|
||||
for _, v := range needsTestVariant {
|
||||
@ -356,14 +355,13 @@ func vendorlessPath(ipath string) string {
|
||||
}
|
||||
|
||||
// getDeps runs an initial go list to determine all the dependency packages.
|
||||
func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage, deps []string, err error) {
|
||||
func getDeps(cfg *Config, words ...string) (initial []*jsonPackage, deps []string, err error) {
|
||||
buf, err := invokeGo(cfg, golistArgsFallback(cfg, words)...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
depsSet := make(map[string]bool)
|
||||
originalSet = make(map[string]*jsonPackage)
|
||||
var testImports []string
|
||||
|
||||
// Extract deps from the JSON.
|
||||
@ -373,7 +371,7 @@ func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage,
|
||||
return nil, nil, fmt.Errorf("JSON decoding failed: %v", err)
|
||||
}
|
||||
|
||||
originalSet[p.ImportPath] = p
|
||||
initial = append(initial, p)
|
||||
for _, dep := range p.Deps {
|
||||
depsSet[dep] = true
|
||||
}
|
||||
@ -407,8 +405,8 @@ func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage,
|
||||
}
|
||||
}
|
||||
|
||||
for orig := range originalSet {
|
||||
delete(depsSet, orig)
|
||||
for _, orig := range initial {
|
||||
delete(depsSet, orig.ImportPath)
|
||||
}
|
||||
|
||||
deps = make([]string, 0, len(depsSet))
|
||||
@ -416,7 +414,7 @@ func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage,
|
||||
deps = append(deps, dep)
|
||||
}
|
||||
sort.Strings(deps) // ensure output is deterministic
|
||||
return originalSet, deps, nil
|
||||
return initial, deps, nil
|
||||
}
|
||||
|
||||
func golistArgsFallback(cfg *Config, words []string) []string {
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
constantpkg "go/constant"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
@ -1222,9 +1221,6 @@ func TestName_ModulesDedup(t *testing.T) {
|
||||
|
||||
func TestJSON(t *testing.T) { packagestest.TestAll(t, testJSON) }
|
||||
func testJSON(t *testing.T, exporter packagestest.Exporter) {
|
||||
if !haveReleaseTag("go1.11") {
|
||||
t.Skip("skipping; flaky before Go 1.11; https://golang.org/issue/28609")
|
||||
}
|
||||
//TODO: add in some errors
|
||||
exported := packagestest.Export(t, exporter, []packagestest.Module{{
|
||||
Name: "golang.org/fake",
|
||||
@ -1637,12 +1633,3 @@ func constant(p *packages.Package, name string) *types.Const {
|
||||
}
|
||||
return c.(*types.Const)
|
||||
}
|
||||
|
||||
func haveReleaseTag(tag string) bool {
|
||||
for _, v := range build.Default.ReleaseTags {
|
||||
if tag == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user