Skip to content

Commit

Permalink
merge Count based on the covermode
Browse files Browse the repository at this point in the history
The cover modes are described as:
From [The Go Blog: The cover story](https://blog.golang.org/cover):

         The go test command accepts a -covermode flag to set the coverage
         mode to one of three settings:

         - set: did each statement run?
         - count: how many times did each statement run?
         - atomic: like count, but counts precisely in parallel programs

Previously, we were always merging like it was "set" mode. This change
instead handles the Count correctly for each `-covermode` type.
  • Loading branch information
wadey committed Mar 31, 2016
1 parent c01c923 commit b5bfa59
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gocovmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func mergeProfileBlock(p *cover.Profile, pb cover.ProfileBlock, startIndex int)
if p.Blocks[i].EndLine != pb.EndLine || p.Blocks[i].EndCol != pb.EndCol {
log.Fatalf("OVERLAP MERGE: %v %v %v", p.FileName, p.Blocks[i], pb)
}
p.Blocks[i].Count |= pb.Count
switch p.Mode {
case "set":
p.Blocks[i].Count |= pb.Count
case "count", "atomic":
p.Blocks[i].Count += pb.Count
default:
log.Fatalf("unsupported covermode: '%s'", p.Mode)
}
} else {
if i > 0 {
pa := p.Blocks[i-1]
Expand Down

0 comments on commit b5bfa59

Please sign in to comment.