diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-09 17:53:15 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-09 17:53:15 -0500 |
| commit | 3f0dcdcdf9ad7401867f997ff165bb47cc46c9a4 (patch) | |
| tree | 53587281bc692c438bf123e2ff209ebf8b277771 /tests | |
| parent | 7e03862f6315af4b960cbbbe670764cbd49b09d1 (diff) | |
| download | chime-3f0dcdcdf9ad7401867f997ff165bb47cc46c9a4.tar.gz chime-3f0dcdcdf9ad7401867f997ff165bb47cc46c9a4.zip | |
test: assert on chime's messages, not on Emacs staying silent
Three sound tests mocked message and counted everything it captured. Under make coverage, chime.el loads as instrumented source, so the sentinel lambda compiles on first call and emits "Warning: argument '_event' not left unused" through message. That warning landed in the capture list, the counts came out one high, and the Coverage job failed while all five Emacs versions passed.
The tests now filter captured messages to chime's own. What they mean is that chime reported the failure once, not that nothing in Emacs said anything.
make test and make test-all never load the instrumented source, so they can't catch this. make coverage reproduces it.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-chime-sound.el | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/test-chime-sound.el b/tests/test-chime-sound.el index 8648331..0160d50 100644 --- a/tests/test-chime-sound.el +++ b/tests/test-chime-sound.el @@ -59,6 +59,15 @@ trampoline, so tests hand the production code a real process instead.") "Spawn a real, immediately-exiting process to stand in for a player." (funcall test-chime-sound--real-start-process "chime-sound-test" nil "true")) +(defun test-chime-sound--chime-messages (messages) + "Return only the chime-emitted entries of MESSAGES. +A test that mocks `message' captures every message Emacs emits, not just +chime's. Under a coverage run the source is loaded uninstrumented and the +sentinel lambda is compiled on first call, so a byte-compiler warning lands +in the capture list and a bare count assertion fails. Assert on what chime +said, not on Emacs having said nothing." + (seq-filter (lambda (m) (string-prefix-p "chime:" m)) messages)) + ;;; Normal Cases (chime-deftest test-chime-sound-find-sound-player-auto-returns-first-available () @@ -235,9 +244,10 @@ synchronous `play-sound-file' path returns t instead." ;; The sentinel fires when the player exits, not before. (while (process-live-p process) (accept-process-output process 0 50))) - (should (= (length messages) 1)) - (should (string-match-p "Failed to play sound" (car messages))) - (should (string-match-p "false" (car messages)))))) + (let ((chime-messages (test-chime-sound--chime-messages messages))) + (should (= (length chime-messages) 1)) + (should (string-match-p "Failed to play sound" (car chime-messages))) + (should (string-match-p "false" (car chime-messages))))))) (chime-deftest test-chime-sound-external-zero-exit-is-silent () "A player that succeeds reports nothing." @@ -250,7 +260,7 @@ synchronous `play-sound-file' path returns t instead." (let ((process (chime--play-sound))) (while (process-live-p process) (accept-process-output process 0 50))) - (should-not messages)))) + (should-not (test-chime-sound--chime-messages messages))))) (chime-deftest test-chime-sound-both-players-failing-reports-once-and-does-not-signal () "When both players fail, the error is reported and not propagated." @@ -270,8 +280,9 @@ synchronous `play-sound-file' path returns t instead." (should-not (condition-case nil (progn (chime--play-sound) nil) (error t))) - (should (= (length messages) 1)) - (should (string-match-p "Failed to play sound" (car messages)))))) + (let ((chime-messages (test-chime-sound--chime-messages messages))) + (should (= (length chime-messages) 1)) + (should (string-match-p "Failed to play sound" (car chime-messages))))))) (chime-deftest test-chime-sound-emacs-player-error-is-reported-not-signalled () "A `play-sound-file' failure is reported and swallowed." @@ -286,8 +297,9 @@ synchronous `play-sound-file' path returns t instead." (should-not (condition-case nil (progn (chime--play-sound) nil) (error t))) - (should (= (length messages) 1)) - (should (string-match-p "Failed to play sound" (car messages)))))) + (let ((chime-messages (test-chime-sound--chime-messages messages))) + (should (= (length chime-messages) 1)) + (should (string-match-p "Failed to play sound" (car chime-messages))))))) (chime-deftest test-chime-sound-device-rejects-non-string-at-customize-time () "Setting `chime-sound-device' to a non-string is rejected." |
