]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.13] cmd/go/internal/test: prepend -test.timeout rather than appending
authorBryan C. Mills <bcmills@google.com>
Wed, 4 Sep 2019 16:59:41 +0000 (12:59 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 5 Sep 2019 11:25:38 +0000 (11:25 +0000)
Tests may accept positional arguments, in which case the -test.timeout
flag must be passed before those arguments.

Updates #34072
Fixes #34083

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: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit d21953df047868ed3bcfd0172a6c1672642f5b4a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/193269

src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_timeout.txt

index 95000011d83b48791350bd7316c782841576f6ca..8141e31c991aeebcb2b9cf119bd606aff622daa2 100644 (file)
@@ -572,8 +572,9 @@ func runTest(cmd *base.Command, args []string) {
        }
 
        // Pass timeout to tests if it exists.
+       // Prepend rather than appending so that it appears before positional arguments.
        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.
index 8dead0a439ad2b124c9613c96ed88343685fa1cc..4de4df450821d4ebf9ff9b61b2c4874061118797 100644 (file)
@@ -2,12 +2,13 @@
 env GO111MODULE=off
 cd a
 
-# No timeout is passed via 'go test' command.
-go test -v
+# If no timeout is set explicitly, 'go test' should set
+# -test.timeout to its internal deadline.
+go test -v . --
 stdout '10m0s'
 
-# Timeout is passed via 'go test' command.
-go test -v -timeout 30m
+# An explicit -timeout argument should be propagated to -test.timeout.
+go test -v -timeout 30m . --
 stdout '30m0s'
 
 -- a/timeout_test.go --
@@ -19,4 +20,4 @@ import (
 )
 func TestTimeout(t *testing.T) {
        fmt.Println(flag.Lookup("test.timeout").Value.String())
-}
\ No newline at end of file
+}