]> Cypherpunks repositories - gostls13.git/commitdiff
cm/go/internal/test: make vet run when using go test -c
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Fri, 20 Jul 2018 06:21:45 +0000 (13:21 +0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 20 Jul 2018 19:57:26 +0000 (19:57 +0000)
Fixes #26451

Change-Id: Icd8d6d55dc42adb5c8953787eec7eb29ba46b2aa
Reviewed-on: https://go-review.googlesource.com/125215
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/testsanitizers/cc_test.go
src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_compile_binary.txt [new file with mode: 0644]

index 306844bdc80a6b56c9792837b7176c78545b9399..f09ad52ceeebef0fc4bc087c7d79252c715d6c87 100644 (file)
@@ -381,12 +381,13 @@ func (c *config) checkRuntime() (skip bool, err error) {
                return false, err
        }
        cmd.Args = append(cmd.Args, "-dM", "-E", "../../../src/runtime/cgo/libcgo.h")
+       cmdStr := strings.Join(cmd.Args, " ")
        out, err := cmd.CombinedOutput()
        if err != nil {
-               return false, fmt.Errorf("%#q exited with %v\n%s", strings.Join(cmd.Args, " "), err, out)
+               return false, fmt.Errorf("%#q exited with %v\n%s", cmdStr, err, out)
        }
        if !bytes.Contains(out, []byte("#define CGO_TSAN")) {
-               return true, fmt.Errorf("%#q did not define CGO_TSAN")
+               return true, fmt.Errorf("%#q did not define CGO_TSAN", cmdStr)
        }
        return false, nil
 }
index 80c99b75765fcd1d2ae73bb0917fd04a36616d29..052c81e28c2d60fe8c2790c84985e22960d987ce 100644 (file)
@@ -892,8 +892,10 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
                }
                runAction = installAction // make sure runAction != nil even if not running test
        }
+       var vetRunAction *work.Action
        if testC {
                printAction = &work.Action{Mode: "test print (nop)", Package: p, Deps: []*work.Action{runAction}} // nop
+               vetRunAction = printAction
        } else {
                // run test
                c := new(runCache)
@@ -906,12 +908,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
                        TryCache:   c.tryCache,
                        Objdir:     testDir,
                }
-               if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
-                       addTestVet(b, ptest, runAction, installAction)
-               }
-               if pxtest != nil {
-                       addTestVet(b, pxtest, runAction, installAction)
-               }
+               vetRunAction = runAction
                cleanAction = &work.Action{
                        Mode:       "test clean",
                        Func:       builderCleanTest,
@@ -928,6 +925,14 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
                        IgnoreFail: true, // print even if test failed
                }
        }
+
+       if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
+               addTestVet(b, ptest, vetRunAction, installAction)
+       }
+       if pxtest != nil {
+               addTestVet(b, pxtest, vetRunAction, installAction)
+       }
+
        if installAction != nil {
                if runAction != installAction {
                        installAction.Deps = append(installAction.Deps, runAction)
diff --git a/src/cmd/go/testdata/script/test_compile_binary.txt b/src/cmd/go/testdata/script/test_compile_binary.txt
new file mode 100644 (file)
index 0000000..6c01bc5
--- /dev/null
@@ -0,0 +1,6 @@
+! go test -c compile_binary/...
+stderr 'build comment'
+
+-- compile_binary/foo_test.go --
+//+build foo
+package foo