You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: no way to get a snapshot of current coverage data accumulator #34263
I am trying to upload the line coverage data periodically while the binary code is running. I've tried to use RegisterCover to inject mine Cover instance but failed to get any data other than zero value from it. Meanwhile the hack function GetCover could always return the data no matter when and where I call it.
So the working way (and it's convenient) I found so far is to add this GetCover function to return the package level variable cover in src/testing/cover.go:
NOTE: This struct is internal to the testing infrastructure and may change. It is not covered (yet) by the Go 1 compatibility guidelines.
Many parts of the testing library predate "internal" packages, and were exported for internal usage only. I think there's a single example in the Go codebase of how to use RegisterCover, but again, it could break in the future and we have no promises to support it externally.
Finally, I don't think we will be adding a new API to something that ought to have been internal in the first place, so I am going to close this issue.
I don't know the best way to help you do what you want, but a better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions. It'll reach a wider audience of people who may have tried something similar.
Activity
toothrot commentedon Sep 16, 2019
Hi @straightdave,
Can you please add more detail about what you're trying to do? Does
testing.RegisterCover(c)do what you want?https://godoc.org/testing#RegisterCover
straightdave commentedon Sep 20, 2019
Hi @toothrot
Thanks for the reply 😃
I am trying to upload the line coverage data periodically while the binary code is running. I've tried to use
RegisterCoverto inject mineCoverinstance but failed to get any data other than zero value from it. Meanwhile the hack functionGetCovercould always return the data no matter when and where I call it.So the working way (and it's convenient) I found so far is to add this
GetCoverfunction to return the package level variablecoverinsrc/testing/cover.go:Any ideas?
toothrot commentedon Sep 20, 2019
@straightdave Thanks for following up!
The
Coverstruct is documented as such:Many parts of the testing library predate "internal" packages, and were exported for internal usage only. I think there's a single example in the Go codebase of how to use
RegisterCover, but again, it could break in the future and we have no promises to support it externally.Finally, I don't think we will be adding a new API to something that ought to have been internal in the first place, so I am going to close this issue.
I don't know the best way to help you do what you want, but a better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions. It'll reach a wider audience of people who may have tried something similar.
straightdave commentedon Sep 26, 2019
🤔Makes sense. Thanks @toothrot