-
Notifications
You must be signed in to change notification settings - Fork 761
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
Integration test code coverage: Add support for merging additional coverage files that were created before the test run completed. #3611
Comments
@saborrie Am I correct that the feature you're requesting is simply:
@hyangah From a technical perspective this shouldn't be hard to add to Go Companion, I just need to scan for files and merge into the coverage map. From a UX perspective, I'm not sure how best to handle this. @saborrie Presumably, you don't want coverage from a previous run to 'pollute' the results of a subsequent run. So those files need to be deleted, or we'd need some way of specifying a new directory for each run. Should it be the extension's responsibility to delete old coverage files at the beginning of a run? From microsoft/vscode#227924 it sounds like there's some possibility that we could get a temp directory for each test run. Should we pass that to the test via an environment variable? |
@firelizzard18, yes that is what I am requesting, but I've dug deeper and I think there might be a simpler solution. You are right that as I have requested it would suffer from the possibility of those coverage files not getting cleaned out at the right time unless vscode-go took responsibility. I checked, and running a regular unit test with vscode-go for coverage will have Perhaps a better revised setting would be a boolean configuration variable such as
Integration tests can then simply check GOCOVERDIR and pass the same value down to the binaries that they run. What I don't know is whether this can still cause issues from multiple test runs happening simultaneously - I don't know if vscode-go prevents that |
I'm pretty confident this is not being done by vscode-go, so it must be something
vscode-go does the same thing as Go Companion (I just checked): it uses the -coverprofile flag. I think For context, I am the original author of vscode-go's test explorer implementation, which is distinct from it's testing commands and code lenses, and I am working on replacing both with a new implementation using gopls. That new implementation currently lives in Go Companion. If you install a preview/prerelease version of vscode-go plus Go Companion, vscode-go will switch to using Go Companion for tests. If you're interested in submitting a PR, I can give you pointers. |
From golang/go#66225, maybe Go itself will get an improvement in this area anyway. It sounds like GOCOVERDIR gets set to a temp directory by go, which would line up with what you've said about I wonder if part of the issue is that there are multiple formats - it sounds like the instrumented binaries output in a newer format than what happens if you use |
You're a bit mixed up. The process is (IIUC):
-coverprofile implicitly sets -cover. Excluding that, all -coverprofile does is instruct go test to generate a report using the old format. Everything else is a function of -cover, which instruments the binary and instructs to emit coverage data in the new format to GOCOVERDIR. It sounds like your use case used to work, but golang/go#57924 updated go test to specifically ignore coverage files from other binaries when generating the coverage report. A possible solution is for vscode-go/Go Companion to read coverage files directly out of GOCOVERDIR. Except AFAIK we can't predict what GOCOVERDIR will be and we can't emit it without modifying the user's code (which is not a path I'm willing to take). |
Is your feature request related to a problem? Please describe.
As well as unit tests, my Go applications will often have a few integration tests that don't call functions from my package, but instead build it into a binary and then execute the binary. I would like these tests to be picked up by vscode-go for reporting and displaying code coverage
Describe the solution you'd like
Go has support in
go build
to add the-cover
option, which will create binaries that report coverage based on theGOCOVERDIR
environment variable. Integration tests would create this as an additional coverage file, rather than being added to the one output from the test run itself, which is triggered by vscode-go.I would like vscode-go to include an additional option such as
go.additionalCoverageFiles
. I could set this option to a directory such as/tmp/my_go_integration_test_coverage
, and then vscode-go can look in that directory after each test run for additonal coverage files, and if found merge them into the main coverage file that was output by the test run.Describe alternatives you've considered
I have tried to do the merge myself, such as in
TestMain
, but the main coverage file doesn't exist until after the tests exit, to there is nothing to merge.Example
The text was updated successfully, but these errors were encountered: