...
1[short] skip
2
3go test flag_test.go -v -args -v=7 # Two distinct -v flags
4go test -v flag_test.go -args -v=7 # Two distinct -v flags
5
6# Using a custom flag mixed with regular 'go test' flags should be OK.
7go test -count=1 -custom -args -v=7
8
9# However, it should be an error to use custom flags when -c is used,
10# since we know for sure that no test binary will run at all.
11! go test -c -custom
12stderr '^go: unknown flag -custom cannot be used with -c$'
13
14# The same should apply even if -c comes after a custom flag.
15! go test -custom -c
16stderr '^go: unknown flag -custom cannot be used with -c$'
17
18-- go.mod --
19module m
20-- flag_test.go --
21package flag_test
22
23import (
24 "flag"
25 "log"
26 "testing"
27)
28
29var v = flag.Int("v", 0, "v flag")
30
31var custom = flag.Bool("custom", false, "")
32
33// Run this as go test pkg -v=7
34func TestVFlagIsSet(t *testing.T) {
35 if *v != 7 {
36 log.Fatal("v flag not set")
37 }
38}
View as plain text