Skip to content

Commit ce3dec5

Browse files
committed
cmd/go: refer to testflag help in go test -help output
The change makes it easier for a user to get to the page where she can check supported test flags, by adding 'go test testflag' reference to the 'go test -help' output. Fix #30365
1 parent f495f54 commit ce3dec5

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/cmd/go/internal/base/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Command struct {
3030
Run func(cmd *Command, args []string)
3131

3232
// UsageLine is the one-line usage message.
33-
// The first word in the line is taken to be the command name.
33+
// The words between "go" and the first flag or argument in the line are taken to be the command name.
3434
UsageLine string
3535

3636
// Short is the short description shown in the 'go help' output.

src/cmd/go/internal/test/test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,16 @@ var testVetFlags = []string{
514514
// "-unusedresult",
515515
}
516516

517+
func testCmdUsage() {
518+
fmt.Fprintf(os.Stderr, "usage: %s\n", CmdTest.UsageLine)
519+
fmt.Fprintf(os.Stderr, "Run 'go help %s' and 'go help %s' for details.\n", CmdTest.LongName(), HelpTestflag.LongName())
520+
os.Exit(2)
521+
}
522+
517523
func runTest(cmd *base.Command, args []string) {
518524
modload.LoadTests = true
519525

520-
pkgArgs, testArgs = testFlags(cmd.Usage, args)
526+
pkgArgs, testArgs = testFlags(testCmdUsage, args)
521527

522528
work.FindExecCmd() // initialize cached result
523529

src/cmd/go/testdata/script/help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ stderr 'Run ''go tool vet -help'' for the vet tool''s flags'
4242
# lines.
4343
! go test -h
4444
stderr 'usage: go test'
45-
stderr 'Run ''go help test'' for details'
45+
stderr 'Run ''go help test'' and ''go help testflag'' for details.'
4646

4747
# go help get shows usage for get
4848
go help get

0 commit comments

Comments
 (0)