aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-07-14 01:08:30 -0400
committerRuss Cox <rsc@golang.org>2015-07-15 05:34:13 +0000
commit307d6919bdc4254206b3376eef51d53f2a081970 (patch)
tree4fc5c04b9969c328d2ba8bab8d8d2dfd737d98ec
parentef6d3a94fbc631299d22c0b0eb09f4a20703f7e0 (diff)
downloadgo-307d6919bdc4254206b3376eef51d53f2a081970.tar.gz
go-307d6919bdc4254206b3376eef51d53f2a081970.zip
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>
-rw-r--r--src/cmd/go/alldocs.go3
-rw-r--r--src/cmd/go/main.go4
-rw-r--r--src/cmd/go/test.go43
3 files changed, 30 insertions, 20 deletions
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index b85e924486..060385c632 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -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
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go
index 659484b76a..c8267e919e 100644
--- a/src/cmd/go/main.go
+++ b/src/cmd/go/main.go
@@ -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)
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index aeb4228600..bae6e04b53 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -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",