Move buffer related functions from ert-x.el to ert.el
* lisp/emacs-lisp/ert-x.el (ert--text-button) (ert--format-test-buffer-name, ert--test-buffers) (ert--test-buffer-button, ert--test-buffer-button-action) (ert--call-with-test-buffer, ert-with-test-buffer) (ert-with-buffer-selected, ert-kill-all-test-buffers) (ert-call-with-buffer-renamed, ert-buffer-string-reindented): Move from here... * lisp/emacs-lisp/ert.el (ert--text-button) (ert--format-test-buffer-name, ert--test-buffers) (ert--test-buffer-button, ert--test-buffer-button-action) (ert--call-with-test-buffer, ert-with-test-buffer) (ert-kill-all-test-buffers, ert-with-buffer-selected) (ert-call-with-buffer-renamed, ert-with-buffer-renamed): ...to here. * doc/misc/ert.texi (Helpers for Buffers): Break out new section... (Helper Functions): ...from here. * lisp/emacs-lisp/ert-x.el (ert-with-test-buffer-selected): Move obsolete definition to the end of the file. * test/lisp/emacs-lisp/ert-x-tests.el (ert--hash-table-to-alist, ert-test-test-buffers) (ert-test-with-buffer-selected/current) (ert-test-with-buffer-selected/selected) (ert-test-with-buffer-selected/nil-buffer) (ert-test-with-buffer-selected/modification-hooks) (ert-test-with-buffer-selected/read-only) (ert-test-with-buffer-selected/return-value) (ert-test-with-test-buffer-selected/modification-hooks) (ert-test-with-test-buffer-selected/read-only) (ert-test-with-test-buffer-selected/return-value) (ert-test-with-test-buffer-selected/buffer-name): Move tests from here... * test/lisp/emacs-lisp/ert-tests.el (ert--hash-table-to-alist, ert-test-test-buffers) (ert-test-with-buffer-selected/current) (ert-test-with-buffer-selected/selected) (ert-test-with-buffer-selected/nil-buffer) (ert-test-with-buffer-selected/modification-hooks) (ert-test-with-buffer-selected/read-only) (ert-test-with-buffer-selected/return-value) (ert-test-with-test-buffer-selected/selected) (ert-test-with-test-buffer-selected/modification-hooks) (ert-test-with-test-buffer-selected/read-only) (ert-test-with-test-buffer-selected/return-value) (ert-test-with-test-buffer-selected/buffer-name): ...to here. * test/lisp/progmodes/hideshow-tests.el (ert-x): * test/lisp/simple-tests.el (ert-x): * test/lisp/whitespace-tests.el (ert-x): Don't require.
This commit is contained in:
parent
d9f165b129
commit
c9e681aa0c
9 changed files with 282 additions and 262 deletions
|
@ -535,6 +535,7 @@ help ERT find the defining call to the macro by putting the property
|
|||
* Useful Techniques:: Some examples.
|
||||
* erts files:: Files containing many buffer tests.
|
||||
* Syntax Highlighting Tests:: Tests for face assignment.
|
||||
* Helpers for Buffers:: Dealing with buffers during tests.
|
||||
* Helper Functions:: Various helper functions.
|
||||
@end menu
|
||||
|
||||
|
@ -1085,13 +1086,20 @@ macros accept the same keyword parameters as @code{ert-deftest} i.e.,
|
|||
@code{:tag} and @code{:expected-result}.
|
||||
|
||||
|
||||
@node Helper Functions
|
||||
@section Various Helper Functions
|
||||
@node Helpers for Buffers
|
||||
@section Handling Buffers during tests
|
||||
|
||||
The package @file{ert-x.el} contains some macros and functions useful
|
||||
for writing tests.
|
||||
ERT comes with some macros for dealing with buffers used when testing.
|
||||
|
||||
@subsection Test Buffers
|
||||
@subsection Creating temporary buffers
|
||||
|
||||
@findex ert-kill-all-test-buffers
|
||||
The @code{ert-with-test-buffer} macro can be used to create a temporary
|
||||
buffer during a test, which is cleaned up automatically if the test is
|
||||
successful. But if the test fails, the buffer stays around so that you
|
||||
can more easily investigate the test failure. When you are done, you
|
||||
can use the command @code{ert-kill-all-test-buffers} to kill all test
|
||||
buffers that have been created by this macro.
|
||||
|
||||
@defmac ert-with-test-buffer ((&key ((:name name-form :selected select-form))) &body body)
|
||||
This macro creates a test buffer and runs @var{body} in that buffer. If
|
||||
|
@ -1144,9 +1152,7 @@ value is the last form in @var{body}. Example:
|
|||
This displays a temporary buffer like @file{ *temp*-739785*}.
|
||||
@end defmac
|
||||
|
||||
@defun ert-kill-all-test-buffers ()
|
||||
It kills all test buffers that are still live.
|
||||
@end defun
|
||||
@subsection Protecting buffers
|
||||
|
||||
@defmac ert-with-buffer-renamed ((buffer-name-form) &body body)
|
||||
This macro protects the buffer @var{buffer-name} from side-effects and
|
||||
|
@ -1163,6 +1169,13 @@ buffer with a fixed name such as @file{*Messages*}. Example:
|
|||
@end lisp
|
||||
@end defmac
|
||||
|
||||
|
||||
@node Helper Functions
|
||||
@section Various Helper Functions
|
||||
|
||||
The package @file{ert-x.el} contains some macros and functions useful
|
||||
for writing tests.
|
||||
|
||||
@defmac ert-with-message-capture (var &rest body)
|
||||
This macro executes @var{body} while collecting messages in @var{var}.
|
||||
It captures messages issued by Lisp code and concatenates them separated
|
||||
|
|
11
etc/NEWS
11
etc/NEWS
|
@ -1408,6 +1408,17 @@ and signal an error if they are given a non-number.
|
|||
They return non-nil if an integer is odd or even, respectively, and
|
||||
signal an error if they are given a non-integer.
|
||||
|
||||
** ERT
|
||||
|
||||
*** Some experimental ERT macros are now considered stable.
|
||||
The following macros, previously only available in the experimental
|
||||
'ert-x' module, are now considered stable and have been moved to 'ert':
|
||||
- ert-with-test-buffer
|
||||
- ert-with-buffer-selected
|
||||
- ert-with-buffer-renamed
|
||||
|
||||
See the ERT manual for more information.
|
||||
|
||||
** Time & Date
|
||||
|
||||
+++
|
||||
|
|
|
@ -32,135 +32,6 @@
|
|||
(require 'ert)
|
||||
(require 'subr-x)
|
||||
|
||||
|
||||
;;; Test buffers.
|
||||
|
||||
(defun ert--text-button (string &rest properties)
|
||||
"Return a string containing STRING as a text button with PROPERTIES.
|
||||
|
||||
See `make-text-button'."
|
||||
(with-temp-buffer
|
||||
(insert string)
|
||||
(apply #'make-text-button (point-min) (point-max) properties)
|
||||
(buffer-string)))
|
||||
|
||||
(defun ert--format-test-buffer-name (base-name)
|
||||
"Compute a test buffer name based on BASE-NAME.
|
||||
|
||||
Helper function for `ert--test-buffers'."
|
||||
(format "*Test buffer (%s)%s*"
|
||||
(or (and (ert-running-test)
|
||||
(ert-test-name (ert-running-test)))
|
||||
"<anonymous test>")
|
||||
(if base-name
|
||||
(format ": %s" base-name)
|
||||
"")))
|
||||
|
||||
(defvar ert--test-buffers (make-hash-table :weakness t)
|
||||
"Table of all test buffers. Keys are the buffer objects, values are t.
|
||||
|
||||
The main use of this table is for `ert-kill-all-test-buffers'.
|
||||
Not all buffers in this table are necessarily live, but all live
|
||||
test buffers are in this table.")
|
||||
|
||||
(define-button-type 'ert--test-buffer-button
|
||||
'action #'ert--test-buffer-button-action
|
||||
'help-echo "mouse-2, RET: Pop to test buffer")
|
||||
|
||||
(defun ert--test-buffer-button-action (button)
|
||||
"Pop to the test buffer that BUTTON is associated with."
|
||||
(pop-to-buffer (button-get button 'ert--test-buffer)))
|
||||
|
||||
(defun ert--call-with-test-buffer (ert--base-name ert--thunk)
|
||||
"Helper function for `ert-with-test-buffer'.
|
||||
|
||||
Create a test buffer with a name based on ERT--BASE-NAME and run
|
||||
ERT--THUNK with that buffer as current."
|
||||
(let* ((ert--buffer (generate-new-buffer
|
||||
(ert--format-test-buffer-name ert--base-name)))
|
||||
(ert--button (ert--text-button (buffer-name ert--buffer)
|
||||
:type 'ert--test-buffer-button
|
||||
'ert--test-buffer ert--buffer)))
|
||||
(puthash ert--buffer 't ert--test-buffers)
|
||||
;; We don't use `unwind-protect' here since we want to kill the
|
||||
;; buffer only on success.
|
||||
(prog1 (with-current-buffer ert--buffer
|
||||
(ert-info (ert--button :prefix "Buffer: ")
|
||||
(funcall ert--thunk)))
|
||||
(kill-buffer ert--buffer)
|
||||
(remhash ert--buffer ert--test-buffers))))
|
||||
|
||||
(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))))
|
||||
|
||||
(cl-defmacro ert-with-buffer-selected (buffer-or-name &body body)
|
||||
"Display a buffer in a temporary selected window and run BODY.
|
||||
|
||||
If BUFFER-OR-NAME is nil, the current buffer is used.
|
||||
|
||||
The buffer is made the current buffer, and the temporary window
|
||||
becomes the `selected-window', before BODY is evaluated. The
|
||||
modification hooks `before-change-functions' and
|
||||
`after-change-functions' are not inhibited during the evaluation
|
||||
of BODY, which makes it easier to use `execute-kbd-macro' to
|
||||
simulate user interaction. The window configuration is restored
|
||||
before returning, even if BODY exits nonlocally. The return
|
||||
value is the last form in BODY."
|
||||
(declare (debug (form body)) (indent 1))
|
||||
`(save-window-excursion
|
||||
(with-current-buffer (or ,buffer-or-name (current-buffer))
|
||||
(with-selected-window (display-buffer (current-buffer))
|
||||
,@body))))
|
||||
|
||||
(cl-defmacro ert-with-test-buffer-selected ((&key name) &body body)
|
||||
"Create a test buffer, switch to it, and run BODY.
|
||||
|
||||
This combines `ert-with-test-buffer' and `ert-with-buffer-selected'.
|
||||
The return value is the last form in BODY."
|
||||
(declare (obsolete ert-with-test-buffer "31.1")
|
||||
(debug ((":name" form) body)) (indent 1))
|
||||
`(ert-with-test-buffer (:name ,name :selected t)
|
||||
,@body))
|
||||
|
||||
;;;###autoload
|
||||
(defun ert-kill-all-test-buffers ()
|
||||
"Kill all test buffers that are still live."
|
||||
(interactive)
|
||||
(let ((count 0))
|
||||
(maphash (lambda (buffer _dummy)
|
||||
(when (or (not (buffer-live-p buffer))
|
||||
(kill-buffer buffer))
|
||||
(incf count)))
|
||||
ert--test-buffers)
|
||||
(message "%s out of %s test buffers killed"
|
||||
count (hash-table-count ert--test-buffers)))
|
||||
;; It could be that some test buffers were actually kept alive
|
||||
;; (e.g., due to `kill-buffer-query-functions'). I'm not sure what
|
||||
;; to do about this. For now, let's just forget them.
|
||||
(clrhash ert--test-buffers)
|
||||
nil)
|
||||
|
||||
|
||||
;;; Simulate commands.
|
||||
|
||||
(defun ert-simulate-command (command)
|
||||
|
@ -275,37 +146,6 @@ structure with the plists in ARGS."
|
|||
(setq current-plist x))))
|
||||
(buffer-string)))
|
||||
|
||||
|
||||
(defun ert-call-with-buffer-renamed (buffer-name thunk)
|
||||
"Protect the buffer named BUFFER-NAME from side-effects and run THUNK.
|
||||
|
||||
Renames the buffer BUFFER-NAME to a new temporary name, creates a
|
||||
new buffer named BUFFER-NAME, executes THUNK, kills the new
|
||||
buffer, and renames the original buffer back to BUFFER-NAME.
|
||||
|
||||
This is useful if THUNK has undesirable side-effects on an Emacs
|
||||
buffer with a fixed name such as *Messages*."
|
||||
(let ((new-buffer-name (generate-new-buffer-name
|
||||
(format "%s orig buffer" buffer-name))))
|
||||
(with-current-buffer (get-buffer-create buffer-name)
|
||||
(rename-buffer new-buffer-name))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(get-buffer-create buffer-name)
|
||||
(funcall thunk))
|
||||
(when (get-buffer buffer-name)
|
||||
(kill-buffer buffer-name))
|
||||
(with-current-buffer new-buffer-name
|
||||
(rename-buffer buffer-name)))))
|
||||
|
||||
(cl-defmacro ert-with-buffer-renamed ((buffer-name-form) &body body)
|
||||
"Protect the buffer named BUFFER-NAME from side-effects and run BODY.
|
||||
|
||||
See `ert-call-with-buffer-renamed' for details."
|
||||
(declare (indent 1))
|
||||
`(ert-call-with-buffer-renamed ,buffer-name-form (lambda () ,@body)))
|
||||
|
||||
|
||||
(defun ert-buffer-string-reindented (&optional buffer)
|
||||
"Return the contents of BUFFER after reindentation.
|
||||
|
||||
|
@ -571,6 +411,19 @@ The same keyword arguments are supported as in
|
|||
(format "/mock::%s" temporary-file-directory))))
|
||||
"Temporary directory for remote file tests.")
|
||||
|
||||
|
||||
;;;; Obsolete
|
||||
|
||||
(cl-defmacro ert-with-test-buffer-selected ((&key name) &body body)
|
||||
"Create a test buffer, switch to it, and run BODY.
|
||||
|
||||
This combines `ert-with-test-buffer' and `ert-with-buffer-selected'.
|
||||
The return value is the last form in BODY."
|
||||
(declare (obsolete ert-with-test-buffer "31.1")
|
||||
(debug ((":name" form) body)) (indent 1))
|
||||
`(ert-with-test-buffer (:name ,name :selected t)
|
||||
,@body))
|
||||
|
||||
(provide 'ert-x)
|
||||
|
||||
;;; ert-x.el ends here
|
||||
|
|
|
@ -2992,6 +2992,152 @@ write erts files."
|
|||
(forward-line 1)))
|
||||
(nreverse specs))))
|
||||
|
||||
|
||||
;;; Buffer related helpers
|
||||
|
||||
(defun ert--text-button (string &rest properties)
|
||||
"Return a string containing STRING as a text button with PROPERTIES.
|
||||
|
||||
See `make-text-button'."
|
||||
(with-temp-buffer
|
||||
(insert string)
|
||||
(apply #'make-text-button (point-min) (point-max) properties)
|
||||
(buffer-string)))
|
||||
|
||||
(defun ert--format-test-buffer-name (base-name)
|
||||
"Compute a test buffer name based on BASE-NAME.
|
||||
|
||||
Helper function for `ert--test-buffers'."
|
||||
(format "*Test buffer (%s)%s*"
|
||||
(or (and (ert-running-test)
|
||||
(ert-test-name (ert-running-test)))
|
||||
"<anonymous test>")
|
||||
(if base-name
|
||||
(format ": %s" base-name)
|
||||
"")))
|
||||
|
||||
(defvar ert--test-buffers (make-hash-table :weakness t)
|
||||
"Table of all test buffers. Keys are the buffer objects, values are t.
|
||||
|
||||
The main use of this table is for `ert-kill-all-test-buffers'.
|
||||
Not all buffers in this table are necessarily live, but all live
|
||||
test buffers are in this table.")
|
||||
|
||||
(define-button-type 'ert--test-buffer-button
|
||||
'action #'ert--test-buffer-button-action
|
||||
'help-echo "mouse-2, RET: Pop to test buffer")
|
||||
|
||||
(defun ert--test-buffer-button-action (button)
|
||||
"Pop to the test buffer that BUTTON is associated with."
|
||||
(pop-to-buffer (button-get button 'ert--test-buffer)))
|
||||
|
||||
(defun ert--call-with-test-buffer (ert--base-name ert--thunk)
|
||||
"Helper function for `ert-with-test-buffer'.
|
||||
|
||||
Create a test buffer with a name based on ERT--BASE-NAME and run
|
||||
ERT--THUNK with that buffer as current."
|
||||
(let* ((ert--buffer (generate-new-buffer
|
||||
(ert--format-test-buffer-name ert--base-name)))
|
||||
(ert--button (ert--text-button (buffer-name ert--buffer)
|
||||
:type 'ert--test-buffer-button
|
||||
'ert--test-buffer ert--buffer)))
|
||||
(puthash ert--buffer 't ert--test-buffers)
|
||||
;; We don't use `unwind-protect' here since we want to kill the
|
||||
;; buffer only on success.
|
||||
(prog1 (with-current-buffer ert--buffer
|
||||
(ert-info (ert--button :prefix "Buffer: ")
|
||||
(funcall ert--thunk)))
|
||||
(kill-buffer ert--buffer)
|
||||
(remhash ert--buffer ert--test-buffers))))
|
||||
|
||||
(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))))
|
||||
|
||||
(defun ert-kill-all-test-buffers ()
|
||||
"Kill all test buffers that are still live."
|
||||
(interactive)
|
||||
(let ((count 0))
|
||||
(maphash (lambda (buffer _dummy)
|
||||
(when (or (not (buffer-live-p buffer))
|
||||
(kill-buffer buffer))
|
||||
(incf count)))
|
||||
ert--test-buffers)
|
||||
(message "%s out of %s test buffers killed"
|
||||
count (hash-table-count ert--test-buffers)))
|
||||
;; It could be that some test buffers were actually kept alive
|
||||
;; (e.g., due to `kill-buffer-query-functions'). I'm not sure what
|
||||
;; to do about this. For now, let's just forget them.
|
||||
(clrhash ert--test-buffers)
|
||||
nil)
|
||||
|
||||
(cl-defmacro ert-with-buffer-selected (buffer-or-name &body body)
|
||||
"Display a buffer in a temporary selected window and run BODY.
|
||||
|
||||
If BUFFER-OR-NAME is nil, the current buffer is used.
|
||||
|
||||
The buffer is made the current buffer, and the temporary window
|
||||
becomes the `selected-window', before BODY is evaluated. The
|
||||
modification hooks `before-change-functions' and
|
||||
`after-change-functions' are not inhibited during the evaluation
|
||||
of BODY, which makes it easier to use `execute-kbd-macro' to
|
||||
simulate user interaction. The window configuration is restored
|
||||
before returning, even if BODY exits nonlocally. The return
|
||||
value is the last form in BODY."
|
||||
(declare (debug (form body)) (indent 1))
|
||||
`(save-window-excursion
|
||||
(with-current-buffer (or ,buffer-or-name (current-buffer))
|
||||
(with-selected-window (display-buffer (current-buffer))
|
||||
,@body))))
|
||||
|
||||
(defun ert-call-with-buffer-renamed (buffer-name thunk)
|
||||
"Protect the buffer named BUFFER-NAME from side-effects and run THUNK.
|
||||
|
||||
Renames the buffer BUFFER-NAME to a new temporary name, creates a
|
||||
new buffer named BUFFER-NAME, executes THUNK, kills the new
|
||||
buffer, and renames the original buffer back to BUFFER-NAME.
|
||||
|
||||
This is useful if THUNK has undesirable side-effects on an Emacs
|
||||
buffer with a fixed name such as *Messages*."
|
||||
(let ((new-buffer-name (generate-new-buffer-name
|
||||
(format "%s orig buffer" buffer-name))))
|
||||
(with-current-buffer (get-buffer-create buffer-name)
|
||||
(rename-buffer new-buffer-name))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(get-buffer-create buffer-name)
|
||||
(funcall thunk))
|
||||
(when (get-buffer buffer-name)
|
||||
(kill-buffer buffer-name))
|
||||
(with-current-buffer new-buffer-name
|
||||
(rename-buffer buffer-name)))))
|
||||
|
||||
(cl-defmacro ert-with-buffer-renamed ((buffer-name-form) &body body)
|
||||
"Protect the buffer named BUFFER-NAME from side-effects and run BODY.
|
||||
|
||||
See `ert-call-with-buffer-renamed' for details."
|
||||
(declare (indent 1))
|
||||
`(ert-call-with-buffer-renamed ,buffer-name-form (lambda () ,@body)))
|
||||
|
||||
;;; Obsolete
|
||||
|
||||
(define-obsolete-function-alias 'ert-equal-including-properties
|
||||
|
|
|
@ -930,6 +930,97 @@ F failing-test
|
|||
(when noninteractive
|
||||
(kill-buffer buffer-name)))))))
|
||||
|
||||
(defun ert--hash-table-to-alist (table)
|
||||
(let ((accu nil))
|
||||
(maphash (lambda (key value)
|
||||
(push (cons key value) accu))
|
||||
table)
|
||||
(nreverse accu)))
|
||||
|
||||
(ert-deftest ert-test-test-buffers ()
|
||||
(let (buffer-1
|
||||
buffer-2)
|
||||
(let ((test-1
|
||||
(make-ert-test
|
||||
:name 'test-1
|
||||
:body (lambda ()
|
||||
(ert-with-test-buffer (:name "foo")
|
||||
(should (string-match
|
||||
"[*]Test buffer (ert-test-test-buffers): foo[*]"
|
||||
(buffer-name)))
|
||||
(setq buffer-1 (current-buffer))))))
|
||||
(test-2
|
||||
(make-ert-test
|
||||
:name 'test-2
|
||||
:body (lambda ()
|
||||
(ert-with-test-buffer (:name "bar")
|
||||
(should (string-match
|
||||
"[*]Test buffer (ert-test-test-buffers): bar[*]"
|
||||
(buffer-name)))
|
||||
(setq buffer-2 (current-buffer))
|
||||
(ert-fail "fail for test"))))))
|
||||
(let ((ert--test-buffers (make-hash-table :weakness t)))
|
||||
(ert-run-tests `(member ,test-1 ,test-2) #'ignore)
|
||||
(should (equal (ert--hash-table-to-alist ert--test-buffers)
|
||||
`((,buffer-2 . t))))
|
||||
(should-not (buffer-live-p buffer-1))
|
||||
(should (buffer-live-p buffer-2))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/current ()
|
||||
(let ((origbuf (current-buffer)))
|
||||
(ert-with-test-buffer ()
|
||||
(let ((buf (current-buffer)))
|
||||
(should (not (eq buf origbuf)))
|
||||
(with-current-buffer origbuf
|
||||
(ert-with-buffer-selected buf
|
||||
(should (eq (current-buffer) buf))))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/selected ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (eq (window-buffer) (current-buffer))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/nil-buffer ()
|
||||
(ert-with-test-buffer ()
|
||||
(let ((buf (current-buffer)))
|
||||
(ert-with-buffer-selected nil
|
||||
(should (eq (window-buffer) buf))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/modification-hooks ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (null inhibit-modification-hooks)))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/read-only ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (null inhibit-read-only))
|
||||
(should (null buffer-read-only)))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/return-value ()
|
||||
(should (equal (ert-with-buffer-selected nil "foo") "foo")))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/selected ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (eq (window-buffer) (current-buffer)))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/modification-hooks ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (null inhibit-modification-hooks))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/read-only ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (null inhibit-read-only))
|
||||
(should (null buffer-read-only))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/return-value ()
|
||||
(should (equal (ert-with-test-buffer (:selected t) "foo") "foo")))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/buffer-name ()
|
||||
(should (equal (ert-with-test-buffer (:name "foo") (buffer-name))
|
||||
(ert-with-test-buffer (:name "foo" :selected t)
|
||||
(buffer-name)))))
|
||||
|
||||
(provide 'ert-tests)
|
||||
|
||||
;;; ert-tests.el ends here
|
||||
|
|
|
@ -46,97 +46,6 @@
|
|||
(emacs-lisp-mode)
|
||||
(should-not (equal (ert-buffer-string-reindented) (buffer-string)))))
|
||||
|
||||
(defun ert--hash-table-to-alist (table)
|
||||
(let ((accu nil))
|
||||
(maphash (lambda (key value)
|
||||
(push (cons key value) accu))
|
||||
table)
|
||||
(nreverse accu)))
|
||||
|
||||
(ert-deftest ert-test-test-buffers ()
|
||||
(let (buffer-1
|
||||
buffer-2)
|
||||
(let ((test-1
|
||||
(make-ert-test
|
||||
:name 'test-1
|
||||
:body (lambda ()
|
||||
(ert-with-test-buffer (:name "foo")
|
||||
(should (string-match
|
||||
"[*]Test buffer (ert-test-test-buffers): foo[*]"
|
||||
(buffer-name)))
|
||||
(setq buffer-1 (current-buffer))))))
|
||||
(test-2
|
||||
(make-ert-test
|
||||
:name 'test-2
|
||||
:body (lambda ()
|
||||
(ert-with-test-buffer (:name "bar")
|
||||
(should (string-match
|
||||
"[*]Test buffer (ert-test-test-buffers): bar[*]"
|
||||
(buffer-name)))
|
||||
(setq buffer-2 (current-buffer))
|
||||
(ert-fail "fail for test"))))))
|
||||
(let ((ert--test-buffers (make-hash-table :weakness t)))
|
||||
(ert-run-tests `(member ,test-1 ,test-2) #'ignore)
|
||||
(should (equal (ert--hash-table-to-alist ert--test-buffers)
|
||||
`((,buffer-2 . t))))
|
||||
(should-not (buffer-live-p buffer-1))
|
||||
(should (buffer-live-p buffer-2))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/current ()
|
||||
(let ((origbuf (current-buffer)))
|
||||
(ert-with-test-buffer ()
|
||||
(let ((buf (current-buffer)))
|
||||
(should (not (eq buf origbuf)))
|
||||
(with-current-buffer origbuf
|
||||
(ert-with-buffer-selected buf
|
||||
(should (eq (current-buffer) buf))))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/selected ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (eq (window-buffer) (current-buffer))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/nil-buffer ()
|
||||
(ert-with-test-buffer ()
|
||||
(let ((buf (current-buffer)))
|
||||
(ert-with-buffer-selected nil
|
||||
(should (eq (window-buffer) buf))))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/modification-hooks ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (null inhibit-modification-hooks)))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/read-only ()
|
||||
(ert-with-test-buffer ()
|
||||
(ert-with-buffer-selected (current-buffer)
|
||||
(should (null inhibit-read-only))
|
||||
(should (null buffer-read-only)))))
|
||||
|
||||
(ert-deftest ert-test-with-buffer-selected/return-value ()
|
||||
(should (equal (ert-with-buffer-selected nil "foo") "foo")))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/selected ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (eq (window-buffer) (current-buffer)))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/modification-hooks ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (null inhibit-modification-hooks))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/read-only ()
|
||||
(ert-with-test-buffer (:selected t)
|
||||
(should (null inhibit-read-only))
|
||||
(should (null buffer-read-only))))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/return-value ()
|
||||
(should (equal (ert-with-test-buffer (:selected t) "foo") "foo")))
|
||||
|
||||
(ert-deftest ert-test-with-test-buffer-selected/buffer-name ()
|
||||
(should (equal (ert-with-test-buffer (:name "foo") (buffer-name))
|
||||
(ert-with-test-buffer (:name "foo" :selected t)
|
||||
(buffer-name)))))
|
||||
|
||||
(ert-deftest ert-filter-string ()
|
||||
(should (equal (ert-filter-string "foo bar baz" "quux")
|
||||
"foo bar baz"))
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ert-x)
|
||||
(require 'hideshow)
|
||||
|
||||
;; Dependencies for testing:
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ert-x)
|
||||
(eval-when-compile (require 'cl-lib))
|
||||
|
||||
(defun simple-test--buffer-substrings ()
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ert-x)
|
||||
(require 'faceup)
|
||||
(require 'whitespace)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue