Permalink
Browse files

Implement test -L, and add tests.

It's an alias for test -h, which had a bug because we were using
os.stat() and now os.lstat().

Addresses issue #58.
  • Loading branch information...
Andy Chu
Andy Chu committed Jan 1, 2018
1 parent 4831d32 commit ce229de83d10206d96efbfcd08c834b6904805de
Showing with 15 additions and 2 deletions.
  1. +2 −2 core/expr_eval.py
  2. +13 −0 spec/builtin-test.test.sh
View
@@ -479,7 +479,7 @@ def Eval(self, node):
arg_type = BOOL_OPS[op_id] # could be static in the LST?
if arg_type == OperandType.Path:
try:
mode = os.stat(s).st_mode
mode = os.lstat(s).st_mode
except OSError as e: # Python 3: FileNotFoundError
# TODO: Signal extra debug information?
#self._AddErrorContext("Error from stat(%r): %s" % (s, e))
@@ -503,7 +503,7 @@ def Eval(self, node):
if op_id == Id.BoolUnary_w:
return os.access(s, os.W_OK)
if op_id == Id.BoolUnary_h:
if op_id in (Id.BoolUnary_h, Id.BoolUnary_L):
return stat.S_ISLNK(mode)
raise NotImplementedError(op_id)
View
@@ -197,3 +197,16 @@ 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"
### -h and -L test for symlink
ln -s -f $TMP/zz $TMP/symlink
test -L $TMP/zz || echo no
test -h $TMP/zz || echo no
test -L $TMP/symlink && echo yes
test -h $TMP/symlink && echo yes
## STDOUT:
no
no
yes
yes
## END

0 comments on commit ce229de

Please sign in to comment.