]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: print all test flags in "go test -h"
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 05:08:30 +0000 (01:08 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 05:34:13 +0000 (05:34 +0000)
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>
src/cmd/go/alldocs.go
src/cmd/go/main.go
src/cmd/go/test.go

index b85e924486cc6403018de193db5625b696e081c4..060385c6323b2edb6ab67b30f325ca01c2e37fec 100644 (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
index 659484b76afa98f93af470ef658ae70be8dd1d31..c8267e919e47878b0789b3654e14904cd547829f 100644 (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)
index aeb422860022d2142c34ea5590728f9cdab35387..bae6e04b530fe1169998ece2d199bffd9e3ba112 100644 (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",