Skip to content

os/exec: TestCommand fails on Windows when NoDefaultCurrentDirectoryInExePath is set in the environment #62594

@bcmills

Description

@bcmills

In investigating the data race reported in https://go.dev/cl/527337, I looked at the existing tests that cover the call to lookExtensions is exec.Cmd.Start on Windows.

I found several test cases in TestCommand that look suspicious: they expect exec.LookPath to always resolve a bare filename relative to the current directory, possibly with an ErrDot error. However, if NoDefaultCurrentDirectoryInExePath is set in the environment, exec.LookPath does not even attempt to resolve in the current directory, so the tests presumably won't pass.

Running the tests on a gomote confirms that hypothesis as of https://go.dev/cl/527337:

gopher@GOLANG-BUILDLET C:\workdir\go\src>set NoDefaultCurrentDirectoryInExePath=TRUE

gopher@GOLANG-BUILDLET C:\workdir\go\src>..\bin\go test os/exec
--- FAIL: TestCommand (0.58s)
    --- FAIL: TestCommand/2 (0.06s)
        lp_windows_test.go:396: test={PATH:p2;p files:[a.exe p\a.exe p2\a.exe] dir: arg
0:a want:a.exe fails:false}: want "a.exe", got "p2\\a.exe"
    --- FAIL: TestCommand/10 (0.07s)
        lp_windows_test.go:396: test={PATH:p2;p files:[a.exe p\a.exe p2\a.exe] dir:p ar
g0:a.exe want:p\a.exe fails:false}: want "p\\a.exe", got "p2\\a.exe"
    --- FAIL: TestCommand/11 (0.06s)
        lp_windows_test.go:396: test={PATH:p2;p files:[a.exe p\a.exe p2\a.exe] dir:p ar
g0:a want:p\a.exe fails:false}: want "p\\a.exe", got "p2\\a.exe"
    --- FAIL: TestCommand/1 (0.06s)
        lp_windows_test.go:396: test={PATH:p2;p files:[a.exe p\a.exe p2\a.exe] dir: arg
0:a.exe want:a.exe fails:false}: want "a.exe", got "p2\\a.exe"
FAIL
FAIL    os/exec 0.947s
FAIL

(CC @golang/windows, @ianlancetaylor)

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-WindowsTestingAn issue that has been verified to require only test changes, not just a test failure.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions