aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cover
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2018-05-28 13:03:08 +1000
committerDavid Symonds <dsymonds@golang.org>2018-05-28 03:35:36 +0000
commit4fe688c6a49e59e852f0bfebbb4cf71366987ce7 (patch)
tree8c9e6f79b7c1b78b07e6191d846b3f96d0b18769 /src/cmd/cover
parentc1d9d1f305df19c66e28a619e17f9f1d7563d977 (diff)
downloadgo-4fe688c6a49e59e852f0bfebbb4cf71366987ce7.tar.gz
go-4fe688c6a49e59e852f0bfebbb4cf71366987ce7.zip
cmd/cover: fix sorting of profile segment boundaries
If a span of coverable code is empty (e.g. an empty select clause) then there will be two Boundary values with the same offset. In that case, the starting Boundary needs to come first so that the generated HTML output will open the <span> tag before it tries to close it. Change-Id: Ib44a8b7c36ae57757c18b6cceb7a88ffa4e95394 Reviewed-on: https://go-review.googlesource.com/114855 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/cover')
-rw-r--r--src/cmd/cover/profile.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/cmd/cover/profile.go b/src/cmd/cover/profile.go
index 5628b91f51..0da42ebfd3 100644
--- a/src/cmd/cover/profile.go
+++ b/src/cmd/cover/profile.go
@@ -174,7 +174,7 @@ func (p *Profile) Boundaries(src []byte) (boundaries []Boundary) {
return b
}
if max <= 1 {
- b.Norm = 0.8 // Profile is in"set" mode; we want a heat map. Use cov8 in the CSS.
+ b.Norm = 0.8 // Profile is in "set" mode; we want a heat map. Use cov8 in the CSS.
} else if count > 0 {
b.Norm = math.Log(float64(count)) / divisor
}
@@ -209,7 +209,10 @@ func (b boundariesByPos) Len() int { return len(b) }
func (b boundariesByPos) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b boundariesByPos) Less(i, j int) bool {
if b[i].Offset == b[j].Offset {
- return !b[i].Start && b[j].Start
+ // Boundaries at the same offset should be ordered Start < !Start.
+ // They represent empty sections of code (e.g. a switch/select clause
+ // without a body).
+ return b[i].Start && !b[j].Start
}
return b[i].Offset < b[j].Offset
}