]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: don't run buildtag check when in vetxonly mode
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 28 Jun 2018 16:18:01 +0000 (17:18 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 29 Jun 2018 08:33:11 +0000 (08:33 +0000)
The check was running in the loop that read source files in, much before
any of the other checks ran. Vetxonly makes vet exit early, but after
all the source files have been read.

To fix this, simply run the buildtag check along with all the other
checks that get run on specific syntax tree nodes.

Add a cmd/go test with go test -a, to ensure that the issue as reported
is fixed.

Fixes #26102.

Change-Id: If6e3b9418ffa8166c0f982668b0d10872283776a
Reviewed-on: https://go-review.googlesource.com/121395
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/testdata/src/vetfail/p1/p1.go
src/cmd/vet/main.go

index cb4a1a04b91d47e6d0dbcce6cd80ddd6352272ad..c2d85c873095bf92cd8c579527a40dc3b6d8644e 100644 (file)
@@ -5817,6 +5817,11 @@ func TestTestVet(t *testing.T) {
        tg.runFail("test", "vetfail/...")
        tg.grepStderr(`Printf format %d`, "did not diagnose bad Printf")
        tg.grepStdout(`ok\s+vetfail/p2`, "did not run vetfail/p2")
+
+       // Use -a so that we need to recompute the vet-specific export data for
+       // vetfail/p1.
+       tg.run("test", "-a", "vetfail/p2")
+       tg.grepStderrNot(`invalid.*constraint`, "did diagnose bad build constraint in vetxonly mode")
 }
 
 func TestTestVetRebuild(t *testing.T) {
index 248317b779a3a4424c66c4fad6e983f4cd03ac12..eaa9b18333168d689e50df2e0c028465860ff14d 100644 (file)
@@ -1,3 +1,5 @@
+// +build !foo-bar
+
 package p1
 
 import "fmt"
index 959a536d257c10e31c6c119807faddf2fd79651e..28da9e2d745f5d745e9964570061a15bd92e3177 100644 (file)
@@ -489,7 +489,6 @@ func doPackage(names []string, basePkg *Package) *Package {
                        file:    parsedFile,
                        dead:    make(map[ast.Node]bool),
                }
-               checkBuildTag(file)
                files = append(files, file)
        }
        if len(astFiles) == 0 {
@@ -541,6 +540,7 @@ func doPackage(names []string, basePkg *Package) *Package {
                }
        }
        for _, file := range files {
+               checkBuildTag(file)
                file.checkers = chk
                if file.file != nil {
                        file.walkFile(file.name, file.file)