def test_compile_only(file_bas, file_bin): """ Should not generate a file """ with EnsureRemoveFile(file_bin): zxb.main(['--parse-only', file_bas, '-o', file_bin]) assert not os.path.isfile( file_bin), 'Should not create file "empty.bin"'
def testBAS(fname, filter_=None, inline=None): """ Test compiling a BASIC (.bas) file. Test is done by compiling the source code into asm and then comparing the output asm against an expected asm output. The output asm file can optionally be filtered using a filter_ regexp (see above). :param fname: Filename (.bas file) to test. :param filter_: regexp for filtering output before comparing. It will be ignored for binary (tzx, tap, etc) files :param inline: whether the test should be run inline or using the system shell :return: True on success false if not """ if inline is None: inline = INLINE options, tfname, ext = _get_testbas_options(fname) okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext) if UPDATE and os.path.exists(okfile): os.unlink(okfile) if inline: func = lambda: zxb.main(options + ['-I', ':'.join(os.path.join(ZXBASIC_ROOT, x) for x in ('library', 'library-asm'))]) else: syscmd = '{0} {1}'.format(ZXB, ' '.join(options)) func = lambda: systemExec(syscmd) result = None with TempTestFile(func, tfname, UPDATE): if not UPDATE: result = is_same_file(okfile, tfname, filter_, is_binary=reBIN.match(fname) is not None) else: updateTest(tfname, FILTER) return result
def upgradeTest(fileList, f3diff): """ Run against the list of files, and a 3rd file containing the diff. If the diff between file1 and file2 are the same as file3, then the .asm file is patched. """ def normalizeDiff(diff): diff = [x.strip(' \t') for x in diff] reHEADER = re.compile(r'[-+]{3}') while diff and reHEADER.match(diff[0]): diff = diff[1:] first = True reHUNK = re.compile(r'@@ [-+](\d+)(,\d+)? [-+](\d+)(,\d+)? @@') for i in range(len(diff)): line = diff[i] if line[:7] in ('-#line ', '+#line '): diff[i] = '' continue match = reHUNK.match(line) if match: g = match.groups() g = [x if x is not None else '' for x in g] if first: first = False O1 = int(g[0]) O2 = int(g[2]) diff[i] = "@@ -%(a)s%(b)s +%(c)s%(d)s\n" % \ {'a': int(g[0]) - O1, 'b': g[1], 'c': int(g[2]) - O2, 'd': g[3]} return diff fdiff = open(f3diff).readlines() fdiff = normalizeDiff(fdiff) for fname in fileList: ext = getExtension(fname) if ext != 'bas': continue if testBAS(fname): continue fname0 = getName(fname) fname1 = fname0 + os.extsep + 'asm' options, tfname, ext = _get_testbas_options(fname) if zxb.main(options): try: os.unlink(tfname) except OSError: pass continue lines = [] is_same_file(fname1, tfname, ignore_regexp=FILTER, diff=lines) lines = normalizeDiff(lines) if lines != fdiff: for x, y in zip(lines, fdiff): x = x.strip() y = y.strip() c = '=' if x == y else '!' _msg('"%s"%s"%s"\n' % (x.strip(), c, y.strip())) os.unlink(tfname) continue # Not the same diff os.unlink(fname1) os.rename(tfname, fname1) _msg("\rTest: %s (%s) updated\n" % (fname, fname1))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # vim: ts=4:sw=4:et: import sys import zxb if __name__ == '__main__': print('-' * 48 + '\n* WARNING: zxb is deprecated! Use zxbc instead *\n' + '-' * 48, file=sys.stderr) sys.exit(zxb.main()) # Exit
def test_org_allows_0xnnnn_format(file_bas, file_bin): """ Should allow hexadecimal format 0x in org """ with EnsureRemoveFile(file_bin): zxb.main(['--parse-only', '--org', '0xC000', file_bas, '-o', file_bin]) assert zxb.OPTIONS.org.value == 0xC000, 'Should set ORG to 0xC000'