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
We currently have a testscript set up to run our executable using cmd/exec; before running the script proper, our internal code for integration testing ensures to build the executable using -cover, if testing.CoverMode() != "".
We are doing this to ensure to mimick as much as possible a real execution scenario and avoid any problems related to the executable running Setenv/Chdir -- or in any way working with a "dirty" state.
At the time being, we've set up a different directory which is used as the GOCOVERDIR when running the subprocesses. That way, we can then use go tool covdata as outlined in the build-cover blogpost.
// SetupTestscriptsCoverage sets up the given testscripts environment for coverage.// It will mostly override `GOCOVERDIR` with the target cover directoryfuncSetupTestscriptsCoverage(p*testscript.Params, coverdirstring) error {
// [elided: create coverdir if it doesn't exist, clean the arg]// Backup the original setup functionorigSetup:=p.Setupp.Setup=func(env*testscript.Env) error {
iforigSetup!=nil {
// Call previous setup firstorigSetup(env)
}
// Override `GOCOVEDIR` directory for sub-executionenv.Setenv("GOCOVERDIR", coverdir)
returnnil
}
returnnil
}
However, I was trying to figure out if it is in any way possible to simplify this workflow and include the coverage data from the sub-binary directly in the cover profile generated by go test (the one specified in go test -coverprofile).
Inspecting through cmd/go/internal/test, this doesn't seem to be a feature supported "directly": mergeCoverProfile, which performs the merging into the eventual coverage profile, is only called for what seem to be files explicitly created by go test. So, what I'm trying to ask is whether there is any known or suggested workaround to make this work; or if the recommended way forward (provided we still want to build the executable as a separate binary) is to keep two different coverage reports.
Thanks!
The text was updated successfully, but these errors were encountered:
We currently have a
testscript
set up to run our executable using cmd/exec; before running the script proper, our internal code for integration testing ensures to build the executable using-cover
, iftesting.CoverMode() != ""
.We are doing this to ensure to mimick as much as possible a real execution scenario and avoid any problems related to the executable running
Setenv
/Chdir
-- or in any way working with a "dirty" state.At the time being, we've set up a different directory which is used as the
GOCOVERDIR
when running the subprocesses. That way, we can then usego tool covdata
as outlined in the build-cover blogpost.However, I was trying to figure out if it is in any way possible to simplify this workflow and include the coverage data from the sub-binary directly in the cover profile generated by
go test
(the one specified ingo test -coverprofile
).Inspecting through
cmd/go/internal/test
, this doesn't seem to be a feature supported "directly":mergeCoverProfile
, which performs the merging into the eventual coverage profile, is only called for what seem to be files explicitly created bygo test
. So, what I'm trying to ask is whether there is any known or suggested workaround to make this work; or if the recommended way forward (provided we still want to build the executable as a separate binary) is to keep two different coverage reports.Thanks!
The text was updated successfully, but these errors were encountered: