cmd/cover: add start lines numbers to each function in -func mode
This CL aims to fix the problem described here: https://groups.google.com/forum/#!topic/golang-nuts/R6ms1n9KjiY This makes it easier to parse via external tools such as editors. Editors can show each function in a list and jump directly to each function with this additional information. This pattern can be seen in other Go tools such as "go test" in the form of: --- FAIL: TestCover (0.52 seconds) cover_test.go:43: example error LGTM=adg R=r, adg, josharian, dave CC=golang-codereviews https://golang.org/cl/131820043
This commit is contained in:
parent
277e5a16d7
commit
ba91af23b8
|
|
@ -24,13 +24,13 @@ import (
|
|||
// file to write ("" means to write to standard output). The function reads the profile and produces
|
||||
// as output the coverage data broken down by function, like this:
|
||||
//
|
||||
// fmt/format.go: init 100.0%
|
||||
// fmt/format.go: computePadding 84.6%
|
||||
// fmt/format.go:30: init 100.0%
|
||||
// fmt/format.go:57: clearflags 100.0%
|
||||
// ...
|
||||
// fmt/scan.go: doScan 100.0%
|
||||
// fmt/scan.go: advance 96.2%
|
||||
// fmt/scan.go: doScanf 96.8%
|
||||
// total: (statements) 91.4%
|
||||
// fmt/scan.go:1046: doScan 100.0%
|
||||
// fmt/scan.go:1075: advance 96.2%
|
||||
// fmt/scan.go:1119: doScanf 96.8%
|
||||
// total: (statements) 91.9%
|
||||
|
||||
func funcOutput(profile, outputFile string) error {
|
||||
profiles, err := cover.ParseProfiles(profile)
|
||||
|
|
@ -68,7 +68,7 @@ func funcOutput(profile, outputFile string) error {
|
|||
// Now match up functions and profile blocks.
|
||||
for _, f := range funcs {
|
||||
c, t := f.coverage(profile)
|
||||
fmt.Fprintf(tabber, "%s:\t%s\t%.1f%%\n", fn, f.name, 100.0*float64(c)/float64(t))
|
||||
fmt.Fprintf(tabber, "%s:%d:\t%s\t%.1f%%\n", fn, f.startLine, f.name, 100.0*float64(c)/float64(t))
|
||||
total += t
|
||||
covered += c
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue