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