tempdir := t.TempDir()
exe := filepath.Join(tempdir, "read3.exe")
- c := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "read3.go")
+ c := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, "read3.go")
// Build the test without cgo, so that C library functions don't
// open descriptors unexpectedly. See issue 25628.
c.Env = append(os.Environ(), "CGO_ENABLED=0")
// Run "cmd.exe /c test.searchFor" with new environment and
// work directory set. All candidates are copies of printpath.exe.
// These will output their program paths when run.
- should, errCmd := test.runProg(t, env, exec.Command("cmd", "/c", test.searchFor))
+ should, errCmd := test.runProg(t, env, testenv.Command(t, "cmd", "/c", test.searchFor))
// Run the lookpath program with new environment and work directory set.
have, errLP := test.runProg(t, env, helperCommand(t, "lookpath", test.searchFor))
// Compare results.
t.Fatalf("failed to execute template: %v", err)
}
outname := name + ".exe"
- cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", outname, srcname)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", outname, srcname)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
// We have no intention of reading from c.
c := make(chan os.Signal, 1)
Notify(c, syscall.SIGHUP)
- if out, err := exec.Command(os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput(); err == nil {
+ if out, err := testenv.Command(t, os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput(); err == nil {
t.Errorf("ran test with -check_sighup_ignored and it succeeded: expected failure.\nOutput:\n%s", out)
}
Stop(c)
}
Ignore(syscall.SIGHUP)
os.Remove("nohup.out")
- out, err := exec.Command("/usr/bin/nohup", os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput()
+ out, err := testenv.Command(t, "/usr/bin/nohup", os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput()
data, _ := os.ReadFile("nohup.out")
os.Remove("nohup.out")
if subTimeout != 0 {
args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
}
- out, err := exec.Command(os.Args[0], args...).CombinedOutput()
+ out, err := testenv.Command(t, os.Args[0], args...).CombinedOutput()
if err == nil {
t.Errorf("ran test with -send_uncaught_sighup=%d and it succeeded: expected failure.\nOutput:\n%s", i, out)
if subTimeout != 0 {
args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
}
- out, err := exec.Command("nohup", args...).CombinedOutput()
+ out, err := testenv.Command(t, "nohup", args...).CombinedOutput()
if err != nil {
t.Errorf("ran test with -send_uncaught_sighup=%d under nohup and it failed: expected success.\nError: %v\nOutput:\n%s", i, err, out)
if deadline, ok := t.Deadline(); ok {
timeout = time.Until(deadline).String()
}
- cmd := exec.Command(os.Args[0], "-test.run=TestAtomicStop", "-test.timeout="+timeout)
+ cmd := testenv.Command(t, os.Args[0], "-test.run=TestAtomicStop", "-test.timeout="+timeout)
cmd.Env = append(os.Environ(), "GO_TEST_ATOMIC_STOP=1")
out, err := cmd.CombinedOutput()
if err == nil {
if subTimeout != 0 {
args = append(args, fmt.Sprintf("-test.timeout=%v", subTimeout))
}
- out, err := exec.Command(os.Args[0], args...).CombinedOutput()
+ out, err := testenv.Command(t, os.Args[0], args...).CombinedOutput()
if err != nil {
t.Errorf("ran test with -check_notify_ctx_notification and it failed with %v.\nOutput:\n%s", err, out)
}
import (
"internal/testenv"
"os"
- "os/exec"
"path/filepath"
"strings"
"syscall"
// compile it
exe := name + ".exe"
defer os.Remove(exe)
- o, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
+ o, err := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
if err != nil {
t.Fatalf("Failed to compile: %v\n%v", err, string(o))
}
// run it
- cmd := exec.Command(exe)
+ cmd := testenv.Command(t, exe)
var buf strings.Builder
cmd.Stdout = &buf
cmd.Stderr = &buf