Skip to content

Commit

Permalink
n
Browse files Browse the repository at this point in the history
Change-Id: I04351ac442c5d5cd25ddca84ad9e76a88bb21abb
  • Loading branch information
qiulaidongfeng committed May 31, 2024
1 parent 7ee45f8 commit 197d6e4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/os/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 197d6e4

Please sign in to comment.