diff options
author | Gemini Lasswell <gazally@runbox.com> | 2017-02-04 13:36:43 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2017-02-04 13:36:43 +0200 |
commit | ef3d8d6f7226e570209e913d2754e828d0cb121c (patch) | |
tree | 598390fc1084a54d90ae1c5cec952ddd79e8dbfc /lisp/emacs-lisp/ert-x.el | |
parent | 8ba27b7ce2f4a98e3c14fe752042c60fd7576fef (diff) | |
download | emacs-ef3d8d6f7226e570209e913d2754e828d0cb121c.tar.gz |
New macro 'ert-with-message-capture'
* lisp/emacs-lisp/ert-x.el (ert-with-message-capture): New macro.
(Bug#25158)
* test/lisp/autorevert-tests.el (auto-revert--wait-for-revert)
(auto-revert-test00-auto-revert-mode)
(auto-revert-test01-auto-revert-several-files)
(auto-revert-test02-auto-revert-deleted-file)
(auto-revert-test03-auto-revert-tail-mode)
(auto-revert-test04-auto-revert-mode-dired):
* test/lisp/filenotify-tests.el (file-notify-test03-autorevert): Use
ert-with-message-capture.
Diffstat (limited to 'lisp/emacs-lisp/ert-x.el')
-rw-r--r-- | lisp/emacs-lisp/ert-x.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el index 8530253d5b4..4cf9d9609e9 100644 --- a/lisp/emacs-lisp/ert-x.el +++ b/lisp/emacs-lisp/ert-x.el @@ -285,6 +285,30 @@ BUFFER defaults to current buffer. Does not modify BUFFER." (kill-buffer clone))))))) +(defmacro ert-with-message-capture (var &rest body) + "Execute BODY while collecting anything written with `message' in VAR. + +Capture all messages produced by `message' when it is called from +Lisp, and concatenate them separated by newlines into one string. + +This is useful for separating the issuance of messages by the +code under test from the behavior of the *Messages* buffer." + (declare (debug (symbolp body)) + (indent 1)) + (let ((g-advice (cl-gensym))) + `(let* ((,var "") + (,g-advice (lambda (func &rest args) + (if (or (null args) (equal (car args) "")) + (apply func args) + (let ((msg (apply #'format-message args))) + (setq ,var (concat ,var msg "\n")) + (funcall func "%s" msg)))))) + (advice-add 'message :around ,g-advice) + (unwind-protect + (progn ,@body) + (advice-remove 'message ,g-advice))))) + + (provide 'ert-x) ;;; ert-x.el ends here |