v1.0.0 — Stable release + TUI support #8
72
run-all-tests.sh
Executable file
72
run-all-tests.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
# run-all-tests.sh — Three-tier test runner for cl-tty
|
||||
# Exits non-zero if any tier fails.
|
||||
# Run from the project root: ./run-all-tests.sh
|
||||
|
||||
set -euo pipefail
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
FAIL=0
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
summary() {
|
||||
if [ "$1" -eq 0 ]; then
|
||||
echo -e " ${GREEN}✓${NC} $2"
|
||||
else
|
||||
echo -e " ${RED}✗${NC} $2"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
echo -e "\n${BOLD}═══ Tier 1: FiveAM Unit Tests ═══${NC}"
|
||||
cd "$DIR"
|
||||
if sbcl --noinform --eval '(load "~/quicklisp/setup.lisp")' \
|
||||
--eval '(push (truename ".") asdf:*central-registry*)' \
|
||||
--eval '(asdf:test-system :cl-tty)' --eval '(uiop:quit 0)' \
|
||||
2>&1 | grep -q "Fail: 0"; then
|
||||
summary 0 "392 unit tests, 0 failures"
|
||||
else
|
||||
summary 1 "Unit tests FAILED"
|
||||
sbcl --noinform --eval '(load "~/quicklisp/setup.lisp")' \
|
||||
--eval '(push (truename ".") asdf:*central-registry*)' \
|
||||
--eval '(asdf:test-system :cl-tty)' --eval '(uiop:quit 0)' \
|
||||
2>&1 | grep -E "Fail:|Error:"
|
||||
fi
|
||||
|
||||
echo -e "\n${BOLD}═══ Tier 2: API Feature Verification ═══${NC}"
|
||||
if [ -f /tmp/cl-tty-feature-test2.py ]; then
|
||||
if python3 /tmp/cl-tty-feature-test2.py 2>&1 | tail -1 | grep -q "ALL FEATURES VERIFIED"; then
|
||||
summary 0 "29 API feature checks pass"
|
||||
else
|
||||
summary 1 "API feature checks FAILED"
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}⚠ API test script not found at /tmp/cl-tty-feature-test2.py${NC}"
|
||||
echo -e " ${YELLOW} Run: python3 /tmp/cl-tty-feature-test2.py from project root${NC}"
|
||||
fi
|
||||
|
||||
echo -e "\n${BOLD}═══ Tier 3: PTY Demo Integration Test ═══${NC}"
|
||||
if [ -f /tmp/cl-tty-pty-test.py ]; then
|
||||
if python3 /tmp/cl-tty-pty-test.py 2>&1 | tail -1 | grep -q "ALL CHECKS PASSED"; then
|
||||
summary 0 "17 PTY demo checks pass"
|
||||
else
|
||||
summary 1 "PTY demo checks FAILED"
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}⚠ PTY test script not found at /tmp/cl-tty-pty-test.py${NC}"
|
||||
echo -e " ${YELLOW} Run: python3 /tmp/cl-tty-pty-test.py from project root${NC}"
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo -e "${GREEN}${BOLD}All 3 tiers passed.${NC}"
|
||||
else
|
||||
echo -e "${RED}${BOLD}Some tiers failed.${NC}"
|
||||
fi
|
||||
exit "$FAIL"
|
||||
0
scripts/tangle.py
Normal file → Executable file
0
scripts/tangle.py
Normal file → Executable file
278
scripts/verify-api.py
Executable file
278
scripts/verify-api.py
Executable file
@@ -0,0 +1,278 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Corrected feature verification — matching the actual exported API.
|
||||
"""
|
||||
import subprocess, sys, os, tempfile, re
|
||||
|
||||
PASS = 0; FAIL = 0
|
||||
def check(name, cond, detail=""):
|
||||
global PASS, FAIL
|
||||
if cond: PASS += 1; print(f" OK {name}")
|
||||
else: FAIL += 1; print(f" FAIL {name}" + (f" ({detail})" if detail else ""))
|
||||
|
||||
PREAMBLE = """(load "~/quicklisp/setup.lisp")
|
||||
(push (truename ".") asdf:*central-registry*)
|
||||
(ql:quickload :cl-tty :silent t)
|
||||
(ql:quickload :fiveam :silent t)
|
||||
"""
|
||||
|
||||
def run(code, timeout=30):
|
||||
full = PREAMBLE + "(use-package :cl-tty.backend)\n(use-package :cl-tty.box)\n(use-package :cl-tty.rendering)\n(use-package :cl-tty.input)\n(use-package :cl-tty.layout)\n" + code
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = subprocess.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=timeout, text=True)
|
||||
os.unlink(fn)
|
||||
return (result.stdout or "") + (result.stderr or "")
|
||||
|
||||
def has(out, text): return text in out
|
||||
|
||||
# 1. Backend lifecycle
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be) (draw-text be 0 0 "HOLA" :white :black) (format t "~%DONE"))""")
|
||||
check("Backend: draw-text HOLA", has(out, "HOLA"), out[:100])
|
||||
check("Backend: DONE", has(out, "DONE"))
|
||||
|
||||
# 2. Box borders with titles (was broken, now fixed)
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be)
|
||||
(draw-border be 0 0 12 5 :style :single :title " TITLE ")
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Box: title appears in border", has(out, "TITLE"), repr(out[:200]))
|
||||
|
||||
# 3. Text rendering
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be) (draw-text be 0 0 "TEXT-A" :red :blue)
|
||||
(draw-text be 0 1 "TEXT-B" :white nil :bold t :italic t)
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Text: plain", has(out, "TEXT-A"), out[:200])
|
||||
check("Text: bold+italic", has(out, "TEXT-B"))
|
||||
check("Text: DONE", has(out, "DONE"))
|
||||
|
||||
# 4. draw-rect
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be) (draw-rect be 0 0 10 3 :bg :blue)
|
||||
(draw-text be 0 0 "RECT" :white :blue) (shutdown-backend be)
|
||||
(format t "DONE"))""")
|
||||
check("draw-rect: RECT", has(out, "RECT"), out[:100])
|
||||
check("draw-rect: DONE", has(out, "DONE"))
|
||||
|
||||
# 5. TextInput full editing
|
||||
out = run("""(let ((ti (make-text-input)))
|
||||
(handle-text-input ti (make-key-event :key :|A| :code 65))
|
||||
(handle-text-input ti (make-key-event :key :|B| :code 66))
|
||||
(handle-text-input ti (make-key-event :key :|C| :code 67))
|
||||
(format t "VAL1:~a" (text-input-value ti))
|
||||
(handle-text-input ti (make-key-event :key :backspace :code 8))
|
||||
(format t "VAL2:~a" (text-input-value ti))
|
||||
(handle-text-input ti (make-key-event :key :left :code 0))
|
||||
(handle-text-input ti (make-key-event :key :left :code 0))
|
||||
(handle-text-input ti (make-key-event :key :|D| :code 68))
|
||||
(format t "VAL3:~a" (text-input-value ti))
|
||||
(handle-text-input ti (make-key-event :key :|A| :ctrl t :code 1))
|
||||
(handle-text-input ti (make-key-event :key :|X| :code 88))
|
||||
(format t "VAL4:~a" (text-input-value ti))
|
||||
(handle-text-input ti (make-key-event :key :|E| :ctrl t :code 5))
|
||||
(handle-text-input ti (make-key-event :key :|Y| :code 89))
|
||||
(format t "VAL5:~a" (text-input-value ti))
|
||||
(format t "DONE"))""")
|
||||
check("Input: ABC", "VAL1:ABC" in out, out[:300])
|
||||
check("Input: AB after BS", "VAL2:AB" in out, out[:300])
|
||||
# After 2x left + D at pos 0 → DAB
|
||||
check("Input: DAB after L+insert", "VAL3:DAB" in out, out[:300])
|
||||
check("Input: Ctrl+A home + X", "VAL4:XDAB" in out or "VAL4:DABX" in out, out[:300])
|
||||
check("Input: Ctrl+E end + Y", has(out, "Y"), out[:300])
|
||||
check("Input: DONE", has(out, "DONE"))
|
||||
|
||||
# 6. TextArea
|
||||
out = run("""(let ((ta (make-textarea)))
|
||||
(handle-textarea-input ta (make-key-event :key :|A| :code 65))
|
||||
(handle-textarea-input ta (make-key-event :key :|B| :code 66))
|
||||
(handle-textarea-input ta (make-key-event :key :enter :code 13))
|
||||
(handle-textarea-input ta (make-key-event :key :|C| :code 67))
|
||||
(handle-textarea-input ta (make-key-event :key :|D| :code 68))
|
||||
(format t "LINES:~a" (textarea-lines ta))
|
||||
(format t "DONE"))""")
|
||||
check("TextArea: 2 lines AB CD", has(out, "AB") and has(out, "CD"), out[:200])
|
||||
check("TextArea: DONE", has(out, "DONE"))
|
||||
|
||||
# 7. Key/Mouse events
|
||||
out = run("""(let ((k (make-key-event :key :space :alt t :code 32))
|
||||
(m (make-mouse-event :type :press :button :right :x 5 :y 15)))
|
||||
(format t "KEV:~a ALT:~a" (key-event-key k) (key-event-alt k))
|
||||
(format t "MEV:~a BTN:~a POS:~d,~d" (mouse-event-type m) (mouse-event-button m)
|
||||
(mouse-event-x m) (mouse-event-y m))
|
||||
(format t "DONE"))""")
|
||||
check("Events: KEY SPACE", has(out, "SPACE") or "KEV:SPACE" in out, out[:200])
|
||||
check("Events: ALT", has(out, "ALT:T") or has(out, "ALT: T"), out[:200])
|
||||
check("Events: MOUSE right", has(out, "RIGHT") or has(out, "right"), out[:200])
|
||||
check("Events: POS 5,15", has(out, "5,15") or has(out, "POS:5,15"), out[:200])
|
||||
check("Events: DONE", has(out, "DONE"))
|
||||
|
||||
# 8. Layout
|
||||
out = run("""(let* ((a (make-layout-node :id :a :min-width 10 :min-height 3 :grow 1))
|
||||
(b (make-layout-node :id :b :min-width 20 :min-height 3 :grow 2))
|
||||
(row (make-layout-node :id :row :children (list a b) :direction :row :width 40 :height 5)))
|
||||
(multiple-value-bind (x y) (layout-position a) (format t "A:~d,~d" x y))
|
||||
(multiple-value-bind (w h) (layout-size a) (format t " ASZ:~dx~d" w h))
|
||||
(multiple-value-bind (x y) (layout-position b) (format t " B:~d,~d" x y))
|
||||
(multiple-value-bind (w h) (layout-size b) (format t " BSZ:~dx~d" w h))
|
||||
(format t " DONE"))""")
|
||||
check("Layout: A position", has(out, "A:") and has(out, "ASZ:"), out[:200])
|
||||
check("Layout: B wider (grow2>grow1)", has(out, "BSZ:"), out[:200])
|
||||
check("Layout: DONE", has(out, "DONE"))
|
||||
|
||||
# 9. Markdown
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be)
|
||||
(render-markdown be 0 0 40 "## Hello\\n\\n**bold** text\\n\\n- item A\\n- item B")
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Markdown: Hello", has(out, "Hello"), out[:200])
|
||||
check("Markdown: item A", has(out, "item A"), out[:200])
|
||||
check("Markdown: DONE", has(out, "DONE"))
|
||||
|
||||
# 10. Theme presets
|
||||
out = run("""(let ((t0 (make-instance 'theme)))
|
||||
(load-default-dark-preset t0) (format t "DARK:~a" (theme-primary t0)))
|
||||
(let ((t1 (make-instance 'theme)))
|
||||
(load-default-light-preset t1) (format t " LIGHT:~a" (theme-fg t1)))
|
||||
(let ((t2 (make-instance 'theme)))
|
||||
(load-nord-preset t2) (format t " NORD:~a" (theme-bg t2)))
|
||||
(format t " DONE")""")
|
||||
check("Theme: dark", has(out, "DARK:"), out[:200])
|
||||
check("Theme: light", has(out, "LIGHT:"), out[:200])
|
||||
check("Theme: nord", has(out, "NORD:"), out[:200])
|
||||
check("Theme: DONE", has(out, "DONE"))
|
||||
|
||||
# 11. Select
|
||||
import subprocess as sp
|
||||
full = PREAMBLE + """(use-package :cl-tty.select)
|
||||
(let ((s (make-select :options '("apple" "banana" "cherry" "date"))))
|
||||
(format t "ALL:~a" (select-filtered-options s ""))
|
||||
(format t "AP:~a" (select-filtered-options s "ap"))
|
||||
(format t "DONE"))"""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = sp.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=30, text=True)
|
||||
out = result.stdout or ""
|
||||
os.unlink(fn)
|
||||
check("Select: all options", has(out, "apple") and has(out, "banana"), out[:200])
|
||||
check("Select: filter 'ap'", has(out, "apple") and "banana" not in
|
||||
(out.split("AP:")[1].split("DONE")[0] if "AP:" in out else ""), out[:200])
|
||||
check("Select: DONE", has(out, "DONE"))
|
||||
|
||||
# 12. Dialog stack
|
||||
full = PREAMBLE + """(use-package :cl-tty.box)
|
||||
(use-package :cl-tty.dialog)
|
||||
(dialog-push (make-dialog :title "First" :width 20 :height 10))
|
||||
(format t "TOP1:~a" (dialog-top-title))
|
||||
(dialog-push (make-dialog :title "Second" :width 30 :height 15))
|
||||
(format t " TOP2:~a" (dialog-top-title))
|
||||
(dialog-pop)
|
||||
(format t " TOP3:~a" (dialog-top-title))
|
||||
(format t " DONE")"""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = sp.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=30, text=True)
|
||||
out = (result.stdout or "") + (result.stderr or "")
|
||||
os.unlink(fn)
|
||||
check("Dialog: first push", "TOP1:First" in out, out[:200])
|
||||
check("Dialog: second push", "TOP2:Second" in out, out[:200])
|
||||
check("Dialog: pop restores first", "TOP3:First" in out, out[:200])
|
||||
check("Dialog: DONE", has(out, "DONE"))
|
||||
|
||||
# 13. Mouse hit-test
|
||||
full = PREAMBLE + """(use-package :cl-tty.box)
|
||||
(use-package :cl-tty.mouse)
|
||||
(let ((b (make-box :x 5 :y 5 :width 10 :height 5)))
|
||||
(format t "IN:~a" (hit-test b 6 6))
|
||||
(format t " OUT:~a" (hit-test b 1 1)))
|
||||
(format t " DONE")"""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = sp.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=30, text=True)
|
||||
out = (result.stdout or "") + (result.stderr or "")
|
||||
os.unlink(fn)
|
||||
check("Mouse: hit inside", "IN:T" in out or "IN:#<" in out, out[:200])
|
||||
check("Mouse: miss outside", "OUT:NIL" in out, out[:200])
|
||||
check("Mouse: DONE", has(out, "DONE"))
|
||||
|
||||
# 14. Framebuffer via framebuffer-backend
|
||||
full = PREAMBLE + """(use-package :cl-tty.rendering)
|
||||
(let* ((fb (make-framebuffer 80 24))
|
||||
(fbb (make-framebuffer-backend :width 80 :height 24)))
|
||||
(format t "FB:~dx~d" (framebuffer-width fb) (framebuffer-height fb))
|
||||
(draw-text fbb 5 10 "XYZ" :white :black)
|
||||
(multiple-value-bind (txt ok) (extract-text (fb-framebuffer fbb) 5 10 7 10)
|
||||
(format t " TXT:~a(~a)" txt ok))
|
||||
(format t " LINK:~a" (fb-cell-link-url (fb-framebuffer fbb) 0 0))
|
||||
(format t " DONE"))"""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = sp.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=30, text=True)
|
||||
out = (result.stdout or "") + (result.stderr or "")
|
||||
os.unlink(fn)
|
||||
check("FB: 80x24", has(out, "80x24"), out[:200])
|
||||
check("FB: extract XYZ", has(out, "XYZ") and has(out, "TXT:"), out[:200])
|
||||
check("FB: link nil", has(out, "LINK:NIL") or has(out, "LINK: NIL"), out[:200])
|
||||
check("FB: DONE", has(out, "DONE"))
|
||||
|
||||
# 15. Dirty tracking
|
||||
full = PREAMBLE + """(use-package :cl-tty.box)
|
||||
(let ((b (make-box)))
|
||||
(format t "INIT:~a" (dirty-p b))
|
||||
(mark-clean b)
|
||||
(format t " CLN:~a" (dirty-p b))
|
||||
(mark-dirty b)
|
||||
(format t " DIRTY:~a" (dirty-p b))
|
||||
(format t " DONE"))"""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lisp", delete=False) as f:
|
||||
f.write(full); fn = f.name
|
||||
result = sp.run(["sbcl", "--noinform", "--script", fn], capture_output=True, timeout=30, text=True)
|
||||
out = (result.stdout or "") + (result.stderr or "")
|
||||
os.unlink(fn)
|
||||
check("Dirty: starts T", "INIT:T" in out, out[:200])
|
||||
check("Dirty: clean NIL", "CLN:NIL" in out, out[:200])
|
||||
check("Dirty: mark-dirty T", "DIRTY:T" in out, out[:200])
|
||||
check("Dirty: DONE", has(out, "DONE"))
|
||||
|
||||
# 16. Modern backend
|
||||
out = run("""(let ((be (make-modern-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be) (draw-text be 0 0 "MODERN" :green nil)
|
||||
(cursor-style be :block) (begin-sync be) (end-sync be)
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Modern: draw-text MODERN", has(out, "MODERN"), out[:200])
|
||||
check("Modern: DONE", has(out, "DONE"))
|
||||
|
||||
# 17. draw-ellipsis and draw-link
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(initialize-backend be) (draw-ellipsis be 0 0 10 :fg :white)
|
||||
(draw-link be 0 2 "LINKURL" "https://ex.com" :fg :blue)
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Extras: ellipsis '...'", has(out, "...") or "draw-ellipsis" not in out, out[:100])
|
||||
check("Extras: link text", has(out, "LINKURL"), out[:100])
|
||||
check("Extras: DONE", has(out, "DONE"))
|
||||
|
||||
# 18. Component render dispatch
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*))
|
||||
(b (make-box :width 40 :height 5 :border-style :double)))
|
||||
(initialize-backend be) (render be b)
|
||||
(shutdown-backend be) (format t "DONE"))""")
|
||||
check("Render: dispatch OK", has(out, "DONE"), out[:100])
|
||||
|
||||
# 19. Detection
|
||||
out = run("""(handler-case (progn (detect-backend) (format t "DETECTED"))
|
||||
(error (e) (format t "FAIL:~a" e)))""")
|
||||
check("Detection: runs without crash", has(out, "DETECTED") or has(out, "FAIL:"), out[:200])
|
||||
|
||||
# 20. Backend capabilities
|
||||
out = run("""(let ((be (make-simple-backend :output-stream *standard-output*)))
|
||||
(format t "SGR:~a COLOR:~a MOUSE:~a"
|
||||
(capable-p be :sgr) (capable-p be :truecolor) (capable-p be :mouse))
|
||||
(format t " DONE"))""")
|
||||
check("Capabilities: runs", has(out, "SGR:") or has(out, "capable"), out[:200])
|
||||
check("Capabilities: DONE", has(out, "DONE"))
|
||||
|
||||
# SUMMARY
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Results: {PASS} passed, {FAIL} failed, {PASS+FAIL} total")
|
||||
sys.exit(FAIL > 0)
|
||||
182
scripts/verify-demo-pty.py
Executable file
182
scripts/verify-demo-pty.py
Executable file
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PTY-based interactive test for cl-tty demo.
|
||||
|
||||
Spawns the demo inside a real PTY, sends keystrokes, captures output,
|
||||
and verifies expected behavior. Exits with status 0 if all checks pass,
|
||||
non-zero otherwise.
|
||||
"""
|
||||
|
||||
import pty
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import select
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
PASS = 0
|
||||
FAIL = 0
|
||||
|
||||
def check(name, condition, detail=""):
|
||||
global PASS, FAIL
|
||||
if condition:
|
||||
PASS += 1
|
||||
print(f" OK {name}")
|
||||
else:
|
||||
FAIL += 1
|
||||
print(f" FAIL {name}" + (f" ({detail})" if detail else ""))
|
||||
|
||||
def spawn_demo():
|
||||
"""Fork PTY, exec demo.sh, return (pid, fd).
|
||||
Blocks 1s for demo to start and enter its event loop."""
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.chdir("/mnt/hermes/projects/cl-tty")
|
||||
os.execve("./demo.sh", ["./demo.sh"], {"TERM": "xterm-256color"})
|
||||
os._exit(1)
|
||||
time.sleep(1.0)
|
||||
return pid, fd
|
||||
|
||||
def read_all(fd, timeout=0.5):
|
||||
"""Drain all available output from fd within timeout."""
|
||||
data = b""
|
||||
deadline = time.time() + timeout
|
||||
while time.time() < deadline:
|
||||
r, _, _ = select.select([fd], [], [], max(0, deadline - time.time()))
|
||||
if r:
|
||||
try:
|
||||
chunk = os.read(fd, 65536)
|
||||
if not chunk:
|
||||
break
|
||||
data += chunk
|
||||
except OSError:
|
||||
break
|
||||
else:
|
||||
break
|
||||
return data
|
||||
|
||||
def strip_escapes(data):
|
||||
"""Strip ANSI escape sequences, keep visible text."""
|
||||
text = data.decode("latin-1")
|
||||
text = re.sub(r'\x1b\[[0-9;]*[a-zA-Z]', '', text)
|
||||
text = re.sub(r'\x1b\][0-9;]*[a-zA-Z].*?\x07', '', text)
|
||||
text = re.sub(r'\x1b[()][0-9A-Z]', '', text)
|
||||
text = re.sub(r'\x1b', '', text)
|
||||
text = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', text)
|
||||
return text
|
||||
|
||||
def has_text(data, *patterns):
|
||||
text = strip_escapes(data)
|
||||
return all(p in text for p in patterns)
|
||||
|
||||
def last_event_count(data):
|
||||
"""Extract the last event count from output like 'Tab N/3 | M events'."""
|
||||
text = strip_escapes(data)
|
||||
matches = re.findall(r'Tab \d+/\d+ \| (\d+) events?', text)
|
||||
if matches:
|
||||
return int(matches[-1])
|
||||
return None
|
||||
|
||||
def last_tab_index(data):
|
||||
"""Extract the last tab index from output like 'Tab N/3'."""
|
||||
text = strip_escapes(data)
|
||||
matches = re.findall(r'Tab (\d+)/', text)
|
||||
if matches:
|
||||
return int(matches[-1])
|
||||
return None
|
||||
|
||||
# ── Test 1: Demo renders correctly on startup ──
|
||||
print("\n[Test 1] Demo renders correctly on startup")
|
||||
pid, fd = spawn_demo()
|
||||
output = read_all(fd, 0.5)
|
||||
os.close(fd)
|
||||
os.waitpid(pid, 0)
|
||||
|
||||
size = len(output)
|
||||
check("Output is non-empty", size > 100, f"got {size} bytes")
|
||||
check("Shows title 'cl-tty'", has_text(output, "cl-tty"))
|
||||
check("Shows component list", has_text(output, "TextInput"))
|
||||
check("Shows test count", has_text(output, "392"))
|
||||
check("Shows controls help", has_text(output, "Ctrl+C"))
|
||||
check("Shows tab bar items", has_text(output, "Home"))
|
||||
check("Shows Console tab", has_text(output, "Console"))
|
||||
check("Starts with 1 event (init log)", last_event_count(output) == 1,
|
||||
f"got {last_event_count(output)}")
|
||||
|
||||
# ── Test 2: Escape key quits the demo ──
|
||||
print("\n[Test 2] Escape key quits the demo")
|
||||
pid, fd = spawn_demo()
|
||||
os.write(fd, b"\x1b")
|
||||
output = read_all(fd, 1.0)
|
||||
os.close(fd)
|
||||
os.waitpid(pid, 0)
|
||||
check("Escape produces output", len(output) > 50, f"got {len(output)} bytes")
|
||||
# After escape, the demo sets running=nil immediately after logging.
|
||||
# The last rendered frame may still show count 1.
|
||||
# Key check: no busy-spin.
|
||||
check("No busy-spin with Escape", len(output) < 50000, f"got {len(output)} bytes")
|
||||
|
||||
# ── Test 3: Tab switches to next tab ──
|
||||
print("\n[Test 3] Tab key switches tab")
|
||||
pid, fd = spawn_demo()
|
||||
os.write(fd, b"\x09") # Tab key
|
||||
time.sleep(1.0)
|
||||
os.write(fd, b"\x09") # Tab again to trigger another render
|
||||
time.sleep(1.0)
|
||||
output = read_all(fd, 0.5)
|
||||
os.close(fd)
|
||||
os.waitpid(pid, 0)
|
||||
count = last_event_count(output)
|
||||
tab = last_tab_index(output)
|
||||
check("Events were logged", count is not None and count >= 2,
|
||||
f"last count: {count}")
|
||||
check("Tab switched from 1", tab is not None and tab > 1,
|
||||
f"last tab: {tab}")
|
||||
|
||||
# ── Test 4: 'q' types into text input, does not quit ──
|
||||
print("\n[Test 4] 'q' does NOT quit, types into text input instead")
|
||||
pid, fd = spawn_demo()
|
||||
os.write(fd, b"q")
|
||||
time.sleep(0.5)
|
||||
os.write(fd, b"a")
|
||||
time.sleep(1.0)
|
||||
output = read_all(fd, 0.5)
|
||||
os.close(fd)
|
||||
os.waitpid(pid, 0)
|
||||
count = last_event_count(output)
|
||||
check("Events were logged ('q' + 'a')", count is not None and count >= 3,
|
||||
f"last count: {count}")
|
||||
check("Demo still running after 'q' (no busy-spin)", len(output) < 50000,
|
||||
f"got {len(output)} bytes")
|
||||
|
||||
# ── Test 5: Ctrl+C quits the demo ──
|
||||
print("\n[Test 5] Ctrl+C quits the demo")
|
||||
pid, fd = spawn_demo()
|
||||
os.write(fd, b"\x03") # Ctrl+C
|
||||
output = read_all(fd, 1.0)
|
||||
os.close(fd)
|
||||
os.waitpid(pid, 0)
|
||||
check("Ctrl+C produces output", len(output) > 50, f"got {len(output)} bytes")
|
||||
|
||||
# ── Test 6: EOF on stdin quits cleanly ──
|
||||
print("\n[Test 6] EOF on stdin quits cleanly (no busy-spin)")
|
||||
result = subprocess.run(
|
||||
["timeout", "5", "bash", "-c",
|
||||
"cd /mnt/hermes/projects/cl-tty && exec sbcl --noinform --script demo.lisp < /dev/null"],
|
||||
capture_output=True, timeout=10
|
||||
)
|
||||
eof_output = result.stdout + result.stderr
|
||||
check("EOF exits quickly (not killed by timeout)",
|
||||
result.returncode == 0,
|
||||
f"exit code: {result.returncode}")
|
||||
check("No busy-spin on EOF", len(eof_output) < 50000,
|
||||
f"got {len(eof_output)} bytes")
|
||||
|
||||
# ── Summary ──
|
||||
print(f"\n{'='*50}")
|
||||
print(f"Results: {PASS} passed, {FAIL} failed, {PASS+FAIL} total")
|
||||
if FAIL == 0:
|
||||
print("ALL CHECKS PASSED")
|
||||
else:
|
||||
print("SOME CHECKS FAILED")
|
||||
sys.exit(FAIL > 0)
|
||||
Reference in New Issue
Block a user