1010import difflib
1111import tempfile
1212
13-
1413reOPT = re .compile (r'^opt([0-9]+)_' ) # To detect -On tests
1514reBIN = re .compile (r'^(?:.*/)?(tzx|tap)_.*' ) # To detect tzx / tap test
1615
4645DEFAULT_STDERR = '/dev/stderr'
4746STDERR = None
4847INLINE = True # Set to false to use system Shell
48+ RAISE_EXCEPTIONS = False # True if we want the testing to abort on compiler crashes
4949
5050
5151class TempTestFile (object ):
5252 """ Uses a python guard context to ensure file deletion.
5353 Executes a system command which creates a temporary file and
5454 ensures file deletion upon return.
5555 """
56+
5657 def __init__ (self , func , fname , keep_file = False ):
5758 """ Initializes the context. The flag dont_remove will only be taken into account
5859 if the System command execution was successful (returns 0)
@@ -381,24 +382,31 @@ def testBAS(fname, filter_=None, inline=None, cmdline_args=None):
381382def testFiles (file_list , cmdline_args = None ):
382383 """ Run tests for the given file extension
383384 """
384- global EXIT_CODE , COUNTER , FAILED
385+ global EXIT_CODE , COUNTER , FAILED , RAISE_EXCEPTIONS
386+
385387 COUNTER = 0
386388 if cmdline_args is None :
387389 cmdline_args = []
388390
389391 for fname in file_list :
390392 fname = fname
391393 ext = getExtension (fname )
392- if ext == 'asm' :
393- if os .path .exists (os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + 'bas' )):
394- continue # Ignore asm files which have a .bas since they're test results
395- result = testASM (fname , inline = INLINE , cmdline_args = cmdline_args )
396- elif ext == 'bas' :
397- result = testBAS (fname , filter_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
398- elif ext == 'bi' :
399- result = testPREPRO (fname , pattern_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
400- else :
401- result = None
394+ try :
395+ if ext == 'asm' :
396+ if os .path .exists (os .path .join (os .path .dirname (fname ), getName (fname ) + os .extsep + 'bas' )):
397+ continue # Ignore asm files which have a .bas since they're test results
398+ result = testASM (fname , inline = INLINE , cmdline_args = cmdline_args )
399+ elif ext == 'bas' :
400+ result = testBAS (fname , filter_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
401+ elif ext == 'bi' :
402+ result = testPREPRO (fname , pattern_ = FILTER , inline = INLINE , cmdline_args = cmdline_args )
403+ else :
404+ result = None
405+ except Exception as e : # noqa
406+ result = False
407+ _msg ("{}: *CRASH* {} exception\n " .format (fname , type (e ).__name__ ))
408+ if RAISE_EXCEPTIONS :
409+ raise
402410
403411 COUNTER += 1
404412 _msg (("%4i " % COUNTER ) + getName (fname ) + ':' )
@@ -522,6 +530,7 @@ def main(argv=None):
522530 global COUNTER
523531 global FAILED
524532 global EXIT_CODE
533+ global RAISE_EXCEPTIONS
525534
526535 COUNTER = FAILED = EXIT_CODE = 0
527536
@@ -538,6 +547,9 @@ def main(argv=None):
538547 parser .add_argument ('-S' , '--use-shell' , action = 'store_true' , help = 'Use system shell for test instead of inline' )
539548 parser .add_argument ('-O' , '--option' , action = 'append' , help = 'Option to pass to compiler in a test '
540549 '(can be used many times)' )
550+ parser .add_argument ('-E' , '--raise-exceptions' , action = 'store_true' , help = 'If an exception is raised (i.e.'
551+ 'the compiler crashes) the testing will '
552+ 'stop with such exception' )
541553 args = parser .parse_args (argv )
542554
543555 STDERR = args .stderr
@@ -547,6 +559,7 @@ def main(argv=None):
547559 STDERR = DEFAULT_STDERR
548560
549561 INLINE = not args .use_shell
562+ RAISE_EXCEPTIONS = args .raise_exceptions
550563
551564 temp_dir_created = False
552565 try :
0 commit comments