Permalink
Browse files

Handle chdir() error, with test.

  • Loading branch information...
Andy Chu
Andy Chu committed Aug 8, 2017
1 parent 150acde commit 6eae98b0f4de907bb9efc2b50cd388229822555e
Showing with 12 additions and 1 deletion.
  1. +6 −1 core/builtin.py
  2. +6 −0 spec/builtins.test.sh
View
@@ -431,7 +431,12 @@ def Cd(argv, mem):
# Save OLDPWD.
state.SetGlobalString(mem, 'OLDPWD', os.getcwd())
os.chdir(dest_dir)
try:
os.chdir(dest_dir)
except OSError as e:
# TODO: Add line number, etc.
util.error("cd %r: %s", dest_dir, os.strerror(e.errno))
return 1
state.SetGlobalString(mem, 'PWD', dest_dir)
return 0
View
@@ -55,6 +55,12 @@ cd
test $(pwd) = "$HOME" && echo OK
# stdout: OK
### cd to nonexistent dir
cd /nonexistent/dir
echo status=$?
# stdout: status=1
# OK dash/mksh stdout: status=2
### pushd/popd
set -o errexit
cd /

0 comments on commit 6eae98b

Please sign in to comment.