mirror of
https://github.com/golang/go
synced 2024-11-18 10:14:45 -07:00
cmd/go: dedup packages in packagesAndErrors
packagesAndErrors function doesn't dedup packages. As a result, `go list io ./io` prints io package twice. Same applies to `go build` and `go test`. * dedup packages. * add a test for go list Change-Id: I54d4063979b1c9359e5416e12327cb85c4823a0f Reviewed-on: https://go-review.googlesource.com/16136 Run-TryBot: Andrew Gerrand <adg@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
d8c6bf916e
commit
76dcedc920
@ -1372,6 +1372,18 @@ func TestGoListCmdOnlyShowsCommands(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoListDedupsPackages(t *testing.T) {
|
||||||
|
tg := testgo(t)
|
||||||
|
defer tg.cleanup()
|
||||||
|
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
|
||||||
|
tg.run("list", "xtestonly", "./testdata/src/xtestonly/...")
|
||||||
|
got := strings.TrimSpace(tg.getStdout())
|
||||||
|
const want = "xtestonly"
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("got %q; want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
|
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
|
||||||
func TestUnsuccessfulGoInstallShouldMentionMissingPackage(t *testing.T) {
|
func TestUnsuccessfulGoInstallShouldMentionMissingPackage(t *testing.T) {
|
||||||
tg := testgo(t)
|
tg := testgo(t)
|
||||||
|
@ -1604,15 +1604,24 @@ func packagesAndErrors(args []string) []*Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args = importPaths(args)
|
args = importPaths(args)
|
||||||
var pkgs []*Package
|
var (
|
||||||
var stk importStack
|
pkgs []*Package
|
||||||
var set = make(map[string]bool)
|
stk importStack
|
||||||
|
seenArg = make(map[string]bool)
|
||||||
|
seenPkg = make(map[*Package]bool)
|
||||||
|
)
|
||||||
|
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if !set[arg] {
|
if seenArg[arg] {
|
||||||
pkgs = append(pkgs, loadPackage(arg, &stk))
|
continue
|
||||||
set[arg] = true
|
|
||||||
}
|
}
|
||||||
|
seenArg[arg] = true
|
||||||
|
pkg := loadPackage(arg, &stk)
|
||||||
|
if seenPkg[pkg] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seenPkg[pkg] = true
|
||||||
|
pkgs = append(pkgs, pkg)
|
||||||
}
|
}
|
||||||
computeStale(pkgs...)
|
computeStale(pkgs...)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user