Skip to content

Commit a171f3f

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
go: use testenv.Command instead of exec.Command in tests
This may help to diagnose whether the hang observed in https://build.golang.org/log/d03db1d27515a4f7e91502e8b58bc83f6e2c04be is related to #56180. Updates #56180. Updates #54773. Change-Id: I81d37e55a35f876905ceabc103fcf0d1ff348e2f Reviewed-on: https://go-review.googlesource.com/c/go/+/450615 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 37ca171 commit a171f3f

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

src/go/doc/comment/std_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ package comment
77
import (
88
"internal/diff"
99
"internal/testenv"
10-
"os/exec"
1110
"sort"
1211
"strings"
1312
"testing"
1413
)
1514

1615
func TestStd(t *testing.T) {
17-
out, err := exec.Command(testenv.GoToolPath(t), "list", "std").CombinedOutput()
16+
out, err := testenv.Command(t, testenv.GoToolPath(t), "list", "std").CombinedOutput()
1817
if err != nil {
1918
t.Fatalf("%v\n%s", err, out)
2019
}

src/go/importer/importer_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"internal/testenv"
1212
"io"
1313
"os"
14-
"os/exec"
1514
"strings"
1615
"testing"
1716
)
@@ -25,7 +24,7 @@ func TestForCompiler(t *testing.T) {
2524
testenv.MustHaveGoBuild(t)
2625

2726
const thePackage = "math/big"
28-
out, err := exec.Command(testenv.GoToolPath(t), "list", "-export", "-f={{context.Compiler}}:{{.Export}}", thePackage).CombinedOutput()
27+
out, err := testenv.Command(t, testenv.GoToolPath(t), "list", "-export", "-f={{context.Compiler}}:{{.Export}}", thePackage).CombinedOutput()
2928
if err != nil {
3029
t.Fatalf("go list %s: %v\n%s", thePackage, err, out)
3130
}

src/go/internal/gccgoimporter/importer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestObjImporter(t *testing.T) {
130130
t.Skip("This test needs gccgo")
131131
}
132132

133-
verout, err := exec.Command(gpath, "--version").CombinedOutput()
133+
verout, err := testenv.Command(t, gpath, "--version").CombinedOutput()
134134
if err != nil {
135135
t.Logf("%s", verout)
136136
t.Fatal(err)
@@ -171,7 +171,7 @@ func TestObjImporter(t *testing.T) {
171171
ofile := filepath.Join(tmpdir, test.pkgpath+".o")
172172
afile := filepath.Join(artmpdir, "lib"+test.pkgpath+".a")
173173

174-
cmd := exec.Command(gpath, "-fgo-pkgpath="+test.pkgpath, "-c", "-o", ofile, gofile)
174+
cmd := testenv.Command(t, gpath, "-fgo-pkgpath="+test.pkgpath, "-c", "-o", ofile, gofile)
175175
out, err := cmd.CombinedOutput()
176176
if err != nil {
177177
t.Logf("%s", out)
@@ -180,7 +180,7 @@ func TestObjImporter(t *testing.T) {
180180

181181
runImporterTest(t, imp, initmap, &test)
182182

183-
cmd = exec.Command("ar", "cr", afile, ofile)
183+
cmd = testenv.Command(t, "ar", "cr", afile, ofile)
184184
out, err = cmd.CombinedOutput()
185185
if err != nil {
186186
t.Logf("%s", out)

src/go/internal/gcimporter/gcimporter_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"internal/goexperiment"
1111
"internal/testenv"
1212
"os"
13-
"os/exec"
1413
"path"
1514
"path/filepath"
1615
"runtime"
@@ -47,7 +46,7 @@ func compile(t *testing.T, dirname, filename, outdirname string, packagefiles ma
4746
importcfgfile := filepath.Join(outdirname, basename) + ".importcfg"
4847
testenv.WriteImportcfg(t, importcfgfile, packagefiles)
4948
pkgpath := path.Join("testdata", basename)
50-
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename)
49+
cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename)
5150
cmd.Dir = dirname
5251
out, err := cmd.CombinedOutput()
5352
if err != nil {

0 commit comments

Comments
 (0)