From 032ba26f7504a7a10f532f345d3d5f183c171fe7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 9 Jul 2026 19:57:45 -0500 Subject: 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. --- tests/test-chime-notify.el | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3