/pygdb2/test/test_pygdb2.py

https://bitbucket.org/antocuni/pygdb2/ · Python · 47 lines · 43 code · 2 blank · 2 comment · 3 complexity · 91a53a23cd598b598a41b6e25d3ce0d7 MD5 · raw file

  1. import py
  2. import os
  3. import sys
  4. import re
  5. import pexpect
  6. def expect_lines(child, *lines):
  7. for line in lines:
  8. child.expect(line)
  9. def test_set_watchpoint(monkeypatch):
  10. root = py.path.local(__file__).join('..', '..', '..')
  11. PYTHONPATH = os.getenv('PYTHONPATH') or ''
  12. if PYTHONPATH:
  13. PYTHONPATH += ':'
  14. PYTHONPATH += str(root)
  15. monkeypatch.setenv('PYTHONPATH', PYTHONPATH)
  16. #
  17. watch_expr = re.escape('*(int*)') + '[0-9]*'
  18. #
  19. cmd = 'gdb --eval "python import pygdb2" --args %s set_watchpoint.py' % sys.executable
  20. child = pexpect.spawn(cmd, timeout=2)
  21. child.logfile = sys.stdout
  22. child.expect_exact ('(gdb) ')
  23. child.sendline('pyrun')
  24. expect_lines(child,
  25. 'program starting',
  26. 'pygdb2: watch %s' % watch_expr,
  27. 'Hardware watchpoint 1: %s' % watch_expr,
  28. '0',
  29. '1',
  30. 'Hardware watchpoint 1: %s' % watch_expr,
  31. 'Old value = 42',
  32. 'New value = 43',
  33. )
  34. child.expect_exact ('(gdb) ')
  35. child.sendline('c')
  36. expect_lines(child,
  37. '2',
  38. '3',
  39. '4',
  40. 'program stopping',
  41. )
  42. child.expect_exact('Program exited normally.')
  43. child.expect_exact ('(gdb) ')
  44. child.sendline('quit')
  45. child.expect(pexpect.EOF)