diff options
author | Vibhav Pant <vibhavp@gmail.com> | 2017-02-05 23:08:53 +0530 |
---|---|---|
committer | Vibhav Pant <vibhavp@gmail.com> | 2017-02-05 23:08:53 +0530 |
commit | ad70ca1dad26da79f0a95cc0ec687902ef20fa9b (patch) | |
tree | 732e8e9ace1fdd7aaf982f0fa5ac6c8e4eb5f7c7 /lisp/emacs-lisp/ert-x.el | |
parent | 2db473bda8be72cf3c1e4694d70ce48f60492b0e (diff) | |
parent | 148100d98319499f0ac6f57b8be08cbd14884a5c (diff) | |
download | emacs-ad70ca1dad26da79f0a95cc0ec687902ef20fa9b.tar.gz emacs-ad70ca1dad26da79f0a95cc0ec687902ef20fa9b.tar.bz2 emacs-ad70ca1dad26da79f0a95cc0ec687902ef20fa9b.zip |
Merge remote-tracking branch 'origin/master' into feature/byte-switch
Diffstat (limited to 'lisp/emacs-lisp/ert-x.el')
-rw-r--r-- | lisp/emacs-lisp/ert-x.el | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el index 7d99cb30274..4cf9d9609e9 100644 --- a/lisp/emacs-lisp/ert-x.el +++ b/lisp/emacs-lisp/ert-x.el @@ -97,7 +97,7 @@ To be used in ERT tests. If BODY finishes successfully, the test buffer is killed; if there is an error, the test buffer is kept around on error for further inspection. Its name is derived from the name of the test and the result of NAME-FORM." - (declare (debug ((form) body)) + (declare (debug ((":name" form) body)) (indent 1)) `(ert--call-with-test-buffer ,name-form (lambda () ,@body))) @@ -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 |