diff options
| author | qiulaidongfeng <2645477756@qq.com> | 2024-06-05 19:06:31 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-06-07 20:13:53 +0000 |
| commit | 5532427c4b1c5e962ad5484258be0071bd270e53 (patch) | |
| tree | 017baad48d4d7ffb6d5a4573aad5f78636b6530f /src/os/exec/exec_test.go | |
| parent | 1634fde4f918223614fd8893db8dd7ca4ebcda01 (diff) | |
| download | go-5532427c4b1c5e962ad5484258be0071bd270e53.tar.xz | |
os/exec: on Windows look for extensions in Run if not already done
CL 512155 fixed #36768, but introduced #62596.
CL 527820 fixed #62596, but meant that the code failed to look up
file extensions on Windows for a relative path.
This CL fixes that problem by recording whether it has already
looked up file extensions.
This does mean that if Path is set manually then we do not update
it with file extensions, as doing that would be racy.
Fixes #66586
Change-Id: I9a0305d1e466c5e07bfbe442566ea12f5255a96e
GitHub-Last-Rev: dc3169f2350f61acac5ef7842b7514013abacbe1
GitHub-Pull-Request: golang/go#67035
Reviewed-on: https://go-review.googlesource.com/c/go/+/581695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/os/exec/exec_test.go')
| -rw-r--r-- | src/os/exec/exec_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index c749de99db..dbe59fea11 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) + } +} |
