-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: go test -o NUL fails on Windows #28035
Comments
Thank you for the report. I am not sure that your proposed fix is the correct change here. Bisected to
I will investigate properly when I have time. Alex |
Hi Alex, I knew it, I had looked very quickly at the differences between the Thanks, Hervé |
Yes, I agree. path/filepath.IsAbs("NUL") returns false on Windows. I think it should return true.
This will not work if user runs go test -c -work -o nul command. But this is another problem.
I do not understand what you are saying. Please try again. Alex |
I agree Alex. Just by reading the code, I was looking for differences explaining why this command was in error with Next time, I will push my analysis further before submitting a hypothesis ;-) |
What does IsAbs( |
I still do not know why commit e83601b creates this issue - I did not have time to investigate properly. So, anything is possible. Feel free to investigate and push hypothesis - correct or wrong. I make mistakes all the time. It is OK to make mistakes.
I do not know. Hopefully, if we make path/filepath.IsAbs("nul") return true, we won't get paths like Alex |
Finally I had time to understand why e83601b introduces this issue. The issue happens because path/filepath.IsAbs("NUL") returns false. See this code go/src/cmd/go/internal/test/test.go Lines 886 to 888 in b4150f7
The difference of what code does before and after e83601b can be seen here ( go/src/cmd/go/internal/work/exec.go Lines 1560 to 1567 in b4150f7
Before e83601b os.Stat on line 1560 fails, so none of 1561-L1567 lines run. And after e83601b os.Stat succeeds. I think the fact that os.Stat( Anyways, we could change os.Stat( So, should we make path/filepath.IsAbs("NUL") return false? ( and others, like CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 - search https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file for NUL). Is that the right thing to do? Should we similarly handle other functions in path/filepath ? Alternatively, we could special case NUL in cmd/go, like Russ did in a3faa80 - Russ adjusted Also a3faa80 determines os.DevNull by comparing cmd/go parameter with os.DevNull string. That will not work on Windows because user can pass both NUL and nul. So we would need to deal with that too. Luckily a3faa80 is a NOP on Windows, so it is not important there. Sorry for long comment. I need decision here (I can create a proposal, if needed). @ianlancetaylor @bradfitz @mattn and everyone else who has anything to add here Thank you. Alex |
I suppose I think that on Windows the special names like If we make that change is that enough to fix this problem? |
SGTM. My only concern is, that we should audit all our path/filepath functions for files like NUL. Maybe will start with path/filepath.IsAbs, and see how it goes.
Yes, fixing path/filepath.IsAbs will fix this issue. I will add a cmd/go test to make sure it stays fixed. Should we also do something about string comparison Alex |
The comparison I see is in cmd/go/internal/work/build.go: In any case that seems like a separate issue to consider after this one is fixed. |
Take caution with -o NUL. Creating a file named NUL on Windows can actually be done inadvertently and may lead to strange behavior where the file and containing directory is difficult to delete. |
Correct. That comparison has no effect on Windows.
There is no problem related to
Both
It is a separate issue from this issue. I will leave that code as is, since nothing is broken yet.
os package uses Windows CreateFile API. How do you create file named "NUL" with this API? Alex |
@alexbrainman disregard my statement about creating NUL. I can niether reproduce it with a trivial example nor have the bandwidth to investigate further. |
Change https://golang.org/cl/145220 mentions this issue: |
Thank you @alexbrainman. |
@neild Does this need to be reopened now that https://golang.org/cl/145220 has been reverted? |
No, https://go.dev/cl/449117 should have retained a fix for |
go test command manages os.DevNull on Windows as relative path not as null device.
What version of Go are you using (
go version
)?go version go1.11.1 windows/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
go test -c -work -o NUL
What did you expect to see?
WORK=C:\Users\Jupiter\AppData\Local\Temp\go-build814365262
What did you see instead?
WORK=C:\Users\Jupiter\AppData\Local\Temp\go-build814365262
go test /C/Users/Jupiter/Documents/echo.test: build output "C:\Users\Jupiter\Documents\echo\NUL" already exists and is not an object file
Hi,
Since the go1.11, still true with the latest version go1.11.1, the os.DevNull value for Windows is not well managed by the go test command (see file flag). NUL is managed as relative path, not as null device.
I suggest to add something like that in the file
src/cmd/go/internal/test/testflag.go
to deal with the-o
flag:Sample code to reproduce :
Then, inside the echo package directory, run the go test command with file flag:
- o
.Hope it helps.
The text was updated successfully, but these errors were encountered: