You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose two changes to gotooltest to better support Go tests which use cgo:
A conditional, [cgo], which tells you whether cgo is enabled. Practically equivalent to the shell [[ $(go env CGO_ENABLED) == "1" ]]. To be used like [!cgo] skip 'this test requires cgo to work'.
Passing the CGO_ENABLED env variable through to test scripts, like GOOS or GOARCH. I can use GOARCH=386 go test to run my Go test scripts with that architecture, but note that cross-compilation in Go disables cgo by default. GOARCH=386 CGO_ENABLED=1 go test doesn't make a difference, as the latter env var isn't forwarded.
I can work around item 1 by implementing the conditional myself, and I have, but might as well have it built-in :)
I can work around item 2 by manually forwarding the env var via the Setup func, but that feels hacky. I can't simply env CGO_ENABLED=1 in the test, because that will go on to assume that cgo can work. Which is not always the case; for instance, GOARCH=386 go test fails on CI because the regular gcc is installed rather than gcc-multilib, and the former can't cross-compile from amd64 to 386 as it fails to find some header files.
Happy to submit the changes, I just thought I'd propose them first. cc @rogpeppe@myitcv
The text was updated successfully, but these errors were encountered:
I propose two changes to gotooltest to better support Go tests which use cgo:
A conditional,
[cgo]
, which tells you whether cgo is enabled. Practically equivalent to the shell[[ $(go env CGO_ENABLED) == "1" ]]
. To be used like[!cgo] skip 'this test requires cgo to work'
.Passing the
CGO_ENABLED
env variable through to test scripts, likeGOOS
orGOARCH
. I can useGOARCH=386 go test
to run my Go test scripts with that architecture, but note that cross-compilation in Go disables cgo by default.GOARCH=386 CGO_ENABLED=1 go test
doesn't make a difference, as the latter env var isn't forwarded.I can work around item 1 by implementing the conditional myself, and I have, but might as well have it built-in :)
I can work around item 2 by manually forwarding the env var via the Setup func, but that feels hacky. I can't simply
env CGO_ENABLED=1
in the test, because that will go on to assume that cgo can work. Which is not always the case; for instance,GOARCH=386 go test
fails on CI because the regulargcc
is installed rather thangcc-multilib
, and the former can't cross-compile from amd64 to 386 as it fails to find some header files.Happy to submit the changes, I just thought I'd propose them first. cc @rogpeppe @myitcv
The text was updated successfully, but these errors were encountered: