Skip to content

Commit 691db37

Browse files
committed
cmd/cover: use golang.org/x/tools/cover directly
As suggested by Bryan in CL 249759, remove the forwarding aliases in cmd/cover and use the symbols from golang.org/x/tools directly. cmd/cover is not an importable package, so it is fine to remove these exported symbols. Change-Id: I887c5e9349f2dbe4c90be57f708412b844e18081 Reviewed-on: https://go-review.googlesource.com/c/go/+/304690 Trust: Tobias Klauser <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 5cec8b8 commit 691db37

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

src/cmd/cover/func.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"runtime"
2424
"strings"
2525
"text/tabwriter"
26+
27+
"golang.org/x/tools/cover"
2628
)
2729

2830
// funcOutput takes two file names as arguments, a coverage profile to read as input and an output
@@ -38,7 +40,7 @@ import (
3840
// total: (statements) 91.9%
3941

4042
func funcOutput(profile, outputFile string) error {
41-
profiles, err := ParseProfiles(profile)
43+
profiles, err := cover.ParseProfiles(profile)
4244
if err != nil {
4345
return err
4446
}
@@ -144,7 +146,7 @@ func (v *FuncVisitor) Visit(node ast.Node) ast.Visitor {
144146
}
145147

146148
// coverage returns the fraction of the statements in the function that were covered, as a numerator and denominator.
147-
func (f *FuncExtent) coverage(profile *Profile) (num, den int64) {
149+
func (f *FuncExtent) coverage(profile *cover.Profile) (num, den int64) {
148150
// We could avoid making this n^2 overall by doing a single scan and annotating the functions,
149151
// but the sizes of the data structures is never very large and the scan is almost instantaneous.
150152
var covered, total int64
@@ -175,7 +177,7 @@ type Pkg struct {
175177
}
176178
}
177179

178-
func findPkgs(profiles []*Profile) (map[string]*Pkg, error) {
180+
func findPkgs(profiles []*cover.Profile) (map[string]*Pkg, error) {
179181
// Run go list to find the location of every package we care about.
180182
pkgs := make(map[string]*Pkg)
181183
var list []string

src/cmd/cover/html.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import (
1515
"os"
1616
"path/filepath"
1717
"strings"
18+
19+
"golang.org/x/tools/cover"
1820
)
1921

2022
// htmlOutput reads the profile data from profile and generates an HTML
2123
// coverage report, writing it to outfile. If outfile is empty,
2224
// it writes the report to a temporary file and opens it in a web browser.
2325
func htmlOutput(profile, outfile string) error {
24-
profiles, err := ParseProfiles(profile)
26+
profiles, err := cover.ParseProfiles(profile)
2527
if err != nil {
2628
return err
2729
}
@@ -92,7 +94,7 @@ func htmlOutput(profile, outfile string) error {
9294
// percentCovered returns, as a percentage, the fraction of the statements in
9395
// the profile covered by the test run.
9496
// In effect, it reports the coverage of a given source file.
95-
func percentCovered(p *Profile) float64 {
97+
func percentCovered(p *cover.Profile) float64 {
9698
var total, covered int64
9799
for _, b := range p.Blocks {
98100
total += int64(b.NumStmt)
@@ -108,7 +110,7 @@ func percentCovered(p *Profile) float64 {
108110

109111
// htmlGen generates an HTML coverage report with the provided filename,
110112
// source code, and tokens, and writes it to the given Writer.
111-
func htmlGen(w io.Writer, src []byte, boundaries []Boundary) error {
113+
func htmlGen(w io.Writer, src []byte, boundaries []cover.Boundary) error {
112114
dst := bufio.NewWriter(w)
113115
for i := range src {
114116
for len(boundaries) > 0 && boundaries[0].Offset == i {

src/cmd/cover/profile.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)