@@ -104,6 +104,70 @@ def test_parser_11():
104
104
tok = lparser (s )
105
105
assert tok == "'"
106
106
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
+
107
171
def test_parser_badinput_1 ():
108
172
# pylint: disable=missing-docstring,invalid-name
109
173
with pytest .raises (ParserInputError ):
@@ -372,7 +436,7 @@ def _compare_proj_str(estr, possible_actual_strs):
372
436
assert False , exceptions
373
437
374
438
375
- def main (argv = None , debugging = False ):
439
+ def main (argv = None , debugging = False , extras = () ):
376
440
'''
377
441
Main entry point, allows quick comparison of eval-based adt parser with this
378
442
eval-free adt parser.
@@ -406,7 +470,7 @@ def main(argv=None, debugging=False):
406
470
skipeval = len (argv ) > 2
407
471
if skipeval :
408
472
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 })
410
474
if not isinstance (projtxt , str ): # on python3 projtxt is bytes not str
411
475
estr = projtxt .decode ('utf-8' )
412
476
else :
@@ -416,14 +480,14 @@ def main(argv=None, debugging=False):
416
480
# normalize strings in input
417
481
else :
418
482
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 )
420
484
421
485
# make sure to do this here not before calling bap the first time
422
486
# Once this runs, if a lot of memory is used, Python can't create
423
487
# child processes in all cases because os.fork() will fail under heavy
424
488
# memory load
425
489
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 )
427
491
428
492
if not skipeval :
429
493
if origproj == new_proj : # done!
0 commit comments