Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merged in bugfix/asm_map_crash (pull request boriel-basic#222)
Browse files Browse the repository at this point in the history
Bugfix/asm map crash

Approved-by: Jose Rodriguez <boriel@gmail.com>
  • Loading branch information
boriel committed Oct 6, 2019
2 parents b726835 + 746a22f commit 7e732a5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
3 changes: 2 additions & 1 deletion tests/functional/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ diffbas:
test: prepro bin asm bas

test_:
./test_.py
pytest . -k 'test_errmsg or test_cmdline'
# ./test_.py

prepro:
./test.py *.bi
Expand Down
33 changes: 25 additions & 8 deletions tests/functional/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def updateTest(tfname, pattern_):
f.write(''.join(lines))


def testPREPRO(fname, pattern_=None, inline=None):
def testPREPRO(fname, pattern_=None, inline=None, cmdline_args=None):
""" Test preprocessing file. Test is done by preprocessing the file and then
comparing the output against an expected one. The output file can optionally be filtered
using a filter_ regexp (see above).
Expand All @@ -253,6 +253,9 @@ def testPREPRO(fname, pattern_=None, inline=None):
if inline is None:
inline = INLINE

if cmdline_args is None:
cmdline_args = []

tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + 'out')
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'out')

Expand All @@ -268,6 +271,8 @@ def testPREPRO(fname, pattern_=None, inline=None):
os.unlink(okfile)

options = [os.path.basename(fname), '-o', tfname] + prep
options.extend(cmdline_args)

if inline:
func = lambda: zxbpp.entry_point(options)
else:
Expand All @@ -291,7 +296,7 @@ def testPREPRO(fname, pattern_=None, inline=None):
return result


def testASM(fname, inline=None):
def testASM(fname, inline=None, cmdline_args=None):
""" Test assembling an ASM (.asm) file. Test is done by assembling the source code into a binary and then
comparing the output file against an expected binary output.
Expand All @@ -302,6 +307,9 @@ def testASM(fname, inline=None):
if inline is None:
inline = INLINE

if cmdline_args is None:
cmdline_args = []

tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + 'bin')
prep = ['-e', '/dev/null'] if CLOSE_STDERR else ['-e', STDERR]
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'bin')
Expand All @@ -312,6 +320,7 @@ def testASM(fname, inline=None):
os.unlink(okfile)

options = [fname, '-o', tfname] + prep
options.extend(cmdline_args)

if inline:
func = lambda: zxbasm.main(options)
Expand All @@ -327,7 +336,7 @@ def testASM(fname, inline=None):
return result


def testBAS(fname, filter_=None, inline=None):
def testBAS(fname, filter_=None, inline=None, cmdline_args=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).
Expand All @@ -340,7 +349,11 @@ def testBAS(fname, filter_=None, inline=None):
if inline is None:
inline = INLINE

if cmdline_args is None:
cmdline_args = []

options, tfname, ext = _get_testbas_options(fname)
options.extend(cmdline_args)
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext)

if UPDATE and os.path.exists(okfile):
Expand All @@ -363,23 +376,25 @@ def testBAS(fname, filter_=None, inline=None):
return result


def testFiles(file_list):
def testFiles(file_list, cmdline_args=None):
""" Run tests for the given file extension
"""
global EXIT_CODE, COUNTER, FAILED
COUNTER = 0
if cmdline_args is None:
cmdline_args = []

for fname in file_list:
fname = fname
ext = getExtension(fname)
if ext == 'asm':
if os.path.exists(os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'bas')):
continue # Ignore asm files which have a .bas since they're test results
result = testASM(fname, inline=INLINE)
result = testASM(fname, inline=INLINE, cmdline_args=cmdline_args)
elif ext == 'bas':
result = testBAS(fname, filter_=FILTER, inline=INLINE)
result = testBAS(fname, filter_=FILTER, inline=INLINE, cmdline_args=cmdline_args)
elif ext == 'bi':
result = testPREPRO(fname, pattern_=FILTER, inline=INLINE)
result = testPREPRO(fname, pattern_=FILTER, inline=INLINE, cmdline_args=cmdline_args)
else:
result = None

Expand Down Expand Up @@ -519,6 +534,8 @@ def main(argv=None):
parser.add_argument('-q', '--quiet', action='store_true', help='Run quietly, suppressing normal output')
parser.add_argument('-e', '--stderr', type=str, default=None, help='File for stderr messages')
parser.add_argument('-S', '--use-shell', action='store_true', help='Use system shell for test instead of inline')
parser.add_argument('-O', '--option', action='append', help='Option to pass to compiler in a test '
'(can be used many times)')
args = parser.parse_args(argv)

STDERR = args.stderr
Expand All @@ -541,7 +558,7 @@ def main(argv=None):
if args.update:
upgradeTest(args.FILES, args.update)
else:
testFiles(args.FILES)
testFiles(args.FILES, args.option)

finally:
if temp_dir_created:
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def main():
current_path = os.path.abspath(os.getcwd())
os.chdir(os.path.realpath(os.path.dirname(__file__) or os.curdir))
result = doctest.testfile('test_errmsg.txt') # evaluates to True on failure
if not result.failed:
result = doctest.testfile('test_cmdline.txt') # Evaluates to True on failure
os.chdir(current_path)
return int(result.failed)

Expand Down
15 changes: 15 additions & 0 deletions tests/functional/test_cmdline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
>>> from test_ import process_file
>>> import os
>>> os.environ['COLUMNS'] = '80'

>>> process_file('arrbase1.bas', ['-q', '-S', '-O --asm', '-O --mmap arrbase1.map'])
usage: zxb [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a] [-A]
[-S ORG] [-e STDERR] [--array-base ARRAY_BASE]
[--string-base STRING_BASE] [-Z] [-H HEAP_SIZE] [--debug-memory]
[--debug-array] [--strict-bool] [--enable-break] [-E] [--explicit]
[-D DEFINES] [-M MEMORY_MAP] [-i] [-I INCLUDE_PATH] [--strict]
[--headerless] [--version] [--parse-only]
[--append-binary APPEND_BINARY]
[--append-headless-binary APPEND_HEADLESS_BINARY]
PROGRAM
zxb: error: Option --asm and --mmap cannot be used together
9 changes: 7 additions & 2 deletions zxb.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def main(args=None):
parser.error('Option --append-binary needs either --tap or --tzx')
return 5

if options.asm and options.memory_map:
parser.error('Option --asm and --mmap cannot be used together')
return 6

OPTIONS.use_loader.value = options.basic
OPTIONS.autorun.value = options.autorun

Expand Down Expand Up @@ -345,8 +349,9 @@ def main(args=None):
return 5 # Error in assembly

if OPTIONS.memory_map.value:
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
f.write(asmparse.MEMORY.memory_map)
if asmparse.MEMORY is not None:
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
f.write(asmparse.MEMORY.memory_map)

return gl.has_errors # Exit success

Expand Down

0 comments on commit 7e732a5

Please sign in to comment.