Permalink
Browse files

Expose a bug in 'dirs' in osh, and reformat a little.

  • Loading branch information...
Andy Chu
Andy Chu committed Dec 19, 2017
1 parent 796aaf9 commit 91d4bccb7a930c61b8396e5e341fd07c9bfaf545
Showing with 18 additions and 13 deletions.
  1. +11 −6 core/builtin.py
  2. +7 −7 spec/builtins2.test.sh
View
@@ -487,19 +487,24 @@ def Cd(argv, mem):
WITHOUT_PREFIX = 2
SINGLE_LINE = 3
def PrintDirStack(dir_stack, mode):
def _PrintDirStack(dir_stack, mode):
dirs = [os.getcwd()]
dirs.extend(dir_stack)
if mode == WITH_PREFIX:
for i, entry in enumerate(dirs):
print('%2d %s' % (i, entry))
elif mode == WITHOUT_PREFIX:
for entry in dirs:
print(entry)
elif mode == SINGLE_LINE:
print(' '.join(dirs))
sys.stdout.flush()
def Pushd(argv, dir_stack):
num_args = len(argv)
if num_args <= 0:
@@ -518,7 +523,7 @@ def Pushd(argv, dir_stack):
return 1
dir_stack.append(current_dir)
PrintDirStack(dir_stack, SINGLE_LINE)
_PrintDirStack(dir_stack, SINGLE_LINE)
return 0
@@ -535,7 +540,7 @@ def Popd(argv, dir_stack):
util.error("popd: %r: %s", dest_dir, os.strerror(e.errno))
return 1
PrintDirStack(dir_stack, SINGLE_LINE)
_PrintDirStack(dir_stack, SINGLE_LINE)
return 0
@@ -553,11 +558,11 @@ def Dirs(argv, dir_stack):
if arg.c:
del dir_stack[:]
elif arg.v:
PrintDirStack(dir_stack, WITH_PREFIX)
_PrintDirStack(dir_stack, WITH_PREFIX)
elif arg.p:
PrintDirStack(dir_stack, WITHOUT_PREFIX)
_PrintDirStack(dir_stack, WITHOUT_PREFIX)
else:
PrintDirStack(dir_stack, SINGLE_LINE)
_PrintDirStack(dir_stack, SINGLE_LINE)
return 0
View
@@ -46,23 +46,23 @@ dirs
### dirs -v to print numbered stack, one entry per line
cd /
pushd / >/dev/null
pushd /tmp >/dev/null
dirs -v
pushd / >/dev/null
pushd /lib >/dev/null
dirs -v
# stdout-json: " 0 /\n 1 /\n 0 /\n 1 /\n 2 /\n"
# stdout-json: " 0 /tmp\n 1 /\n 0 /lib\n 1 /tmp\n 2 /\n"
# status: 0
# zsh uses tabs
# OK zsh stdout-json: "0\t/\n1\t/\n0\t/\n1\t/\n2\t/\n"
# OK zsh stdout-json: "0\t/tmp\n1\t/\n0\t/lib\n1\t/tmp\n2\t/\n"
# N-I dash/mksh status: 127
# N-I dash/mksh stdout-json: ""
### dirs -p to print one entry per line
cd /
pushd / >/dev/null
pushd /tmp >/dev/null
dirs -p
pushd / >/dev/null
pushd /lib >/dev/null
dirs -p
# stdout-json: "/\n/\n/\n/\n/\n"
# stdout-json: "/tmp\n/\n/lib\n/tmp\n/\n"
# N-I dash/mksh status: 127
# N-I dash/mksh stdout-json: ""

0 comments on commit 91d4bcc

Please sign in to comment.