Skip to content

Commit

Permalink
Fix coverage collection with modified COVERAGE_DIR env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 9, 2024
1 parent 3c51b96 commit 00b201b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/tools/bzltestutil/lcov.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"testing/internal/testdeps"
)

// Lock in the COVERAGE_DIR during test setup in case the test uses e.g. os.Clearenv.
var coverageDir = os.Getenv("COVERAGE_DIR")

// ConvertCoverToLcov converts the go coverprofile file coverage.dat.cover to
// the expectedLcov format and stores it in coverage.dat, where it is picked up by
// Bazel.
Expand All @@ -42,8 +45,12 @@ func ConvertCoverToLcov() error {
}
defer in.Close()

if coverageDir == "" {
log.Printf("Not collecting coverage: COVERAGE_DIR is not set")
return nil
}
// All *.dat files in $COVERAGE_DIR will be merged by Bazel's lcov_merger tool.
out, err := os.CreateTemp(os.Getenv("COVERAGE_DIR"), "go_coverage.*.dat")
out, err := os.CreateTemp(coverageDir, "go_coverage.*.dat")
if err != nil {
return err
}
Expand Down

0 comments on commit 00b201b

Please sign in to comment.