From 772f70e5bd29f244bfcd4365735dc35d6564d1fb Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 26 Sep 2020 18:10:09 +0200 Subject: [PATCH] pkg/cover: fix function coverage in html reports The HTML code assumes that files and functions match one-to-one as they are identified by indices (file_N should match function_N). Since we only add non-empty functions, this relation is broken and a the report shows function coverage for a random file. Moreover, since the order is based on map iteration (random each time), function coverage shown for a file also randomly changes each time. Follow up to #2074 --- pkg/cover/report.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/cover/report.go b/pkg/cover/report.go index ebf88400..784c470a 100644 --- a/pkg/cover/report.go +++ b/pkg/cover/report.go @@ -355,9 +355,7 @@ func addFunctionCoverage(file *file, data *templateData) { buf.WriteString(fmt.Sprintf("of %v", strconv.Itoa(len(function.totalPCs)))) buf.WriteString("
\n") } - if buf.Len() > 0 { - data.Functions = append(data.Functions, template.HTML(buf.String())) - } + data.Functions = append(data.Functions, template.HTML(buf.String())) } func processDir(dir *templateDir) {