Permalink
Browse files

Implement test -ot and -nt.

Aboriginal uses them.  Addresses issue #58.
  • Loading branch information...
Andy Chu
Andy Chu committed Jan 8, 2018
1 parent fa7ea76 commit 5a09f28a928f9be60c7b387e99604a14c58eb681
Showing with 20 additions and 1 deletion.
  1. +6 −1 core/expr_eval.py
  2. +14 −0 spec/builtin-test.test.sh
View
@@ -552,8 +552,13 @@ def Eval(self, node):
st1 = os.stat(s1)
st2 = os.stat(s2)
# TODO: test newer than (mtime)
if op_id == Id.BoolBinary_nt:
return True # TODO: test newer than (mtime)
return st1[stat.ST_MTIME] > st2[stat.ST_MTIME]
if op_id == Id.BoolBinary_ot:
return st1[stat.ST_MTIME] < st2[stat.ST_MTIME]
raise NotImplementedError(op_id)
if arg_type == OperandType.Int:
# NOTE: We assume they are constants like [[ 3 -eq 3 ]].
View
@@ -232,3 +232,17 @@ echo status=$?
echo status=$?
## stdout: status=2
## BUG bash stdout: status=1
### -ot and -nt
touch -d 2017/12/31 $TMP/x
touch -d 2018/01/01 > $TMP/y
test $TMP/x -ot $TMP/y && echo 'older'
test $TMP/x -nt $TMP/y || echo 'not newer'
test $TMP/x -ot $TMP/x || echo 'not older than itself'
test $TMP/x -nt $TMP/x || echo 'not newer than itself'
## STDOUT:
older
not newer
not older than itself
not newer than itself
## END

0 comments on commit 5a09f28

Please sign in to comment.