1 [short] skip 'runs test'
2
3 env GO111MODULE=on
4
5 # Issue 35837: "go vet -<analyzer> <std package>" should use the requested
6 # analyzers, not the default analyzers for 'go test'.
7 go vet -n -buildtags=false runtime
8 stderr '-buildtags=false'
9 ! stderr '-unsafeptr=false'
10
11 # Issue 37030: "go vet <std package>" without other flags should disable the
12 # unsafeptr check by default.
13 go vet -n runtime
14 stderr '-unsafeptr=false'
15 ! stderr '-unreachable=false'
16
17 # However, it should be enabled if requested explicitly.
18 go vet -n -unsafeptr runtime
19 stderr '-unsafeptr'
20 ! stderr '-unsafeptr=false'
21
22 # -unreachable is disabled during test but on during plain vet.
23 # The -a makes sure the vet result is not cached, or else we won't print the command line.
24 go test -a -n runtime
25 stderr '-unreachable=false'
26
27 # A flag terminator should be allowed before the package list.
28 go vet -n -- .
29
30 [short] stop
31
32 # Analyzer flags should be included from GOFLAGS, and should override
33 # the defaults.
34 go vet .
35 env GOFLAGS='-tags=buggy'
36 ! go vet .
37 stderr 'possible Printf formatting directive'
38
39 # Enabling one analyzer in GOFLAGS should disable the rest implicitly...
40 env GOFLAGS='-tags=buggy -unsafeptr'
41 go vet .
42
43 # ...but enabling one on the command line should not disable the analyzers
44 # enabled via GOFLAGS.
45 env GOFLAGS='-tags=buggy -printf'
46 ! go vet -unsafeptr
47 stderr 'possible Printf formatting directive'
48
49 # Analyzer flags don't exist unless we're running 'go vet',
50 # and we shouldn't run the vet tool to discover them otherwise.
51 # (Maybe someday we'll hard-code the analyzer flags for the default vet
52 # tool to make this work, but not right now.)
53 env GOFLAGS='-unsafeptr'
54 ! go list .
55 stderr 'go: parsing \$GOFLAGS: unknown flag -unsafeptr'
56 env GOFLAGS=
57
58 # "go test" on a user package should by default enable an explicit list of analyzers.
59 go test -n -run=none .
60 stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
61
62 # An explicitly-empty -vet argument should imply the default analyzers.
63 go test -n -vet= -run=none .
64 stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
65
66 # "go test" on a standard package should by default disable an explicit list.
67 go test -a -n -run=none encoding/binary
68 stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
69
70 go test -a -n -vet= -run=none encoding/binary
71 stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
72
73 # Both should allow users to override via the -vet flag.
74 go test -a -n -vet=unreachable -run=none .
75 stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
76 go test -a -n -vet=unreachable -run=none encoding/binary
77 stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
78
79 -- go.mod --
80 module example.com/x
81 -- x.go --
82 package x
83 -- x_test.go --
84 package x
85 -- x_tagged.go --
86 // +build buggy
87
88 package x
89
90 import "fmt"
91
92 func init() {
93 fmt.Sprint("%s") // oops!
94 }
95
View as plain text