aboutsummaryrefslogtreecommitdiff
path: root/tests/test-host-environment--display-predicates.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 08:25:45 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 09:13:43 -0500
commit21d5a737f0278baeafd4d72e59cc9505043d91a9 (patch)
tree7d7ce883c2ec9594d4033ef535b7fad4020c4daa /tests/test-host-environment--display-predicates.el
parent17e2366180838b7e170230ff881cd3406be84a70 (diff)
downloaddotemacs-21d5a737f0278baeafd4d72e59cc9505043d91a9.tar.gz
dotemacs-21d5a737f0278baeafd4d72e59cc9505043d91a9.zip
test(host-environment): cover laptop/desktop, platform, display, timezone predicates
Four new test files extending the existing test-host-environment.el (which already covered the two battery helpers). - platform-predicates: env-linux-p, env-bsd-p, env-macos-p, env-windows-p walked across every supported system-type value. 8 tests. - display-predicates: env-x-p, env-x11-p, env-wayland-p, env-terminal-p, env-gui-p exercised under every relevant combination of window-system, WAYLAND_DISPLAY, and display-graphic-p. 13 tests. - env-laptop-p: composition over the helpers, with Linux dispatch isolated from non-Linux dispatch via system-type binding. 8 tests including env-desktop-p as the inverse. battery-status-function is forward-declared in this test file (initialized to nil) so cl-letf's symbol-value place can read the prior value without hitting void-variable. - detect-system-timezone: the four-method priority chain. Mocks cj/match-localtime-to-zoneinfo and getenv at the boundary; uses cl-letf on file-exists-p / insert-file-contents to exercise the /etc/timezone fall-through without touching real system files. 5 tests. 34 new tests for host-environment, all passing. Full suite green.
Diffstat (limited to 'tests/test-host-environment--display-predicates.el')
-rw-r--r--tests/test-host-environment--display-predicates.el112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test-host-environment--display-predicates.el b/tests/test-host-environment--display-predicates.el
new file mode 100644
index 00000000..15dff2ef
--- /dev/null
+++ b/tests/test-host-environment--display-predicates.el
@@ -0,0 +1,112 @@
+;;; test-host-environment--display-predicates.el --- Tests for env-x/x11/wayland/terminal/gui-p -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the display-environment predicates in host-environment.el.
+;; Mocks `window-system', `getenv', and `display-graphic-p' at the
+;; framework boundary so each predicate can be exercised under every
+;; relevant combination of (window-system, WAYLAND_DISPLAY, graphic-p).
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'host-environment)
+
+(defmacro test-host-env--with-display (window-system-value
+ wayland-display
+ graphic-p
+ &rest body)
+ "Run BODY with display state stubbed.
+WINDOW-SYSTEM-VALUE becomes the return of `(window-system)'.
+WAYLAND-DISPLAY becomes the value of $WAYLAND_DISPLAY (nil for unset).
+GRAPHIC-P becomes the return of `(display-graphic-p)'."
+ (declare (indent 3) (debug t))
+ `(cl-letf (((symbol-function 'window-system)
+ (lambda (&optional _) ,window-system-value))
+ ((symbol-function 'getenv)
+ (lambda (name)
+ (when (string= name "WAYLAND_DISPLAY") ,wayland-display)))
+ ((symbol-function 'display-graphic-p)
+ (lambda (&optional _) ,graphic-p)))
+ ,@body))
+
+;;; env-x-p
+
+(ert-deftest test-host-environment-x-p-true-when-window-system-is-x ()
+ "Normal: env-x-p returns t when window-system is `x'."
+ (test-host-env--with-display 'x nil t
+ (should (env-x-p))))
+
+(ert-deftest test-host-environment-x-p-false-when-window-system-is-pgtk ()
+ "Boundary: env-x-p returns nil when window-system is `pgtk'."
+ (test-host-env--with-display 'pgtk nil t
+ (should-not (env-x-p))))
+
+(ert-deftest test-host-environment-x-p-false-when-no-window-system ()
+ "Boundary: env-x-p returns nil under no window system (terminal)."
+ (test-host-env--with-display nil nil nil
+ (should-not (env-x-p))))
+
+;;; env-x11-p
+
+(ert-deftest test-host-environment-x11-p-true-on-x-without-wayland-display ()
+ "Normal: env-x11-p returns t under X with no WAYLAND_DISPLAY."
+ (test-host-env--with-display 'x nil t
+ (should (env-x11-p))))
+
+(ert-deftest test-host-environment-x11-p-false-under-xwayland ()
+ "Boundary: env-x11-p returns nil when running through XWayland.
+Detected via WAYLAND_DISPLAY being set even though window-system is `x'."
+ (test-host-env--with-display 'x "wayland-0" t
+ (should-not (env-x11-p))))
+
+(ert-deftest test-host-environment-x11-p-false-on-pgtk ()
+ "Boundary: env-x11-p returns nil under pure-GTK Wayland."
+ (test-host-env--with-display 'pgtk "wayland-0" t
+ (should-not (env-x11-p))))
+
+;;; env-wayland-p
+
+(ert-deftest test-host-environment-wayland-p-true-when-wayland-display-set ()
+ "Normal: env-wayland-p returns t when WAYLAND_DISPLAY is set."
+ (test-host-env--with-display 'pgtk "wayland-0" t
+ (should (env-wayland-p))))
+
+(ert-deftest test-host-environment-wayland-p-false-when-wayland-display-unset ()
+ "Boundary: env-wayland-p returns nil when WAYLAND_DISPLAY is unset."
+ (test-host-env--with-display 'x nil t
+ (should-not (env-wayland-p))))
+
+(ert-deftest test-host-environment-wayland-p-true-under-xwayland ()
+ "Boundary: env-wayland-p returns t even under XWayland.
+WAYLAND_DISPLAY is set by the compositor regardless of which X surface
+Emacs uses, so XWayland counts as Wayland by this predicate."
+ (test-host-env--with-display 'x "wayland-0" t
+ (should (env-wayland-p))))
+
+;;; env-terminal-p / env-gui-p
+
+(ert-deftest test-host-environment-terminal-p-true-when-not-graphical ()
+ "Normal: env-terminal-p returns t when display-graphic-p is nil."
+ (test-host-env--with-display nil nil nil
+ (should (env-terminal-p))))
+
+(ert-deftest test-host-environment-terminal-p-false-when-graphical ()
+ "Boundary: env-terminal-p returns nil under a graphical frame."
+ (test-host-env--with-display 'x nil t
+ (should-not (env-terminal-p))))
+
+(ert-deftest test-host-environment-gui-p-true-when-graphical ()
+ "Normal: env-gui-p returns t under a graphical frame."
+ (test-host-env--with-display 'x nil t
+ (should (env-gui-p))))
+
+(ert-deftest test-host-environment-gui-p-false-in-terminal ()
+ "Boundary: env-gui-p returns nil under a terminal frame."
+ (test-host-env--with-display nil nil nil
+ (should-not (env-gui-p))))
+
+(provide 'test-host-environment--display-predicates)
+;;; test-host-environment--display-predicates.el ends here