Permalink
Browse files

Implement test -r and test -w.

Fix bug in test -x.  We should be have been using os.access to for the
"effective" uid/gid?
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 14, 2017
1 parent bee2d0f commit 89a89be9fd1ed5109e1631b327223e206cfda228
Showing with 24 additions and 2 deletions.
  1. +7 −2 core/expr_eval.py
  2. +17 −0 spec/test-builtin.test.sh
View
@@ -489,8 +489,13 @@ def Eval(self, node):
return stat.S_ISDIR(mode)
if op_id == Id.BoolUnary_x:
# TODO: Bash and dash do something more complicated with faccessat()?
return bool(mode & os.X_OK)
return os.access(s, os.X_OK)
if op_id == Id.BoolUnary_r:
return os.access(s, os.R_OK)
if op_id == Id.BoolUnary_w:
return os.access(s, os.W_OK)
raise NotImplementedError(op_id)
View
@@ -179,3 +179,20 @@ chmod +x $TMP/x
test -x $TMP/x && echo 'yes'
test -x $TMP/__nonexistent__ || echo 'bad'
# stdout-json: "no\nyes\nbad\n"
### -r
echo '1' > $TMP/testr_yes
echo '2' > $TMP/testr_no
chmod -r $TMP/testr_no # remove read permission
test -r $TMP/testr_yes && echo 'yes'
test -r $TMP/testr_no || echo 'no'
# stdout-json: "yes\nno\n"
### -w
rm -f $TMP/testw_*
echo '1' > $TMP/testw_yes
echo '2' > $TMP/testw_no
chmod -w $TMP/testw_no # remove write permission
test -w $TMP/testw_yes && echo 'yes'
test -w $TMP/testw_no || echo 'no'
# stdout-json: "yes\nno\n"

0 comments on commit 89a89be

Please sign in to comment.