From 712654d4c023a2ab13190c6905d313e0ba897965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 2 Oct 2023 19:26:40 +0200 Subject: Rewrite test running system. --- tests/unit/termios/termios.scm | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/unit/termios/termios.scm (limited to 'tests/unit/termios') diff --git a/tests/unit/termios/termios.scm b/tests/unit/termios/termios.scm new file mode 100644 index 00000000..3e472d81 --- /dev/null +++ b/tests/unit/termios/termios.scm @@ -0,0 +1,49 @@ +;;; Commentary: +;; Tests that my termios function works, at least somewhat. +;; Note that this actually modifies the terminal it's run on, and might fail +;; if the terminal doesn't support the wanted modes. See termios(3). +;; It might also leave the terminal in a broken state if exited prematurely. +;;; Code: + +(define-module (test termios) + :use-module (srfi srfi-64) + :use-module (srfi srfi-88) + :use-module ((hnh util) :select (set!)) + :use-module ((vulgar termios) + :select (make-termios + copy-termios + lflag + tcgetattr! + tcsetattr! + ECHO + ICANON)) + :use-module ((srfi srfi-60) + :select ((bitwise-ior . ||) + (bitwise-not . ~) + (bitwise-and . &)))) + +(define tty (open-input-file "/dev/tty")) + +(define-syntax-rule (&= lvalue val) + (set! lvalue = ((lambda (v) (& v val))))) + +(define t (make-termios)) + +(test-equal 0 (tcgetattr! t tty)) + +(define ifl (lflag t)) + +(define copy (copy-termios t)) + +#!curly-infix {(lflag t) &= (~ (|| ECHO ICANON))} + +(test-equal 0 (tcsetattr! t tty)) + +(test-equal + (& ifl (~ (|| ECHO ICANON))) + (lflag t)) + +(test-equal 0 (tcsetattr! copy tty)) + + +'((vulgar termios)) -- cgit v1.2.3