Skip to content
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

Supporting Code Coverage #1150

Closed
jeb2239 opened this issue Dec 18, 2017 · 10 comments
Closed

Supporting Code Coverage #1150

jeb2239 opened this issue Dec 18, 2017 · 10 comments

Comments

@jeb2239
Copy link

jeb2239 commented Dec 18, 2017

I noticed that coverage is not supported , but there seems to be some experimental support. How can I contribute to the progression of this feature?

@ianthehat
Copy link
Contributor

All the things needed to correctly run coverage are done, the issues are how to collect the results and how to display them.
We either need to massage the results into a form that Bazel can understand, or provide an easy way to use the normal go tooling. Maybe even both.

@jeb2239
Copy link
Author

jeb2239 commented Dec 19, 2017

Is there a way to make a profile go test -coverprofile=c.out currently in bazel.

@jayconrod
Copy link
Contributor

You can pass arguments to tests on the command line with --test_arg=arg.

Note that tests run in a sandbox by default, and Bazel will clean up their output files after they run. You can disable the sandbox with --test_strategy=standalone.

@jeb2239
Copy link
Author

jeb2239 commented Jan 23, 2018

the --test_arg method doesn't work is there another way to get this coverage profile besides using the go_path method? This profile is needed to do anything related to code coverage.

@jayconrod
Copy link
Contributor

The way to do this is with --test_arg -test.coverprofile=out. However, I just tried this and got this message:

==================== Test output for //:go_default_test:
testing: cannot use -test.coverprofile because test binary was not built with coverage enabled

I think that used to work, but it doesn't anymore. It looks like we need to set the Mode field in Cover objects.

@jayconrod jayconrod added the bug label Jan 23, 2018
@jeb2239
Copy link
Author

jeb2239 commented Jan 30, 2018

Hello has any progress been made with this?

@jayconrod
Copy link
Contributor

I just checked this again with rules_go on master and Bazel 0.10.0rc6, and I'm getting a different error. Not sure if something changed, or I was running it wrong before.

$ bazel coverage :go_default_test --test_arg -test.coverprofile=$PWD/cover.out
...
testing: open /usr/local/google/home/jayconrod/go/src/example.com/repo/cover.out: read-only file system

I think this fails because of sandboxing; the test can't write anything outside of the sandbox. Running with --test_strategy=standalone did not work. You can write to /tmp though.

$ bazel coverage :go_default_test --test_arg -test.coverprofile=/tmp/cover.out
...
//:go_default_test                                                       PASSED in 0.1s

$ go test -coverprofile=/tmp/cover.out
go test -coverprofile=/tmp/cover.out
PASS
coverage: 100.0% of statements
ok  	example.com/repo	0.011s

Sorry I know this isn't a great solution. There's a long-term plan for Bazel rules in various languages to all produce coverage data in the same format, then produce unified reports for multiple tests across multiple languages. We'll provide Go support for that as soon as the Bazel backend for it is ready.

jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Mar 26, 2018
jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Apr 12, 2018
This fixes a filename stutter bug introduced in bazelbuild#1407.

Related bazelbuild#1406
Related bazelbuild#1150
jayconrod added a commit that referenced this issue Apr 16, 2018
This fixes a filename stutter bug introduced in #1407.

Related #1406
Related #1150
@jayconrod
Copy link
Contributor

An update: Bazel folks are working on coverage support. See the design doc. They are planning to migrate the internal coverage format to Cobertura XML, and they'll generate reports based on that. There are already tools to convert Go coverage data to this format, so once Bazel supports coverage, completing the support in rules_go won't take much work.

@dansiviter
Copy link

Duplicate of #140?

@jayconrod
Copy link
Contributor

Sure, no reason to have two tracking issues for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants