From 84cae5a52d05a28a369276b5336c1b19e65064a8 Mon Sep 17 00:00:00 2001 From: Nathan John Youngman Date: Tue, 24 Sep 2013 17:27:26 +1000 Subject: [PATCH] go.tools/cover: clean up usage information R=golang-dev, r, minux.ma CC=golang-dev https://golang.org/cl/13532052 --- cmd/cover/cover.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/cmd/cover/cover.go b/cmd/cover/cover.go index 9fec01a1..3862cf71 100644 --- a/cmd/cover/cover.go +++ b/cmd/cover/cover.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Cover is a program for analyzing the coverage profiles generated by -// 'go test -coverprofile'. +// 'go test -coverprofile=cover.out'. // // Cover is also used by 'go test -cover' to rewrite the source code with // annotations to track which parts of each function are executed. @@ -12,6 +12,10 @@ // than binary-rewriting coverage tools, but also a little less capable. // For instance, it does not probe inside && and || expressions, and can // be mildly confused by single statements with multiple function literals. +// +// For usage information, please see: +// go help testflag +// go tool cover -help package main import ( @@ -30,23 +34,28 @@ import ( const usageMessage = "" + `Usage of 'go tool cover': -Given a coverage profile produced by 'go test -coverprofile=c.out', open -a web browser displaying annotated source code: - go tool cover -html=c.out -The same, but write the generated HTML to a file instead of starting a browser: - go tool cover -html=c.out -o coverage.html -Write to standard output coverage percentages for each function: - go tool cover -func=c.out -Generate modified source code with coverage annotations (what go test -cover does): - go tool cover -mode=set -var=CoverageVariableName program.go +Given a coverage profile produced by 'go test': + go test -coverprofile=c.out -Only one of -html, -func, or -mode may be set. +Open a web browser displaying annotated source code: + go tool cover -html=c.out + +Write out an HTML file instead of launching a web browser: + go tool cover -html=c.out -o coverage.html + +Display coverage percentages to stdout for each function: + go tool cover -func=c.out + +Finally, to generate modified source code with coverage annotations +(what go test -cover does): + go tool cover -mode=set -var=CoverageVariableName program.go ` func usage() { fmt.Fprintln(os.Stderr, usageMessage) fmt.Fprintln(os.Stderr, "Flags:") flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\n Only one of -html, -func, or -mode may be set.") os.Exit(2) }