aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-calendar-sync--expand-monthly.el4
-rw-r--r--tests/test-elfeed-config-helpers.el39
-rw-r--r--tests/test-org-roam-config-format.el22
-rw-r--r--tests/test-system-commands-resolve-and-run.el32
4 files changed, 51 insertions, 46 deletions
diff --git a/tests/test-calendar-sync--expand-monthly.el b/tests/test-calendar-sync--expand-monthly.el
index 75404937..41b196a7 100644
--- a/tests/test-calendar-sync--expand-monthly.el
+++ b/tests/test-calendar-sync--expand-monthly.el
@@ -278,8 +278,10 @@ instead of the RFC 5545 skip."
:start '(2030 1 31 10 0)
:end '(2030 1 31 11 0)))
(rrule (list :freq 'monthly :interval 1))
+ ;; End the range past Dec 31: the range end is midnight, so ending
+ ;; ON the 31st would exclude that day's 10:00 occurrence.
(range (list (calendar-sync--date-to-time '(2030 1 1))
- (calendar-sync--date-to-time '(2030 12 31))))
+ (calendar-sync--date-to-time '(2031 1 1))))
(occurrences (calendar-sync--expand-monthly base-event rrule range))
(months (mapcar (lambda (o) (nth 1 (plist-get o :start))) occurrences))
(days (mapcar (lambda (o) (nth 2 (plist-get o :start))) occurrences)))
diff --git a/tests/test-elfeed-config-helpers.el b/tests/test-elfeed-config-helpers.el
index 16cbb744..95a98e83 100644
--- a/tests/test-elfeed-config-helpers.el
+++ b/tests/test-elfeed-config-helpers.el
@@ -1,10 +1,7 @@
;;; test-elfeed-config-helpers.el --- Tests for elfeed stream/process helpers -*- lexical-binding: t; -*-
;;; Commentary:
-;; Coverage for two elfeed-config helpers that were untested:
-;; - cj/extract-stream-url: runs yt-dlp -g to resolve a direct stream URL,
-;; returning the URL, nil on non-URL / nonzero exit, or signalling when
-;; yt-dlp is absent.
+;; Coverage for the elfeed-config entry-processing helper:
;; - cj/elfeed-process-entries: applies an action to each selected entry,
;; marking them read; errors when nothing is selected, skips entries with
;; no link, and (by default) catches per-entry action errors.
@@ -34,40 +31,6 @@
(require 'elfeed-config)
(require 'elfeed nil t)
-;;; cj/extract-stream-url
-
-(ert-deftest test-elfeed-extract-stream-url-normal-returns-url ()
- "Normal: a successful yt-dlp run returns the trimmed https stream URL."
- (cl-letf (((symbol-function 'executable-find)
- (lambda (p &rest _) (and (equal p "yt-dlp") "/usr/bin/yt-dlp")))
- ((symbol-function 'cj/log-silently) #'ignore)
- ((symbol-function 'call-process)
- (lambda (_prog _infile _dest _disp &rest _args)
- (insert "https://stream.example/abc\n") 0)))
- (should (equal "https://stream.example/abc"
- (cj/extract-stream-url "https://youtube.com/watch?v=x" "best")))))
-
-(ert-deftest test-elfeed-extract-stream-url-boundary-non-url-output-is-nil ()
- "Boundary: output that is not an http(s) URL yields nil, not the raw text."
- (cl-letf (((symbol-function 'executable-find) (lambda (_ &rest _) "/usr/bin/yt-dlp"))
- ((symbol-function 'cj/log-silently) #'ignore)
- ((symbol-function 'call-process)
- (lambda (_p _i _d _disp &rest _) (insert "ERROR: unavailable\n") 0)))
- (should (null (cj/extract-stream-url "u" nil)))))
-
-(ert-deftest test-elfeed-extract-stream-url-boundary-nonzero-exit-is-nil ()
- "Boundary: a nonzero yt-dlp exit code yields nil."
- (cl-letf (((symbol-function 'executable-find) (lambda (_ &rest _) "/usr/bin/yt-dlp"))
- ((symbol-function 'cj/log-silently) #'ignore)
- ((symbol-function 'call-process)
- (lambda (_p _i _d _disp &rest _) (insert "boom") 1)))
- (should (null (cj/extract-stream-url "u" nil)))))
-
-(ert-deftest test-elfeed-extract-stream-url-error-without-yt-dlp ()
- "Error: a missing yt-dlp signals before attempting the call."
- (cl-letf (((symbol-function 'executable-find) (lambda (_ &rest _) nil)))
- (should-error (cj/extract-stream-url "u" "best") :type 'error)))
-
;;; cj/elfeed-process-entries
(defun cj/test--elfeed-entry (link)
diff --git a/tests/test-org-roam-config-format.el b/tests/test-org-roam-config-format.el
index caafe563..16370ca1 100644
--- a/tests/test-org-roam-config-format.el
+++ b/tests/test-org-roam-config-format.el
@@ -147,13 +147,21 @@ Returns the formatted file content."
(let ((result (test-format "Title" "id" "* Content")))
(should (string-match-p "#\\+FILETAGS: Topic\n\n\\* Content" result))))
-(ert-deftest test-org-roam-config-capture-templates-declared-special ()
- "Normal: org-roam-capture-templates is declared special in the module.
-cj/org-roam-node-insert-immediate let-binds it; without the defvar the
-byte-compiled let is a dead lexical binding and :immediate-finish never
-reaches org-roam-node-insert -- the \"immediate\" insert opens a capture
-buffer."
- (should (special-variable-p 'org-roam-capture-templates)))
+(defvar org-roam-capture-templates)
+
+(ert-deftest test-org-roam-config-immediate-insert-binding-is-dynamic ()
+ "Normal: the immediate-insert template binding reaches the insert call.
+Without the module's defvar, the byte-compiled let is a dead lexical
+binding: org-roam-node-insert would see the untouched global templates
+and :immediate-finish never applies -- the \"immediate\" insert opens a
+capture buffer. Asserted behaviorally (not via special-variable-p,
+whose answer differs between the package-loaded and bare batch envs)."
+ (let ((org-roam-capture-templates '(("d" "default")))
+ seen)
+ (cl-letf (((symbol-function 'org-roam-node-insert)
+ (lambda (&rest _) (setq seen org-roam-capture-templates))))
+ (cj/org-roam-node-insert-immediate nil))
+ (should (equal seen '(("d" "default" :immediate-finish t))))))
(provide 'test-org-roam-config-format)
;;; test-org-roam-config-format.el ends here
diff --git a/tests/test-system-commands-resolve-and-run.el b/tests/test-system-commands-resolve-and-run.el
index 9d92c5d6..7e5146b1 100644
--- a/tests/test-system-commands-resolve-and-run.el
+++ b/tests/test-system-commands-resolve-and-run.el
@@ -230,5 +230,37 @@ kill-emacs directly (the service owns the daemon lifecycle)."
(cj/system-command-menu))
(should (eq called 'cj/system-cmd-lock))))
+;;; Lock command resolves the locker at call time
+
+(defun test-system-cmd--run-lock-capturing ()
+ "Run the lock command; return the shell command line it launched."
+ (let (cmd-line)
+ (cl-letf (((symbol-function 'start-process-shell-command)
+ (lambda (_name _buf c) (setq cmd-line c) 'fake-proc))
+ ((symbol-function 'set-process-query-on-exit-flag) #'ignore)
+ ((symbol-function 'set-process-sentinel) #'ignore)
+ ((symbol-function 'message) #'ignore))
+ (cj/system-cmd-lock))
+ cmd-line))
+
+(ert-deftest test-system-cmd-lock-follows-session-type-at-call-time ()
+ "Normal: the locker tracks the live session type, not the load-time bake.
+A daemon started before WAYLAND_DISPLAY was imported used to freeze the
+locker to slock forever; Lock then failed silently on Wayland."
+ (let ((lockscreen-cmd nil))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () t)))
+ (should (string-match-p "loginctl lock-session"
+ (test-system-cmd--run-lock-capturing))))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () nil)))
+ (should (string-match-p "slock"
+ (test-system-cmd--run-lock-capturing))))))
+
+(ert-deftest test-system-cmd-lock-explicit-override-wins ()
+ "Boundary: a user-set lockscreen-cmd overrides the session-type resolution."
+ (let ((lockscreen-cmd "my-locker --now"))
+ (cl-letf (((symbol-function 'env-wayland-p) (lambda () t)))
+ (should (string-match-p "my-locker --now"
+ (test-system-cmd--run-lock-capturing))))))
+
(provide 'test-system-commands-resolve-and-run)
;;; test-system-commands-resolve-and-run.el ends here