Commit d21953df authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/test: prepend -test.timeout rather than appending

Tests may accept positional arguments, in which case the -test.timeout
flag must be passed before those arguments.

Fixes #34072

Change-Id: I5b92d7c0edc4f9e1efb63b0733937b76236c0eff
Reviewed-on: https://go-review.googlesource.com/c/go/+/193297
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 5ff38e47
...@@ -572,8 +572,9 @@ func runTest(cmd *base.Command, args []string) { ...@@ -572,8 +572,9 @@ func runTest(cmd *base.Command, args []string) {
} }
// Pass timeout to tests if it exists. // Pass timeout to tests if it exists.
// Prepend rather than appending so that it appears before positional arguments.
if testActualTimeout > 0 { if testActualTimeout > 0 {
testArgs = append(testArgs, "-test.timeout="+testActualTimeout.String()) testArgs = append([]string{"-test.timeout=" + testActualTimeout.String()}, testArgs...)
} }
// show passing test output (after buffering) with -v flag. // show passing test output (after buffering) with -v flag.
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
env GO111MODULE=off env GO111MODULE=off
cd a cd a
# No timeout is passed via 'go test' command. # If no timeout is set explicitly, 'go test' should set
go test -v # -test.timeout to its internal deadline.
go test -v . --
stdout '10m0s' stdout '10m0s'
# Timeout is passed via 'go test' command. # An explicit -timeout argument should be propagated to -test.timeout.
go test -v -timeout 30m go test -v -timeout 30m . --
stdout '30m0s' stdout '30m0s'
-- a/timeout_test.go -- -- a/timeout_test.go --
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment