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

x/tools/cover: doesn't handle multiple sample from the same location in cover profile. #23076

Closed
haya14busa opened this issue Dec 10, 2017 · 2 comments

Comments

@haya14busa
Copy link
Contributor

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

N/A

Does this issue reproduce with the latest release?

yes. This issue might be a problem with upcoming Go 1.10 release.

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

N/A

What did you do?

Parse the test cover profile result with x/tools/cover package.

What did you expect to see?

Multiple samples from the same location will be merged when parsing cover
profile in the same way as src/cmd/cover/profile.go1.

What did you see instead?

The implementation between x/tools/cover and src/cmd/cover/profile.go is
different and x/tools/cover won't handle multiple samples from the same location.

Now that go test supported -coverprofile with multiple packages (#6909),
x/tools/cover/profile should also handle multiple samples from the same
location.

Because go test -coverprofile with multiple packages just merges the cover
profile result by appending cover profile2, if users specify -coverpkg flag, the
merged profile will contain the multiple samples from the same location.

How to reproduce

  1. Run go1.10beta1 test -v -coverprofile=coverage.out -coverpkg=./... ./... under this directory https://github.com/haya14busa/goverage/tree/master/example/root
mode: count
github.com/haya14busa/goverage/example/root/root.go:8.24,10.2 1 1
github.com/haya14busa/goverage/example/root/root.go:8.24,10.2 1 0
github.com/haya14busa/goverage/example/root/root.go:12.17,15.2 2 1
github.com/haya14busa/goverage/example/root/root.go:12.17,15.2 2 0
github.com/haya14busa/goverage/example/root/sub/sub.go:3.23,5.2 1 0
github.com/haya14busa/goverage/example/root/sub/sub.go:3.23,5.2 1 1
github.com/haya14busa/goverage/example/root/sub/sub.go:7.24,9.2 1 1
github.com/haya14busa/goverage/example/root/sub/sub.go:7.24,9.2 1 0
github.com/haya14busa/goverage/example/root/sub/sub.go:11.30,13.2 1 1
github.com/haya14busa/goverage/example/root/sub/sub.go:11.30,13.2 1 1
  1. Parse this profile using x/tools/cover
package main

import (
	"fmt"

	"golang.org/x/tools/cover"
)

func main() {
	profile, _ := cover.ParseProfiles("./coverage.out")
	for _, p := range profile {
		fmt.Println(p.FileName)
		for _, b := range p.Blocks {
			fmt.Printf("StartLine:%v EndLine:%v Count:%v\n", b.StartLine, b.EndLine, b.Count)
		}
	}
}

Output:

github.com/haya14busa/goverage/example/root/root.go
StartLine:8 EndLine:10 Count:1
StartLine:8 EndLine:10 Count:0
StartLine:12 EndLine:15 Count:1
StartLine:12 EndLine:15 Count:0
github.com/haya14busa/goverage/example/root/sub/sub.go
StartLine:3 EndLine:5 Count:0
StartLine:3 EndLine:5 Count:1
StartLine:7 EndLine:9 Count:1
StartLine:7 EndLine:9 Count:0
StartLine:11 EndLine:13 Count:1
StartLine:11 EndLine:13 Count:1

Expect:

github.com/haya14busa/goverage/example/root/root.go
StartLine:8 EndLine:10 Count:1
StartLine:12 EndLine:15 Count:1
github.com/haya14busa/goverage/example/root/sub/sub.go
StartLine:3 EndLine:5 Count:1
StartLine:7 EndLine:9 Count:1
StartLine:11 EndLine:13 Count:1

I'll send a CL soon.

@gopherbot gopherbot added this to the Unreleased milestone Dec 10, 2017
@gopherbot
Copy link

Change https://golang.org/cl/83078 mentions this issue: cover: handle multiple samples from the same location

@JicLotus
Copy link

Did you add some test for this issue?

@mikioh mikioh changed the title x/tools/cover doesn't handle multiple sample from the same location in cover profile. x/tools/cover: doesn't handle multiple sample from the same location in cover profile. Jan 5, 2018
@golang golang locked and limited conversation to collaborators Jan 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants