uitest.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python3
  2. """End-to-end UI test for the shell: compile-error jump + Ctrl-K-D quit.
  3. Compiler correctness is covered by matrix/run_compile_tests.sh (fast, no pty).
  4. This test covers the *shell* behaviour that only exists interactively:
  5. 1. W loads a work file (LoadWorkFile ends with a Pause: needs a filler key)
  6. 2. C reports a TP3 error (error number + relative text position)
  7. 3. ESC opens the editor with the cursor ON the error position
  8. (TP3 kcwait: waitesc ; BX:=txerrpos ; DEC BX ; JMP editor2)
  9. 4. Ctrl-K D returns to the main menu
  10. 5. Q exits the shell cleanly with status 0
  11. (a bare HALT aborts with SIGABRT under gm2 -fiso)
  12. Fixture: t02_writeln.pas fails with error 41 at pos 28, which is line 3,
  13. column 10 (1-based) - the '(' just after 'writeln'.
  14. Usage: uitest.py [fixture.pas]
  15. """
  16. import os
  17. import sys
  18. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  19. from ptyharness import CTRL_K, SHELL_DIR, Screen, drain, reap, send, spawn, status_str, visible
  20. FIXTURE = sys.argv[1] if len(sys.argv) > 1 else os.path.join(
  21. os.path.dirname(os.path.abspath(__file__)), "fixtures", "t02_writeln.pas")
  22. EXPECT_ERR = "41"
  23. EXPECT_LINE = 3
  24. EXPECT_COL = 10
  25. def main():
  26. pid, fd = spawn()
  27. checks = []
  28. try:
  29. drain(fd, quiet=0.6)
  30. send(fd, b"w")
  31. send(fd, FIXTURE.encode())
  32. send(fd, b"\r", quiet=0.8)
  33. send(fd, b" ", quiet=0.5) # clears LoadWorkFile's Pause
  34. comp = visible(send(fd, b"c", quiet=1.5))
  35. checks.append(("compile reports a TP3 error", "TP3-style error" in comp))
  36. checks.append(("error number is %s (not the 0 from the old "
  37. "self-assignment)" % EXPECT_ERR,
  38. ("error %s " % EXPECT_ERR) in comp))
  39. checks.append(("compile did not claim success", "Compiled OK" not in comp))
  40. ed = send(fd, b"\x1b", quiet=1.0) # accept the error jump
  41. scr = Screen()
  42. scr.feed(ed)
  43. text = scr.text()
  44. row = scr.row_with("writeln")
  45. checks.append(("editor opened", "Line %d" % EXPECT_LINE in text))
  46. checks.append(("cursor on the faulty line (screen row carries 'writeln')",
  47. row is not None))
  48. checks.append(("status line reports Line %d" % EXPECT_LINE,
  49. ("Line %d" % EXPECT_LINE) in text.split("\n")[0]))
  50. checks.append(("status line reports Col %d" % EXPECT_COL,
  51. ("Col %d" % EXPECT_COL) in text.split("\n")[0]))
  52. checks.append(("cursor is on that row", row is not None and row == scr.r))
  53. send(fd, CTRL_K, quiet=0.4)
  54. after = visible(send(fd, b"d", quiet=0.6))
  55. checks.append(("Ctrl-K D returned to the main menu", "Main file" in after))
  56. send(fd, b"q", quiet=0.6)
  57. finally:
  58. status = reap(fd, pid)
  59. checks.append(("shell exited cleanly (status 0)", os.WIFEXITED(status)
  60. and os.WEXITSTATUS(status) == 0))
  61. print("UI TEST: %s" % os.path.basename(FIXTURE))
  62. print("-" * 60)
  63. ok = True
  64. for name, passed in checks:
  65. print("%-58s %s" % (name, "PASS" if passed else "FAIL"))
  66. ok = ok and passed
  67. print("-" * 60)
  68. print("child: %s" % status_str(status))
  69. print("RESULT: %s" % ("ALL PASS" if ok else "FAILURES PRESENT"))
  70. return 0 if ok else 1
  71. if __name__ == "__main__":
  72. sys.exit(main())