aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Hogander <jouni.hogander@unikie.com>2020-08-20 15:48:28 +0300
committerDmitry Vyukov <dvyukov@google.com>2020-09-26 17:47:37 +0200
commit769c9b7a94fbe6491efdb1faf9908aba2227c0fe (patch)
tree7454c99ce98b9a0231f141482670f251a2c767e6
parent6f0ea384b170a6e3db2647ee8759a9cf6c85b1da (diff)
pkg/cover: add new view for function coverage
Add new view where function coverage is shown when clicking file coverage percent
-rw-r--r--pkg/cover/report.go62
1 files changed, 55 insertions, 7 deletions
diff --git a/pkg/cover/report.go b/pkg/cover/report.go
index 666babb02..0a65c11a7 100644
--- a/pkg/cover/report.go
+++ b/pkg/cover/report.go
@@ -330,14 +330,36 @@ func (rg *ReportGenerator) generateHTML(w io.Writer, progs []Prog, files map[str
}
d.Contents = append(d.Contents, template.HTML(buf.String()))
f.Index = len(d.Contents) - 1
+
+ addFunctionCoverage(file, d)
}
for _, prog := range progs {
d.Progs = append(d.Progs, template.HTML(html.EscapeString(prog.Data)))
}
+
processDir(d.Root)
return coverTemplate.Execute(w, d)
}
+func addFunctionCoverage(file *file, data *templateData) {
+ var buf bytes.Buffer
+ for functionName, function := range file.functions {
+ var percentage string
+ if len(function.coverPCs) > 0 {
+ percentage = fmt.Sprintf("%d%%", percent(len(function.coverPCs), len(function.totalPCs)))
+ } else {
+ percentage = "---"
+ }
+ buf.WriteString(fmt.Sprintf("<span class='hover'>%v", functionName))
+ buf.WriteString(fmt.Sprintf("<span class='cover hover'>%v", percentage))
+ buf.WriteString(fmt.Sprintf("<span class='cover-right'>of %v", strconv.Itoa(len(function.totalPCs))))
+ buf.WriteString("</span></span></span><br>\n")
+ }
+ if buf.Len() > 0 {
+ data.Functions = append(data.Functions, template.HTML(buf.String()))
+ }
+}
+
func processDir(dir *templateDir) {
for len(dir.Dirs) == 1 && len(dir.Files) == 0 {
for _, child := range dir.Dirs {
@@ -611,9 +633,10 @@ func archCallInsn(target *targets.Target) ([][]byte, [][]byte) {
}
type templateData struct {
- Root *templateDir
- Contents []template.HTML
- Progs []template.HTML
+ Root *templateDir
+ Contents []template.HTML
+ Progs []template.HTML
+ Functions []template.HTML
}
type templateBase struct {
@@ -663,6 +686,18 @@ var coverTemplate = template.Must(template.New("").Parse(`
left: 0;
width: 24%;
}
+ .function {
+ height: 100%;
+ position: fixed;
+ z-index: 1;
+ top: 0;
+ overflow-x: hidden;
+ display: none;
+ }
+ .list {
+ left: 24%;
+ width: 30%;
+ }
.right {
border-left: 2px solid #444;
right: 0;
@@ -738,6 +773,9 @@ var coverTemplate = template.Must(template.New("").Parse(`
{{range $i, $p := .Progs}}
<pre class="file" id="prog_{{$i}}">{{$p}}</pre>
{{end}}
+ {{range $i, $p := .Functions}}
+ <div class="function list" id="function_{{$i}}">{{$p}}</div>
+ {{end}}
</div>
</body>
<script>
@@ -761,6 +799,13 @@ var coverTemplate = template.Must(template.New("").Parse(`
}
})();
var visible;
+ function onPercentClick(index) {
+ if (visible)
+ visible.style.display = 'none';
+ visible = document.getElementById("function_" + index);
+ visible.style.display = 'block';
+ document.getElementById("right_pane").scrollTo(0, 0);
+ }
function onFileClick(index) {
if (visible)
visible.style.display = 'none';
@@ -797,11 +842,14 @@ var coverTemplate = template.Must(template.New("").Parse(`
<li><span class="hover">
{{if $file.Covered}}
<a href="#{{$file.Path}}" id="path/{{$file.Path}}" onclick="onFileClick({{$file.Index}})">
- {{$file.Name}}<span class="cover hover">
- {{$file.Percent}}%
- <span class="cover-right">of {{$file.Total}}</span>
- </span>
+ {{$file.Name}}
</a>
+ <span class="cover hover">
+ <a href="#{{$file.Path}}/func_cov" id="path/{{$file.Path}}/func_cov" onclick="onPercentClick({{$file.Index}})">
+ {{$file.Percent}}%
+ </a>
+ <span class="cover-right">of {{$file.Total}}</span>
+ </span>
{{else}}
{{$file.Name}}<span class="cover hover">---<span class="cover-right">
of {{$file.Total}}</span></span>