1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
"""
PC-BASIC tests.test_debug
Tests for debugging module
(c) 2020--2023 Rob Hagemans
This file is released under the GNU GPL version 3 or later.
"""
from pcbasic import debug
from pcbasic.basic.base import error
from tests.unit.utils import TestCase, run_tests
class DebugTest(TestCase):
"""Debug module tests."""
tag = u'debug'
def test_get_platform_info(self):
"""Ensure get_platform_info outputs unicode."""
info = debug.get_platform_info()
assert isinstance(info, type(u''))
def test_debug(self):
"""Exercise debug statements."""
with debug.DebugSession() as s:
s.execute('_dir')
s.execute('_logprint "test"')
s.execute('_logwrite "test"')
s.execute('_showvariables')
s.execute('_showscreen')
s.execute('_showprogram')
s.execute('_showplatform')
s.execute('_python "print(\'--test--\')"')
def test_trace_watch(self):
"""Exercise _trace and _watch."""
with debug.DebugSession() as s:
s.execute('_trace')
# string
s.execute('_watch "a$"')
# single
s.execute('_watch "a!"')
# error
s.execute('_watch "log(-1)"')
s.execute('10 a=1:? a')
s.execute('20 a$="test"')
s.execute('run')
s.execute('_trace 0')
s.execute('run')
def test_crash(self):
"""Test _crash."""
with self.assertRaises(debug.DebugException):
with debug.DebugSession() as s:
s.execute('_crash')
def test_debugexception_repr(self):
"""Test DebugException.__repr__."""
assert isinstance(repr(debug.DebugException()), str)
def test_restart(self):
"""Test _restart."""
# Restart exception is not absorbed
with self.assertRaises(error.Reset):
with debug.DebugSession() as s:
s.execute('_restart')
def test_exit(self):
"""Test _exit."""
with debug.DebugSession() as s:
# Exit exception would be absorbed by the Session context
with self.assertRaises(error.Exit):
s.execute('_exit')
def test_exception(self):
"""Test exception in debug statement."""
with debug.DebugSession() as s:
# no exception raised
s.execute('_python "blah"')
if __name__ == '__main__':
run_tests()
|