diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 05:40:24 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 05:40:24 -0500 |
| commit | ee90de269e4f65a9b57b4fc9e260d3aa6948b6ca (patch) | |
| tree | 6f16459e8bf47a6925131ccc743b59e33cd9b9ae /tests/test-chime-async-helpers.el | |
| parent | 73faba8658ea783bca8392e4d4cc14cf7f94a48f (diff) | |
| download | chime-ee90de269e4f65a9b57b4fc9e260d3aa6948b6ca.tar.gz chime-ee90de269e4f65a9b57b4fc9e260d3aa6948b6ca.zip | |
feat: add per-event :CHIME_NOTIFY_BEFORE: interval override
Chime's migration from org-wild-notifier dropped the per-event notify-before property, so a heading could no longer override the global chime-alert-intervals. I brought it back.
A heading's :CHIME_NOTIFY_BEFORE: N (a non-negative integer) means "notify once, N minutes before, severity medium" and replaces chime-alert-intervals for that event. The org-wild-notifier name :WILD_NOTIFIER_NOTIFY_BEFORE: still works, as a deprecated alias. When it supplies the value, chime emits one per-session warning pointing at the new name. :CHIME_NOTIFY_BEFORE: wins when both are set. A malformed value logs a message naming the heading and falls back to the global.
chime--gather-info reads the property in the async child. The deprecation flag rides on the event alist so the parent emits the warning without changing the async return contract.
I also touched two test files. test-chime-async-helpers.el's fixtures fed bare symbols where chime--handle-async-success now expects event alists, so they build real events via chime--make-event. And the new test file's message-capture macro had a lexical-scoping bug (the captured list was invisible after the macro returned), so the two affected tests inline the capture and the macro is gone.
Diffstat (limited to 'tests/test-chime-async-helpers.el')
| -rw-r--r-- | tests/test-chime-async-helpers.el | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/tests/test-chime-async-helpers.el b/tests/test-chime-async-helpers.el index 86c5ed8..3e0e562 100644 --- a/tests/test-chime-async-helpers.el +++ b/tests/test-chime-async-helpers.el @@ -27,21 +27,32 @@ ;;; Code: (require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'testutil-time (expand-file-name "testutil-time.el")) ;;; Setup and Teardown (defun test-chime-async-helpers-setup () - "Reset counters and modeline state before each test." + "Reset counters, modeline state, and the deprecation-warning guard before each test." (setq chime--consecutive-async-failures 0) (setq chime-max-consecutive-failures 5) (setq chime-modeline-no-events-text "*") - (setq chime-modeline-string nil)) + (setq chime-modeline-string nil) + (setq chime--deprecated-property-warned nil)) (defun test-chime-async-helpers-teardown () - "Restore default state after each test." + "Restore default state after each test, including the deprecation-warning guard." (setq chime--consecutive-async-failures 0) (setq chime-max-consecutive-failures 5) - (setq chime-modeline-string nil)) + (setq chime-modeline-string nil) + (setq chime--deprecated-property-warned nil)) + +(defun test-chime-async-helpers--event (title &optional deprecated-property) + "Build a minimal valid Chime event alist with TITLE. +DEPRECATED-PROPERTY, when given, marks the event as having used a +deprecated per-event property of that name." + (let ((time (test-time-tomorrow-at 14 0))) + (chime--make-event (list (cons (test-timestamp-string time) time)) + title '((10 . medium)) nil nil deprecated-property))) ;;;; Tests for chime--record-async-failure @@ -103,19 +114,22 @@ (setq chime--consecutive-async-failures 3) (chime--handle-async-success (lambda (events) (setq called-with events)) - '(event1 event2)) + (list (test-chime-async-helpers--event "A") + (test-chime-async-helpers--event "B"))) (should (= 0 chime--consecutive-async-failures))) (test-chime-async-helpers-teardown))) (ert-deftest test-chime-handle-async-success-normal-invokes-callback-with-events () - "Normal: calls the supplied callback with the events list." + "Normal: calls the supplied callback with the events list verbatim." (test-chime-async-helpers-setup) (unwind-protect - (let ((called-with 'unset)) + (let* ((called-with 'unset) + (events (list (test-chime-async-helpers--event "A") + (test-chime-async-helpers--event "B")))) (chime--handle-async-success - (lambda (events) (setq called-with events)) - '(a b c)) - (should (equal '(a b c) called-with))) + (lambda (e) (setq called-with e)) + events) + (should (eq events called-with))) (test-chime-async-helpers-teardown))) (ert-deftest test-chime-handle-async-success-boundary-empty-events () @@ -134,13 +148,30 @@ "Boundary: counter starts at zero, stays at zero, callback still fires." (test-chime-async-helpers-setup) (unwind-protect - (let ((called-with 'unset)) + (let* ((called-with 'unset) + (events (list (test-chime-async-helpers--event "X")))) (setq chime--consecutive-async-failures 0) (chime--handle-async-success - (lambda (events) (setq called-with events)) - '(x)) + (lambda (e) (setq called-with e)) + events) (should (= 0 chime--consecutive-async-failures)) - (should (equal '(x) called-with))) + (should (eq events called-with))) + (test-chime-async-helpers-teardown))) + +(ert-deftest test-chime-handle-async-success-normal-warns-on-deprecated-property () + "Normal: warns once when an event used a deprecated per-event property." + (test-chime-async-helpers-setup) + (unwind-protect + (let ((warned nil)) + (cl-letf (((symbol-function 'display-warning) + (lambda (_type msg &rest _) (push msg warned)))) + (chime--handle-async-success + #'ignore + (list (test-chime-async-helpers--event "A") + (test-chime-async-helpers--event "B" "WILD_NOTIFIER_NOTIFY_BEFORE")))) + (should (= 1 (length warned))) + (should (string-match-p "WILD_NOTIFIER_NOTIFY_BEFORE" (car warned))) + (should chime--deprecated-property-warned)) (test-chime-async-helpers-teardown))) (provide 'test-chime-async-helpers) |
