Skip to content

cmd/cover: should support -coverprofile unifying tests from multiple packages #6909

Description

@wadey
What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. run `go test -coverprofile=coverage.out ./...`

What is the expected output?

coverage.out contains coverage all of the specified packages

What do you see instead?

`cannot use test profile flag with multiple packages`

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

OS X 10.9

Which version are you using?  (run 'go version')

go version go1.2 darwin/amd64

Please provide any additional information below.

If I manually construct a coverage.out file from multiple packages, it seems to work
fine:

1. go test -coverprofile a.part ./a
2. go test -coverprofile b.part ./b
3. echo "mode: set" >coverage.out
4. grep -h -v "mode: set" *.part >>coverage.out
5. go tool cover -html=coverage.out

Why can't `go test -coverprofile` do this automatically?

Activity

  1. minux commented on Dec 6, 2013

    @minux
    Member

    Comment 1:

    Labels changed: added release-go1.3maybe, repo-tools.

    Status changed to Accepted.

  2. rsc commented on May 9, 2014

    @rsc
    Contributor

    Comment 3:

    Labels changed: added release-none, removed release-go1.3maybe.

  3. gopherbot commented on Aug 27, 2014

    @gopherbot
    Contributor

    Comment 5 by phuna24:

    I'm also facing same problem today with 1.3.1. Is there plan for fixing this soon?
  4. gopherbot commented on Aug 27, 2014

    @gopherbot
    Contributor

    Comment 6 by hwang.dev:

    It is not an urgent issue. The workaround is simple, please check the shell script:
    https://gist.github.com/hailiang/0f22736320abe6be71ce
  5. gopherbot commented on Aug 27, 2014

    @gopherbot
    Contributor

    Comment 7 by phuna24:

    Hi,
    Thanks for the link. Very helpful.
  6. gopherbot commented on Oct 16, 2014

    @gopherbot
    Contributor

    Comment 8:

    CL https://golang.org/cl/159910044 mentions this issue.
  7. dlsniper commented on Feb 8, 2015

    @dlsniper
    Contributor

    Can this be included in 1.5. I don't see any technical reason for it to not be. Thank you.

  8. changed the title [-]go.tools/cmd/cover: should support -coverprofile for multiple packages[/-] [+]cmd/cover: should support -coverprofile for multiple packages[/+] on Feb 8, 2015
  9. minux commented on Feb 8, 2015

    @minux
    Member
  10. added this to the Unplanned milestone on Apr 10, 2015
  11. 60 remaining items

  12. oshalygin commented on Jul 3, 2017

    @oshalygin

    @dnephin I like the approach, any thoughts on whether or not this would be considered?

  13. dlsniper commented on Jul 17, 2017

    @dlsniper
    Contributor

    @rsc I would be happy to work on this for 1.10, provided anything required by this is in place by then. Any guidance from you or anyone else would be good. Also this can have the IDE label as well.

  14. AlekSi commented on Jul 25, 2017

    @AlekSi
    Contributor

    In the mean time, I made another tool: https://github.com/AlekSi/gocoverutil. Unlike some bash scripts mentioned there, it sets exit status correctly if tests fail, it sets -coverpkg to include all packages, etc.
    But I'm really looking forward to retiring it when this issue and #21126 are closed.

  15. rasky commented on Nov 6, 2017

    @rasky
    Member

    @rsc now that the build cache is in, are we closer to fix this bug? I think people are waiting here for some guidance on how to fix it. I can attempt something myself, but it would be great if you could provide some guidance. Thanks!

  16. dlsniper commented on Nov 6, 2017

    @dlsniper
    Contributor

    Maybe a different way to see the problem is that we should have a different covermode for which we can apply this feature.

    For example, running go test -coverprofile=coverage.out ./... should detect that the user wants to run in a recursive mode thus set the covermode to a recursive (or better named mode) in which, regardless of how many times a line is executed, it counts only as a simple boolean value (yes / no)?

  17. dlsniper commented on Nov 6, 2017

    @dlsniper
    Contributor

    Of course, this could also be done in a more complex way, by storing which test hit which line and then, on a per-line basis, and then offer for each line of code touched by tests a slice of test names. It would then be up to the tools to read that information and display it to the users, in the most simplistic way doing this as described above with a simple yes / no mode.

    Sorry for the double message.

  18. andradei commented on Nov 7, 2017

    @andradei

    The first suggestions is a great way to get this started. But the more powerful and resourceful go test -converprofile is , the better.

  19. gopherbot commented on Nov 10, 2017

    @gopherbot
    Contributor

    Change https://golang.org/cl/76875 mentions this issue: cmd/go: allow -coverprofile with multiple packages being tested

  20. modified the milestones: Unreleased, Go1.10 on Nov 10, 2017
  21. changed the title [-]x/tools/cmd/cover: should support -coverprofile unifying tests from multiple packages[/-] [+]cmd/cover: should support -coverprofile unifying tests from multiple packages[/+] on Nov 10, 2017
  22. locked and limited conversation to collaborators on Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions