Skip to content
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

Exit process with correct error codes #2445

Merged
merged 2 commits into from
Sep 18, 2016
Merged

Exit process with correct error codes #2445

merged 2 commits into from
Sep 18, 2016

Conversation

Munter
Copy link
Contributor

@Munter Munter commented Aug 15, 2016

  • Exit with code 130 on SIGINT
  • Exit with code 1 if any error occurred
  • Exit with an exit code of max 255 to avoid 8-bit overflow mistakingly reporting no errors

Closes #2438

@1999
Copy link
Contributor

1999 commented Aug 17, 2016

Many developers are waiting for failed number of tests in exit code of mocha, not just for 0, 1 and 130. Is this a really necessary breaking change?

@Munter
Copy link
Contributor Author

Munter commented Aug 18, 2016

Whether the full scope of the change is necessary is up for debate. Certainly the false pass has to be fixed.

Many developers are waiting for failed number of tests in exit code of mocha

Do you have any examples in the wild or any known numbers or is this just a case of ad-hoc statistics?

The current state of Mocha is at odds with proper unix exit code semantics. You could also argue that these many people have been doing it wrong all the time and misinterpreting signals like "exit caused by SIGINT", "exit caused by invalid command", "file not found" etc as indicating the number of test failures, while the actual error condition was a completely different one

@1999
Copy link
Contributor

1999 commented Aug 18, 2016

Well in my personal opinion this is a necessary change. I noticed that our QA guys are looking at the process exit code as the failuresNum but I usually ask them not to do that. Still it seems to be a breaking change that should be placed under some flag.

cc @boneskull

@boneskull
Copy link
Contributor

I don't see this as a necessary breaking change unless someone can document that their workflow is broken because of it. I agree it's "incorrect" and should probably be fixed at some point, but we need to be actually helping people when we break the API--not just in theory.

However, the exit code should be capped at 255 or whatever so as to not exit with a false positive 0 if there happen to be 256 failing tests.

@Munter Can you modify the PR?

@Munter
Copy link
Contributor Author

Munter commented Aug 23, 2016

@boneskull Updated

@Munter
Copy link
Contributor Author

Munter commented Aug 26, 2016

All green after restarting all the tests that failed because of broken phantomjs install

Copy link
Contributor

@boneskull boneskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Given we were tossing the

process.on('SIGINT', function() { runner.abort(); })
process.on('SIGINT', function() {
runner.abort();
process.exit(130);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to cause problems, because runner.abort() is attempting to exit cleanly.

Instead, you should be able to override runner.failures; see here.

@boneskull
Copy link
Contributor

Please ignore the "LGTM" comment; I don't see how to remove it. But line 433 will need fixing..after that this is OK (after conflicts are resolved). Thanks!

@Munter
Copy link
Contributor Author

Munter commented Sep 17, 2016

@boneskull Requested changes are implemented, branch is rebased and all test are green

@boneskull boneskull merged commit 3e22a83 into master Sep 18, 2016
@boneskull boneskull deleted the fix-issue-2438 branch September 18, 2016 21:48
1999 pushed a commit to 1999/mocha that referenced this pull request Sep 19, 2016
…roperty-currentretry

* upstream/master:
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
1999 pushed a commit to 1999/mocha that referenced this pull request Sep 22, 2016
…-files-cache

* upstream/master:
  attempt windows-friendly reproducible case for mochajs#2315
  fix: fix uncaught TypeError if error occurs on next tick, closes mochajs#2315 (mochajs#2439)
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
sgilroy pushed a commit to TwineHealth/mocha that referenced this pull request Feb 27, 2019
* Exit with code 130 in SIGINT. Refs mochajs#2438

* Exit with code 255 if more errors than 255 were returned. Fixes mochajs#2438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants