]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cover: use golang.org/x/tools/cover directly
authorTobias Klauser <tklauser@distanz.ch>
Thu, 25 Mar 2021 19:48:27 +0000 (20:48 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Thu, 25 Mar 2021 20:57:58 +0000 (20:57 +0000)
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>
src/cmd/cover/func.go
src/cmd/cover/html.go
src/cmd/cover/profile.go [deleted file]

index ce7c771ac961971af670b00c1c79ea1c8b22153c..76a16b3fc4a11ef75c9ba4aabde154189ddf151d 100644 (file)
@@ -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
index b2865c427c8161239355a6ad88b4ec1c0cb1af41..3c1d17e7b956af110d816bc58a7a7878a0e411ec 100644 (file)
@@ -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 (file)
index 839444e..0000000
+++ /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