Skip to content

Commit 95d5e56

Browse files
committed
Add tests with manual attributes with escapes
Includes tests with both --map-terms-using and --map-terms-with
1 parent d336df5 commit 95d5e56

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

tests/test_noeval_parser.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,70 @@ def test_parser_11():
104104
tok = lparser(s)
105105
assert tok == "'"
106106

107+
def test_compare_to_old_escapes_1(tmpdir):
108+
# pylint: disable=missing-docstring,invalid-name
109+
import os
110+
tmpdir.join('test.c').write('int main() { return 0; }')
111+
with tmpdir.as_cwd():
112+
assert os.system('gcc -o test.out test.c') == 0
113+
comment = r'a slash: \\'
114+
main([None, 'test.out'], extras=([
115+
'--map-terms-with',
116+
'((true) (comment "{}"))'.format(comment),
117+
'--map-terms'],))
118+
main([None, 'test.out', 'skip'], extras=([
119+
'--map-terms-with',
120+
'((true) (comment "{}"))'.format(comment),
121+
'--map-terms'],))
122+
123+
def test_compare_to_old_escapes_2(tmpdir):
124+
# pylint: disable=missing-docstring,invalid-name
125+
import os
126+
tmpdir.join('test.c').write('int main() { return 0; }')
127+
with tmpdir.as_cwd():
128+
assert os.system('gcc -o test.out test.c') == 0
129+
comment = r'an escaped quote: \"'
130+
main([None, 'test.out'], extras=([
131+
'--map-terms-with',
132+
'((true) (comment "{}"))'.format(comment),
133+
'--map-terms'],))
134+
main([None, 'test.out', 'skip'], extras=([
135+
'--map-terms-with',
136+
'((true) (comment "{}"))'.format(comment),
137+
'--map-terms'],))
138+
139+
def test_compare_to_old_escapes_3(tmpdir):
140+
# pylint: disable=missing-docstring,invalid-name
141+
import os
142+
tmpdir.join('test.c').write('int main() { return 0; }')
143+
with tmpdir.as_cwd():
144+
assert os.system('gcc -o test.out test.c') == 0
145+
comment = r'an escaped slash and then escaped quote: \\\"'
146+
main([None, 'test.out'], extras=([
147+
'--map-terms-with',
148+
'((true) (comment "{}"))'.format(comment),
149+
'--map-terms'],))
150+
main([None, 'test.out', 'skip'], extras=([
151+
'--map-terms-with',
152+
'((true) (comment "{}"))'.format(comment),
153+
'--map-terms'],))
154+
155+
def test_compare_to_old_escapes_4(tmpdir):
156+
# pylint: disable=missing-docstring,invalid-name
157+
comment = r'an escaped slash and then escaped quote: \\\"'
158+
import os
159+
tmpdir.join('test.c').write('int main() { return 0; }')
160+
comment_file = tmpdir.join('comment.scm')
161+
comment_file.write('((true) (comment "{}"))'.format(comment))
162+
with tmpdir.as_cwd():
163+
assert os.system('gcc -o test.out test.c') == 0
164+
main([None, 'test.out'], extras=([
165+
'--map-terms-using=%s' % comment_file,
166+
'--map-terms'],))
167+
main([None, 'test.out', 'skip'], extras=([
168+
'--map-terms-using=%s' % comment_file,
169+
'--map-terms'],))
170+
107171
def test_parser_badinput_1():
108172
# pylint: disable=missing-docstring,invalid-name
109173
with pytest.raises(ParserInputError):
@@ -372,7 +436,7 @@ def _compare_proj_str(estr, possible_actual_strs):
372436
assert False, exceptions
373437

374438

375-
def main(argv=None, debugging=False):
439+
def main(argv=None, debugging=False, extras=()):
376440
'''
377441
Main entry point, allows quick comparison of eval-based adt parser with this
378442
eval-free adt parser.
@@ -406,7 +470,7 @@ def main(argv=None, debugging=False):
406470
skipeval = len(argv) > 2
407471
if skipeval:
408472
logger.info("Calling bap.run(%r, parser=PASSTHRU)", toparse)
409-
projtxt = bap.run(toparse, parser={'format':'adt', 'load':lambda s: s})
473+
projtxt = bap.run(toparse, *extras, parser={'format':'adt', 'load':lambda s: s})
410474
if not isinstance(projtxt, str): # on python3 projtxt is bytes not str
411475
estr = projtxt.decode('utf-8')
412476
else:
@@ -416,14 +480,14 @@ def main(argv=None, debugging=False):
416480
# normalize strings in input
417481
else:
418482
logger.info("Calling bap.run(%r, parser=WITHEVAL)", toparse)
419-
origproj = bap.run(toparse, parser=witheval_adt_parser)
483+
origproj = bap.run(toparse, *extras, parser=witheval_adt_parser)
420484

421485
# make sure to do this here not before calling bap the first time
422486
# Once this runs, if a lot of memory is used, Python can't create
423487
# child processes in all cases because os.fork() will fail under heavy
424488
# memory load
425489
logger.info("Calling bap.run(%r, parser=EVALFREE)", toparse)
426-
new_proj = bap.run(toparse, parser=EVALFREE_ADT_PARSER)
490+
new_proj = bap.run(toparse, *extras, parser=EVALFREE_ADT_PARSER)
427491

428492
if not skipeval:
429493
if origproj == new_proj: # done!

0 commit comments

Comments
 (0)