Skip to content

Commit b0866b3

Browse files
authored
Merge pull request #229 from boriel/bugfix/asm_map_crash
Bugfix/asm map crash
2 parents 6558153 + af51985 commit b0866b3

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

tests/functional/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ diffbas:
99
test: prepro bin asm bas
1010

1111
test_:
12-
./test_.py
12+
pytest . -k 'test_errmsg or test_cmdline'
13+
# ./test_.py
1314

1415
prepro:
1516
./test.py *.bi

tests/functional/test.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def updateTest(tfname, pattern_):
238238
f.write(''.join(lines))
239239

240240

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

256+
if cmdline_args is None:
257+
cmdline_args = []
258+
256259
tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + 'out')
257260
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'out')
258261

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

270273
options = [os.path.basename(fname), '-o', tfname] + prep
274+
options.extend(cmdline_args)
275+
271276
if inline:
272277
func = lambda: zxbpp.entry_point(options)
273278
else:
@@ -291,7 +296,7 @@ def testPREPRO(fname, pattern_=None, inline=None):
291296
return result
292297

293298

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

310+
if cmdline_args is None:
311+
cmdline_args = []
312+
305313
tfname = os.path.join(TEMP_DIR, 'test' + getName(fname) + os.extsep + 'bin')
306314
prep = ['-e', '/dev/null'] if CLOSE_STDERR else ['-e', STDERR]
307315
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'bin')
@@ -312,6 +320,7 @@ def testASM(fname, inline=None):
312320
os.unlink(okfile)
313321

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

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

329338

330-
def testBAS(fname, filter_=None, inline=None):
339+
def testBAS(fname, filter_=None, inline=None, cmdline_args=None):
331340
""" Test compiling a BASIC (.bas) file. Test is done by compiling the source code into asm and then
332341
comparing the output asm against an expected asm output. The output asm file can optionally be filtered
333342
using a filter_ regexp (see above).
@@ -340,7 +349,11 @@ def testBAS(fname, filter_=None, inline=None):
340349
if inline is None:
341350
inline = INLINE
342351

352+
if cmdline_args is None:
353+
cmdline_args = []
354+
343355
options, tfname, ext = _get_testbas_options(fname)
356+
options.extend(cmdline_args)
344357
okfile = os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + ext)
345358

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

365378

366-
def testFiles(file_list):
379+
def testFiles(file_list, cmdline_args=None):
367380
""" Run tests for the given file extension
368381
"""
369382
global EXIT_CODE, COUNTER, FAILED
370383
COUNTER = 0
384+
if cmdline_args is None:
385+
cmdline_args = []
371386

372387
for fname in file_list:
373388
fname = fname
374389
ext = getExtension(fname)
375390
if ext == 'asm':
376391
if os.path.exists(os.path.join(os.path.dirname(fname), getName(fname) + os.extsep + 'bas')):
377392
continue # Ignore asm files which have a .bas since they're test results
378-
result = testASM(fname, inline=INLINE)
393+
result = testASM(fname, inline=INLINE, cmdline_args=cmdline_args)
379394
elif ext == 'bas':
380-
result = testBAS(fname, filter_=FILTER, inline=INLINE)
395+
result = testBAS(fname, filter_=FILTER, inline=INLINE, cmdline_args=cmdline_args)
381396
elif ext == 'bi':
382-
result = testPREPRO(fname, pattern_=FILTER, inline=INLINE)
397+
result = testPREPRO(fname, pattern_=FILTER, inline=INLINE, cmdline_args=cmdline_args)
383398
else:
384399
result = None
385400

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

524541
STDERR = args.stderr
@@ -541,7 +558,7 @@ def main(argv=None):
541558
if args.update:
542559
upgradeTest(args.FILES, args.update)
543560
else:
544-
testFiles(args.FILES)
561+
testFiles(args.FILES, args.option)
545562

546563
finally:
547564
if temp_dir_created:

tests/functional/test_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def main():
4343
current_path = os.path.abspath(os.getcwd())
4444
os.chdir(os.path.realpath(os.path.dirname(__file__) or os.curdir))
4545
result = doctest.testfile('test_errmsg.txt') # evaluates to True on failure
46+
if not result.failed:
47+
result = doctest.testfile('test_cmdline.txt') # Evaluates to True on failure
4648
os.chdir(current_path)
4749
return int(result.failed)
4850

tests/functional/test_cmdline.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
>>> from test_ import process_file
2+
>>> import os
3+
>>> os.environ['COLUMNS'] = '80'
4+
5+
>>> process_file('arrbase1.bas', ['-q', '-S', '-O --asm', '-O --mmap arrbase1.map'])
6+
usage: zxb [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a] [-A]
7+
[-S ORG] [-e STDERR] [--array-base ARRAY_BASE]
8+
[--string-base STRING_BASE] [-Z] [-H HEAP_SIZE] [--debug-memory]
9+
[--debug-array] [--strict-bool] [--enable-break] [-E] [--explicit]
10+
[-D DEFINES] [-M MEMORY_MAP] [-i] [-I INCLUDE_PATH] [--strict]
11+
[--headerless] [--version] [--parse-only]
12+
[--append-binary APPEND_BINARY]
13+
[--append-headless-binary APPEND_HEADLESS_BINARY]
14+
PROGRAM
15+
zxb: error: Option --asm and --mmap cannot be used together

zxb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def main(args=None):
209209
parser.error('Option --append-binary needs either --tap or --tzx')
210210
return 5
211211

212+
if options.asm and options.memory_map:
213+
parser.error('Option --asm and --mmap cannot be used together')
214+
return 6
215+
212216
OPTIONS.use_loader.value = options.basic
213217
OPTIONS.autorun.value = options.autorun
214218

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

347351
if OPTIONS.memory_map.value:
348-
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
349-
f.write(asmparse.MEMORY.memory_map)
352+
if asmparse.MEMORY is not None:
353+
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
354+
f.write(asmparse.MEMORY.memory_map)
350355

351356
return gl.has_errors # Exit success
352357

0 commit comments

Comments
 (0)