-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
hides the exit status of the test binary
#45508
Comments
Technically it may be possible to scan all of the test output and look for a |
Change https://golang.org/cl/309250 mentions this issue: |
I don't think that's coherent: in general |
That seems like a reasonable concern, but I think we should address it more directly. Perhaps we could have Or, perhaps the behavior noted in #38382 is actually the solution here: at the moment, it seems that you can detect an incomplete test run by the presence of a Although, that still leaves the problem of detecting programs that panic (or invoke |
@bcmills thank you for the quick reply.
There is already a clear pattern for handling this in the Go toolchain (and other software):
That seems quite coherent to me. The user is requesting one thing "run all of these tests", if that request is not satisfied (all tests are not run), then indicating it with the exit code seems appropriate. It doesn't matter that some packages did run all tests.
I considered that, but it seems like doing so would be a lot more involved, could be significantly more error prone (because there are many cases to handle), and may not actually provide any more value than the simple solution.
#38382 describes an abnormal case. Most of the time, when a test panics, it does include an
This seems like the correct behaviour. It is the package that is incomplete, not the test.
How is that a better solution than simply not hiding the relevant exit code? That seems to be a lot more involved and error prone. There are many things that can change the list of tests, environment variables, build tags, or even command line flags. On a separate note, could you comment on why the current behaviour is correct? Why should |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
When a test binary fails with a panic it exits with code 2 (like all other Go binaries).
go test
, however, hides that exit code and always exits with code 1. The only way I could get an exit code other than 0 or 1 fromgo test
was to cause a build error. Common causes of panics are:-test.timeout
is reached, and causes a panic.In both of these cases the output from the compiled test binary will only contain the tests that have run before the panic. There is no output for the tests that were not run.
Any program which runs
go test -json
and wants to attempt to re-run failed tests (ex: gotestsum --rerun-fails) needs to be able to differentiate these two cases:It seems like it is not currently possible to detect these two cases, which makes it impossible to safely rerun individual failed tests. If the program running tests attempts to re-run tests after a panic, it will only know about the tests that ran, not any of the tests that were missed.
What did you expect to see?
I would like to make
go test
always use the exit code of the compiled test binary. That way if the test binary panics,go test
will exit code 2. If there is some reason not to use exit code 2 for this purpose, any exit code other than 1 would also work.The text was updated successfully, but these errors were encountered: