aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/autorevert-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/autorevert-tests.el')
-rw-r--r--test/lisp/autorevert-tests.el170
1 files changed, 78 insertions, 92 deletions
diff --git a/test/lisp/autorevert-tests.el b/test/lisp/autorevert-tests.el
index aea855ae02f..c6f103321c6 100644
--- a/test/lisp/autorevert-tests.el
+++ b/test/lisp/autorevert-tests.el
@@ -24,24 +24,29 @@
24;;; Code: 24;;; Code:
25 25
26(require 'ert) 26(require 'ert)
27(require 'ert-x)
27(require 'autorevert) 28(require 'autorevert)
28(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" 29(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
29 auto-revert-stop-on-user-input nil) 30 auto-revert-stop-on-user-input nil)
30 31
31(defconst auto-revert--timeout 10 32(defconst auto-revert--timeout 10
32 "Time to wait until a message appears in the *Messages* buffer.") 33 "Time to wait for a message.")
34
35(defvar auto-revert--messages nil
36 "Used to collect messages issued during a section of a test.")
33 37
34(defun auto-revert--wait-for-revert (buffer) 38(defun auto-revert--wait-for-revert (buffer)
35 "Wait until the *Messages* buffer reports reversion of BUFFER." 39 "Wait until a message reports reversion of BUFFER.
40This expects `auto-revert--messages' to be bound by
41`ert-with-message-capture' before calling."
36 (with-timeout (auto-revert--timeout nil) 42 (with-timeout (auto-revert--timeout nil)
37 (with-current-buffer "*Messages*" 43 (while
38 (while 44 (null (string-match
39 (null (string-match 45 (format-message "Reverting buffer `%s'." (buffer-name buffer))
40 (format-message "Reverting buffer `%s'." (buffer-name buffer)) 46 auto-revert--messages))
41 (buffer-string))) 47 (if (with-current-buffer buffer auto-revert-use-notify)
42 (if (with-current-buffer buffer auto-revert-use-notify) 48 (read-event nil nil 0.1)
43 (read-event nil nil 0.1) 49 (sleep-for 0.1)))))
44 (sleep-for 0.1))))))
45 50
46(ert-deftest auto-revert-test00-auto-revert-mode () 51(ert-deftest auto-revert-test00-auto-revert-mode ()
47 "Check autorevert for a file." 52 "Check autorevert for a file."
@@ -51,41 +56,38 @@
51 buf) 56 buf)
52 (unwind-protect 57 (unwind-protect
53 (progn 58 (progn
54 (with-current-buffer (get-buffer-create "*Messages*") 59 (write-region "any text" nil tmpfile nil 'no-message)
55 (narrow-to-region (point-max) (point-max)))
56 (write-region "any text" nil tmpfile nil 'no-message)
57 (setq buf (find-file-noselect tmpfile)) 60 (setq buf (find-file-noselect tmpfile))
58 (with-current-buffer buf 61 (with-current-buffer buf
59 (should (string-equal (buffer-string) "any text")) 62 (ert-with-message-capture auto-revert--messages
60 ;; `buffer-stale--default-function' checks for 63 (should (string-equal (buffer-string) "any text"))
61 ;; `verify-visited-file-modtime'. We must ensure that it 64 ;; `buffer-stale--default-function' checks for
62 ;; returns nil. 65 ;; `verify-visited-file-modtime'. We must ensure that it
63 (sleep-for 1) 66 ;; returns nil.
64 (auto-revert-mode 1) 67 (sleep-for 1)
65 (should auto-revert-mode) 68 (auto-revert-mode 1)
69 (should auto-revert-mode)
66 70
67 ;; Modify file. We wait for a second, in order to have 71 ;; Modify file. We wait for a second, in order to have
68 ;; another timestamp. 72 ;; another timestamp.
69 (sleep-for 1) 73 (sleep-for 1)
70 (write-region "another text" nil tmpfile nil 'no-message) 74 (write-region "another text" nil tmpfile nil 'no-message)
71 75
72 ;; Check, that the buffer has been reverted. 76 ;; Check, that the buffer has been reverted.
73 (auto-revert--wait-for-revert buf) 77 (auto-revert--wait-for-revert buf))
74 (should (string-match "another text" (buffer-string))) 78 (should (string-match "another text" (buffer-string)))
75 79
76 ;; When the buffer is modified, it shall not be reverted. 80 ;; When the buffer is modified, it shall not be reverted.
77 (with-current-buffer (get-buffer-create "*Messages*") 81 (ert-with-message-capture auto-revert--messages
78 (narrow-to-region (point-max) (point-max))) 82 (set-buffer-modified-p t)
79 (set-buffer-modified-p t) 83 (sleep-for 1)
80 (sleep-for 1) 84 (write-region "any text" nil tmpfile nil 'no-message)
81 (write-region "any text" nil tmpfile nil 'no-message)
82 85
83 ;; Check, that the buffer hasn't been reverted. 86 ;; Check, that the buffer hasn't been reverted.
84 (auto-revert--wait-for-revert buf) 87 (auto-revert--wait-for-revert buf))
85 (should-not (string-match "any text" (buffer-string))))) 88 (should-not (string-match "any text" (buffer-string)))))
86 89
87 ;; Exit. 90 ;; Exit.
88 (with-current-buffer "*Messages*" (widen))
89 (ignore-errors 91 (ignore-errors
90 (with-current-buffer buf (set-buffer-modified-p nil)) 92 (with-current-buffer buf (set-buffer-modified-p nil))
91 (kill-buffer buf)) 93 (kill-buffer buf))
@@ -106,13 +108,11 @@
106 (make-temp-file (expand-file-name "auto-revert-test" tmpdir1))) 108 (make-temp-file (expand-file-name "auto-revert-test" tmpdir1)))
107 buf1 buf2) 109 buf1 buf2)
108 (unwind-protect 110 (unwind-protect
109 (progn 111 (ert-with-message-capture auto-revert--messages
110 (with-current-buffer (get-buffer-create "*Messages*") 112 (write-region "any text" nil tmpfile1 nil 'no-message)
111 (narrow-to-region (point-max) (point-max))) 113 (setq buf1 (find-file-noselect tmpfile1))
112 (write-region "any text" nil tmpfile1 nil 'no-message) 114 (write-region "any text" nil tmpfile2 nil 'no-message)
113 (setq buf1 (find-file-noselect tmpfile1)) 115 (setq buf2 (find-file-noselect tmpfile2))
114 (write-region "any text" nil tmpfile2 nil 'no-message)
115 (setq buf2 (find-file-noselect tmpfile2))
116 116
117 (dolist (buf (list buf1 buf2)) 117 (dolist (buf (list buf1 buf2))
118 (with-current-buffer buf 118 (with-current-buffer buf
@@ -148,7 +148,6 @@
148 (should (string-match "another text" (buffer-string)))))) 148 (should (string-match "another text" (buffer-string))))))
149 149
150 ;; Exit. 150 ;; Exit.
151 (with-current-buffer "*Messages*" (widen))
152 (ignore-errors 151 (ignore-errors
153 (dolist (buf (list buf1 buf2)) 152 (dolist (buf (list buf1 buf2))
154 (with-current-buffer buf (set-buffer-modified-p nil)) 153 (with-current-buffer buf (set-buffer-modified-p nil))
@@ -165,8 +164,6 @@
165 buf) 164 buf)
166 (unwind-protect 165 (unwind-protect
167 (progn 166 (progn
168 (with-current-buffer (get-buffer-create "*Messages*")
169 (narrow-to-region (point-max) (point-max)))
170 (write-region "any text" nil tmpfile nil 'no-message) 167 (write-region "any text" nil tmpfile nil 'no-message)
171 (setq buf (find-file-noselect tmpfile)) 168 (setq buf (find-file-noselect tmpfile))
172 (with-current-buffer buf 169 (with-current-buffer buf
@@ -184,42 +181,38 @@
184 'before-revert-hook 181 'before-revert-hook
185 (lambda () (delete-file buffer-file-name)) 182 (lambda () (delete-file buffer-file-name))
186 nil t) 183 nil t)
187 (with-current-buffer (get-buffer-create "*Messages*")
188 (narrow-to-region (point-max) (point-max)))
189 (sleep-for 1)
190 (write-region "another text" nil tmpfile nil 'no-message)
191 184
192 ;; Check, that the buffer hasn't been reverted. File 185 (ert-with-message-capture auto-revert--messages
193 ;; notification should be disabled, falling back to 186 (sleep-for 1)
194 ;; polling. 187 (write-region "another text" nil tmpfile nil 'no-message)
195 (auto-revert--wait-for-revert buf) 188 (auto-revert--wait-for-revert buf))
189 ;; Check, that the buffer hasn't been reverted. File
190 ;; notification should be disabled, falling back to
191 ;; polling.
196 (should (string-match "any text" (buffer-string))) 192 (should (string-match "any text" (buffer-string)))
197 (should-not auto-revert-use-notify) 193 ;; With w32notify, the 'stopped' events are not sent.
194 (or (eq file-notify--library 'w32notify)
195 (should-not auto-revert-use-notify))
198 196
199 ;; Once the file has been recreated, the buffer shall be 197 ;; Once the file has been recreated, the buffer shall be
200 ;; reverted. 198 ;; reverted.
201 (kill-local-variable 'before-revert-hook) 199 (kill-local-variable 'before-revert-hook)
202 (with-current-buffer (get-buffer-create "*Messages*") 200 (ert-with-message-capture auto-revert--messages
203 (narrow-to-region (point-max) (point-max))) 201 (sleep-for 1)
204 (sleep-for 1) 202 (write-region "another text" nil tmpfile nil 'no-message)
205 (write-region "another text" nil tmpfile nil 'no-message) 203 (auto-revert--wait-for-revert buf))
206 204 ;; Check, that the buffer has been reverted.
207 ;; Check, that the buffer has been reverted.
208 (auto-revert--wait-for-revert buf)
209 (should (string-match "another text" (buffer-string))) 205 (should (string-match "another text" (buffer-string)))
210 206
211 ;; An empty file shall still be reverted. 207 ;; An empty file shall still be reverted.
212 (with-current-buffer (get-buffer-create "*Messages*") 208 (ert-with-message-capture auto-revert--messages
213 (narrow-to-region (point-max) (point-max))) 209 (sleep-for 1)
214 (sleep-for 1) 210 (write-region "" nil tmpfile nil 'no-message)
215 (write-region "" nil tmpfile nil 'no-message) 211 (auto-revert--wait-for-revert buf))
216 212 ;; Check, that the buffer has been reverted.
217 ;; Check, that the buffer has been reverted.
218 (auto-revert--wait-for-revert buf)
219 (should (string-equal "" (buffer-string))))) 213 (should (string-equal "" (buffer-string)))))
220 214
221 ;; Exit. 215 ;; Exit.
222 (with-current-buffer "*Messages*" (widen))
223 (ignore-errors 216 (ignore-errors
224 (with-current-buffer buf (set-buffer-modified-p nil)) 217 (with-current-buffer buf (set-buffer-modified-p nil))
225 (kill-buffer buf)) 218 (kill-buffer buf))
@@ -232,9 +225,7 @@
232 (let ((tmpfile (make-temp-file "auto-revert-test")) 225 (let ((tmpfile (make-temp-file "auto-revert-test"))
233 buf) 226 buf)
234 (unwind-protect 227 (unwind-protect
235 (progn 228 (ert-with-message-capture auto-revert--messages
236 (with-current-buffer (get-buffer-create "*Messages*")
237 (narrow-to-region (point-max) (point-max)))
238 (write-region "any text" nil tmpfile nil 'no-message) 229 (write-region "any text" nil tmpfile nil 'no-message)
239 (setq buf (find-file-noselect tmpfile)) 230 (setq buf (find-file-noselect tmpfile))
240 (with-current-buffer buf 231 (with-current-buffer buf
@@ -259,7 +250,6 @@
259 (string-match "modified text\nanother text" (buffer-string))))) 250 (string-match "modified text\nanother text" (buffer-string)))))
260 251
261 ;; Exit. 252 ;; Exit.
262 (with-current-buffer "*Messages*" (widen))
263 (ignore-errors (kill-buffer buf)) 253 (ignore-errors (kill-buffer buf))
264 (ignore-errors (delete-file tmpfile))))) 254 (ignore-errors (delete-file tmpfile)))))
265 255
@@ -283,33 +273,29 @@
283 (should 273 (should
284 (string-match name (substring-no-properties (buffer-string)))) 274 (string-match name (substring-no-properties (buffer-string))))
285 275
286 ;; Delete file. We wait for a second, in order to have 276 (ert-with-message-capture auto-revert--messages
287 ;; another timestamp. 277 ;; Delete file. We wait for a second, in order to have
288 (with-current-buffer (get-buffer-create "*Messages*") 278 ;; another timestamp.
289 (narrow-to-region (point-max) (point-max))) 279 (sleep-for 1)
290 (sleep-for 1) 280 (delete-file tmpfile)
291 (delete-file tmpfile) 281 (auto-revert--wait-for-revert buf))
292 282 ;; Check, that the buffer has been reverted.
293 ;; Check, that the buffer has been reverted.
294 (auto-revert--wait-for-revert buf)
295 (should-not 283 (should-not
296 (string-match name (substring-no-properties (buffer-string)))) 284 (string-match name (substring-no-properties (buffer-string))))
297 285
298 ;; Make dired buffer modified. Check, that the buffer has 286 (ert-with-message-capture auto-revert--messages
299 ;; been still reverted. 287 ;; Make dired buffer modified. Check, that the buffer has
300 (with-current-buffer (get-buffer-create "*Messages*") 288 ;; been still reverted.
301 (narrow-to-region (point-max) (point-max))) 289 (set-buffer-modified-p t)
302 (set-buffer-modified-p t) 290 (sleep-for 1)
303 (sleep-for 1) 291 (write-region "any text" nil tmpfile nil 'no-message)
304 (write-region "any text" nil tmpfile nil 'no-message)
305 292
306 ;; Check, that the buffer has been reverted. 293 (auto-revert--wait-for-revert buf))
307 (auto-revert--wait-for-revert buf) 294 ;; Check, that the buffer has been reverted.
308 (should 295 (should
309 (string-match name (substring-no-properties (buffer-string)))))) 296 (string-match name (substring-no-properties (buffer-string))))))
310 297
311 ;; Exit. 298 ;; Exit.
312 (with-current-buffer "*Messages*" (widen))
313 (ignore-errors 299 (ignore-errors
314 (with-current-buffer buf (set-buffer-modified-p nil)) 300 (with-current-buffer buf (set-buffer-modified-p nil))
315 (kill-buffer buf)) 301 (kill-buffer buf))