aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-notify.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-09 19:57:45 -0500
committerCraig Jennings <c@cjennings.net>2026-07-09 19:57:45 -0500
commit032ba26f7504a7a10f532f345d3d5f183c171fe7 (patch)
treed39434dee17b958eb84ebc9890e1864f9ac1f5f5 /tests/test-chime-notify.el
parent372b61dcce34778d8a8b59bc6f02a942455dc825 (diff)
downloadchime-032ba26f7504a7a10f532f345d3d5f183c171fe7.tar.gz
chime-032ba26f7504a7a10f532f345d3d5f183c171fe7.zip
test: add failing tests for the per-event alert guard
One test asserts that an alert error is reported rather than signalled. The other asserts that a failing event doesn't cost us the notifications after it, driving chime--process-notifications over three events with the middle one raising.
Diffstat (limited to 'tests/test-chime-notify.el')
-rw-r--r--tests/test-chime-notify.el43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test-chime-notify.el b/tests/test-chime-notify.el
index 822bf00..68cb938 100644
--- a/tests/test-chime-notify.el
+++ b/tests/test-chime-notify.el
@@ -221,5 +221,48 @@
(should alert-called)))
(test-chime-notify-teardown)))
+(ert-deftest test-chime-notify-alert-error-does-not-propagate ()
+ "An `alert' failure is reported, not signalled.
+`chime--process-notifications' maps `chime--notify' over every due event, so
+an alert that signals (a dbus error, say) would drop every remaining
+notification in the batch and be miscounted as a fetch failure."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((messages nil))
+ (cl-letf (((symbol-function 'chime--play-sound) (lambda () nil))
+ ((symbol-function 'alert)
+ (lambda (&rest _) (error "Dbus is having a bad day")))
+ ((symbol-function 'message)
+ (lambda (fmt &rest args) (push (apply #'format fmt args) messages))))
+ (should-not (condition-case nil
+ (progn (chime--notify "Test Event") nil)
+ (error t)))
+ (let ((chime-messages
+ (seq-filter (lambda (m) (string-prefix-p "chime:" m)) messages)))
+ (should (= (length chime-messages) 1))
+ (should (string-match-p "Failed to show notification" (car chime-messages))))))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-alert-error-does-not-stop-the-batch ()
+ "One event's alert failure does not drop the notifications after it."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((delivered nil))
+ (cl-letf (((symbol-function 'chime--play-sound) (lambda () nil))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil))
+ ((symbol-function 'chime--check-event)
+ (lambda (event) (list event)))
+ ((symbol-function 'alert)
+ (lambda (msg &rest _)
+ (if (equal msg "second")
+ (error "Dbus is having a bad day")
+ (push msg delivered))))
+ ((symbol-function 'message) (lambda (&rest _) nil)))
+ (chime--process-notifications (list "first" "second" "third"))
+ ;; The failing middle event must not cost us the third.
+ (should (equal (nreverse delivered) (list "first" "third")))))
+ (test-chime-notify-teardown)))
+
(provide 'test-chime-notify)
;;; test-chime-notify.el ends here