From 197d6e445c67fb74bb429bda11b6fc17a5c0d037 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Fri, 31 May 2024 16:07:48 +0800 Subject: [PATCH] n Change-Id: I04351ac442c5d5cd25ddca84ad9e76a88bb21abb --- src/os/exec/exec_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index c749de99db69e1..dbe59fea119e70 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -1835,3 +1835,32 @@ func TestPathRace(t *testing.T) { t.Logf("running in background: %v", cmd) <-done } + +func TestAbsPathExec(t *testing.T) { + testenv.MustHaveExec(t) + testenv.MustHaveGoBuild(t) // must have GOROOT/bin/gofmt, but close enough + + // A simple exec of a full path should work. + // Go 1.22 broke this on Windows, requiring ".exe"; see #66586. + exe := filepath.Join(testenv.GOROOT(t), "bin/gofmt") + cmd := exec.Command(exe) + if cmd.Path != exe { + t.Errorf("exec.Command(%#q) set Path=%#q", exe, cmd.Path) + } + err := cmd.Run() + if err != nil { + t.Errorf("using exec.Command(%#q): %v", exe, err) + } + + cmd = &exec.Cmd{Path: exe} + err = cmd.Run() + if err != nil { + t.Errorf("using exec.Cmd{Path: %#q}: %v", cmd.Path, err) + } + + cmd = &exec.Cmd{Path: "gofmt", Dir: "/"} + err = cmd.Run() + if err == nil { + t.Errorf("using exec.Cmd{Path: %#q}: unexpected success", cmd.Path) + } +}