Skip to content

Commit

Permalink
Support --combined_report=lcov
Browse files Browse the repository at this point in the history
  • Loading branch information
tingilee committed Nov 8, 2022
1 parent 497f92c commit e68899e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions go/private/rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def _go_library_impl(ctx):
library,
source,
archive,
coverage_common.instrumented_files_info(
ctx,
source_attributes = ["srcs"],
dependency_attributes = ["deps", "embed"],
),
DefaultInfo(
files = depset([archive.data.file]),
),
Expand Down
12 changes: 8 additions & 4 deletions tests/core/coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,19 @@ func TestPanic(t *testing.T) {

func TestCoverage(t *testing.T) {
t.Run("without-race", func(t *testing.T) {
testCoverage(t, "set")
testCoverage(t, "set", "bazel-testlogs/a_test/coverage.dat")
})

t.Run("with-race", func(t *testing.T) {
testCoverage(t, "atomic", "--@io_bazel_rules_go//go/config:race")
testCoverage(t, "atomic", "bazel-testlogs/a_test/coverage.dat", "--@io_bazel_rules_go//go/config:race")
})

t.Run("with-combined-lcov", func(t *testing.T) {
testCoverage(t, "set", "bazel-out/_coverage/_coverage_report.dat", "--combined_report=lcov")
})
}

func testCoverage(t *testing.T, expectedCoverMode string, extraArgs ...string) {
func testCoverage(t *testing.T, expectedCoverMode string, expectedCoveragePath string, extraArgs ...string) {
args := append([]string{"coverage"}, append(
extraArgs,
"--instrumentation_filter=-//:b",
Expand All @@ -193,7 +197,7 @@ func testCoverage(t *testing.T, expectedCoverMode string, extraArgs ...string) {
t.Fatal(err)
}

coveragePath := filepath.FromSlash("bazel-testlogs/a_test/coverage.dat")
coveragePath := filepath.FromSlash(expectedCoveragePath)
coverageData, err := ioutil.ReadFile(coveragePath)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit e68899e

Please sign in to comment.