-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Ambiguous cli exit status #2438
Comments
At the very least, clamping the result to a maximum would be necessary to resolve the rollover problem; using 1 for test failure in general seems like a good idea in principle, too, but there are a few things I'd like to double-check.
(Ok, I know I should be able to look through the documentation again and answer that last one, I'm just throwing it out there in case anybody remembers and can say so before I go looking for it. There's also the fact that it's tested, which in some philosophies is intended partly as documentation, but I don't know how strictly that intersects with semver.) |
My take on this was that unless there's a reported bug regarding this, let's leave the current behavior as-is for now; except clamp the result as @ScottFreeCode suggested. |
100% agree with @Munter. At work, i use bash to run mocha tests and if 0 tests are passing, the exit code is 0! That's nuts! Caused a lot of headache for me. |
@Pombam actually the exit code should be equivalent to how many errors you've had. If you have ran 0 tests, then exit code 0 is ok. Regarding this issue: IMO it would be more semantic to exit with 0 when there are no errors and 1 when there are any. According to lots of sources (such as @Munter suggested himself), some codes have meaning, for example, if we exit with 127 then someone may think there may have been an non-existing command somewhere along the way. Also, I've taken a look at the docs and I couldn't find any information about this kind of behavior. |
@Pombam What headaches did this cause? We've established Mocha's behavior is "incorrect"; that's not up for debate. But we haven't yet established that it's actually causing real-world problems. If it is--and those problems have no reasonable workarounds--then we need to break Mocha's API to fix it. So I'm especially curious what your "headache" was, as it were. |
Firstly, I am not debating anything, i am just putting forward my two cents here. Conclusion: |
@Pombam That sounds like a different bug--skipped tests causing a false positive. I can't reproduce this trivially--can you open another issue if you can make a minimal, reproducible case? |
* Exit with code 130 in SIGINT. Refs mochajs#2438 * Exit with code 255 if more errors than 255 were returned. Fixes mochajs#2438
Mocha exits with an exit status equal to the amount of errors in the test run. This is a potentially huge problem causing ambiguous exit codes.
Exit codes have a range from 0-255. An exit value greater than 255 returns an exit code modulo 256.
This means a test with 256 errors will exit with code 0. Run this example as a proof:
then
echo $?
Further more, certain exit codes have special meaning which can cause tools further down a unix pipe to misbehave. See http://tldp.org/LDP/abs/html/exitcodes.html
Mocha cli should always exit with code 1 if there are tests failing and code 0 if there are no tests failing
The text was updated successfully, but these errors were encountered: