Function: ert-with-test-buffer
ert-with-test-buffer is a macro defined in ert.el.gz.
Signature
(ert-with-test-buffer (&key ((:name NAME-FORM) nil) ((:selected SELECT-FORM) nil)) &body BODY)
Documentation
Create a test buffer and run BODY in that buffer.
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 for further inspection. The name of the buffer is derived from the name of the test and the result of NAME-FORM.
If SELECT-FORM is non-nil, switch to the test buffer before running
BODY, as if body was in ert-with-buffer-selected.
The return value is the last form in BODY.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
(cl-defmacro ert-with-test-buffer ((&key ((:name name-form))
((:selected select-form)))
&body body)
"Create a test buffer and run BODY in that buffer.
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 for
further inspection. The name of the buffer is derived from the name of
the test and the result of NAME-FORM.
If SELECT-FORM is non-nil, switch to the test buffer before running
BODY, as if body was in `ert-with-buffer-selected'.
The return value is the last form in BODY."
(declare (debug ((":name" form) (":selected" form) def-body))
(indent 1))
`(ert--call-with-test-buffer
,name-form
,(if select-form
`(lambda () (ert-with-buffer-selected (current-buffer)
,@body))
`(lambda () ,@body))))