go binary cover instrumentation for test binary

183 views
Skip to first unread message

Radu Berinde

unread,
Aug 11, 2023, 12:56:04 PM8/11/23
to golang-nuts
Go 1.20 adds binary instrumentation for code coverage (https://go.dev/testing/coverage/#running).

We have a kind of "meta test" that is passed the path of a test binary for another package and invokes it. I want to instrument this binary for coverage (where I can use GOCOVERDIR to dump the coverage data in a directory). Currently we build the binary using `go test -c` but if I pass `-cover` to `go test` it will build in the test-specific logic for coverage, not the one for binaries.

I realize this is an odd question, and perhaps the correct thing to do is to create a regular command that runs those "inner" tests. But I'm still curious if there's a lower-level way of building the test binary with the right kind of instrumentation.

Thanks,
-Radu
Reply all
Reply to author
Forward
0 new messages