diff --git a/src/cmd/cover/func.go b/src/cmd/cover/func.go index ce7c771ac96..76a16b3fc4a 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 b2865c427c8..3c1d17e7b95 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 839444edb71..00000000000 --- 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 tag and will be used to colorize the source -type Boundary = cover.Boundary