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
This commit is contained in:
Dmitry Vyukov 2020-09-26 18:10:09 +02:00
parent 2111afe851
commit 772f70e5bd

View File

@ -355,9 +355,7 @@ func addFunctionCoverage(file *file, data *templateData) {
buf.WriteString(fmt.Sprintf("<span class='cover-right'>of %v", strconv.Itoa(len(function.totalPCs)))) buf.WriteString(fmt.Sprintf("<span class='cover-right'>of %v", strconv.Itoa(len(function.totalPCs))))
buf.WriteString("</span></span></span><br>\n") buf.WriteString("</span></span></span><br>\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) { func processDir(dir *templateDir) {