luv

Workshop wiki

tests.lisp

terminal/tests.lisp

system luv/terminal/test · 12 definitions · on GitHub

defpackage#:luv.terminal.tests
:use#:cl#:rove
:local-nicknames
#:ghostty#:luv.ghostty
#:terminal#:luv.terminal
in-package#:luv.terminal.tests
defmacrowith-pty-test
deviceterminal&restopen-arguments
&bodybody
`
ghostty:with-terminal
,terminal:columns40:rows6
let
,devicenil
unwind-protect
progn
setf,device
,@body
when,device
defunsend-canvas-key
devicekey&optionalcharacter
terminal:send-pty-device-canvas-key-eventdevice
make-instance'luv:canvas-key-press-event:timestamp0:key-namekey:charactercharacter:unshifted-charactercharacter
defunwait-for-terminal-text
deviceneedle&key
timeout1.0
let
deadline
+
get-internal-real-time
round
*timeoutinternal-time-units-per-second
loopfortext=when
searchneedletext
do
returntext
when
>=
get-internal-real-time
deadline
dodo
sleep0.01
deftestpty-child-output-and-input-drive-one-terminal
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""printf 'term:%s\\r\\nready\\r\\n' \"$TERM\"; IFS= read -r line; printf 'got:%s\\r\\n' \"$line\""
terminal:send-pty-device-textdevice
formatnil"hello~%"
ok
eq:exited
let
ok
search"ready"text
ok
search"term:xterm-256color"text
ok
search"got:hello"text
deftestpty-echo-reaches-the-terminal-before-enter
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""IFS= read -r line"
terminal:send-pty-device-textdevice"visible-before-enter"
ok
search"visible-before-enter"
wait-for-terminal-textdevice"visible-before-enter"
ok
deftestpty-child-owns-a-controlling-terminal
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""test -c /dev/tty && printf 'controlling-tty-ok\\r\\n' > /dev/tty"
ok
eq:exited
ok
search"controlling-tty-ok"
deftestghostty-query-responses-return-through-the-pty
let*
python"python3"
script
formatnil"import os, termios, tty~%old = termios.tcgetattr(0)~%tty.setraw(0)~%os.write(1, b'\\x1b[6n')~%reply = b''~%while not reply.endswith(b'R'):~% reply += os.read(0, 1)~%termios.tcsetattr(0, termios.TCSANOW, old)~%os.write(1, b'query-ok:' + reply.hex().encode() + b'\\r\\n')~%"
with-pty-test
deviceghostty-terminal:programpython:arguments
list"-c"script
ok
eq:exited
ok
search"query-ok:1b5b313b3152"
deftestportable-canvas-keys-reach-the-pty-child
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""printf 'key-ready\r\n'; IFS= read -r line; printf 'key:%s\r\n' \"$line\""
send-canvas-keydevice:h#\h
send-canvas-keydevice:i#\i
send-canvas-keydevice:return#\Return
ok
eq:exited
let
ok
search"key-ready"text
ok
search"key:hi"text
deftestresize-coordinates-the-kernel-pty-and-ghostty-grid
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""IFS= read -r line; stty size"
terminal:resize-pty-devicedevice429:cell-width-pixels8:cell-height-pixels16
terminal:send-pty-device-textdevice
formatnil"size~%"
ok
eq:exited
multiple-value-bind
columnsrows
ok
=columns42
ok
=rows9
ok
search"9 42"
deftestclosing-a-running-device-releases-only-its-pty
with-pty-test
deviceghostty-terminal:program"/bin/sh":arguments
list"-c""printf 'waiting\\r\\n'; sleep 30"
ok
ok
not
sb-thread:thread-alive-p
luv.terminal::pty-device-threaddevice

The device owns the child and descriptor, not the semantic terminal.

ok
ghostty:terminal-open-pghostty-terminal
ok
eqghostty-terminal
ghostty:write-terminalghostty-terminal"still owned outside"