You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# For backward-compatibility with previous releases of the 'go' command,
13
-
# arguments that appear after unrecognized flags should not be treated
13
+
# arguments that appear after unrecognized flags should not be treated
14
14
# as packages, even if they are unambiguously not arguments to flags.
15
15
# Even though ./x looks like a package path, the real package should be
16
16
# the implicit '.'.
17
17
! go test --answer=42 ./x
18
18
stderr '^no Go files in .+$'
19
19
! stderr '/x'
20
20
21
+
# However, *flags* that appear after unrecognized flags should still be
22
+
# interpreted as flags, under the (possibly-erroneous) assumption that
23
+
# unrecognized flags are non-boolean.
24
+
25
+
go test -v -x ./x -timeout 24h -boolflag=true foo -timeout 25h
26
+
stdout 'args: foo -timeout 25h'
27
+
stdout 'timeout: 24h0m0s$' # -timeout is unambiguously not a flag, so the real flag wins.
28
+
29
+
go test -v -x ./x -timeout 24h -boolflag foo -timeout 25h
30
+
stdout 'args: foo -test\.timeout=25h0m0s' # For legacy reasons, '-timeout ' is erroneously rewritten to -test.timeout; see https://golang.org/issue/40763.
31
+
stdout 'timeout: 24h0m0s$' # Actual flag wins.
32
+
33
+
go test -v -x ./x -timeout 24h -stringflag foo -timeout 25h
34
+
stdout 'args: $'
35
+
stdout 'timeout: 25h0m0s$' # Later flag wins.
36
+
21
37
# An explicit '-outputdir=' argument should set test.outputdir
22
38
# to the 'go' command's working directory, not zero it out
23
39
# for the test binary.
@@ -30,23 +46,23 @@ exists ./cover.out
30
46
# with the 'test.' prefix in the GOFLAGS entry...
31
47
env GOFLAGS='-test.timeout=24h0m0s -count=1'
32
48
go test -v -x ./x
33
-
stdout '.*: 24h0m0s$'
49
+
stdout 'timeout: 24h0m0s$'
34
50
stderr '-test.count=1'
35
51
36
52
# ...or without.
37
53
env GOFLAGS='-timeout=24h0m0s -count=1'
38
54
go test -v -x ./x
39
-
stdout '.*: 24h0m0s$'
55
+
stdout 'timeout: 24h0m0s$'
40
56
stderr '-test.count=1'
41
57
42
58
# Arguments from the command line should override GOFLAGS...
43
59
go test -v -x -timeout=25h0m0s ./x
44
-
stdout '.*: 25h0m0s$'
60
+
stdout 'timeout: 25h0m0s$'
45
61
stderr '-test.count=1'
46
62
47
63
# ...even if they use a different flag name.
48
64
go test -v -x -test.timeout=26h0m0s ./x
49
-
stdout '.*: 26h0m0s$'
65
+
stdout 'timeout: 26h0m0s$'
50
66
stderr '-test\.timeout=26h0m0s'
51
67
! stderr 'timeout=24h0m0s'
52
68
stderr '-test.count=1'
@@ -99,11 +115,18 @@ package x
99
115
100
116
import (
101
117
"flag"
118
+
"strings"
102
119
"testing"
103
120
)
104
121
105
122
var _ = flag.String("usage_message", "", "dummy flag to check usage message")
123
+
var boolflag = flag.Bool("boolflag", false, "ignored boolean flag")
124
+
var stringflag = flag.String("stringflag", "", "ignored string flag")
0 commit comments