aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2015-06-02 23:47:17 +0200
committerMichael Albinus2015-06-02 23:47:17 +0200
commit420b293c7da575f800a5048e245c25905472697f (patch)
tree2422f97eb65ce3a69f2d99a8e66f3768f0a8bc95
parent7f01832e1360b5203695d48605a45228f1362b42 (diff)
downloademacs-420b293c7da575f800a5048e245c25905472697f.tar.gz
emacs-420b293c7da575f800a5048e245c25905472697f.zip
Ensure, that autorevert works for remote files in file-notify-tests.el
* test/automated/file-notify-tests.el (file-notify--test-desc): New defvar. (file-notify--test-remote-enabled) (file-notify-test00-availability, file-notify-test01-add-watch) (file-notify-test02-events): Use it. (file-notify--test-event-test): Check proper descriptor. (file-notify-test03-autorevert): Ensure, that `visited-file-modtime' has changed. Fixes: debbugs:20392
-rw-r--r--test/automated/file-notify-tests.el195
1 files changed, 101 insertions, 94 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index 46d287fe60d..a45eff73957 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -57,6 +57,7 @@
57 57
58(defvar file-notify--test-tmpfile nil) 58(defvar file-notify--test-tmpfile nil)
59(defvar file-notify--test-tmpfile1 nil) 59(defvar file-notify--test-tmpfile1 nil)
60(defvar file-notify--test-desc nil)
60(defvar file-notify--test-results nil) 61(defvar file-notify--test-results nil)
61(defvar file-notify--test-event nil) 62(defvar file-notify--test-event nil)
62 63
@@ -84,20 +85,21 @@ being the result.")
84(defun file-notify--test-remote-enabled () 85(defun file-notify--test-remote-enabled ()
85 "Whether remote file notification is enabled." 86 "Whether remote file notification is enabled."
86 (unless (consp file-notify--test-remote-enabled-checked) 87 (unless (consp file-notify--test-remote-enabled-checked)
87 (let (desc) 88 (unwind-protect
88 (unwind-protect 89 (ignore-errors
89 (ignore-errors 90 (and
90 (and 91 (file-remote-p file-notify-test-remote-temporary-file-directory)
91 (file-remote-p file-notify-test-remote-temporary-file-directory) 92 (file-directory-p file-notify-test-remote-temporary-file-directory)
92 (file-directory-p file-notify-test-remote-temporary-file-directory) 93 (file-writable-p file-notify-test-remote-temporary-file-directory)
93 (file-writable-p file-notify-test-remote-temporary-file-directory) 94 (setq file-notify--test-desc
94 (setq desc 95 (file-notify-add-watch
95 (file-notify-add-watch 96 file-notify-test-remote-temporary-file-directory
96 file-notify-test-remote-temporary-file-directory 97 '(change) 'ignore))))
97 '(change) 'ignore)))) 98 ;; Unwind forms.
98 ;; Unwind forms. 99 (setq file-notify--test-remote-enabled-checked
99 (setq file-notify--test-remote-enabled-checked (cons t desc)) 100 (cons t file-notify--test-desc))
100 (when desc (file-notify-rm-watch desc))))) 101 (when file-notify--test-desc
102 (file-notify-rm-watch file-notify--test-desc))))
101 ;; Return result. 103 ;; Return result.
102 (cdr file-notify--test-remote-enabled-checked)) 104 (cdr file-notify--test-remote-enabled-checked))
103 105
@@ -116,11 +118,11 @@ being the result.")
116(ert-deftest file-notify-test00-availability () 118(ert-deftest file-notify-test00-availability ()
117 "Test availability of `file-notify'." 119 "Test availability of `file-notify'."
118 (skip-unless (file-notify--test-local-enabled)) 120 (skip-unless (file-notify--test-local-enabled))
119 (let (desc) 121 ;; Check, that different valid parameters are accepted.
120 ;; Check, that different valid parameters are accepted. 122 (should
121 (should (setq desc (file-notify-add-watch 123 (setq file-notify--test-desc
122 temporary-file-directory '(change) 'ignore))) 124 (file-notify-add-watch temporary-file-directory '(change) 'ignore)))
123 (file-notify-rm-watch desc))) 125 (file-notify-rm-watch file-notify--test-desc))
124 126
125(file-notify--deftest-remote file-notify-test00-availability 127(file-notify--deftest-remote file-notify-test00-availability
126 "Test availability of `file-notify' for remote files.") 128 "Test availability of `file-notify' for remote files.")
@@ -128,34 +130,37 @@ being the result.")
128(ert-deftest file-notify-test01-add-watch () 130(ert-deftest file-notify-test01-add-watch ()
129 "Check `file-notify-add-watch'." 131 "Check `file-notify-add-watch'."
130 (skip-unless (file-notify--test-local-enabled)) 132 (skip-unless (file-notify--test-local-enabled))
131 (let (desc) 133 ;; Check, that different valid parameters are accepted.
132 ;; Check, that different valid parameters are accepted. 134 (should
133 (should (setq desc (file-notify-add-watch 135 (setq file-notify--test-desc
134 temporary-file-directory '(change) 'ignore))) 136 (file-notify-add-watch temporary-file-directory '(change) 'ignore)))
135 (file-notify-rm-watch desc) 137 (file-notify-rm-watch file-notify--test-desc)
136 (should (setq desc (file-notify-add-watch 138 (should
137 temporary-file-directory 139 (setq file-notify--test-desc
138 '(attribute-change) 'ignore))) 140 (file-notify-add-watch
139 (file-notify-rm-watch desc) 141 temporary-file-directory '(attribute-change) 'ignore)))
140 (should (setq desc (file-notify-add-watch 142 (file-notify-rm-watch file-notify--test-desc)
141 temporary-file-directory 143 (should
142 '(change attribute-change) 'ignore))) 144 (setq file-notify--test-desc
143 (file-notify-rm-watch desc) 145 (file-notify-add-watch
144 146 temporary-file-directory '(change attribute-change) 'ignore)))
145 ;; Check error handling. 147 (file-notify-rm-watch file-notify--test-desc)
146 (should-error (file-notify-add-watch 1 2 3 4) 148
147 :type 'wrong-number-of-arguments) 149 ;; Check error handling.
148 (should 150 (should-error (file-notify-add-watch 1 2 3 4)
149 (equal (should-error (file-notify-add-watch 1 2 3)) 151 :type 'wrong-number-of-arguments)
150 '(wrong-type-argument 1))) 152 (should
151 (should 153 (equal (should-error
152 (equal (should-error (file-notify-add-watch 154 (file-notify-add-watch 1 2 3))
153 temporary-file-directory 2 3)) 155 '(wrong-type-argument 1)))
154 '(wrong-type-argument 2))) 156 (should
155 (should 157 (equal (should-error
156 (equal (should-error (file-notify-add-watch 158 (file-notify-add-watch temporary-file-directory 2 3))
157 temporary-file-directory '(change) 3)) 159 '(wrong-type-argument 2)))
158 '(wrong-type-argument 3))))) 160 (should
161 (equal (should-error
162 (file-notify-add-watch temporary-file-directory '(change) 3))
163 '(wrong-type-argument 3))))
159 164
160(file-notify--deftest-remote file-notify-test01-add-watch 165(file-notify--deftest-remote file-notify-test01-add-watch
161 "Check `file-notify-add-watch' for remote files.") 166 "Check `file-notify-add-watch' for remote files.")
@@ -165,6 +170,8 @@ being the result.")
165We cannot pass arguments, so we assume that `file-notify--test-event' 170We cannot pass arguments, so we assume that `file-notify--test-event'
166is bound somewhere." 171is bound somewhere."
167 ;(message "Event %S" file-notify--test-event) 172 ;(message "Event %S" file-notify--test-event)
173 ;; Check the descriptor.
174 (should (equal (car file-notify--test-event) file-notify--test-desc))
168 ;; Check the file name. 175 ;; Check the file name.
169 (should 176 (should
170 (string-equal (file-notify--event-file-name file-notify--test-event) 177 (string-equal (file-notify--event-file-name file-notify--test-event)
@@ -199,42 +206,42 @@ TIMEOUT is the maximum time to wait for, in seconds."
199(ert-deftest file-notify-test02-events () 206(ert-deftest file-notify-test02-events ()
200 "Check file creation/removal notifications." 207 "Check file creation/removal notifications."
201 (skip-unless (file-notify--test-local-enabled)) 208 (skip-unless (file-notify--test-local-enabled))
202 (let (desc) 209 (unwind-protect
203 (unwind-protect 210 (progn
204 (progn 211 (setq file-notify--test-results nil
205 (setq file-notify--test-results nil 212 file-notify--test-tmpfile (file-notify--test-make-temp-name)
206 file-notify--test-tmpfile (file-notify--test-make-temp-name) 213 file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
207 file-notify--test-tmpfile1 (file-notify--test-make-temp-name) 214 file-notify--test-desc
208 desc 215 (file-notify-add-watch
209 (file-notify-add-watch 216 file-notify--test-tmpfile
210 file-notify--test-tmpfile 217 '(change) 'file-notify--test-event-handler))
211 '(change) 'file-notify--test-event-handler)) 218 (should file-notify--test-desc)
212 219
213 ;; Check creation and removal. 220 ;; Check creation and removal.
214 (write-region 221 (write-region
215 "any text" nil file-notify--test-tmpfile nil 'no-message) 222 "any text" nil file-notify--test-tmpfile nil 'no-message)
216 (delete-file file-notify--test-tmpfile) 223 (delete-file file-notify--test-tmpfile)
217 (sleep-for 0.1) 224 (sleep-for 0.1)
218 225
219 ;; Check copy and rename. 226 ;; Check copy and rename.
220 (write-region 227 (write-region
221 "any text" nil file-notify--test-tmpfile nil 'no-message) 228 "any text" nil file-notify--test-tmpfile nil 'no-message)
222 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) 229 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
223 (delete-file file-notify--test-tmpfile) 230 (delete-file file-notify--test-tmpfile)
224 (delete-file file-notify--test-tmpfile1) 231 (delete-file file-notify--test-tmpfile1)
225 (sleep-for 0.1) 232 (sleep-for 0.1)
226 233
227 (write-region 234 (write-region
228 "any text" nil file-notify--test-tmpfile nil 'no-message) 235 "any text" nil file-notify--test-tmpfile nil 'no-message)
229 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) 236 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
230 (delete-file file-notify--test-tmpfile1) 237 (delete-file file-notify--test-tmpfile1)
231 (sleep-for 0.1)) 238 (sleep-for 0.1))
232 239
233 ;; Wait for events, and exit. 240 ;; Wait for events, and exit.
234 (file-notify--wait-for-events 5 file-notify--test-results) 241 (file-notify--wait-for-events 5 file-notify--test-results)
235 (file-notify-rm-watch desc) 242 (file-notify-rm-watch file-notify--test-desc)
236 (ignore-errors (delete-file file-notify--test-tmpfile)) 243 (ignore-errors (delete-file file-notify--test-tmpfile))
237 (ignore-errors (delete-file file-notify--test-tmpfile1)))) 244 (ignore-errors (delete-file file-notify--test-tmpfile1)))
238 245
239 (should file-notify--test-results) 246 (should file-notify--test-results)
240 (dolist (result file-notify--test-results) 247 (dolist (result file-notify--test-results)
@@ -245,11 +252,10 @@ TIMEOUT is the maximum time to wait for, in seconds."
245(file-notify--deftest-remote file-notify-test02-events 252(file-notify--deftest-remote file-notify-test02-events
246 "Check file creation/removal notifications for remote files.") 253 "Check file creation/removal notifications for remote files.")
247 254
248(defvar auto-revert-remote-files)
249(defvar auto-revert-stop-on-user-input)
250(setq auto-revert-remote-files t
251 auto-revert-stop-on-user-input nil)
252(require 'autorevert) 255(require 'autorevert)
256(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
257 auto-revert-remote-files t
258 auto-revert-stop-on-user-input nil)
253 259
254(ert-deftest file-notify-test03-autorevert () 260(ert-deftest file-notify-test03-autorevert ()
255 "Check autorevert via file notification. 261 "Check autorevert via file notification.
@@ -257,9 +263,8 @@ This test is skipped in batch mode."
257 (skip-unless (file-notify--test-local-enabled)) 263 (skip-unless (file-notify--test-local-enabled))
258 ;; `auto-revert-buffers' runs every 5". And we must wait, until the 264 ;; `auto-revert-buffers' runs every 5". And we must wait, until the
259 ;; file has been reverted. 265 ;; file has been reverted.
260 (let* ((remote (file-remote-p temporary-file-directory)) 266 (let ((timeout (if (file-remote-p temporary-file-directory) 60 10))
261 (timeout (if remote 60 10)) 267 buf)
262 buf)
263 (unwind-protect 268 (unwind-protect
264 (progn 269 (progn
265 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 270 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
@@ -269,6 +274,10 @@ This test is skipped in batch mode."
269 (setq buf (find-file-noselect file-notify--test-tmpfile)) 274 (setq buf (find-file-noselect file-notify--test-tmpfile))
270 (with-current-buffer buf 275 (with-current-buffer buf
271 (should (string-equal (buffer-string) "any text")) 276 (should (string-equal (buffer-string) "any text"))
277 ;; `buffer-stale--default-function' checks for
278 ;; `verify-visited-file-modtime'. We must ensure that it
279 ;; returns nil.
280 (sleep-for 1)
272 (auto-revert-mode 1) 281 (auto-revert-mode 1)
273 282
274 ;; `auto-revert-buffers' runs every 5". 283 ;; `auto-revert-buffers' runs every 5".
@@ -284,10 +293,8 @@ This test is skipped in batch mode."
284 ;; Modify file. We wait for a second, in order to 293 ;; Modify file. We wait for a second, in order to
285 ;; have another timestamp. 294 ;; have another timestamp.
286 (sleep-for 1) 295 (sleep-for 1)
287 (shell-command 296 (write-region
288 (format "echo -n 'another text' >%s" 297 "another text" nil file-notify--test-tmpfile nil 'no-message)
289 (or (file-remote-p file-notify--test-tmpfile 'localname)
290 file-notify--test-tmpfile)))
291 298
292 ;; Check, that the buffer has been reverted. 299 ;; Check, that the buffer has been reverted.
293 (with-current-buffer (get-buffer-create "*Messages*") 300 (with-current-buffer (get-buffer-create "*Messages*")