Skip to content

Commit 4fe688c

Browse files
committed
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 <[email protected]> Run-TryBot: Rob Pike <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent c1d9d1f commit 4fe688c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cmd/cover/profile.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (p *Profile) Boundaries(src []byte) (boundaries []Boundary) {
174174
return b
175175
}
176176
if max <= 1 {
177-
b.Norm = 0.8 // Profile is in"set" mode; we want a heat map. Use cov8 in the CSS.
177+
b.Norm = 0.8 // Profile is in "set" mode; we want a heat map. Use cov8 in the CSS.
178178
} else if count > 0 {
179179
b.Norm = math.Log(float64(count)) / divisor
180180
}
@@ -209,7 +209,10 @@ func (b boundariesByPos) Len() int { return len(b) }
209209
func (b boundariesByPos) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
210210
func (b boundariesByPos) Less(i, j int) bool {
211211
if b[i].Offset == b[j].Offset {
212-
return !b[i].Start && b[j].Start
212+
// Boundaries at the same offset should be ordered Start < !Start.
213+
// They represent empty sections of code (e.g. a switch/select clause
214+
// without a body).
215+
return b[i].Start && !b[j].Start
213216
}
214217
return b[i].Offset < b[j].Offset
215218
}

0 commit comments

Comments
 (0)