Skip to content

Commit 834d224

Browse files
cuonglmianlancetaylor
authored andcommitted
cm/go/internal/test: make vet run when using go test -c
Fixes #26451 Change-Id: Icd8d6d55dc42adb5c8953787eec7eb29ba46b2aa Reviewed-on: https://go-review.googlesource.com/125215 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 59699aa commit 834d224

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

misc/cgo/testsanitizers/cc_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,13 @@ func (c *config) checkRuntime() (skip bool, err error) {
381381
return false, err
382382
}
383383
cmd.Args = append(cmd.Args, "-dM", "-E", "../../../src/runtime/cgo/libcgo.h")
384+
cmdStr := strings.Join(cmd.Args, " ")
384385
out, err := cmd.CombinedOutput()
385386
if err != nil {
386-
return false, fmt.Errorf("%#q exited with %v\n%s", strings.Join(cmd.Args, " "), err, out)
387+
return false, fmt.Errorf("%#q exited with %v\n%s", cmdStr, err, out)
387388
}
388389
if !bytes.Contains(out, []byte("#define CGO_TSAN")) {
389-
return true, fmt.Errorf("%#q did not define CGO_TSAN")
390+
return true, fmt.Errorf("%#q did not define CGO_TSAN", cmdStr)
390391
}
391392
return false, nil
392393
}

src/cmd/go/internal/test/test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,10 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
892892
}
893893
runAction = installAction // make sure runAction != nil even if not running test
894894
}
895+
var vetRunAction *work.Action
895896
if testC {
896897
printAction = &work.Action{Mode: "test print (nop)", Package: p, Deps: []*work.Action{runAction}} // nop
898+
vetRunAction = printAction
897899
} else {
898900
// run test
899901
c := new(runCache)
@@ -906,12 +908,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
906908
TryCache: c.tryCache,
907909
Objdir: testDir,
908910
}
909-
if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
910-
addTestVet(b, ptest, runAction, installAction)
911-
}
912-
if pxtest != nil {
913-
addTestVet(b, pxtest, runAction, installAction)
914-
}
911+
vetRunAction = runAction
915912
cleanAction = &work.Action{
916913
Mode: "test clean",
917914
Func: builderCleanTest,
@@ -928,6 +925,14 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
928925
IgnoreFail: true, // print even if test failed
929926
}
930927
}
928+
929+
if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
930+
addTestVet(b, ptest, vetRunAction, installAction)
931+
}
932+
if pxtest != nil {
933+
addTestVet(b, pxtest, vetRunAction, installAction)
934+
}
935+
931936
if installAction != nil {
932937
if runAction != installAction {
933938
installAction.Deps = append(installAction.Deps, runAction)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! go test -c compile_binary/...
2+
stderr 'build comment'
3+
4+
-- compile_binary/foo_test.go --
5+
//+build foo
6+
package foo

0 commit comments

Comments
 (0)