From: Bryan C. Mills Date: Tue, 15 Nov 2022 14:37:11 +0000 (-0500) Subject: go: use testenv.Command instead of exec.Command in tests X-Git-Tag: go1.20rc1~256 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a171f3fe49f8c5aa96189a822dbb8e3ef6900f91;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills --- diff --git a/src/go/doc/comment/std_test.go b/src/go/doc/comment/std_test.go index ae32dcd984..89206e6bc8 100644 --- a/src/go/doc/comment/std_test.go +++ b/src/go/doc/comment/std_test.go @@ -7,14 +7,13 @@ package comment import ( "internal/diff" "internal/testenv" - "os/exec" "sort" "strings" "testing" ) func TestStd(t *testing.T) { - out, err := exec.Command(testenv.GoToolPath(t), "list", "std").CombinedOutput() + out, err := testenv.Command(t, testenv.GoToolPath(t), "list", "std").CombinedOutput() if err != nil { t.Fatalf("%v\n%s", err, out) } diff --git a/src/go/importer/importer_test.go b/src/go/importer/importer_test.go index 3c39138038..142efd30f4 100644 --- a/src/go/importer/importer_test.go +++ b/src/go/importer/importer_test.go @@ -11,7 +11,6 @@ import ( "internal/testenv" "io" "os" - "os/exec" "strings" "testing" ) @@ -25,7 +24,7 @@ func TestForCompiler(t *testing.T) { testenv.MustHaveGoBuild(t) const thePackage = "math/big" - out, err := exec.Command(testenv.GoToolPath(t), "list", "-export", "-f={{context.Compiler}}:{{.Export}}", thePackage).CombinedOutput() + out, err := testenv.Command(t, testenv.GoToolPath(t), "list", "-export", "-f={{context.Compiler}}:{{.Export}}", thePackage).CombinedOutput() if err != nil { t.Fatalf("go list %s: %v\n%s", thePackage, err, out) } diff --git a/src/go/internal/gccgoimporter/importer_test.go b/src/go/internal/gccgoimporter/importer_test.go index 55e2feb9fa..76b4500f3b 100644 --- a/src/go/internal/gccgoimporter/importer_test.go +++ b/src/go/internal/gccgoimporter/importer_test.go @@ -130,7 +130,7 @@ func TestObjImporter(t *testing.T) { t.Skip("This test needs gccgo") } - verout, err := exec.Command(gpath, "--version").CombinedOutput() + verout, err := testenv.Command(t, gpath, "--version").CombinedOutput() if err != nil { t.Logf("%s", verout) t.Fatal(err) @@ -171,7 +171,7 @@ func TestObjImporter(t *testing.T) { ofile := filepath.Join(tmpdir, test.pkgpath+".o") afile := filepath.Join(artmpdir, "lib"+test.pkgpath+".a") - cmd := exec.Command(gpath, "-fgo-pkgpath="+test.pkgpath, "-c", "-o", ofile, gofile) + cmd := testenv.Command(t, gpath, "-fgo-pkgpath="+test.pkgpath, "-c", "-o", ofile, gofile) out, err := cmd.CombinedOutput() if err != nil { t.Logf("%s", out) @@ -180,7 +180,7 @@ func TestObjImporter(t *testing.T) { runImporterTest(t, imp, initmap, &test) - cmd = exec.Command("ar", "cr", afile, ofile) + cmd = testenv.Command(t, "ar", "cr", afile, ofile) out, err = cmd.CombinedOutput() if err != nil { t.Logf("%s", out) diff --git a/src/go/internal/gcimporter/gcimporter_test.go b/src/go/internal/gcimporter/gcimporter_test.go index bcbaa558d3..af99e7a852 100644 --- a/src/go/internal/gcimporter/gcimporter_test.go +++ b/src/go/internal/gcimporter/gcimporter_test.go @@ -10,7 +10,6 @@ import ( "internal/goexperiment" "internal/testenv" "os" - "os/exec" "path" "path/filepath" "runtime" @@ -47,7 +46,7 @@ func compile(t *testing.T, dirname, filename, outdirname string, packagefiles ma importcfgfile := filepath.Join(outdirname, basename) + ".importcfg" testenv.WriteImportcfg(t, importcfgfile, packagefiles) pkgpath := path.Join("testdata", basename) - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename) + cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename) cmd.Dir = dirname out, err := cmd.CombinedOutput() if err != nil {