Commit 198e7daa authored by Eckhart Arnold's avatar Eckhart Arnold

added configuration 'test_supress_lookahead_failures'

parent d1cc7e98
......@@ -200,3 +200,19 @@ CONFIG_PRESET['log_server'] = False
# Python multiprocessing module
# Default value: True
CONFIG_PRESET['test_parallelization'] = True
# Employs heuristics to allow lookahead-based parsers to pass unit-test
# in case a reported error may only be due to the fact that the test
# string a) either did include a substring for a lookahead check, the
# was then left over when parsing stopped (which would usually result
# in a "parser stopped before end"-error) or b) did not include a
# substring expected by a lookahead check as this is not part of the
# sequence that the tested parser should return in form of a concrete
# syntax-tree. (This would otherwise result in a 'parser did not match'-
# error.)
# Beware that a) these heuristics can fail, so that certain
# test-failures may fail to be reported and b) the abstract-syntax-trees
# resulting from parsers that contain lookahead checks may have a
# structure that would not occur outside the testing-environment.
# Default value: True
CONFIG_PRESET['test_supress_lookahead_failures'] = True
......@@ -1603,7 +1603,7 @@ class OneOrMore(UnaryParser):
>>> Grammar(sentence)('Wo viel der Weisheit, da auch viel des Grämens.').content
'Wo viel der Weisheit, da auch viel des Grämens.'
>>> str(Grammar(sentence)('.')) # an empty sentence also matches
' <<< Error on "." | Parser did not match! >>> '
' <<< Error on "." | Parser "{/\\w+,?/ ~}+ \'.\' ~" did not match! >>> '
>>> forever = OneOrMore(RegExp(''))
>>> Grammar(forever)('') # infinite loops will automatically be broken
Node(:EMPTY__, )
......@@ -1724,7 +1724,7 @@ class Series(NaryParser):
>>> Grammar(variable_name)('variable_1').content
'variable_1'
>>> str(Grammar(variable_name)('1_variable'))
' <<< Error on "1_variable" | Parser did not match! >>> '
' <<< Error on "1_variable" | Parser "/(?!\\d)\\w/ /\\w*/ ~" did not match! >>> '
EBNF-Notation: ``... ...`` (sequence of parsers separated by a blank or new line)
......
......@@ -350,6 +350,8 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
This is required for testing of parsers that put a lookahead
operator at the end. See test_testing.TestLookahead.
"""
if not get_config_value('test_supress_lookahead_failures'):
return False
raw_errors = syntax_tree.errors_sorted
is_artifact = ({e.code for e in raw_errors} <=
{Error.PARSER_LOOKAHEAD_FAILURE_ONLY,
......@@ -478,7 +480,6 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
errata.append('Unknown parser "{}" in fail test "{}"!'.format(parser_name, test_name))
tests.setdefault('__err__', {})[test_name] = errata[-1]
if not (is_error(cst.error_flag) and not lookahead_artifact(cst)):
print(test_name, cst.errors_sorted)
errata.append('Fail test "%s" for parser "%s" yields match instead of '
'expected failure!' % (test_name, parser_name))
tests.setdefault('__err__', {})[test_name] = errata[-1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment