aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2013-07-05 16:06:14 +0200
committerMichael Albinus2013-07-05 16:06:14 +0200
commit84b6d3df1ad4f84faaf2bdf511f184ae1716762e (patch)
tree22f1139b75e49a99ced63f0e317ec6eaf5cfdc95
parentd610f6dd0f7afd919c243e1c0786174010c19be8 (diff)
downloademacs-84b6d3df1ad4f84faaf2bdf511f184ae1716762e.tar.gz
emacs-84b6d3df1ad4f84faaf2bdf511f184ae1716762e.zip
* automated/file-notify-tests.el
(file-notify-test-remote-temporary-file-directory): Use `null-device' on w32. (file-notify--test-tmpfile, file-notify--test-tmpfile1) (file-notify--test-results, file-notify--test-event) (file-notify--deftest-remote, file-notify--event-test) (file-notify--test-event-handler) (file-notify--test-make-temp-name): Renamed, in order to mark them internal. (tramp-message-show-message, tramp-read-passwd): Tweak them for better fitting in noninteractive tests. (file-notify-test00-availability): Renamed from `file-notify-test0'. (file-notify-test01-add-watch): Renamed from `file-notify-test1'. Use `temporary-file-directory '. (file-notify-test01-add-watch-remote): New test. (file-notify-test02-events): Renamed from `file-notify-test2'. (file-notify-test02-events-remote): Renamed from `file-notify-test3'. (file-notify-test03-autorevert): Renamed from `file-notify-test4'. Use timeouts. (file-notify-test03-autorevert-remote): Renamed from `file-notify-test5'.
-rw-r--r--test/ChangeLog24
-rw-r--r--test/automated/file-notify-tests.el232
2 files changed, 151 insertions, 105 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index ab7a57bc35d..aded5473304 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,27 @@
12013-07-05 Michael Albinus <michael.albinus@gmx.de>
2
3 * automated/file-notify-tests.el
4 (file-notify-test-remote-temporary-file-directory): Use
5 `null-device' on w32.
6 (file-notify--test-tmpfile, file-notify--test-tmpfile1)
7 (file-notify--test-results, file-notify--test-event)
8 (file-notify--deftest-remote, file-notify--event-test)
9 (file-notify--test-event-handler)
10 (file-notify--test-make-temp-name): Renamed, in order to mark them
11 internal.
12 (tramp-message-show-message, tramp-read-passwd): Tweak them for
13 better fitting in noninteractive tests.
14 (file-notify-test00-availability): Renamed from `file-notify-test0'.
15 (file-notify-test01-add-watch): Renamed from `file-notify-test1'.
16 Use `temporary-file-directory '.
17 (file-notify-test01-add-watch-remote): New test.
18 (file-notify-test02-events): Renamed from `file-notify-test2'.
19 (file-notify-test02-events-remote): Renamed from `file-notify-test3'.
20 (file-notify-test03-autorevert): Renamed from
21 `file-notify-test4'. Use timeouts.
22 (file-notify-test03-autorevert-remote): Renamed from
23 `file-notify-test5'.
24
12013-07-04 Michael Albinus <michael.albinus@gmx.de> 252013-07-04 Michael Albinus <michael.albinus@gmx.de>
2 26
3 * automated/file-notify-tests.el: New package. 27 * automated/file-notify-tests.el: New package.
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index 56259cd3ff4..8fcfbe548fc 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -21,27 +21,77 @@
21 21
22;; Some of the tests are intended to run over remote files. Set 22;; Some of the tests are intended to run over remote files. Set
23;; `file-notify-test-remote-temporary-file-directory' to a suitable 23;; `file-notify-test-remote-temporary-file-directory' to a suitable
24;; value. The remote host must also provide the `inotifywait' program. 24;; value. It must NOT require an interactive password prompt, when
25;; running the tests in batch mode.
26
27;; If you want to skip tests for remote files, set this variable to
28;; `null-device'.
25 29
26;;; Code: 30;;; Code:
27 31
28(require 'ert) 32(require 'ert)
29(require 'filenotify) 33(require 'filenotify)
30 34
31(ert-deftest file-notify-test0 () 35;; There is no default value on w32 systems, which could work out of the box.
32 "Test availability of \\[file-notify]." 36(defconst file-notify-test-remote-temporary-file-directory
37 (if (eq system-type 'windows-nt) null-device "/ssh::/tmp")
38 "Temporary directory for Tramp tests.")
39
40(defvar file-notify--test-tmpfile nil)
41(defvar file-notify--test-tmpfile1 nil)
42(defvar file-notify--test-results nil)
43(defvar file-notify--test-event nil)
44
45(require 'tramp)
46(setq tramp-verbose 0
47 tramp-message-show-message nil)
48(when noninteractive (defalias 'tramp-read-passwd 'ignore))
49
50(defmacro file-notify--deftest-remote (test docstring)
51 "Define ert `TEST-remote' for remote files."
52 `(when (ignore-errors
53 (and
54 (file-remote-p file-notify-test-remote-temporary-file-directory)
55 (file-directory-p file-notify-test-remote-temporary-file-directory)
56 (file-writable-p file-notify-test-remote-temporary-file-directory)))
57 ;; Define the test.
58 (ert-deftest ,(intern (concat (symbol-name test) "-remote")) ()
59 ,docstring
60 (let* ((temporary-file-directory
61 file-notify-test-remote-temporary-file-directory)
62 (ert-test (ert-get-test ',test))
63 (most-recent-result (ert-test-most-recent-result ert-test))
64 result)
65 (unwind-protect
66 (progn
67 (setq result
68 (condition-case err
69 (ert-run-test ert-test)
70 ((error quit)
71 (ert-fail err))))
72 (when (ert-test-failed-p result)
73 (ert-fail
74 (cadr (ert-test-result-with-condition-condition result)))))
75 ;; Reset status of TEST.
76 (setf (ert-test-most-recent-result ert-test) most-recent-result))))))
77
78(ert-deftest file-notify-test00-availability ()
79 "Test availability of `file-notify'."
33 (should (memq file-notify-support '(gfilenotify inotify w32notify)))) 80 (should (memq file-notify-support '(gfilenotify inotify w32notify))))
34 81
35(ert-deftest file-notify-test1 () 82(ert-deftest file-notify-test01-add-watch ()
36 "Add watch via \\[file-notify-add-watch]." 83 "Check `file-notify-add-watch'."
37 (let (desc) 84 (let (desc)
38 ;; Check, that different valid parameters are accepted. 85 ;; Check, that different valid parameters are accepted.
39 (should (setq desc (file-notify-add-watch "/" '(change) 'ignore))) 86 (should (setq desc (file-notify-add-watch
87 temporary-file-directory '(change) 'ignore)))
40 (file-notify-rm-watch desc) 88 (file-notify-rm-watch desc)
41 (should (setq desc (file-notify-add-watch "/" '(attribute-change) 'ignore))) 89 (should (setq desc (file-notify-add-watch
90 temporary-file-directory '(attribute-change) 'ignore)))
42 (file-notify-rm-watch desc) 91 (file-notify-rm-watch desc)
43 (should (setq desc (file-notify-add-watch 92 (should (setq desc (file-notify-add-watch
44 "/" '(change attribute-change) 'ignore))) 93 temporary-file-directory
94 '(change attribute-change) 'ignore)))
45 (file-notify-rm-watch desc) 95 (file-notify-rm-watch desc)
46 96
47 ;; Check error handling. 97 ;; Check error handling.
@@ -52,121 +102,85 @@
52 (equal (should-error (file-notify-add-watch 1 2 3)) 102 (equal (should-error (file-notify-add-watch 1 2 3))
53 '(wrong-type-argument 1))) 103 '(wrong-type-argument 1)))
54 (should 104 (should
55 (equal (should-error (file-notify-add-watch "/" 2 3)) 105 (equal (should-error (file-notify-add-watch temporary-file-directory 2 3))
56 '(wrong-type-argument 2))) 106 '(wrong-type-argument 2)))
57 (should 107 (should
58 (equal (should-error (file-notify-add-watch "/" '(change) 3)) 108 (equal (should-error (file-notify-add-watch
109 temporary-file-directory '(change) 3))
59 '(wrong-type-argument 3))))) 110 '(wrong-type-argument 3)))))
60 111
61(defvar file-notify-test-tmpfile nil) 112(file-notify--deftest-remote file-notify-test01-add-watch
62(defvar file-notify-test-tmpfile1 nil) 113 "Check `file-notify-add-watch' for remote files.")
63(defvar file-notify-test-results nil)
64(defconst file-notify-test-remote-temporary-file-directory "/ssh::/tmp"
65 "Temporary directory for Tramp tests.")
66
67(defvar tramp-verbose)
68(setq tramp-verbose 0)
69(defvar file-notify--event)
70
71(defun file-notify-test-run-remote-test ()
72 "Check, whether the remote tests can be run."
73 (ignore-errors
74 (and
75 (file-directory-p file-notify-test-remote-temporary-file-directory)
76 (file-writable-p file-notify-test-remote-temporary-file-directory))))
77 114
78(defun file-notify-event-test () 115(defun file-notify--test-event-test ()
79 "Ert test function to be called by `file-notify-test-event-handler'. 116 "Ert test function to be called by `file-notify--test-event-handler'.
80We cannot pass arguments, so we assume that `file-notify--event' 117We cannot pass arguments, so we assume that `file-notify--test-event'
81is bound somewhere." 118is bound somewhere."
82 (message "Event %S" file-notify--event) 119 ;(message "Event %S" file-notify--test-event)
83 ;; Check the file name. 120 ;; Check the file name.
84 (should 121 (should
85 (string-equal (file-notify--event-file-name file-notify--event) 122 (string-equal (file-notify--event-file-name file-notify--test-event)
86 file-notify-test-tmpfile)) 123 file-notify--test-tmpfile))
87 ;; Check the second file name if exists. 124 ;; Check the second file name if exists.
88 (when (eq (nth 1 file-notify--event) 'renamed) 125 (when (eq (nth 1 file-notify--test-event) 'renamed)
89 (should 126 (should
90 (string-equal 127 (string-equal
91 (file-notify--event-file1-name file-notify--event) 128 (file-notify--event-file1-name file-notify--test-event)
92 file-notify-test-tmpfile1)))) 129 file-notify--test-tmpfile1))))
93 130
94(defun file-notify-test-event-handler (file-notify--event) 131(defun file-notify--test-event-handler (file-notify--test-event)
95 "Run a test over FILE-NOTIFY--EVENT. 132 "Run a test over FILE-NOTIFY--TEST-EVENT.
96Save the result in `file-notify-test-results', for later analysis." 133Save the result in `file-notify--test-results', for later analysis."
97 (let ((result (ert-run-test (make-ert-test :body 'file-notify-event-test)))) 134 (let ((result
98 (setq file-notify-test-results 135 (ert-run-test (make-ert-test :body 'file-notify--test-event-test))))
99 (append file-notify-test-results `(,result))))) 136 (setq file-notify--test-results
100 137 (append file-notify--test-results `(,result)))))
101(defun file-notify-test-make-temp-name () 138
139(defun file-notify--test-make-temp-name ()
102 "Create a temporary file name for test." 140 "Create a temporary file name for test."
103 (expand-file-name 141 (expand-file-name
104 (make-temp-name "file-notify-test") temporary-file-directory)) 142 (make-temp-name "file-notify-test") temporary-file-directory))
105 143
106(ert-deftest file-notify-test2 () 144(ert-deftest file-notify-test02-events ()
107 "Check file creation/removal notifications." 145 "Check file creation/removal notifications."
108 (let (desc) 146 (let (desc)
109 (unwind-protect 147 (unwind-protect
110 (progn 148 (progn
111 (setq file-notify-test-results nil 149 (setq file-notify--test-results nil
112 file-notify-test-tmpfile (file-notify-test-make-temp-name) 150 file-notify--test-tmpfile (file-notify--test-make-temp-name)
113 file-notify-test-tmpfile1 (file-notify-test-make-temp-name) 151 file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
114 desc 152 desc
115 (file-notify-add-watch 153 (file-notify-add-watch
116 file-notify-test-tmpfile 154 file-notify--test-tmpfile
117 '(change) 'file-notify-test-event-handler)) 155 '(change) 'file-notify--test-event-handler))
118 156
119 ;; Check creation and removal. 157 ;; Check creation and removal.
120 (write-region "any text" nil file-notify-test-tmpfile) 158 (write-region "any text" nil file-notify--test-tmpfile)
121 (delete-file file-notify-test-tmpfile) 159 (delete-file file-notify--test-tmpfile)
122 160
123 ;; Check copy and rename. 161 ;; Check copy and rename.
124 (write-region "any text" nil file-notify-test-tmpfile) 162 (write-region "any text" nil file-notify--test-tmpfile)
125 (copy-file file-notify-test-tmpfile file-notify-test-tmpfile1) 163 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
126 (delete-file file-notify-test-tmpfile) 164 (delete-file file-notify--test-tmpfile)
127 (delete-file file-notify-test-tmpfile1) 165 (delete-file file-notify--test-tmpfile1)
128 166
129 (write-region "any text" nil file-notify-test-tmpfile) 167 (write-region "any text" nil file-notify--test-tmpfile)
130 (rename-file file-notify-test-tmpfile file-notify-test-tmpfile1) 168 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
131 (delete-file file-notify-test-tmpfile1)) 169 (delete-file file-notify--test-tmpfile1))
132 170
133 ;; Wait for events, and exit. 171 ;; Wait for events, and exit.
134 (sit-for 5 'nodisplay) 172 (sit-for 5 'nodisplay)
135 (file-notify-rm-watch desc) 173 (file-notify-rm-watch desc)
136 (ignore-errors (delete-file file-notify-test-tmpfile)) 174 (ignore-errors (delete-file file-notify--test-tmpfile))
137 (ignore-errors (delete-file file-notify-test-tmpfile1)))) 175 (ignore-errors (delete-file file-notify--test-tmpfile1))))
138 176
139 (dolist (result file-notify-test-results) 177 (dolist (result file-notify--test-results)
140 ;(message "%s" (ert-test-result-messages result)) 178 ;(message "%s" (ert-test-result-messages result))
141 (when (ert-test-failed-p result) 179 (when (ert-test-failed-p result)
142 (ert-fail (cadr (ert-test-result-with-condition-condition result)))))) 180 (ert-fail (cadr (ert-test-result-with-condition-condition result))))))
143 181
144;; TODO: When the remote test fails, suppress FAILED indication for TEST. 182(file-notify--deftest-remote file-notify-test02-events
145(defmacro file-notify-test-remote (test) 183 "Check file creation/removal notifications for remote files.")
146 "Run ert TEST for remote files."
147 `(let* ((temporary-file-directory
148 file-notify-test-remote-temporary-file-directory)
149 (ert-test (ert-get-test ,test))
150 (most-recent-result (ert-test-most-recent-result ert-test))
151 result)
152 (unwind-protect
153 (progn
154 (setq result
155 (condition-case err
156 (ert-run-test (ert-get-test ,test))
157 ((error quit)
158 (ert-fail err))))
159 (when (ert-test-failed-p result)
160 (ert-fail
161 (cadr (ert-test-result-with-condition-condition result)))))
162 ;; Reset status of TEST.
163 (setf (ert-test-most-recent-result ert-test) most-recent-result))))
164
165(when (file-notify-test-run-remote-test)
166 (ert-deftest file-notify-test3 ()
167 "Check file creation/removal notification for remote files."
168 (file-notify-test-remote 'file-notify-test2))
169) ;; (file-notify-test-run-remote-test)
170 184
171;; autorevert runs only in interactive mode. 185;; autorevert runs only in interactive mode.
172(defvar auto-revert-remote-files) 186(defvar auto-revert-remote-files)
@@ -174,50 +188,58 @@ Save the result in `file-notify-test-results', for later analysis."
174(require 'autorevert) 188(require 'autorevert)
175(when (null noninteractive) 189(when (null noninteractive)
176 190
177 (ert-deftest file-notify-test4 () 191 (ert-deftest file-notify-test03-autorevert ()
178 "Check autorevert via file notification. 192 "Check autorevert via file notification.
179This test is skipped in batch mode." 193This test is skipped in batch mode."
180 ;; `auto-revert-buffers' runs every 5". And we must wait, until 194 ;; `auto-revert-buffers' runs every 5". And we must wait, until
181 ;; the file has been reverted. 195 ;; the file has been reverted.
182 (let ((wait 10) 196 (let ((timeout 10)
183 buf) 197 buf)
184 (unwind-protect 198 (unwind-protect
185 (progn 199 (progn
186 (setq file-notify-test-tmpfile (file-notify-test-make-temp-name)) 200 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
187 201
188 (write-region "any text" nil file-notify-test-tmpfile) 202 (write-region "any text" nil file-notify--test-tmpfile)
189 (setq buf (find-file-noselect file-notify-test-tmpfile)) 203 (setq buf (find-file-noselect file-notify--test-tmpfile))
190 (with-current-buffer buf 204 (with-current-buffer buf
191 (should (string-equal (buffer-string) "any text")) 205 (should (string-equal (buffer-string) "any text"))
192 (auto-revert-mode 1) 206 (auto-revert-mode 1)
207
193 ;; `auto-revert-buffers' runs every 5". 208 ;; `auto-revert-buffers' runs every 5".
194 (sit-for wait) 209 (with-timeout (timeout (ignore))
210 (while (null auto-revert-notify-watch-descriptor)
211 (sit-for 0.1 'nodisplay)))
195 212
196 ;; Check, that file notification has been used. 213 ;; Check, that file notification has been used.
197 (should auto-revert-mode) 214 (should auto-revert-mode)
198 (should auto-revert-use-notify) 215 (should auto-revert-use-notify)
199 (should auto-revert-notify-watch-descriptor) 216 (should auto-revert-notify-watch-descriptor)
200 217
201 ;; Modify file. 218 ;; Modify file. We wait for a second, in order to
219 ;; have another timestamp.
220 (sit-for 1)
202 (shell-command 221 (shell-command
203 (format "echo -n 'another text' >%s" 222 (format "echo -n 'another text' >%s"
204 (or (file-remote-p file-notify-test-tmpfile 'localname) 223 (or (file-remote-p file-notify--test-tmpfile 'localname)
205 file-notify-test-tmpfile))) 224 file-notify--test-tmpfile)))
206 (sit-for wait)
207 225
208 ;; Check, that the buffer has been reverted. 226 ;; Check, that the buffer has been reverted.
227 (with-current-buffer (get-buffer-create "*Messages*")
228 (with-timeout (timeout (ignore))
229 (while
230 (null (string-match
231 (format "Reverting buffer `%s'." (buffer-name buf))
232 (buffer-string)))
233 (sit-for 0.1 'nodisplay))))
209 (should (string-equal (buffer-string) "another text")))) 234 (should (string-equal (buffer-string) "another text"))))
210 235
211 ;; Exit. 236 ;; Exit.
212 (ignore-errors (kill-buffer buf)) 237 (ignore-errors (kill-buffer buf))
213 (ignore-errors (delete-file file-notify-test-tmpfile))))) 238 (ignore-errors (delete-file file-notify--test-tmpfile)))))
214 239
215 (when (file-notify-test-run-remote-test) 240 (file-notify--deftest-remote file-notify-test03-autorevert
216 (ert-deftest file-notify-test5 () 241 "Check autorevert via file notification for remote files.
217 "Check autorevert via file notification for remote files. 242This test is skipped in batch mode.")
218This test is skipped in batch mode."
219 (file-notify-test-remote 'file-notify-test4))
220 ) ;; (file-notify-test-run-remote-test)
221 ) ;; (null noninteractive) 243 ) ;; (null noninteractive)
222 244
223(defun file-notify-test-all (&optional interactive) 245(defun file-notify-test-all (&optional interactive)