aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-06 14:49:22 -0400
committerRuss Cox <rsc@golang.org>2014-10-06 14:49:22 -0400
commit7e6e502f9b9a253603c43bb783b82a043a67c3d4 (patch)
tree0716e2a9cee4840df19c3f8990d56ca6c9da8366 /src
parent9a5b055b95c6719083f32c1f8089725a0a890425 (diff)
downloadgo-7e6e502f9b9a253603c43bb783b82a043a67c3d4.tar.xz
cmd/go: fix 'go vet' of package with external tests
For example, fixes 'go vet syscall', which has source files in package syscall_test. Fixes #8511. LGTM=r R=golang-codereviews, r CC=golang-codereviews, iant https://golang.org/cl/152220044
Diffstat (limited to 'src')
-rwxr-xr-xsrc/cmd/go/test.bash14
-rw-r--r--src/cmd/go/testdata/src/vetpkg/a_test.go1
-rw-r--r--src/cmd/go/testdata/src/vetpkg/b.go7
-rw-r--r--src/cmd/go/vet.go23
4 files changed, 40 insertions, 5 deletions
diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash
index 6a72bcde07..652ef3b5b6 100755
--- a/src/cmd/go/test.bash
+++ b/src/cmd/go/test.bash
@@ -1085,6 +1085,20 @@ fi
unset GOPATH
rm -rf $d
+TEST go vet with external tests
+d=$(mktemp -d -t testgoXXX)
+export GOPATH=$(pwd)/testdata
+if ./testgo vet vetpkg >$d/err 2>&1; then
+ echo "go vet vetpkg passes incorrectly"
+ ok=false
+elif ! grep -q 'missing argument for Printf' $d/err; then
+ echo "go vet vetpkg did not find missing argument for Printf"
+ cat $d/err
+ ok=false
+fi
+unset GOPATH
+rm -rf $d
+
# clean up
if $started; then stop; fi
rm -rf testdata/bin testdata/bin1
diff --git a/src/cmd/go/testdata/src/vetpkg/a_test.go b/src/cmd/go/testdata/src/vetpkg/a_test.go
new file mode 100644
index 0000000000..9b64e8e1a2
--- /dev/null
+++ b/src/cmd/go/testdata/src/vetpkg/a_test.go
@@ -0,0 +1 @@
+package p_test
diff --git a/src/cmd/go/testdata/src/vetpkg/b.go b/src/cmd/go/testdata/src/vetpkg/b.go
new file mode 100644
index 0000000000..99e18f63dc
--- /dev/null
+++ b/src/cmd/go/testdata/src/vetpkg/b.go
@@ -0,0 +1,7 @@
+package p
+
+import "fmt"
+
+func f() {
+ fmt.Printf("%d")
+}
diff --git a/src/cmd/go/vet.go b/src/cmd/go/vet.go
index ffb4318373..de7befc611 100644
--- a/src/cmd/go/vet.go
+++ b/src/cmd/go/vet.go
@@ -4,6 +4,8 @@
package main
+import "path/filepath"
+
func init() {
addBuildFlagsNX(cmdVet)
}
@@ -28,10 +30,21 @@ See also: go fmt, go fix.
}
func runVet(cmd *Command, args []string) {
- for _, pkg := range packages(args) {
- // Use pkg.gofiles instead of pkg.Dir so that
- // the command only applies to this package,
- // not to packages in subdirectories.
- run(tool("vet"), relPaths(stringList(pkg.gofiles, pkg.sfiles)))
+ for _, p := range packages(args) {
+ // Vet expects to be given a set of files all from the same package.
+ // Run once for package p and once for package p_test.
+ if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 {
+ runVetFiles(p, stringList(p.GoFiles, p.CgoFiles, p.TestGoFiles, p.SFiles))
+ }
+ if len(p.XTestGoFiles) > 0 {
+ runVetFiles(p, stringList(p.XTestGoFiles))
+ }
+ }
+}
+
+func runVetFiles(p *Package, files []string) {
+ for i := range files {
+ files[i] = filepath.Join(p.Dir, files[i])
}
+ run(tool("vet"), relPaths(files))
}