]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add -tags option to go vet
authorRob Pike <r@golang.org>
Thu, 4 Jun 2015 21:28:14 +0000 (14:28 -0700)
committerRob Pike <r@golang.org>
Fri, 5 Jun 2015 05:39:36 +0000 (05:39 +0000)
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 <rsc@golang.org>
src/cmd/go/alldocs.go
src/cmd/go/test.bash
src/cmd/go/testdata/src/vetpkg/c.go [new file with mode: 0644]
src/cmd/go/vet.go

index 2c4451a0a7dc404db3e3abfc1ab9efa0624c6d70..3abe5b91bdc3965de18022749f6f0b71f5ab6940 100644 (file)
@@ -699,7 +699,7 @@ Run go tool vet on packages
 
 Usage:
 
-       go vet [-n] [-x] [packages]
+       go vet [-n] [-x] [build flags] [packages]
 
 Vet runs the Go vet command on the packages named by the import paths.
 
@@ -711,6 +711,8 @@ To run the vet tool with specific options, run 'go tool vet'.
 The -n flag prints commands that would be executed.
 The -x flag prints commands as they are executed.
 
+For more about build flags, see 'go help build'.
+
 See also: go fmt, go fix.
 
 
index 4f36584de38216ab05f69a085df5beaaf1102e6c..d9ac3f793e5ee39eb58973fd5ca89aa33e36dae3 100755 (executable)
@@ -1290,6 +1290,22 @@ fi
 unset GOPATH
 rm -rf $d
 
+TEST go vet with -tags
+d=$(mktemp -d -t testgoXXX)
+export GOPATH=$d
+./testgo get golang.org/x/tools/cmd/vet
+export GOPATH=$(pwd)/testdata
+if ./testgo vet -tags tagtest vetpkg >$d/err 2>&1; then
+       echo "go vet vetpkg passes incorrectly"
+       ok=false
+elif ! grep -q 'c\.go.*wrong number of args for format' $d/err; then
+       echo "go vet vetpkg did not scan tagged file"
+       cat $d/err
+       ok=false
+fi
+unset GOPATH
+rm -rf $d
+
 TEST go get ./rsc.io/toolstash '(golang.org/issue/9767)'
 d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
 export GOPATH=$d
diff --git a/src/cmd/go/testdata/src/vetpkg/c.go b/src/cmd/go/testdata/src/vetpkg/c.go
new file mode 100644 (file)
index 0000000..ef5648f
--- /dev/null
@@ -0,0 +1,9 @@
+// +build tagtest
+
+package p
+
+import "fmt"
+
+func g() {
+       fmt.Printf("%d", 3, 4)
+}
index 2634536afffc81aa1acea1d482c8b0e1b2cea456..902edbbe730108c2322661015ad6b31d5443df2b 100644 (file)
@@ -7,12 +7,12 @@ package main
 import "path/filepath"
 
 func init() {
-       addBuildFlagsNX(cmdVet)
+       addBuildFlags(cmdVet)
 }
 
 var cmdVet = &Command{
        Run:       runVet,
-       UsageLine: "vet [-n] [-x] [packages]",
+       UsageLine: "vet [-n] [-x] [build flags] [packages]",
        Short:     "run go tool vet on packages",
        Long: `
 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'.
 The -n flag prints commands that would be executed.
 The -x flag prints commands as they are executed.
 
+For more about build flags, see 'go help build'.
+
 See also: go fmt, go fix.
        `,
 }