1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-01 18:41:32 +00:00

Catch exception from address overflow in "add_label" command

This commit is contained in:
Mike Naberezny 2016-12-07 09:03:02 -08:00
parent 37cefce91a
commit 70dd9687a9
2 changed files with 27 additions and 6 deletions

View File

@ -759,10 +759,15 @@ class Monitor(cmd.Cmd):
self._output("Syntax error: %s" % args)
return self.help_add_label()
address = self._address_parser.number(split[0])
label = split[1]
self._address_parser.labels[label] = address
try:
address = self._address_parser.number(split[0])
except KeyError as exc:
self._output(exc.args[0]) # "Label not found: foo"
except OverflowError:
self._output("Overflow error: %s" % args)
else:
label = split[1]
self._address_parser.labels[label] = address
def help_show_labels(self):
self._output("show_labels")

View File

@ -92,9 +92,25 @@ class MonitorTests(unittest.TestCase):
def test_do_add_label_syntax_error(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_add_label('should be label space value')
mon.do_add_label('should be address space label')
out = stdout.getvalue()
err = "Syntax error: should be label space value\n"
err = "Syntax error: should be address space label\n"
self.assertTrue(out.startswith(err))
def test_do_add_label_overflow_error(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_add_label('$10000 toobig')
out = stdout.getvalue()
err = "Overflow error: $10000 toobig\n"
self.assertTrue(out.startswith(err))
def test_do_add_label_label_error(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_add_label('nonexistent foo')
out = stdout.getvalue()
err = "Label not found: nonexistent\n"
self.assertTrue(out.startswith(err))
def test_do_add_label_adds_label(self):