mirror of
https://github.com/golang/go
synced 2024-11-23 13:00:07 -07:00
cmd/go: use testenv.Command instead of exec.Command in tests
testenv.Command sets a default timeout based on the test's deadline and sends SIGQUIT (where supported) in case of a hang. Change-Id: Ic19172b6cd05526cf6776b904e2dfebdd8b055a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/450697 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
2cb103ff58
commit
c9f7370a09
@ -487,7 +487,7 @@ func (tg *testgoData) doRun(args []string) error {
|
||||
}
|
||||
|
||||
tg.t.Logf("running testgo %v", args)
|
||||
cmd := exec.Command(prog, args...)
|
||||
cmd := testenv.Command(tg.t, prog, args...)
|
||||
tg.stdout.Reset()
|
||||
tg.stderr.Reset()
|
||||
cmd.Dir = tg.execDir
|
||||
@ -530,7 +530,7 @@ func (tg *testgoData) runFail(args ...string) {
|
||||
// runGit runs a git command, and expects it to succeed.
|
||||
func (tg *testgoData) runGit(dir string, args ...string) {
|
||||
tg.t.Helper()
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd := testenv.Command(tg.t, "git", args...)
|
||||
tg.stdout.Reset()
|
||||
tg.stderr.Reset()
|
||||
cmd.Stdout = &tg.stdout
|
||||
@ -1583,7 +1583,7 @@ func TestCgoPkgConfig(t *testing.T) {
|
||||
tg.run("env", "PKG_CONFIG")
|
||||
pkgConfig := strings.TrimSpace(tg.getStdout())
|
||||
testenv.MustHaveExecPath(t, pkgConfig)
|
||||
if out, err := exec.Command(pkgConfig, "--atleast-pkgconfig-version", "0.24").CombinedOutput(); err != nil {
|
||||
if out, err := testenv.Command(t, pkgConfig, "--atleast-pkgconfig-version", "0.24").CombinedOutput(); err != nil {
|
||||
t.Skipf("%s --atleast-pkgconfig-version 0.24: %v\n%s", pkgConfig, err, out)
|
||||
}
|
||||
|
||||
@ -2281,7 +2281,7 @@ func testBuildmodePIE(t *testing.T, useCgo, setBuildmodeToPIE bool) {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
out, err := exec.Command(obj).CombinedOutput()
|
||||
out, err := testenv.Command(t, obj).CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -2298,7 +2298,7 @@ func TestUpxCompression(t *testing.T) {
|
||||
}
|
||||
|
||||
testenv.MustHaveExecPath(t, "upx")
|
||||
out, err := exec.Command("upx", "--version").CombinedOutput()
|
||||
out, err := testenv.Command(t, "upx", "--version").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("upx --version failed: %v", err)
|
||||
}
|
||||
@ -2332,13 +2332,13 @@ func TestUpxCompression(t *testing.T) {
|
||||
obj := tg.path("main")
|
||||
tg.run("build", "-o", obj, src)
|
||||
|
||||
out, err = exec.Command("upx", obj).CombinedOutput()
|
||||
out, err = testenv.Command(t, "upx", obj).CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("executing upx\n%s\n", out)
|
||||
t.Fatalf("upx failed with %v", err)
|
||||
}
|
||||
|
||||
out, err = exec.Command(obj).CombinedOutput()
|
||||
out, err = testenv.Command(t, obj).CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", out)
|
||||
t.Fatalf("running compressed go binary failed with error %s", err)
|
||||
|
@ -5,8 +5,8 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"internal/testenv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -38,7 +38,7 @@ func TestAbsolutePath(t *testing.T) {
|
||||
|
||||
noVolume := file[len(filepath.VolumeName(file)):]
|
||||
wrongPath := filepath.Join(dir, noVolume)
|
||||
cmd := exec.Command(tg.goTool(), "build", noVolume)
|
||||
cmd := testenv.Command(t, tg.goTool(), "build", noVolume)
|
||||
cmd.Dir = dir
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
|
@ -6,7 +6,6 @@ package main_test
|
||||
|
||||
import (
|
||||
"internal/testenv"
|
||||
"os/exec"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
@ -27,7 +26,7 @@ func BenchmarkExecGoEnv(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
cmd := exec.Command(gotool, "env", "GOARCH")
|
||||
cmd := testenv.Command(b, gotool, "env", "GOARCH")
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
b.Fatal(err)
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
@ -199,7 +198,7 @@ func TestLockNotDroppedByExecCommand(t *testing.T) {
|
||||
// Some kinds of file locks are dropped when a duplicated or forked file
|
||||
// descriptor is unlocked. Double-check that the approach used by os/exec does
|
||||
// not accidentally drop locks.
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^$")
|
||||
cmd := testenv.Command(t, os.Args[0], "-test.run=^$")
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("exec failed: %v", err)
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
@ -226,7 +225,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(os.Args[0], "-test.run="+t.Name())
|
||||
cmd := testenv.Command(t, os.Args[0], "-test.run="+t.Name())
|
||||
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", dirVar, dir))
|
||||
|
||||
qDone := make(chan struct{})
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"internal/diff"
|
||||
"internal/testenv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
@ -43,7 +42,7 @@ func checkScriptReadme(t *testing.T, engine *script.Engine, env []string) {
|
||||
}
|
||||
|
||||
doc := new(strings.Builder)
|
||||
cmd := exec.Command(testGo, "doc", "cmd/go/internal/script")
|
||||
cmd := testenv.Command(t, testGo, "doc", "cmd/go/internal/script")
|
||||
cmd.Env = env
|
||||
cmd.Stdout = doc
|
||||
if err := cmd.Run(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user