aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/test/testflag.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-07-02 12:32:13 -0700
committerIan Lance Taylor <iant@golang.org>2020-07-06 21:47:57 +0000
commit6a167c73977384f3646f4651901fe38347711b10 (patch)
tree9475bb3cd3f8d5dd451537510f37f407106f07dc /src/cmd/go/internal/test/testflag.go
parent20afbe86beda00676a608399638887538bd8f669 (diff)
downloadgo-6a167c73977384f3646f4651901fe38347711b10.tar.gz
go-6a167c73977384f3646f4651901fe38347711b10.zip
cmd/go: display test binary output if invoked with -help
Fixes #39997 Change-Id: I87ea616bac809b96fcd40f3bbdbbf1c603b9d00e Reviewed-on: https://go-review.googlesource.com/c/go/+/240878 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/test/testflag.go')
-rw-r--r--src/cmd/go/internal/test/testflag.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index 9a3042bfe7..1ff34f7445 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -333,6 +333,23 @@ func testFlags(args []string) (packageNames, passToTest []string) {
injectedFlags = append(injectedFlags, "-test.outputdir="+testOutputDir)
}
+ // If the user is explicitly passing -help or -h, show output
+ // of the test binary so that the help output is displayed
+ // even though the test will exit with success.
+ // This loop is imperfect: it will do the wrong thing for a case
+ // like -args -test.outputdir -help. Such cases are probably rare,
+ // and getting this wrong doesn't do too much harm.
+helpLoop:
+ for _, arg := range explicitArgs {
+ switch arg {
+ case "--":
+ break helpLoop
+ case "-h", "-help", "--help":
+ testHelp = true
+ break helpLoop
+ }
+ }
+
// Ensure that -race and -covermode are compatible.
if testCoverMode == "" {
testCoverMode = "set"