|
9 | 9 | import subprocess |
10 | 10 | import difflib |
11 | 11 | import tempfile |
| 12 | +import shutil |
12 | 13 |
|
13 | 14 | from typing import List |
14 | 15 |
|
@@ -87,7 +88,7 @@ def __exit__(self, type_, value, traceback): |
87 | 88 | try: |
88 | 89 | os.unlink(self.fname) |
89 | 90 | except (OSError, FileNotFoundError): |
90 | | - pass # Ok. It might be that the wasn't created |
| 91 | + pass # Ok. It might be that it wasn't created |
91 | 92 |
|
92 | 93 |
|
93 | 94 | def _error(msg, exit_code=None): |
@@ -222,17 +223,14 @@ def _get_testbas_options(fname: str): |
222 | 223 | options.extend(['--%s' % ext, fname, '-o', tfname, '-a', '-B'] + prep) |
223 | 224 | else: |
224 | 225 | ext = 'asm' |
225 | | - if not UPDATE: |
226 | | - tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + ext) |
227 | | - else: |
228 | | - tfname = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext) |
| 226 | + tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + ext) |
229 | 227 | options.extend(['--asm', fname, '-o', tfname] + prep) |
230 | 228 | return options, tfname, ext |
231 | 229 |
|
232 | 230 |
|
233 | 231 | def updateTest(tfname: str, pattern_, strip_blanks: bool = True): |
234 | 232 | if not os.path.exists(tfname): |
235 | | - return # was deleted -> The test is an error test and no compile filed should exist |
| 233 | + return # was deleted -> The test is an error test and no compile file should exist |
236 | 234 |
|
237 | 235 | if reBIN.match(tfname): # Binary files do not need updating |
238 | 236 | return |
@@ -366,22 +364,26 @@ def testBAS(fname, filter_=None, inline=None, cmdline_args=None): |
366 | 364 | options.extend(cmdline_args) |
367 | 365 | okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext) |
368 | 366 |
|
369 | | - if UPDATE and os.path.exists(okfile): |
370 | | - os.unlink(okfile) |
371 | | - |
372 | 367 | if inline: |
373 | 368 | func = lambda: libzxbc.main(options + ['-I', ':'.join(os.path.join(ZXBASIC_ROOT, x) |
374 | 369 | for x in ('library', 'library-asm'))]) |
375 | 370 | else: |
376 | 371 | syscmd = '{0} {1}'.format(ZXB, ' '.join(options)) |
377 | 372 | func = lambda: systemExec(syscmd) |
378 | 373 |
|
379 | | - result = None |
380 | 374 | with TempTestFile(func, tfname, UPDATE): |
381 | | - if not UPDATE: |
382 | | - result = is_same_file(okfile, tfname, filter_, is_binary=reBIN.match(fname) is not None) |
383 | | - else: |
384 | | - updateTest(tfname, FILTER) |
| 375 | + result = is_same_file(okfile, tfname, filter_, is_binary=reBIN.match(fname) is not None) |
| 376 | + if UPDATE: |
| 377 | + if not result: # File changed |
| 378 | + if os.path.exists(okfile): |
| 379 | + os.unlink(okfile) |
| 380 | + if os.path.exists(tfname): |
| 381 | + updateTest(tfname, FILTER) |
| 382 | + shutil.move(tfname, okfile) |
| 383 | + result = None |
| 384 | + else: # The file has not changed. Delete it |
| 385 | + if os.path.exists(tfname): |
| 386 | + os.unlink(tfname) |
385 | 387 |
|
386 | 388 | return result |
387 | 389 |
|
|
0 commit comments