Skip to content

Commit 3757284

Browse files
committed
cmd/vet: reenable cgo test
The reason the 386 trybot was happy but 'GOARCH=386 go test cmd/vet' was not is that CgoEnabled defaults to false in a cross build; I have no idea why. Now we ask the go command for the effective value so that the test works in both cases. Also, remove stale comment. Fixes #28829 Change-Id: I1210af34da6986f47924059de5c1f08b2824ace9 Reviewed-on: https://go-review.googlesource.com/c/149958 Run-TryBot: Alan Donovan <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 478af80 commit 3757284

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/cmd/vet/vet_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func vetCmd(t *testing.T, args ...string) *exec.Cmd {
7070
return cmd
7171
}
7272

73-
// TestVet is equivalent to running this:
74-
// go build -o ./testvet
75-
// errorCheck the output of ./testvet -printfuncs='Warn:1,Warnf:1' testdata/*.go testdata/*.s
76-
// rm ./testvet
77-
//
7873
func TestVet(t *testing.T) {
7974
t.Parallel()
8075
Build(t)
@@ -106,9 +101,8 @@ func TestVet(t *testing.T) {
106101
t.Run(pkg, func(t *testing.T) {
107102
t.Parallel()
108103

109-
// Skip for now, pending investigation.
110-
if pkg == "cgo" {
111-
t.Skip("cgo test disabled -- github.com/golang/go/issues/28829")
104+
// Skip cgo test on platforms without cgo.
105+
if pkg == "cgo" && !cgoEnabled(t) {
112106
return
113107
}
114108

@@ -137,6 +131,17 @@ func TestVet(t *testing.T) {
137131
}
138132
}
139133

134+
func cgoEnabled(t *testing.T) bool {
135+
// Don't trust build.Default.CgoEnabled as it is false for
136+
// cross-builds unless CGO_ENABLED is explicitly specified.
137+
// That's fine for the builders, but causes commands like
138+
// 'GOARCH=386 go test .' to fail.
139+
// Instead, we ask the go command.
140+
cmd := exec.Command(testenv.GoToolPath(t), "list", "-f", "{{context.CgoEnabled}}")
141+
out, _ := cmd.CombinedOutput()
142+
return string(out) == "true\n"
143+
}
144+
140145
func errchk(c *exec.Cmd, files []string, t *testing.T) {
141146
output, err := c.CombinedOutput()
142147
if _, ok := err.(*exec.ExitError); !ok {

0 commit comments

Comments
 (0)