Skip to content

Commit

Permalink
More reorganization of parse error tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Aug 22, 2018
1 parent c66042c commit 9766004
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions osh/word_parse.py
Expand Up @@ -366,7 +366,7 @@ def _ParseVarExpr(self, arg_lex_mode):
token=self.cur_token)

else:
p_die('Unexpected token %s', self.cur_token, token=self.cur_token)
p_die('Unexpected token %r', self.cur_token.val, token=self.cur_token)

part.suffix_op = op

Expand Down Expand Up @@ -497,7 +497,7 @@ def _ReadBracedBracedVarSub(self, d_quoted=False):

else:
# e.g. ${^}
p_die('Unexpected token %s', self.cur_token, token=self.cur_token)
p_die('Unexpected token %r', self.cur_token.val, token=self.cur_token)

part.spids.append(left_spid)

Expand Down
35 changes: 30 additions & 5 deletions test/parse-errors.sh
Expand Up @@ -50,6 +50,13 @@ patsub() {
# osh/word_parse.py
word-parse() {
set +o errexit

_error-case 'echo ${'

# This parses like a slice, but that's OK. Maybe talk about arithmetic
# expression. Maybe say where it started?
_error-case '${foo:}'

_error-case 'echo ${a[@Z'

_error-case 'echo ${x.}'
Expand All @@ -71,10 +78,15 @@ word-parse() {
_error-case 'for (( i = 0; i < 10; i++ /'

_error-case 'echo @(extglob|foo'
}

array-literal() {
set +o errexit

# Array literal with invalid TokenWord.
_error-case 'a=(1 & 2)'
_error-case 'a= (1 2)'
_error-case 'a=(1 2'
}

arith-context() {
Expand All @@ -83,6 +95,8 @@ arith-context() {
# $(( ))
_error-case 'echo $(( 1 + 2 ;'
_error-case 'echo $(( 1 + 2 );'
_error-case 'echo $(( '
_error-case 'echo $(( 1'

# Non-standard arith sub $[1 + 2]
_error-case 'echo $[ 1 + 2 ;'
Expand All @@ -91,10 +105,13 @@ arith-context() {
_error-case 'echo $[ 1 + 2 /'

_error-case 'echo $[ 1 + 2 / 3'
_error-case 'echo $['

# (( ))
_error-case '(( 1 + 2 /'
_error-case '(( 1 + 2 )/'
_error-case '(( 1'
_error-case '(('
}

arith-expr() {
Expand Down Expand Up @@ -129,6 +146,9 @@ bool-expr() {
_error-case '[[ == ]]'
_error-case '[[ ) ]]'
_error-case '[[ ( ]]'

_error-case '[[ ;;; ]]'
_error-case '[['
}

quoted-strings() {
Expand All @@ -149,20 +169,25 @@ quoted-strings() {
line 2"
}


cases-in-strings() {
cmd-parse() {
set +o errexit

_error-case 'echo < <<'
_error-case '${foo:}'
_error-case '$(( 1 + ))'
_error-case 'echo $( echo > >> )'
_error-case 'echo ${'
}

cases-in-strings() {
set +o errexit

cmd-parse

# Word
word-parse
array-literal
patsub
quoted-strings

# Arith
arith-context
arith-expr

Expand Down

0 comments on commit 9766004

Please sign in to comment.