...
1[short] skip 'runs test'
2
3env GO111MODULE=on
4
5# Issue 35837: "go vet -<analyzer> <std package>" should use the requested
6# analyzers, not the default analyzers for 'go test'.
7go vet -n -buildtags=false runtime
8stderr '-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.
13go vet -n runtime
14stderr '-unsafeptr=false'
15! stderr '-unreachable=false'
16
17# However, it should be enabled if requested explicitly.
18go vet -n -unsafeptr runtime
19stderr '-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.
24go test -a -n runtime
25stderr '-unreachable=false'
26
27# A flag terminator should be allowed before the package list.
28go vet -n -- .
29
30[short] stop
31
32# Analyzer flags should be included from GOFLAGS, and should override
33# the defaults.
34go vet .
35env GOFLAGS='-tags=buggy'
36! go vet .
37stderr 'possible Printf formatting directive'
38
39# Enabling one analyzer in GOFLAGS should disable the rest implicitly...
40env GOFLAGS='-tags=buggy -unsafeptr'
41go vet .
42
43# ...but enabling one on the command line should not disable the analyzers
44# enabled via GOFLAGS.
45env GOFLAGS='-tags=buggy -printf'
46! go vet -unsafeptr
47stderr '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.)
53env GOFLAGS='-unsafeptr'
54! go list .
55stderr 'go: parsing \$GOFLAGS: unknown flag -unsafeptr'
56env GOFLAGS=
57
58# "go test" on a user package should by default enable an explicit list of analyzers.
59go test -n -run=none .
60stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
61
62# An explicitly-empty -vet argument should imply the default analyzers.
63go test -n -vet= -run=none .
64stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
65
66# "go test" on a standard package should by default disable an explicit list.
67go test -a -n -run=none encoding/binary
68stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
69
70go test -a -n -vet= -run=none encoding/binary
71stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
72
73# Both should allow users to override via the -vet flag.
74go test -a -n -vet=unreachable -run=none .
75stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
76go test -a -n -vet=unreachable -run=none encoding/binary
77stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
78
79-- go.mod --
80module example.com/x
81-- x.go --
82package x
83-- x_test.go --
84package x
85-- x_tagged.go --
86// +build buggy
87
88package x
89
90import "fmt"
91
92func init() {
93 fmt.Sprint("%s") // oops!
94}
View as plain text