"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
// total: (statements) 91.9%
func funcOutput(profile, outputFile string) error {
- profiles, err := ParseProfiles(profile)
+ profiles, err := cover.ParseProfiles(profile)
if err != nil {
return err
}
}
// 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
}
}
-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
"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
}
// 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)
// 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 {
+++ /dev/null
-// 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