aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cover
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2021-03-25 20:48:27 +0100
committerTobias Klauser <tobias.klauser@gmail.com>2021-03-25 20:57:58 +0000
commit691db3737c989ba07ec4565c16628d35cb08418c (patch)
treeeb7441885d35c451299c127b8057c31f05c8a4c8 /src/cmd/cover
parent5cec8b85e5dc75ef21b62efb6bd93f9007385e34 (diff)
downloadgo-691db3737c989ba07ec4565c16628d35cb08418c.tar.gz
go-691db3737c989ba07ec4565c16628d35cb08418c.zip
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 <tobias.klauser@gmail.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/cover')
-rw-r--r--src/cmd/cover/func.go8
-rw-r--r--src/cmd/cover/html.go8
-rw-r--r--src/cmd/cover/profile.go30
3 files changed, 10 insertions, 36 deletions
diff --git a/src/cmd/cover/func.go b/src/cmd/cover/func.go
index ce7c771ac9..76a16b3fc4 100644
--- a/src/cmd/cover/func.go
+++ b/src/cmd/cover/func.go
@@ -23,6 +23,8 @@ import (
"runtime"
"strings"
"text/tabwriter"
+
+ "golang.org/x/tools/cover"
)
// funcOutput takes two file names as arguments, a coverage profile to read as input and an output
@@ -38,7 +40,7 @@ import (
// total: (statements) 91.9%
func funcOutput(profile, outputFile string) error {
- profiles, err := ParseProfiles(profile)
+ profiles, err := cover.ParseProfiles(profile)
if err != nil {
return err
}
@@ -144,7 +146,7 @@ func (v *FuncVisitor) Visit(node ast.Node) ast.Visitor {
}
// coverage returns the fraction of the statements in the function that were covered, as a numerator and denominator.
-func (f *FuncExtent) coverage(profile *Profile) (num, den int64) {
+func (f *FuncExtent) coverage(profile *cover.Profile) (num, den int64) {
// We could avoid making this n^2 overall by doing a single scan and annotating the functions,
// but the sizes of the data structures is never very large and the scan is almost instantaneous.
var covered, total int64
@@ -175,7 +177,7 @@ type Pkg struct {
}
}
-func findPkgs(profiles []*Profile) (map[string]*Pkg, error) {
+func findPkgs(profiles []*cover.Profile) (map[string]*Pkg, error) {
// Run go list to find the location of every package we care about.
pkgs := make(map[string]*Pkg)
var list []string
diff --git a/src/cmd/cover/html.go b/src/cmd/cover/html.go
index b2865c427c..3c1d17e7b9 100644
--- a/src/cmd/cover/html.go
+++ b/src/cmd/cover/html.go
@@ -15,13 +15,15 @@ import (
"os"
"path/filepath"
"strings"
+
+ "golang.org/x/tools/cover"
)
// htmlOutput reads the profile data from profile and generates an HTML
// coverage report, writing it to outfile. If outfile is empty,
// it writes the report to a temporary file and opens it in a web browser.
func htmlOutput(profile, outfile string) error {
- profiles, err := ParseProfiles(profile)
+ profiles, err := cover.ParseProfiles(profile)
if err != nil {
return err
}
@@ -92,7 +94,7 @@ func htmlOutput(profile, outfile string) error {
// percentCovered returns, as a percentage, the fraction of the statements in
// the profile covered by the test run.
// In effect, it reports the coverage of a given source file.
-func percentCovered(p *Profile) float64 {
+func percentCovered(p *cover.Profile) float64 {
var total, covered int64
for _, b := range p.Blocks {
total += int64(b.NumStmt)
@@ -108,7 +110,7 @@ func percentCovered(p *Profile) float64 {
// htmlGen generates an HTML coverage report with the provided filename,
// source code, and tokens, and writes it to the given Writer.
-func htmlGen(w io.Writer, src []byte, boundaries []Boundary) error {
+func htmlGen(w io.Writer, src []byte, boundaries []cover.Boundary) error {
dst := bufio.NewWriter(w)
for i := range src {
for len(boundaries) > 0 && boundaries[0].Offset == i {
diff --git a/src/cmd/cover/profile.go b/src/cmd/cover/profile.go
deleted file mode 100644
index 839444edb7..0000000000
--- a/src/cmd/cover/profile.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file provides support for parsing coverage profiles
-// generated by "go test -coverprofile=cover.out".
-// It is a alias of golang.org/x/tools/cover/profile.go.
-
-package main
-
-import (
- "golang.org/x/tools/cover"
-)
-
-// Profile represents the profiling data for a specific file.
-type Profile = cover.Profile
-
-// ProfileBlock represents a single block of profiling data.
-type ProfileBlock = cover.ProfileBlock
-
-// ParseProfiles parses profile data in the specified file and returns a
-// Profile for each source file described therein.
-func ParseProfiles(fileName string) ([]*Profile, error) {
- return cover.ParseProfiles(fileName)
-}
-
-// Boundary represents the position in a source file of the beginning or end of a
-// block as reported by the coverage profile. In HTML mode, it will correspond to
-// the opening or closing of a <span> tag and will be used to colorize the source
-type Boundary = cover.Boundary