aboutsummaryrefslogtreecommitdiff
path: root/tests/test-host-environment--platform-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--platform-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--platform-predicates.el')
-rw-r--r--tests/test-host-environment--platform-predicates.el63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-host-environment--platform-predicates.el b/tests/test-host-environment--platform-predicates.el
new file mode 100644
index 00000000..3430a939
--- /dev/null
+++ b/tests/test-host-environment--platform-predicates.el
@@ -0,0 +1,63 @@
+;;; test-host-environment--platform-predicates.el --- Tests for env-linux/bsd/macos/windows-p -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the platform predicates in host-environment.el. Each is a
+;; thin wrapper around `system-type'. Tests rely on `system-type'
+;; being a special variable (so a `let'-binding shadows the global
+;; value) and walk every supported platform to confirm the right
+;; predicate returns t.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'host-environment)
+
+(ert-deftest test-host-environment-linux-p-true-on-gnu-linux ()
+ "Normal: env-linux-p returns t when system-type is gnu/linux."
+ (let ((system-type 'gnu/linux))
+ (should (env-linux-p))))
+
+(ert-deftest test-host-environment-linux-p-false-on-other-platforms ()
+ "Boundary: env-linux-p returns nil on every non-Linux platform."
+ (dolist (other '(darwin berkeley-unix windows-nt cygwin ms-dos))
+ (let ((system-type other))
+ (should-not (env-linux-p)))))
+
+(ert-deftest test-host-environment-bsd-p-true-on-berkeley-unix ()
+ "Normal: env-bsd-p returns t when system-type is berkeley-unix."
+ (let ((system-type 'berkeley-unix))
+ (should (env-bsd-p))))
+
+(ert-deftest test-host-environment-bsd-p-false-on-other-platforms ()
+ "Boundary: env-bsd-p returns nil on every non-BSD platform."
+ (dolist (other '(gnu/linux darwin windows-nt cygwin ms-dos))
+ (let ((system-type other))
+ (should-not (env-bsd-p)))))
+
+(ert-deftest test-host-environment-macos-p-true-on-darwin ()
+ "Normal: env-macos-p returns t when system-type is darwin."
+ (let ((system-type 'darwin))
+ (should (env-macos-p))))
+
+(ert-deftest test-host-environment-macos-p-false-on-other-platforms ()
+ "Boundary: env-macos-p returns nil on every non-Darwin platform."
+ (dolist (other '(gnu/linux berkeley-unix windows-nt cygwin ms-dos))
+ (let ((system-type other))
+ (should-not (env-macos-p)))))
+
+(ert-deftest test-host-environment-windows-p-true-on-each-windows-variant ()
+ "Normal: env-windows-p returns t on cygwin, windows-nt, and ms-dos."
+ (dolist (win '(cygwin windows-nt ms-dos))
+ (let ((system-type win))
+ (should (env-windows-p)))))
+
+(ert-deftest test-host-environment-windows-p-false-on-unix-platforms ()
+ "Boundary: env-windows-p returns nil on Unix-family platforms."
+ (dolist (other '(gnu/linux darwin berkeley-unix))
+ (let ((system-type other))
+ (should-not (env-windows-p)))))
+
+(provide 'test-host-environment--platform-predicates)
+;;; test-host-environment--platform-predicates.el ends here