mirror of
https://github.com/golang/go
synced 2024-11-18 18:24:48 -07:00
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
This commit is contained in:
parent
9a5b055b95
commit
7e6e502f9b
@ -1085,6 +1085,20 @@ fi
|
|||||||
unset GOPATH
|
unset GOPATH
|
||||||
rm -rf $d
|
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
|
# clean up
|
||||||
if $started; then stop; fi
|
if $started; then stop; fi
|
||||||
rm -rf testdata/bin testdata/bin1
|
rm -rf testdata/bin testdata/bin1
|
||||||
|
1
src/cmd/go/testdata/src/vetpkg/a_test.go
vendored
Normal file
1
src/cmd/go/testdata/src/vetpkg/a_test.go
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
package p_test
|
7
src/cmd/go/testdata/src/vetpkg/b.go
vendored
Normal file
7
src/cmd/go/testdata/src/vetpkg/b.go
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package p
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func f() {
|
||||||
|
fmt.Printf("%d")
|
||||||
|
}
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "path/filepath"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
addBuildFlagsNX(cmdVet)
|
addBuildFlagsNX(cmdVet)
|
||||||
}
|
}
|
||||||
@ -28,10 +30,21 @@ See also: go fmt, go fix.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runVet(cmd *Command, args []string) {
|
func runVet(cmd *Command, args []string) {
|
||||||
for _, pkg := range packages(args) {
|
for _, p := range packages(args) {
|
||||||
// Use pkg.gofiles instead of pkg.Dir so that
|
// Vet expects to be given a set of files all from the same package.
|
||||||
// the command only applies to this package,
|
// Run once for package p and once for package p_test.
|
||||||
// not to packages in subdirectories.
|
if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 {
|
||||||
run(tool("vet"), relPaths(stringList(pkg.gofiles, pkg.sfiles)))
|
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))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user