-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save test coverage data to bazel-testlogs. #1387
Save test coverage data to bazel-testlogs. #1387
Conversation
Do you know of any coverage tools which work with this dat file or ones that this was tested with? |
This lets `bazel coverage //some:test` produce a Go coverage data file in `bazel-testlogs/some/test/coverage.dat`. This file can be processed by normal Go coverage tooling to produce a coverage report. The change to `go/private/rules/test.bzl` needs some explanation -- Bazel only looks for coverage data if the test target has an `InstrumentedFilesProvider`, but this provider can currently only be created using "legacy" provider syntax. Old and new provider syntaxes can be combined by putting new-style providers in a `providers` field of the old-style struct. If the provider is found and at least one source file is present, Bazel will set the `COVERAGE_OUTPUT_FILE` environment variable during tests and will save that file to the build events + test outputs.
911c7cc
to
a624fe1
Compare
This is the plain Go coverage data (same as generated by
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I copied the comment from your commit message to test.bzl.
The I'm guessing we'll need to break this when Bazel has full coverage support. Blaze (Google internal version) expects coverage data in the lcov format, so we may need to write that instead of Go's format. For now though, this is welcome. Thanks for submitting this. |
I've been talking with the Bazel devs about coverage as part of the Envoy project, and one of the sticking points is whether coverage should be Blaze-style (unified for all languages), or toolchain-specific. Being able to gather code coverage in the native format from Go will be useful data for that decision, and I'm hopeful we can expand this approach to other Skylark rulesets. |
This lets `bazel coverage //some:test` produce a Go coverage data file in `bazel-testlogs/some/test/coverage.dat`. This file can be processed by normal Go coverage tooling to produce a coverage report. The change to `go/private/rules/test.bzl` needs some explanation -- Bazel only looks for coverage data if the test target has an `InstrumentedFilesProvider`, but this provider can currently only be created using "legacy" provider syntax. Old and new provider syntaxes can be combined by putting new-style providers in a `providers` field of the old-style struct. If the provider is found and at least one source file is present, Bazel will set the `COVERAGE_OUTPUT_FILE` environment variable during tests and will save that file to the build events + test outputs.
This lets
bazel coverage //some:test
produce a Go coverage data filein
bazel-testlogs/some/test/coverage.dat
. This file can be processedby normal Go coverage tooling to produce a coverage report.
The change to
go/private/rules/test.bzl
needs some explanation --Bazel only looks for coverage data if the test target has an
InstrumentedFilesProvider
, but this provider can currently only becreated using "legacy" provider syntax. Old and new provider syntaxes
can be combined by putting new-style providers in a
providers
fieldof the old-style struct.
If the provider is found and at least one source file is present, Bazel
will set the
COVERAGE_OUTPUT_FILE
environment variable during testsand will save that file to the build events + test outputs.
Related to #1150 and #140