Skip to content

Commit

Permalink
Share VMTEST_GOCOVERDIR with VM instead of GOCOVERDIR
Browse files Browse the repository at this point in the history
When running VM tests with `GOCOVERDIR=$x go test -cover`, Go overrides
the GOCOVERDIR for the test process, but does not share the coverage
data in any way.

Upstream issue is golang/go#60182

Signed-off-by: Chris Koch <chrisko@google.com>
  • Loading branch information
hugelgupf committed Jan 27, 2024
1 parent af94139 commit 2c3f300
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"github.com/hugelgupf/vmtest/testtmp"
)

// ShareGOCOVERDIR shares GOCOVERDIR with the guest if it's available in the
// ShareGOCOVERDIR shares VMTEST_GOCOVERDIR with the guest if it's available in the
// environment.
//
// Call guest.GOCOVERDIR to set up the directory in the guest.
func ShareGOCOVERDIR() Opt {
return func(t testing.TB, v *VMOptions) error {
goCov := os.Getenv("GOCOVERDIR")
goCov := os.Getenv("VMTEST_GOCOVERDIR")
if goCov == "" {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tests/gocover/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func TestStartVM(t *testing.T) {
t.Setenv("VMTEST_GO_PROFILE", goProfile)
}

goCov := os.Getenv("GOCOVERDIR")
goCov := os.Getenv("VMTEST_GOCOVERDIR")
if goCov == "" {
goCov = testtmp.TempDir(t)
t.Setenv("GOCOVERDIR", goCov)
t.Setenv("VMTEST_GOCOVERDIR", goCov)
}

t.Run("test", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions tests/shellgocoverdir/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestStartVM(t *testing.T) {
"donothing\nsync\necho \"TESTS PASSED MARKER\"\nshutdown",
} {
t.Run(script, func(t *testing.T) {
goCov := os.Getenv("GOCOVERDIR")
goCov := os.Getenv("VMTEST_GOCOVERDIR")
if goCov == "" {
goCov = testtmp.TempDir(t)
t.Setenv("GOCOVERDIR", goCov)
t.Setenv("VMTEST_GOCOVERDIR", goCov)
}

vmtest.RunCmdsInVM(t, script,
Expand Down

0 comments on commit 2c3f300

Please sign in to comment.