aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/cover/html.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-12-13 14:56:00 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-12-13 18:56:36 +0100
commita733efbda5ffc8f76ca1f62b0c777c21d0254653 (patch)
tree27fd19935a4579da7d4e97a0474b9f592dce8585 /pkg/cover/html.go
parent65950d721d8dd9fe24b3661f69c853ae3f27401e (diff)
pkg/cover: don't show func coverage if we don't have it
Diffstat (limited to 'pkg/cover/html.go')
-rw-r--r--pkg/cover/html.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/pkg/cover/html.go b/pkg/cover/html.go
index 6212febf5..b353029a3 100644
--- a/pkg/cover/html.go
+++ b/pkg/cover/html.go
@@ -65,6 +65,7 @@ func (rg *ReportGenerator) DoHTML(w io.Writer, progs []Prog) error {
Total: file.totalPCs,
Covered: file.coveredPCs,
},
+ HasFunctions: len(file.functions) != 0,
}
pos.Files = append(pos.Files, f)
if file.coveredPCs == 0 {
@@ -354,7 +355,8 @@ type templateDir struct {
type templateFile struct {
templateBase
- Index int
+ Index int
+ HasFunctions bool
}
var coverTemplate = template.Must(template.New("").Parse(`
@@ -541,7 +543,8 @@ var coverTemplate = template.Must(template.New("").Parse(`
{{$file.Name}}
</a>
<span class="cover hover">
- <a href="#{{$file.Path}}/func_cov" id="path/{{$file.Path}}/func_cov" onclick="onPercentClick({{$file.Index}})">
+ <a href="#{{$file.Path}}" id="path/{{$file.Path}}"
+ onclick="{{if .HasFunctions}}onPercentClick{{else}}onFileClick{{end}}({{$file.Index}})">
{{$file.Percent}}%
</a>
<span class="cover-right">of {{$file.Total}}</span>