Skip to content

Commit 197d6e4

Browse files
n
Change-Id: I04351ac442c5d5cd25ddca84ad9e76a88bb21abb
1 parent 7ee45f8 commit 197d6e4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/os/exec/exec_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -1835,3 +1835,32 @@ func TestPathRace(t *testing.T) {
18351835
t.Logf("running in background: %v", cmd)
18361836
<-done
18371837
}
1838+
1839+
func TestAbsPathExec(t *testing.T) {
1840+
testenv.MustHaveExec(t)
1841+
testenv.MustHaveGoBuild(t) // must have GOROOT/bin/gofmt, but close enough
1842+
1843+
// A simple exec of a full path should work.
1844+
// Go 1.22 broke this on Windows, requiring ".exe"; see #66586.
1845+
exe := filepath.Join(testenv.GOROOT(t), "bin/gofmt")
1846+
cmd := exec.Command(exe)
1847+
if cmd.Path != exe {
1848+
t.Errorf("exec.Command(%#q) set Path=%#q", exe, cmd.Path)
1849+
}
1850+
err := cmd.Run()
1851+
if err != nil {
1852+
t.Errorf("using exec.Command(%#q): %v", exe, err)
1853+
}
1854+
1855+
cmd = &exec.Cmd{Path: exe}
1856+
err = cmd.Run()
1857+
if err != nil {
1858+
t.Errorf("using exec.Cmd{Path: %#q}: %v", cmd.Path, err)
1859+
}
1860+
1861+
cmd = &exec.Cmd{Path: "gofmt", Dir: "/"}
1862+
err = cmd.Run()
1863+
if err == nil {
1864+
t.Errorf("using exec.Cmd{Path: %#q}: unexpected success", cmd.Path)
1865+
}
1866+
}

0 commit comments

Comments
 (0)