aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-query.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-21 08:31:24 -0400
committerCraig Jennings <c@cjennings.net>2026-06-21 08:31:24 -0400
commit55c60f025e834c6bc60523542644ac0ec03d035c (patch)
treef8bce1933679fd46674996ef7da6a6ce68fb2f1e /tests/test-wttrin-query.el
parent021b5bb771bff834bc67d82fa61b870e175bdf71 (diff)
downloademacs-wttrin-55c60f025e834c6bc60523542644ac0ec03d035c.tar.gz
emacs-wttrin-55c60f025e834c6bc60523542644ac0ec03d035c.zip
test: extract message-capture helper into testutil
Five test files hand-rolled the same scaffolding to capture the echo-area message: a nil-initialized var, a cl-letf on message, and a lambda that stored the formatted string. Centralize it as testutil-wttrin-with-captured-message, which binds the var and captures the last message shown. Behavior is unchanged. The full suite stays green. Sites that mock message for a different reason are left alone: the ones that silence it with #'ignore, and the one that accumulates every message into a list.
Diffstat (limited to 'tests/test-wttrin-query.el')
-rw-r--r--tests/test-wttrin-query.el25
1 files changed, 11 insertions, 14 deletions
diff --git a/tests/test-wttrin-query.el b/tests/test-wttrin-query.el
index 396507b..4c4de87 100644
--- a/tests/test-wttrin-query.el
+++ b/tests/test-wttrin-query.el
@@ -102,20 +102,17 @@
"When fetch returns nil, the user should see an error message, not a crash."
(test-wttrin-query-setup)
(unwind-protect
- (let ((saved-callback nil)
- (displayed-message nil))
- (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch)
- (lambda (_location callback)
- (setq saved-callback callback)))
- ((symbol-function 'message)
- (lambda (fmt &rest args)
- (setq displayed-message (apply #'format fmt args)))))
- (wttrin-query "BadLocation")
- ;; Simulate fetch returning nil
- (funcall saved-callback nil)
- ;; Should have shown error message (from wttrin--display-weather validation)
- (should displayed-message)
- (should (string-match-p "Cannot retrieve" displayed-message))))
+ (let ((saved-callback nil))
+ (testutil-wttrin-with-captured-message displayed-message
+ (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch)
+ (lambda (_location callback)
+ (setq saved-callback callback))))
+ (wttrin-query "BadLocation")
+ ;; Simulate fetch returning nil
+ (funcall saved-callback nil)
+ ;; Should have shown error message (from wttrin--display-weather validation)
+ (should displayed-message)
+ (should (string-match-p "Cannot retrieve" displayed-message)))))
(test-wttrin-query-teardown)))
(provide 'test-wttrin-query)