Skip to content

Commit bbc4351

Browse files
committed
cmd/go: add -tags option to go vet
Actually add all build flags, so we also get things like -race. Fixes #10228. Change-Id: I5f77dda9d1ee3208e1833702f12f68c2731c4b22 Reviewed-on: https://go-review.googlesource.com/10697 Reviewed-by: Russ Cox <[email protected]>
1 parent 3a1f163 commit bbc4351

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/cmd/go/alldocs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ Run go tool vet on packages
699699
700700
Usage:
701701
702-
go vet [-n] [-x] [packages]
702+
go vet [-n] [-x] [build flags] [packages]
703703
704704
Vet runs the Go vet command on the packages named by the import paths.
705705
@@ -711,6 +711,8 @@ To run the vet tool with specific options, run 'go tool vet'.
711711
The -n flag prints commands that would be executed.
712712
The -x flag prints commands as they are executed.
713713
714+
For more about build flags, see 'go help build'.
715+
714716
See also: go fmt, go fix.
715717
716718

src/cmd/go/test.bash

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,22 @@ fi
12901290
unset GOPATH
12911291
rm -rf $d
12921292

1293+
TEST go vet with -tags
1294+
d=$(mktemp -d -t testgoXXX)
1295+
export GOPATH=$d
1296+
./testgo get golang.org/x/tools/cmd/vet
1297+
export GOPATH=$(pwd)/testdata
1298+
if ./testgo vet -tags tagtest vetpkg >$d/err 2>&1; then
1299+
echo "go vet vetpkg passes incorrectly"
1300+
ok=false
1301+
elif ! grep -q 'c\.go.*wrong number of args for format' $d/err; then
1302+
echo "go vet vetpkg did not scan tagged file"
1303+
cat $d/err
1304+
ok=false
1305+
fi
1306+
unset GOPATH
1307+
rm -rf $d
1308+
12931309
TEST go get ./rsc.io/toolstash '(golang.org/issue/9767)'
12941310
d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
12951311
export GOPATH=$d

src/cmd/go/testdata/src/vetpkg/c.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build tagtest
2+
3+
package p
4+
5+
import "fmt"
6+
7+
func g() {
8+
fmt.Printf("%d", 3, 4)
9+
}

src/cmd/go/vet.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package main
77
import "path/filepath"
88

99
func init() {
10-
addBuildFlagsNX(cmdVet)
10+
addBuildFlags(cmdVet)
1111
}
1212

1313
var cmdVet = &Command{
1414
Run: runVet,
15-
UsageLine: "vet [-n] [-x] [packages]",
15+
UsageLine: "vet [-n] [-x] [build flags] [packages]",
1616
Short: "run go tool vet on packages",
1717
Long: `
1818
Vet runs the Go vet command on the packages named by the import paths.
@@ -25,6 +25,8 @@ To run the vet tool with specific options, run 'go tool vet'.
2525
The -n flag prints commands that would be executed.
2626
The -x flag prints commands as they are executed.
2727
28+
For more about build flags, see 'go help build'.
29+
2830
See also: go fmt, go fix.
2931
`,
3032
}

0 commit comments

Comments
 (0)