Permalink
Browse files

Use the newer form of parse error handling in unit tests.

  • Loading branch information...
Andy Chu
Andy Chu committed Aug 30, 2018
1 parent fd737dd commit 067893e163eb81021bf55911d33ef82b3702c7c3
Showing with 13 additions and 30 deletions.
  1. +10 −23 osh/cmd_parse_test.py
  2. +3 −7 osh/word_parse_test.py
View
@@ -34,19 +34,15 @@ def _assertParseMethod(test, code_str, method, expect_success=True):
try:
node = m()
except util.ParseError as e:
ui.PrettyPrintError(e, arena, sys.stdout)
if expect_success:
test.fail('%r failed' % code_str)
node = None
if node:
else:
ast_lib.PrettyPrint(node)
if not expect_success:
test.fail('Expected %r to fail ' % code_str)
else:
# TODO: Could copy PrettyPrintError from pysh.py
err = c_parser.Error()
print(err)
ui.PrintErrorStack(err, arena, sys.stdout)
if expect_success:
test.fail('%r failed' % code_str)
return node
@@ -56,20 +52,11 @@ def _assertParseCommandListError(test, code_str):
try:
node = c_parser.ParseCommandLine()
except util.ParseError as e:
print(e)
return
# TODO: Don't check two kinds of failures!
if not node:
err = c_parser.Error()
#print(err)
ui.PrintErrorStack(err, arena, sys.stdout)
return
print('UNEXPECTED:')
ast_lib.PrettyPrint(node)
test.fail("Expected %r to fail" % code_str)
return
ui.PrettyPrintError(e, arena, sys.stdout)
else:
print('UNEXPECTED:')
ast_lib.PrettyPrint(node)
test.fail("Expected %r to fail" % code_str)
#
View
@@ -84,13 +84,9 @@ def _assertReadWordFailure(test, word_str):
w = w_parser.ReadWord(lex_mode_e.OUTER)
except util.ParseError as e:
print(e)
return
if not w:
print(w_parser.Error())
return
ast_lib.PrettyPrint(w)
test.fail('Expected a parser error, got %r' % w)
else:
ast_lib.PrettyPrint(w)
test.fail('Expected a parser error, got %r' % w)
def _GetSuffixOp(test, w):

0 comments on commit 067893e

Please sign in to comment.