1
0
mirror of https://github.com/golang/go synced 2024-11-23 05:30:07 -07:00

cmd/go: print all test flags in "go test -h"

Originally 'go test -h' printed the output of 'go help test'.
Then issue #6576 was filed, because that output didn't list (for example) -bench.
CL 14502065 changed 'go test -h' to print the output of 'go help testflag'.
Then issue #9209 was filed, because that output didn't list (for example) -c.

To print all the relevant flags, parts of both 'go help test' and 'go help testflag'
are needed. Refactor the help messages to make those parts available
and print them.

Fixes #9209.

Change-Id: Ie8205b8fb37d00c10d25b3fc98f14286ec46c4e3
Reviewed-on: https://go-review.googlesource.com/12173
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Russ Cox 2015-07-14 01:08:30 -04:00
parent ef6d3a94fb
commit 307d6919bd
3 changed files with 30 additions and 20 deletions

View File

@ -673,9 +673,8 @@ In addition to the build flags, the flags handled by 'go test' itself are:
Compile the test binary to the named file.
The test still runs (unless -c or -i is specified).
The test binary also accepts flags that control execution of the test; these
flags are also accessible by 'go test'. See 'go help testflag' for details.
flags are also accessible by 'go test'. See 'go help testflag' for details.
If the test binary needs any other flags, they should be presented after the
package names. The go tool treats as a flag the first argument that begins with

View File

@ -258,7 +258,9 @@ func printUsage(w io.Writer) {
func usage() {
// special case "go test -h"
if len(os.Args) > 1 && os.Args[1] == "test" {
help([]string{"testflag"})
os.Stdout.WriteString(testUsage + "\n\n" +
strings.TrimSpace(testFlag1) + "\n\n" +
strings.TrimSpace(testFlag2) + "\n")
os.Exit(2)
}
printUsage(os.Stderr)

View File

@ -33,9 +33,11 @@ func init() {
cmdTest.Run = runTest
}
const testUsage = "test [-c] [-i] [build and test flags] [packages] [flags for test binary]"
var cmdTest = &Command{
CustomFlags: true,
UsageLine: "test [-c] [-i] [build and test flags] [packages] [flags for test binary]",
UsageLine: testUsage,
Short: "test packages",
Long: `
'Go test' automates testing the packages named by the import paths.
@ -64,6 +66,21 @@ with source in the current directory, including tests, and runs the tests.
The package is built in a temporary directory so it does not interfere with the
non-test installation.
` + strings.TrimSpace(testFlag1) + ` See 'go help testflag' for details.
If the test binary needs any other flags, they should be presented after the
package names. The go tool treats as a flag the first argument that begins with
a minus sign that it does not recognize itself; that argument and all subsequent
arguments are passed as arguments to the test binary.
For more about build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
See also: go build, go vet.
`,
}
const testFlag1 = `
In addition to the build flags, the flags handled by 'go test' itself are:
-c
@ -83,21 +100,9 @@ In addition to the build flags, the flags handled by 'go test' itself are:
Compile the test binary to the named file.
The test still runs (unless -c or -i is specified).
The test binary also accepts flags that control execution of the test; these
flags are also accessible by 'go test'. See 'go help testflag' for details.
If the test binary needs any other flags, they should be presented after the
package names. The go tool treats as a flag the first argument that begins with
a minus sign that it does not recognize itself; that argument and all subsequent
arguments are passed as arguments to the test binary.
For more about build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
See also: go build, go vet.
`,
}
flags are also accessible by 'go test'.
`
var helpTestflag = &Command{
UsageLine: "testflag",
@ -114,6 +119,11 @@ options of pprof control how the information is presented.
The following flags are recognized by the 'go test' command and
control the execution of any test:
` + strings.TrimSpace(testFlag2) + `
`,
}
const testFlag2 = `
-bench regexp
Run benchmarks matching the regular expression.
By default, no benchmarks run. To run all benchmarks,
@ -238,8 +248,7 @@ The test flags that generate profiles (other than for coverage) also
leave the test binary in pkg.test for use when analyzing the profiles.
Flags not recognized by 'go test' must be placed after any specified packages.
`,
}
`
var helpTestfunc = &Command{
UsageLine: "testfunc",