Permalink
Browse files

Fix test for closing ] in [.

Fixes issue #82.
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 4, 2018
1 parent 744d0d2 commit 2192156eb1cb404b6e52e91850b0082be92ed042
Showing with 18 additions and 3 deletions.
  1. +1 −1 core/test_builtin.py
  2. +2 −0 doc/osh-quick-ref-toc.txt
  3. +15 −2 spec/builtin-test.test.sh
View
@@ -119,7 +119,7 @@ def Test(argv, need_right_bracket):
The only difference between test and [ is that [ needs a matching ].
"""
if need_right_bracket:
if argv[-1] != ']':
if not argv or argv[-1] != ']':
util.error('[: missing closing ]')
return 2
del argv[-1]
@@ -32,6 +32,7 @@ X [Conditional] switch match if-expr (
X [Iteration] for-expr ( while-expr (
X [Grouping] proc func lazy pure do { shell {
X [Context] with-cd with-redir with-env with-vars with-file
with-logger
X [Concurrency] fork
X [Redirects] multiline-string '''_""" file-descriptor !0
@@ -157,6 +158,7 @@ X [xargs] each
OIL LIBRARIES
X [Builtin Procs] log die
X [Builtin Funcs] shEvalArith() shEvalWord()
X [getopts] ?
X [Testing] ?
View
@@ -65,16 +65,29 @@ test -n x ]
echo status=$?
test -n x y
echo status=$?
# stdout-json: "status=2\nstatus=2\n"
## STDOUT:
status=2
status=2
## END
### ] syntax errors
[
echo status=$?
test # not a syntax error
echo status=$?
[ -n x # missing ]
echo status=$?
[ -n x ] y # extra arg after ]
echo status=$?
[ -n x y # extra arg
echo status=$?
# stdout-json: "status=2\nstatus=2\nstatus=2\n"
## STDOUT:
status=2
status=1
status=2
status=2
status=2
## END
### -n
test -n 'a' && echo true

0 comments on commit 2192156

Please sign in to comment.