Skip to content

Commit 4c5e5f6

Browse files
committed
Make test.py to update only failed tests
When using -U (force update failed tests), only failed tests should be updated, not all.
1 parent be1f777 commit 4c5e5f6

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

tests/functional/test.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import subprocess
1010
import difflib
1111
import tempfile
12+
import shutil
1213

1314
from typing import List
1415

@@ -87,7 +88,7 @@ def __exit__(self, type_, value, traceback):
8788
try:
8889
os.unlink(self.fname)
8990
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
9192

9293

9394
def _error(msg, exit_code=None):
@@ -222,17 +223,14 @@ def _get_testbas_options(fname: str):
222223
options.extend(['--%s' % ext, fname, '-o', tfname, '-a', '-B'] + prep)
223224
else:
224225
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)
229227
options.extend(['--asm', fname, '-o', tfname] + prep)
230228
return options, tfname, ext
231229

232230

233231
def updateTest(tfname: str, pattern_, strip_blanks: bool = True):
234232
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
236234

237235
if reBIN.match(tfname): # Binary files do not need updating
238236
return
@@ -366,22 +364,26 @@ def testBAS(fname, filter_=None, inline=None, cmdline_args=None):
366364
options.extend(cmdline_args)
367365
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext)
368366

369-
if UPDATE and os.path.exists(okfile):
370-
os.unlink(okfile)
371-
372367
if inline:
373368
func = lambda: libzxbc.main(options + ['-I', ':'.join(os.path.join(ZXBASIC_ROOT, x)
374369
for x in ('library', 'library-asm'))])
375370
else:
376371
syscmd = '{0} {1}'.format(ZXB, ' '.join(options))
377372
func = lambda: systemExec(syscmd)
378373

379-
result = None
380374
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)
385387

386388
return result
387389

0 commit comments

Comments
 (0)