annotate lisp/emacs-lisp/ert-x.el @ 112415:555faf6e40d0

mm-decode.el (mm-preferred-alternative-precedence): Don't bug out on nested related parts. nnfolder.el (nnfolder-request-expire-articles): Return the list of unexpired articles. This fixes the regression that led expiry marks to disappear from nnfolder groups.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sat, 22 Jan 2011 12:34:50 +0000
parents c5917804ecad
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112201
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
1 ;;; ert-x.el --- Staging area for experimental extensions to ERT
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
2
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
4
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
5 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
6 ;; Author: Christian Ohler <ohler@gnu.org>
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
7
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
9
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
10 ;; This program is free software: you can redistribute it and/or
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
11 ;; modify it under the terms of the GNU General Public License as
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
12 ;; published by the Free Software Foundation, either version 3 of the
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
13 ;; License, or (at your option) any later version.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
14 ;;
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful, but
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
18 ;; General Public License for more details.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
19 ;;
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
21 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
22
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
24
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
25 ;; This file includes some extra helper functions to use while writing
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
26 ;; automated tests with ERT. These have been proposed as extensions
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
27 ;; to ERT but are not mature yet and likely to change.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
28
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
29 ;;; Code:
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
30
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
31 (eval-when-compile
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
32 (require 'cl))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
33 (require 'ert)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
34
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
35
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
36 ;;; Test buffers.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
37
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
38 (defun ert--text-button (string &rest properties)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
39 "Return a string containing STRING as a text button with PROPERTIES.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
40
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
41 See `make-text-button'."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
42 (with-temp-buffer
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
43 (insert string)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
44 (apply #'make-text-button (point-min) (point-max) properties)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
45 (buffer-string)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
46
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
47 (defun ert--format-test-buffer-name (base-name)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
48 "Compute a test buffer name based on BASE-NAME.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
49
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
50 Helper function for `ert--test-buffers'."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
51 (format "*Test buffer (%s)%s*"
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
52 (or (and (ert-running-test)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
53 (ert-test-name (ert-running-test)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
54 "<anonymous test>")
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
55 (if base-name
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
56 (format ": %s" base-name)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
57 "")))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
58
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
59 (defvar ert--test-buffers (make-hash-table :weakness t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
60 "Table of all test buffers. Keys are the buffer objects, values are t.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
61
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
62 The main use of this table is for `ert-kill-all-test-buffers'.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
63 Not all buffers in this table are necessarily live, but all live
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
64 test buffers are in this table.")
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
65
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
66 (define-button-type 'ert--test-buffer-button
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
67 'action #'ert--test-buffer-button-action
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
68 'help-echo "mouse-2, RET: Pop to test buffer")
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
69
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
70 (defun ert--test-buffer-button-action (button)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
71 "Pop to the test buffer that BUTTON is associated with."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
72 (pop-to-buffer (button-get button 'ert--test-buffer)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
73
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
74 (defun ert--call-with-test-buffer (ert--base-name ert--thunk)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
75 "Helper function for `ert-with-test-buffer'.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
76
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
77 Create a test buffer with a name based on ERT--BASE-NAME and run
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
78 ERT--THUNK with that buffer as current."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
79 (let* ((ert--buffer (generate-new-buffer
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
80 (ert--format-test-buffer-name ert--base-name)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
81 (ert--button (ert--text-button (buffer-name ert--buffer)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
82 :type 'ert--test-buffer-button
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
83 'ert--test-buffer ert--buffer)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
84 (puthash ert--buffer 't ert--test-buffers)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
85 ;; We don't use `unwind-protect' here since we want to kill the
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
86 ;; buffer only on success.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
87 (prog1 (with-current-buffer ert--buffer
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
88 (ert-info (ert--button :prefix "Buffer: ")
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
89 (funcall ert--thunk)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
90 (kill-buffer ert--buffer)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
91 (remhash ert--buffer ert--test-buffers))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
92
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
93 (defmacro* ert-with-test-buffer ((&key ((:name name-form)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
94 &body body)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
95 "Create a test buffer and run BODY in that buffer.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
96
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
97 To be used in ERT tests. If BODY finishes successfully, the test
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
98 buffer is killed; if there is an error, the test buffer is kept
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
99 around on error for further inspection. Its name is derived from
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
100 the name of the test and the result of NAME-FORM."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
101 (declare (debug ((form) body))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
102 (indent 1))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
103 `(ert--call-with-test-buffer ,name-form (lambda () ,@body)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
104
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
105 ;; We use these `put' forms in addition to the (declare (indent)) in
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
106 ;; the defmacro form since the `declare' alone does not lead to
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
107 ;; correct indentation before the .el/.elc file is loaded.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
108 ;; Autoloading these `put' forms solves this.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
109 ;;;###autoload
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
110 (progn
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
111 ;; TODO(ohler): Figure out what these mean and make sure they are correct.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
112 (put 'ert-with-test-buffer 'lisp-indent-function 1))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
113
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
114 ;;;###autoload
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
115 (defun ert-kill-all-test-buffers ()
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
116 "Kill all test buffers that are still live."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
117 (interactive)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
118 (let ((count 0))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
119 (maphash (lambda (buffer dummy)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
120 (when (or (not (buffer-live-p buffer))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
121 (kill-buffer buffer))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
122 (incf count)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
123 ert--test-buffers)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
124 (message "%s out of %s test buffers killed"
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
125 count (hash-table-count ert--test-buffers)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
126 ;; It could be that some test buffers were actually kept alive
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
127 ;; (e.g., due to `kill-buffer-query-functions'). I'm not sure what
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
128 ;; to do about this. For now, let's just forget them.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
129 (clrhash ert--test-buffers)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
130 nil)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
131
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
132
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
133 ;;; Simulate commands.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
134
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
135 (defun ert-simulate-command (command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
136 ;; FIXME: add unread-events
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
137 "Simulate calling COMMAND the way the Emacs command loop would call it.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
138
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
139 This effectively executes
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
140
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
141 \(apply (car COMMAND) (cdr COMMAND)\)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
142
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
143 and returns the same value, but additionally runs hooks like
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
144 `pre-command-hook' and `post-command-hook', and sets variables
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
145 like `this-command' and `last-command'.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
146
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
147 COMMAND should be a list where the car is the command symbol and
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
148 the rest are arguments to the command.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
149
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
150 NOTE: Since the command is not called by `call-interactively'
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
151 test for `called-interactively' in the command will fail."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
152 (assert (listp command) t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
153 (assert (commandp (car command)) t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
154 (assert (not unread-command-events) t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
155 (let (return-value)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
156 ;; For the order of things here see command_loop_1 in keyboard.c.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
157 ;;
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
158 ;; The command loop will reset the command-related variables so
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
159 ;; there is no reason to let-bind them. They are set here,
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
160 ;; however, to be able to test several commands in a row and how
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
161 ;; they affect each other.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
162 (setq deactivate-mark nil
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
163 this-original-command (car command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
164 ;; remap through active keymaps
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
165 this-command (or (command-remapping this-original-command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
166 this-original-command))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
167 (run-hooks 'pre-command-hook)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
168 (setq return-value (apply (car command) (cdr command)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
169 (run-hooks 'post-command-hook)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
170 (when deferred-action-list
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
171 (run-hooks 'deferred-action-function))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
172 (setq real-last-command (car command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
173 last-command this-command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
174 (when (boundp 'last-repeatable-command)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
175 (setq last-repeatable-command real-last-command))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
176 (when (and deactivate-mark transient-mark-mode) (deactivate-mark))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
177 (assert (not unread-command-events) t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
178 return-value))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
179
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
180 (defun ert-run-idle-timers ()
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
181 "Run all idle timers (from `timer-idle-list')."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
182 (dolist (timer (copy-sequence timer-idle-list))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
183 (timer-event-handler timer)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
184
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
185
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
186 ;;; Miscellaneous utilities.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
187
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
188 (defun ert-filter-string (s &rest regexps)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
189 "Return a copy of S with all matches of REGEXPS removed.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
190
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
191 Elements of REGEXPS may also be two-element lists \(REGEXP
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
192 SUBEXP\), where SUBEXP is the number of a subexpression in
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
193 REGEXP. In that case, only that subexpression will be removed
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
194 rather than the entire match."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
195 ;; Use a temporary buffer since replace-match copies strings, which
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
196 ;; would lead to N^2 runtime.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
197 (with-temp-buffer
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
198 (insert s)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
199 (dolist (x regexps)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
200 (destructuring-bind (regexp subexp) (if (listp x) x `(,x nil))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
201 (goto-char (point-min))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
202 (while (re-search-forward regexp nil t)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
203 (replace-match "" t t nil subexp))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
204 (buffer-string)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
205
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
206
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
207 (defun ert-propertized-string (&rest args)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
208 "Return a string with properties as specified by ARGS.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
209
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
210 ARGS is a list of strings and plists. The strings in ARGS are
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
211 concatenated to produce an output string. In the output string,
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
212 each string from ARGS will be have the preceding plist as its
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
213 property list, or no properties if there is no plist before it.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
214
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
215 As a simple example,
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
216
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
217 \(ert-propertized-string \"foo \" '(face italic) \"bar\" \" baz\" nil \
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
218 \" quux\"\)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
219
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
220 would return the string \"foo bar baz quux\" where the substring
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
221 \"bar baz\" has a `face' property with the value `italic'.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
222
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
223 None of the ARGS are modified, but the return value may share
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
224 structure with the plists in ARGS."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
225 (with-temp-buffer
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
226 (loop with current-plist = nil
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
227 for x in args do
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
228 (etypecase x
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
229 (string (let ((begin (point)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
230 (insert x)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
231 (set-text-properties begin (point) current-plist)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
232 (list (unless (zerop (mod (length x) 2))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
233 (error "Odd number of args in plist: %S" x))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
234 (setq current-plist x))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
235 (buffer-string)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
236
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
237
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
238 (defun ert-call-with-buffer-renamed (buffer-name thunk)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
239 "Protect the buffer named BUFFER-NAME from side-effects and run THUNK.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
240
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
241 Renames the buffer BUFFER-NAME to a new temporary name, creates a
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
242 new buffer named BUFFER-NAME, executes THUNK, kills the new
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
243 buffer, and renames the original buffer back to BUFFER-NAME.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
244
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
245 This is useful if THUNK has undesirable side-effects on an Emacs
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
246 buffer with a fixed name such as *Messages*."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
247 (lexical-let ((new-buffer-name (generate-new-buffer-name
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
248 (format "%s orig buffer" buffer-name))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
249 (with-current-buffer (get-buffer-create buffer-name)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
250 (rename-buffer new-buffer-name))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
251 (unwind-protect
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
252 (progn
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
253 (get-buffer-create buffer-name)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
254 (funcall thunk))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
255 (when (get-buffer buffer-name)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
256 (kill-buffer buffer-name))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
257 (with-current-buffer new-buffer-name
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
258 (rename-buffer buffer-name)))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
259
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
260 (defmacro* ert-with-buffer-renamed ((buffer-name-form) &body body)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
261 "Protect the buffer named BUFFER-NAME from side-effects and run BODY.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
262
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
263 See `ert-call-with-buffer-renamed' for details."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
264 (declare (indent 1))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
265 `(ert-call-with-buffer-renamed ,buffer-name-form (lambda () ,@body)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
266
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
267
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
268 (defun ert-buffer-string-reindented (&optional buffer)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
269 "Return the contents of BUFFER after reindentation.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
270
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
271 BUFFER defaults to current buffer. Does not modify BUFFER."
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
272 (with-current-buffer (or buffer (current-buffer))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
273 (let ((clone nil))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
274 (unwind-protect
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
275 (progn
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
276 ;; `clone-buffer' doesn't work if `buffer-file-name' is non-nil.
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
277 (let ((buffer-file-name nil))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
278 (setq clone (clone-buffer)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
279 (with-current-buffer clone
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
280 (let ((inhibit-read-only t))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
281 (indent-region (point-min) (point-max)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
282 (buffer-string)))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
283 (when clone
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
284 (let ((kill-buffer-query-functions nil))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
285 (kill-buffer clone)))))))
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
286
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
287
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
288 (provide 'ert-x)
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
289
c5917804ecad Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff changeset
290 ;;; ert-x.el ends here