diff options
Diffstat (limited to 'tests/test-chime-notify.el')
| -rw-r--r-- | tests/test-chime-notify.el | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/tests/test-chime-notify.el b/tests/test-chime-notify.el index cd7b350..68cb938 100644 --- a/tests/test-chime-notify.el +++ b/tests/test-chime-notify.el @@ -26,9 +26,6 @@ (require 'test-bootstrap (expand-file-name "test-bootstrap.el")) -;; Load test utilities -(require 'testutil-general (expand-file-name "testutil-general.el")) - ;;; Setup and Teardown (defun test-chime-notify-setup () @@ -39,7 +36,12 @@ (setq chime-notification-icon nil) (setq chime-extra-alert-plist nil) ;; Use a simple test path for sound file - (setq chime-sound-file "/tmp/test-chime.wav")) + (setq chime-sound-file "/tmp/test-chime.wav") + ;; Route sound through `play-sound-file' so these tests mock one function + ;; and never spawn a real external player. The player-selection contract + ;; itself is covered in test-chime-sound.el. + (setq chime-sound-player 'emacs) + (setq chime-sound-device nil)) (defun test-chime-notify-teardown () "Teardown function run after each test." @@ -60,7 +62,7 @@ ((symbol-function 'file-exists-p) (lambda (file) t)) ;; Mock play-sound-file to track if called ((symbol-function 'play-sound-file) - (lambda (file) + (lambda (&rest _) (setq sound-played t))) ;; Mock alert to track if called ((symbol-function 'alert) @@ -149,7 +151,7 @@ ;; Mock file-exists-p to return nil ((symbol-function 'file-exists-p) (lambda (file) nil)) ((symbol-function 'play-sound-file) - (lambda (file) (setq sound-played t))) + (lambda (&rest _) (setq sound-played t))) ((symbol-function 'alert) (lambda (msg &rest args) (setq alert-called t)))) (chime--notify "Test Event") @@ -172,7 +174,7 @@ ((symbol-function 'file-exists-p) (lambda (file) t)) ;; Mock play-sound-file to throw error ((symbol-function 'play-sound-file) - (lambda (file) (error "Sound playback failed"))) + (lambda (&rest _) (error "Sound playback failed"))) ((symbol-function 'alert) (lambda (msg &rest args) (setq alert-called t)))) ;; Should not throw error @@ -219,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 |
