Skip to content

testing: no way to get a snapshot of current coverage data accumulator #34263

Closed

Description

@straightdave

What version of Go are you using (go version)?

$ go version
go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wei.wu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wei.wu/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/wei.wu/repos/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t0/zqt5zk8152n89780p5_qvb9r0000gn/T/go-build258050164=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to find a way to get value of coverage data accumulator.

What did you expect to see?

There's a way to register a coverage data accumulator. Hence there should be a way to get value of coverage data accumulator.

What did you see instead?

Found no way to get the value of a package level non-exposing variable cover.

Activity

  1. toothrot commented on Sep 16, 2019

    @toothrot
    Contributor

    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

  2. added
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on Sep 17, 2019
  3. straightdave commented on Sep 20, 2019

    @straightdave
    Author

    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 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:

    var cover Cover
    
    // hack function
    func GetCover() Cover {
        return cover
    }

    Any ideas?

  4. toothrot commented on Sep 20, 2019

    @toothrot
    Contributor

    @straightdave Thanks for following up!

    The Cover struct is documented as such:

    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.

  5. straightdave commented on Sep 26, 2019

    @straightdave
    Author

    🤔Makes sense. Thanks @toothrot

  6. locked and limited conversation to collaborators on Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions