From 55c60f025e834c6bc60523542644ac0ec03d035c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 21 Jun 2026 08:31:24 -0400 Subject: 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. --- tests/testutil-wttrin.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/testutil-wttrin.el') diff --git a/tests/testutil-wttrin.el b/tests/testutil-wttrin.el index 7c71a84..e4e2e4e 100644 --- a/tests/testutil-wttrin.el +++ b/tests/testutil-wttrin.el @@ -111,6 +111,20 @@ (funcall callback nil))))) ,@body)) +;;; Message Capture Helpers + +(defmacro testutil-wttrin-with-captured-message (msg-var &rest body) + "Run BODY with `message' captured into MSG-VAR. +MSG-VAR starts nil and is set to each formatted message string as `message' +is called, so after BODY it holds the last message shown (or nil if none). +Other mocks BODY needs can be set in a nested `cl-letf'." + (declare (indent 1)) + `(let ((,msg-var nil)) + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) + (setq ,msg-var (apply #'format fmt args))))) + ,@body))) + ;;; Mode-line Cache Helpers (defun testutil-wttrin-set-mode-line-cache (data &optional age-seconds) -- cgit v1.2.3