From dceee2e983f5dab65c3905ecf40e70e15cf41b7d Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 24 Feb 2025 09:43:41 +0100 Subject: all: use testenv.Executable instead of os.Executable and os.Args[0] In test files, using testenv.Executable is more reliable than os.Executable or os.Args[0]. Change-Id: I88e577efeabc20d02ada27bf706ae4523129128e Reviewed-on: https://go-review.googlesource.com/c/go/+/651955 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/runtime/debug/stack_test.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'src/runtime/debug/stack_test.go') diff --git a/src/runtime/debug/stack_test.go b/src/runtime/debug/stack_test.go index e1559303f0..88d4ad0c0f 100644 --- a/src/runtime/debug/stack_test.go +++ b/src/runtime/debug/stack_test.go @@ -87,12 +87,7 @@ func TestStack(t *testing.T) { // initial (not current) environment. Spawn a subprocess to determine the // real baked-in GOROOT. t.Logf("found GOROOT %q from environment; checking embedded GOROOT value", envGoroot) - testenv.MustHaveExec(t) - exe, err := os.Executable() - if err != nil { - t.Fatal(err) - } - cmd := exec.Command(exe) + cmd := exec.Command(testenv.Executable(t)) cmd.Env = append(os.Environ(), "GOROOT=", "GO_RUNTIME_DEBUG_TEST_ENTRYPOINT=dumpgoroot") out, err := cmd.Output() if err != nil { @@ -137,18 +132,12 @@ func TestStack(t *testing.T) { } func TestSetCrashOutput(t *testing.T) { - testenv.MustHaveExec(t) - exe, err := os.Executable() - if err != nil { - t.Fatal(err) - } - crashOutput := filepath.Join(t.TempDir(), "crash.out") - cmd := exec.Command(exe) + cmd := exec.Command(testenv.Executable(t)) cmd.Stderr = new(strings.Builder) cmd.Env = append(os.Environ(), "GO_RUNTIME_DEBUG_TEST_ENTRYPOINT=setcrashoutput", "CRASHOUTPUT="+crashOutput) - err = cmd.Run() + err := cmd.Run() stderr := fmt.Sprint(cmd.Stderr) if err == nil { t.Fatalf("child process succeeded unexpectedly (stderr: %s)", stderr) -- cgit v1.3