mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
go.tools/cmd/cover: add -o outputfile option
Makes it easier to get error output when run from the go tool. R=adonovan CC=golang-dev https://golang.org/cl/10190043
This commit is contained in:
parent
0d2f7d411b
commit
0ca15cc618
@ -30,8 +30,10 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
mode = flag.String("mode", "set", "coverage mode: set, count, atomic")
|
mode = flag.String("mode", "set", "coverage mode: set, count, atomic")
|
||||||
countVar = flag.String("count", "__count", "name of coverage count array variable")
|
countVar = flag.String("count", "GoCoverCount", "name of coverage count array variable")
|
||||||
posVar = flag.String("pos", "__pos", "name of coverage count position variable")
|
posVar = flag.String("pos", "GoCoverPos", "name of coverage position array variable")
|
||||||
|
|
||||||
|
output = flag.String("o", "", "file for output; standard output by default")
|
||||||
)
|
)
|
||||||
|
|
||||||
var counterStmt func(*File, ast.Expr) ast.Stmt
|
var counterStmt func(*File, ast.Expr) ast.Stmt
|
||||||
@ -42,7 +44,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s [options] file\n", os.Args[0])
|
fmt.Fprintf(os.Stderr, "Usage: %s [options] onefile.go\n", os.Args[0])
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
@ -183,8 +185,6 @@ func (f *File) addImport(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cover(name string) {
|
func cover(name string) {
|
||||||
var files []*File
|
|
||||||
var astFiles []*ast.File
|
|
||||||
fs := token.NewFileSet()
|
fs := token.NewFileSet()
|
||||||
f, err := os.Open(name)
|
f, err := os.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -199,23 +199,27 @@ func cover(name string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cover: %s: %s", name, err)
|
log.Fatalf("cover: %s: %s", name, err)
|
||||||
}
|
}
|
||||||
thisFile := &File{
|
file := &File{
|
||||||
fset: fs,
|
fset: fs,
|
||||||
name: name,
|
name: name,
|
||||||
astFile: parsedFile,
|
astFile: parsedFile,
|
||||||
}
|
}
|
||||||
files = append(files, thisFile)
|
if *mode == "atomic" {
|
||||||
astFiles = append(astFiles, parsedFile)
|
file.atomicPkg = file.addImport(atomicPackagePath)
|
||||||
for _, file := range files {
|
|
||||||
if *mode == "atomic" {
|
|
||||||
file.atomicPkg = file.addImport(atomicPackagePath)
|
|
||||||
}
|
|
||||||
ast.Walk(file, file.astFile)
|
|
||||||
file.print(os.Stdout)
|
|
||||||
// After printing the source tree, add some declarations for the counters etc.
|
|
||||||
// We could do this by adding to the tree, but it's easier just to print the text.
|
|
||||||
file.addVariables(os.Stdout)
|
|
||||||
}
|
}
|
||||||
|
ast.Walk(file, file.astFile)
|
||||||
|
fd := os.Stdout
|
||||||
|
if *output != "" {
|
||||||
|
var err error
|
||||||
|
fd, err = os.Create(*output)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cover: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.print(fd)
|
||||||
|
// After printing the source tree, add some declarations for the counters etc.
|
||||||
|
// We could do this by adding to the tree, but it's easier just to print the text.
|
||||||
|
file.addVariables(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) print(w io.Writer) {
|
func (f *File) print(w io.Writer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user