@@ -238,7 +238,7 @@ def updateTest(tfname, pattern_):
238238 f .write ('' .join (lines ))
239239
240240
241- def testPREPRO (fname , pattern_ = None , inline = None ):
241+ def testPREPRO (fname , pattern_ = None , inline = None , cmdline_args = None ):
242242 """ Test preprocessing file. Test is done by preprocessing the file and then
243243 comparing the output against an expected one. The output file can optionally be filtered
244244 using a filter_ regexp (see above).
@@ -253,6 +253,9 @@ def testPREPRO(fname, pattern_=None, inline=None):
253253 if inline is None :
254254 inline = INLINE
255255
256+ if cmdline_args is None :
257+ cmdline_args = []
258+
256259 tfname = os .path .join (TEMP_DIR , 'test' + getName (fname ) + os .extsep + 'out' )
257260 okfile = os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + 'out' )
258261
@@ -268,6 +271,8 @@ def testPREPRO(fname, pattern_=None, inline=None):
268271 os .unlink (okfile )
269272
270273 options = [os .path .basename (fname ), '-o' , tfname ] + prep
274+ options .extend (cmdline_args )
275+
271276 if inline :
272277 func = lambda : zxbpp .entry_point (options )
273278 else :
@@ -291,7 +296,7 @@ def testPREPRO(fname, pattern_=None, inline=None):
291296 return result
292297
293298
294- def testASM (fname , inline = None ):
299+ def testASM (fname , inline = None , cmdline_args = None ):
295300 """ Test assembling an ASM (.asm) file. Test is done by assembling the source code into a binary and then
296301 comparing the output file against an expected binary output.
297302
@@ -302,6 +307,9 @@ def testASM(fname, inline=None):
302307 if inline is None :
303308 inline = INLINE
304309
310+ if cmdline_args is None :
311+ cmdline_args = []
312+
305313 tfname = os .path .join (TEMP_DIR , 'test' + getName (fname ) + os .extsep + 'bin' )
306314 prep = ['-e' , '/dev/null' ] if CLOSE_STDERR else ['-e' , STDERR ]
307315 okfile = os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + 'bin' )
@@ -312,6 +320,7 @@ def testASM(fname, inline=None):
312320 os .unlink (okfile )
313321
314322 options = [fname , '-o' , tfname ] + prep
323+ options .extend (cmdline_args )
315324
316325 if inline :
317326 func = lambda : zxbasm .main (options )
@@ -327,7 +336,7 @@ def testASM(fname, inline=None):
327336 return result
328337
329338
330- def testBAS (fname , filter_ = None , inline = None ):
339+ def testBAS (fname , filter_ = None , inline = None , cmdline_args = None ):
331340 """ Test compiling a BASIC (.bas) file. Test is done by compiling the source code into asm and then
332341 comparing the output asm against an expected asm output. The output asm file can optionally be filtered
333342 using a filter_ regexp (see above).
@@ -340,7 +349,11 @@ def testBAS(fname, filter_=None, inline=None):
340349 if inline is None :
341350 inline = INLINE
342351
352+ if cmdline_args is None :
353+ cmdline_args = []
354+
343355 options , tfname , ext = _get_testbas_options (fname )
356+ options .extend (cmdline_args )
344357 okfile = os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + ext )
345358
346359 if UPDATE and os .path .exists (okfile ):
@@ -363,23 +376,25 @@ def testBAS(fname, filter_=None, inline=None):
363376 return result
364377
365378
366- def testFiles (file_list ):
379+ def testFiles (file_list , cmdline_args = None ):
367380 """ Run tests for the given file extension
368381 """
369382 global EXIT_CODE , COUNTER , FAILED
370383 COUNTER = 0
384+ if cmdline_args is None :
385+ cmdline_args = []
371386
372387 for fname in file_list :
373388 fname = fname
374389 ext = getExtension (fname )
375390 if ext == 'asm' :
376391 if os .path .exists (os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + 'bas' )):
377392 continue # Ignore asm files which have a .bas since they're test results
378- result = testASM (fname , inline = INLINE )
393+ result = testASM (fname , inline = INLINE , cmdline_args = cmdline_args )
379394 elif ext == 'bas' :
380- result = testBAS (fname , filter_ = FILTER , inline = INLINE )
395+ result = testBAS (fname , filter_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
381396 elif ext == 'bi' :
382- result = testPREPRO (fname , pattern_ = FILTER , inline = INLINE )
397+ result = testPREPRO (fname , pattern_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
383398 else :
384399 result = None
385400
@@ -519,6 +534,8 @@ def main(argv=None):
519534 parser .add_argument ('-q' , '--quiet' , action = 'store_true' , help = 'Run quietly, suppressing normal output' )
520535 parser .add_argument ('-e' , '--stderr' , type = str , default = None , help = 'File for stderr messages' )
521536 parser .add_argument ('-S' , '--use-shell' , action = 'store_true' , help = 'Use system shell for test instead of inline' )
537+ parser .add_argument ('-O' , '--option' , action = 'append' , help = 'Option to pass to compiler in a test '
538+ '(can be used many times)' )
522539 args = parser .parse_args (argv )
523540
524541 STDERR = args .stderr
@@ -541,7 +558,7 @@ def main(argv=None):
541558 if args .update :
542559 upgradeTest (args .FILES , args .update )
543560 else :
544- testFiles (args .FILES )
561+ testFiles (args .FILES , args . option )
545562
546563 finally :
547564 if temp_dir_created :
0 commit comments