Merge pull request #3307 from xonsh/fnf_exit_1

Non-zero exit code when script path not found
This commit is contained in:
Morten Enemark Lund 2019-09-09 22:12:41 +02:00 committed by GitHub
commit 7829074d9a
Failed to generate hash of commit
3 changed files with 39 additions and 0 deletions

31
news/fnf_exit_1.rst Normal file
View file

@ -0,0 +1,31 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* ``xonsh`` will return a non-zero exit code if it is run in file mode and
cannot find the file specified, e.g.
.. code-block::
$ xonsh thisfiledoesntexist.xsh
xonsh: thisfiledoesntexist.xsh: No such file or directory.
$ _.returncode
1
**Security:**
* <news item>

View file

@ -186,3 +186,9 @@ def test_xonsh_failback_script_from_file(shell, monkeypatch, monkeypatch_stderr)
with pytest.raises(Exception):
xonsh.main.main()
assert len(checker) == 0
def test_xonsh_no_file_returncode(shell, monkeypatch, monkeypatch_stderr):
monkeypatch.setattr(sys, "argv", ["xonsh", "foobazbarzzznotafileatall.xsh"])
with pytest.raises(SystemExit):
xonsh.main.main()

View file

@ -447,6 +447,8 @@ def main_xonsh(args):
)
else:
print("xonsh: {0}: No such file or directory.".format(args.file))
events.on_exit.fire()
sys.exit(1)
elif args.mode == XonshMode.script_from_stdin:
# run a script given on stdin
code = sys.stdin.read()