Skip to content

Commit 941b3b7

Browse files
myitcvianlancetaylor
authored andcommitted
cmd/go: fix go list -test where C is a dependency.
Currently go list -test runtime/cgo fails with an index out of range error. This appears to be because the updating of import paths that happens as part of -test doesn't take into account the fact that the Internal.Imports of a package do not contain "C", whereas the public Imports do. Therefore we skip the public Import of "C" if it exists and continue. Change-Id: I5cdc8968890fa7e5da3e375718606037d3282754 Reviewed-on: https://go-review.googlesource.com/111175 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent cf4e559 commit 941b3b7

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/cmd/go/go_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,9 @@ func TestGoListTest(t *testing.T) {
19461946
tg.grepStdout(`^cmd/doc\.test$`, "missing cmd/doc test")
19471947
tg.grepStdoutNot(`^cmd/dist\.test$`, "unexpected cmd/dist test")
19481948
tg.grepStdoutNot(`^testing`, "unexpected testing")
1949+
1950+
tg.run("list", "-test", "runtime/cgo")
1951+
tg.grepStdout(`^runtime/cgo$`, "missing runtime/cgo")
19491952
}
19501953

19511954
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.

src/cmd/go/internal/list/list.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,14 @@ func runList(cmd *base.Command, args []string) {
318318
}
319319
// Update import path lists to use new strings.
320320
for _, p := range all {
321+
j := 0
321322
for i := range p.Imports {
322-
p.Imports[i] = p.Internal.Imports[i].ImportPath
323+
// Internal skips "C"
324+
if p.Imports[i] == "C" {
325+
continue
326+
}
327+
p.Imports[i] = p.Internal.Imports[j].ImportPath
328+
j++
323329
}
324330
}
325331
// Recompute deps lists using new strings, from the leaves up.

0 commit comments

Comments
 (0)