aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2013-10-24 09:38:45 +0200
committerMichael Albinus2013-10-24 09:38:45 +0200
commit4ddbf128362dcb0a0a8abe42348ff20d3d511ab6 (patch)
tree52352f57953b0dab9b8462990720fdc007412616
parent50b5b857412f310d69cac74ffe906837da6757c6 (diff)
downloademacs-4ddbf128362dcb0a0a8abe42348ff20d3d511ab6.tar.gz
emacs-4ddbf128362dcb0a0a8abe42348ff20d3d511ab6.zip
* automated/ert-tests.el (ert-test-skip-unless): New test case.
(ert-test-deftest): Adapt test for changed macro expansion. (ert-test-run-tests-interactively): * automated/ert-x-tests.el (ert-test-run-tests-interactively-2): Add a skipping test. * automated/file-notify-tests.el (top): Do not require tramp-sh.el. (file-notify--test-local-enabled): Make it a function. Check also for `file-remote-p' of `temporary-file-directory'. (file-notify--test-remote-enabled-checked): New defvar. (file-notify--test-remote-enabled): Rewrite. Do not use Tramp internal functions. Cache result. (file-notify--deftest-remote, file-notify-test00-availability) (file-notify-test01-add-watch, file-notify-test02-events) (file-notify-test03-autorevert): Add checks with `skip_unless'. (file-notify-test-all): Do not check `file-notify--test-local-enabled'.
-rw-r--r--test/ChangeLog19
-rw-r--r--test/automated/ert-tests.el76
-rw-r--r--test/automated/ert-x-tests.el22
-rw-r--r--test/automated/file-notify-tests.el338
4 files changed, 252 insertions, 203 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index c392b792142..10acf187967 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,22 @@
12013-10-24 Michael Albinus <michael.albinus@gmx.de>
2
3 * automated/ert-tests.el (ert-test-skip-unless): New test case.
4 (ert-test-deftest): Adapt test for changed macro expansion.
5 (ert-test-run-tests-interactively):
6 * automated/ert-x-tests.el (ert-test-run-tests-interactively-2):
7 Add a skipping test.
8
9 * automated/file-notify-tests.el (top): Do not require tramp-sh.el.
10 (file-notify--test-local-enabled): Make it a function. Check also
11 for `file-remote-p' of `temporary-file-directory'.
12 (file-notify--test-remote-enabled-checked): New defvar.
13 (file-notify--test-remote-enabled): Rewrite. Do not use Tramp
14 internal functions. Cache result.
15 (file-notify--deftest-remote, file-notify-test00-availability)
16 (file-notify-test01-add-watch, file-notify-test02-events)
17 (file-notify-test03-autorevert): Add checks with `skip_unless'.
18 (file-notify-test-all): Do not check `file-notify--test-local-enabled'.
19
12013-10-24 Dmitry Gutov <dgutov@yandex.ru> 202013-10-24 Dmitry Gutov <dgutov@yandex.ru>
2 21
3 * indent/ruby.rb: Fix syntax error in the latest example. 22 * indent/ruby.rb: Fix syntax error in the latest example.
diff --git a/test/automated/ert-tests.el b/test/automated/ert-tests.el
index a2be534c25c..cc82893dace 100644
--- a/test/automated/ert-tests.el
+++ b/test/automated/ert-tests.el
@@ -294,6 +294,20 @@ failed or if there was a problem."
294 "the error signaled was a subtype of the expected type"))))) 294 "the error signaled was a subtype of the expected type")))))
295 )) 295 ))
296 296
297(ert-deftest ert-test-skip-unless ()
298 ;; Don't skip.
299 (let ((test (make-ert-test :body (lambda () (skip-unless t)))))
300 (let ((result (ert-run-test test)))
301 (should (ert-test-passed-p result))))
302 ;; Skip.
303 (let ((test (make-ert-test :body (lambda () (skip-unless nil)))))
304 (let ((result (ert-run-test test)))
305 (should (ert-test-skipped-p result))))
306 ;; Skip in case of error.
307 (let ((test (make-ert-test :body (lambda () (skip-unless (error "Foo"))))))
308 (let ((result (ert-run-test test)))
309 (should (ert-test-skipped-p result)))))
310
297(defmacro ert--test-my-list (&rest args) 311(defmacro ert--test-my-list (&rest args)
298 "Don't use this. Instead, call `list' with ARGS, it does the same thing. 312 "Don't use this. Instead, call `list' with ARGS, it does the same thing.
299 313
@@ -332,23 +346,31 @@ This macro is used to test if macroexpansion in `should' works."
332 346
333(ert-deftest ert-test-deftest () 347(ert-deftest ert-test-deftest ()
334 (should (equal (macroexpand '(ert-deftest abc () "foo" :tags '(bar))) 348 (should (equal (macroexpand '(ert-deftest abc () "foo" :tags '(bar)))
335 '(progn 349 '(progn
336 (ert-set-test 'abc 350 (ert-set-test 'abc
337 (make-ert-test :name 'abc 351 (progn
338 :documentation "foo" 352 (vector 'cl-struct-ert-test 'abc "foo"
339 :tags '(bar) 353 #'(lambda nil)
340 :body (lambda ()))) 354 nil ':passed
341 (push '(ert-deftest . abc) current-load-list) 355 '(bar))))
342 'abc))) 356 (setq current-load-list
357 (cons
358 '(ert-deftest . abc)
359 current-load-list))
360 'abc)))
343 (should (equal (macroexpand '(ert-deftest def () 361 (should (equal (macroexpand '(ert-deftest def ()
344 :expected-result ':passed)) 362 :expected-result ':passed))
345 '(progn 363 '(progn
346 (ert-set-test 'def 364 (ert-set-test 'def
347 (make-ert-test :name 'def 365 (progn
348 :expected-result-type ':passed 366 (vector 'cl-struct-ert-test 'def nil
349 :body (lambda ()))) 367 #'(lambda nil)
350 (push '(ert-deftest . def) current-load-list) 368 nil ':passed 'nil)))
351 'def))) 369 (setq current-load-list
370 (cons
371 '(ert-deftest . def)
372 current-load-list))
373 'def)))
352 ;; :documentation keyword is forbidden 374 ;; :documentation keyword is forbidden
353 (should-error (macroexpand '(ert-deftest ghi () 375 (should-error (macroexpand '(ert-deftest ghi ()
354 :documentation "foo")))) 376 :documentation "foo"))))
@@ -543,7 +565,10 @@ This macro is used to test if macroexpansion in `should' works."
543 :body (lambda () (ert-pass)))) 565 :body (lambda () (ert-pass))))
544 (failing-test (make-ert-test :name 'failing-test 566 (failing-test (make-ert-test :name 'failing-test
545 :body (lambda () (ert-fail 567 :body (lambda () (ert-fail
546 "failure message"))))) 568 "failure message"))))
569 (skipped-test (make-ert-test :name 'skipped-test
570 :body (lambda () (ert-skip
571 "skip message")))))
547 (let ((ert-debug-on-error nil)) 572 (let ((ert-debug-on-error nil))
548 (let* ((buffer-name (generate-new-buffer-name " *ert-test-run-tests*")) 573 (let* ((buffer-name (generate-new-buffer-name " *ert-test-run-tests*"))
549 (messages nil) 574 (messages nil)
@@ -554,23 +579,26 @@ This macro is used to test if macroexpansion in `should' works."
554 (unwind-protect 579 (unwind-protect
555 (let ((case-fold-search nil)) 580 (let ((case-fold-search nil))
556 (ert-run-tests-interactively 581 (ert-run-tests-interactively
557 `(member ,passing-test ,failing-test) buffer-name 582 `(member ,passing-test ,failing-test, skipped-test) buffer-name
558 mock-message-fn) 583 mock-message-fn)
559 (should (equal messages `(,(concat 584 (should (equal messages `(,(concat
560 "Ran 2 tests, 1 results were " 585 "Ran 3 tests, 1 results were "
561 "as expected, 1 unexpected")))) 586 "as expected, 1 unexpected, "
587 "1 skipped"))))
562 (with-current-buffer buffer-name 588 (with-current-buffer buffer-name
563 (goto-char (point-min)) 589 (goto-char (point-min))
564 (should (equal 590 (should (equal
565 (buffer-substring (point-min) 591 (buffer-substring (point-min)
566 (save-excursion 592 (save-excursion
567 (forward-line 4) 593 (forward-line 5)
568 (point))) 594 (point)))
569 (concat 595 (concat
570 "Selector: (member <passing-test> <failing-test>)\n" 596 "Selector: (member <passing-test> <failing-test> "
571 "Passed: 1\n" 597 "<skipped-test>)\n"
572 "Failed: 1 (1 unexpected)\n" 598 "Passed: 1\n"
573 "Total: 2/2\n"))))) 599 "Failed: 1 (1 unexpected)\n"
600 "Skipped: 1\n"
601 "Total: 3/3\n")))))
574 (when (get-buffer buffer-name) 602 (when (get-buffer buffer-name)
575 (kill-buffer buffer-name)))))))) 603 (kill-buffer buffer-name))))))))
576 604
diff --git a/test/automated/ert-x-tests.el b/test/automated/ert-x-tests.el
index dc67fe34833..0a657fd4a84 100644
--- a/test/automated/ert-x-tests.el
+++ b/test/automated/ert-x-tests.el
@@ -111,6 +111,9 @@
111 'a 'b)) 111 'a 'b))
112 (ert-fail 112 (ert-fail
113 "failure message"))))) 113 "failure message")))))
114 (skipped-test (make-ert-test :name 'skipped-test
115 :body (lambda () (ert-skip
116 "skip message"))))
114 (ert-debug-on-error nil) 117 (ert-debug-on-error nil)
115 (buffer-name (generate-new-buffer-name "*ert-test-run-tests*")) 118 (buffer-name (generate-new-buffer-name "*ert-test-run-tests*"))
116 (messages nil) 119 (messages nil)
@@ -119,10 +122,12 @@
119 (push (apply #'format format-string args) messages)))) 122 (push (apply #'format format-string args) messages))))
120 (cl-flet ((expected-string (with-font-lock-p) 123 (cl-flet ((expected-string (with-font-lock-p)
121 (ert-propertized-string 124 (ert-propertized-string
122 "Selector: (member <passing-test> <failing-test>)\n" 125 "Selector: (member <passing-test> <failing-test> "
123 "Passed: 1\n" 126 "<skipped-test>)\n"
124 "Failed: 1 (1 unexpected)\n" 127 "Passed: 1\n"
125 "Total: 2/2\n\n" 128 "Failed: 1 (1 unexpected)\n"
129 "Skipped: 1\n"
130 "Total: 3/3\n\n"
126 "Started at:\n" 131 "Started at:\n"
127 "Finished.\n" 132 "Finished.\n"
128 "Finished at:\n\n" 133 "Finished at:\n\n"
@@ -132,7 +137,7 @@
132 face ,(if with-font-lock-p 137 face ,(if with-font-lock-p
133 'ert-test-result-unexpected 138 'ert-test-result-unexpected
134 'button)) 139 'button))
135 ".F" nil "\n\n" 140 ".Fs" nil "\n\n"
136 `(category ,(button-category-symbol 141 `(category ,(button-category-symbol
137 'ert--results-expand-collapse-button) 142 'ert--results-expand-collapse-button)
138 button (t) 143 button (t)
@@ -153,11 +158,12 @@
153 (unwind-protect 158 (unwind-protect
154 (let ((case-fold-search nil)) 159 (let ((case-fold-search nil))
155 (ert-run-tests-interactively 160 (ert-run-tests-interactively
156 `(member ,passing-test ,failing-test) buffer-name 161 `(member ,passing-test ,failing-test ,skipped-test) buffer-name
157 mock-message-fn) 162 mock-message-fn)
158 (should (equal messages `(,(concat 163 (should (equal messages `(,(concat
159 "Ran 2 tests, 1 results were " 164 "Ran 3 tests, 1 results were "
160 "as expected, 1 unexpected")))) 165 "as expected, 1 unexpected, "
166 "1 skipped"))))
161 (with-current-buffer buffer-name 167 (with-current-buffer buffer-name
162 (font-lock-mode 0) 168 (font-lock-mode 0)
163 (should (ert-equal-including-properties 169 (should (ert-equal-including-properties
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index 9f552ee7ab1..627333bffd7 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -43,60 +43,61 @@
43(defvar file-notify--test-event nil) 43(defvar file-notify--test-event nil)
44 44
45(require 'tramp) 45(require 'tramp)
46(require 'tramp-sh)
47(setq tramp-verbose 0 46(setq tramp-verbose 0
48 tramp-message-show-message nil) 47 tramp-message-show-message nil)
49(when noninteractive (defalias 'tramp-read-passwd 'ignore)) 48(when noninteractive (defalias 'tramp-read-passwd 'ignore))
50 49
51;; We do not want to try and fail `file-notify-add-watch'. 50;; We do not want to try and fail `file-notify-add-watch'.
52(defconst file-notify--test-local-enabled file-notify--library 51(defun file-notify--test-local-enabled ()
53 "Whether local file notification is enabled.") 52 "Whether local file notification is enabled.
53This is needed for local `temporary-file-directory' only, in the
54remote case we return always `t'."
55 (or file-notify--library
56 (not (file-remote-p temporary-file-directory))))
57
58(defvar file-notify--test-remote-enabled-checked nil
59 "Cached result of `file-notify--test-remote-enabled'.
60If the function did run, the value is a cons cell, the `cdr'
61being the result.")
54 62
55;; We need also a check on the remote side, w/o adding a file monitor.
56(defun file-notify--test-remote-enabled () 63(defun file-notify--test-remote-enabled ()
57 "Whether remote file notification is enabled." 64 "Whether remote file notification is enabled."
58 (ignore-errors 65 (unless (consp file-notify--test-remote-enabled-checked)
59 (and (file-remote-p file-notify-test-remote-temporary-file-directory) 66 (let (desc)
60 (file-directory-p file-notify-test-remote-temporary-file-directory) 67 (unwind-protect
61 (file-writable-p file-notify-test-remote-temporary-file-directory) 68 (ignore-errors
62 ;; Extracted from tramp-sh-handle-file-notify-add-watch. 69 (and
63 ;; Even though the "remote" system is just ssh@localhost, 70 (file-remote-p file-notify-test-remote-temporary-file-directory)
64 ;; the PATH might not be the same as the "local" PATH. 71 (file-directory-p file-notify-test-remote-temporary-file-directory)
65 ;; Eg this seems to be the case on hydra.nixos.org. 72 (file-writable-p file-notify-test-remote-temporary-file-directory)
66 ;; Without this, tests fail with: 73 (setq desc
67 ;; "No file notification program found on /ssh:localhost:" 74 (file-notify-add-watch
68 ;; Try to fix PATH instead? 75 file-notify-test-remote-temporary-file-directory
69 (with-parsed-tramp-file-name 76 '(change) 'ignore))))
70 file-notify-test-remote-temporary-file-directory nil 77 ;; Unwind forms.
71 (or (tramp-get-remote-gvfs-monitor-dir v) 78 (setq file-notify--test-remote-enabled-checked (cons t desc))
72 (tramp-get-remote-inotifywait v)))))) 79 (when desc (file-notify-rm-watch desc)))))
80 ;; Return result.
81 (cdr file-notify--test-remote-enabled-checked))
73 82
74(defmacro file-notify--deftest-remote (test docstring) 83(defmacro file-notify--deftest-remote (test docstring)
75 "Define ert `TEST-remote' for remote files." 84 "Define ert `TEST-remote' for remote files."
76 `(when (and (file-notify--test-remote-enabled) (ert-get-test ',test)) 85 `(ert-deftest ,(intern (concat (symbol-name test) "-remote")) ()
77 ;; Define the test. 86 ,docstring
78 (ert-deftest ,(intern (concat (symbol-name test) "-remote")) () 87 (let* ((temporary-file-directory
79 ,docstring 88 file-notify-test-remote-temporary-file-directory)
80 (let* ((temporary-file-directory 89 (ert-test (ert-get-test ',test)))
81 file-notify-test-remote-temporary-file-directory) 90 (skip-unless (file-notify--test-remote-enabled))
82 (ert-test (ert-get-test ',test)) 91 ;; The local test could have passed, skipped, or quit. All of
83 (most-recent-result (ert-test-most-recent-result ert-test)) 92 ;; these results should not prevent us to run the remote test.
84 result) 93 ;; That's why we skip only for failed local tests.
85 (unwind-protect 94 (skip-unless
86 (progn 95 (not (ert-test-failed-p (ert-test-most-recent-result ert-test))))
87 (setq result 96 (funcall (ert-test-body ert-test)))))
88 (condition-case err
89 (ert-run-test ert-test)
90 ((error quit)
91 (ert-fail err))))
92 (when (ert-test-failed-p result)
93 (ert-fail
94 (cadr (ert-test-result-with-condition-condition result)))))
95 ;; Reset status of TEST.
96 (setf (ert-test-most-recent-result ert-test) most-recent-result))))))
97 97
98(ert-deftest file-notify-test00-availability () 98(ert-deftest file-notify-test00-availability ()
99 "Test availability of `file-notify'." 99 "Test availability of `file-notify'."
100 (skip-unless (file-notify--test-local-enabled))
100 (let (desc) 101 (let (desc)
101 ;; Check, that different valid parameters are accepted. 102 ;; Check, that different valid parameters are accepted.
102 (should (setq desc (file-notify-add-watch 103 (should (setq desc (file-notify-add-watch
@@ -106,42 +107,40 @@
106(file-notify--deftest-remote file-notify-test00-availability 107(file-notify--deftest-remote file-notify-test00-availability
107 "Test availability of `file-notify' for remote files.") 108 "Test availability of `file-notify' for remote files.")
108 109
109(when file-notify--test-local-enabled 110(ert-deftest file-notify-test01-add-watch ()
111 "Check `file-notify-add-watch'."
112 (skip-unless (file-notify--test-local-enabled))
113 (let (desc)
114 ;; Check, that different valid parameters are accepted.
115 (should (setq desc (file-notify-add-watch
116 temporary-file-directory '(change) 'ignore)))
117 (file-notify-rm-watch desc)
118 (should (setq desc (file-notify-add-watch
119 temporary-file-directory
120 '(attribute-change) 'ignore)))
121 (file-notify-rm-watch desc)
122 (should (setq desc (file-notify-add-watch
123 temporary-file-directory
124 '(change attribute-change) 'ignore)))
125 (file-notify-rm-watch desc)
110 126
111 (ert-deftest file-notify-test01-add-watch () 127 ;; Check error handling.
112 "Check `file-notify-add-watch'." 128 (should-error (file-notify-add-watch 1 2 3 4)
113 (let (desc) 129 :type 'wrong-number-of-arguments)
114 ;; Check, that different valid parameters are accepted. 130 (should
115 (should (setq desc (file-notify-add-watch 131 (equal (should-error (file-notify-add-watch 1 2 3))
116 temporary-file-directory '(change) 'ignore))) 132 '(wrong-type-argument 1)))
117 (file-notify-rm-watch desc) 133 (should
118 (should (setq desc (file-notify-add-watch 134 (equal (should-error (file-notify-add-watch
119 temporary-file-directory 135 temporary-file-directory 2 3))
120 '(attribute-change) 'ignore))) 136 '(wrong-type-argument 2)))
121 (file-notify-rm-watch desc) 137 (should
122 (should (setq desc (file-notify-add-watch 138 (equal (should-error (file-notify-add-watch
123 temporary-file-directory 139 temporary-file-directory '(change) 3))
124 '(change attribute-change) 'ignore))) 140 '(wrong-type-argument 3)))))
125 (file-notify-rm-watch desc)
126 141
127 ;; Check error handling. 142(file-notify--deftest-remote file-notify-test01-add-watch
128 (should-error (file-notify-add-watch 1 2 3 4) 143 "Check `file-notify-add-watch' for remote files.")
129 :type 'wrong-number-of-arguments)
130 (should
131 (equal (should-error (file-notify-add-watch 1 2 3))
132 '(wrong-type-argument 1)))
133 (should
134 (equal (should-error (file-notify-add-watch
135 temporary-file-directory 2 3))
136 '(wrong-type-argument 2)))
137 (should
138 (equal (should-error (file-notify-add-watch
139 temporary-file-directory '(change) 3))
140 '(wrong-type-argument 3)))))
141
142 (file-notify--deftest-remote file-notify-test01-add-watch
143 "Check `file-notify-add-watch' for remote files.")
144 ) ;; file-notify--test-local-enabled
145 144
146(defun file-notify--test-event-test () 145(defun file-notify--test-event-test ()
147 "Ert test function to be called by `file-notify--test-event-handler'. 146 "Ert test function to be called by `file-notify--test-event-handler'.
@@ -172,117 +171,114 @@ Save the result in `file-notify--test-results', for later analysis."
172 (expand-file-name 171 (expand-file-name
173 (make-temp-name "file-notify-test") temporary-file-directory)) 172 (make-temp-name "file-notify-test") temporary-file-directory))
174 173
175(when file-notify--test-local-enabled 174(ert-deftest file-notify-test02-events ()
175 "Check file creation/removal notifications."
176 (skip-unless (file-notify--test-local-enabled))
177 (let (desc)
178 (unwind-protect
179 (progn
180 (setq file-notify--test-results nil
181 file-notify--test-tmpfile (file-notify--test-make-temp-name)
182 file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
183 desc
184 (file-notify-add-watch
185 file-notify--test-tmpfile
186 '(change) 'file-notify--test-event-handler))
187
188 ;; Check creation and removal.
189 (write-region "any text" nil file-notify--test-tmpfile)
190 (delete-file file-notify--test-tmpfile)
191
192 ;; Check copy and rename.
193 (write-region "any text" nil file-notify--test-tmpfile)
194 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
195 (delete-file file-notify--test-tmpfile)
196 (delete-file file-notify--test-tmpfile1)
197
198 (write-region "any text" nil file-notify--test-tmpfile)
199 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
200 (delete-file file-notify--test-tmpfile1))
201
202 ;; Wait for events, and exit.
203 (sit-for 5 'nodisplay)
204 (file-notify-rm-watch desc)
205 (ignore-errors (delete-file file-notify--test-tmpfile))
206 (ignore-errors (delete-file file-notify--test-tmpfile1))))
176 207
177 (ert-deftest file-notify-test02-events () 208 (dolist (result file-notify--test-results)
178 "Check file creation/removal notifications." 209 ;(message "%s" (ert-test-result-messages result))
179 (let (desc) 210 (when (ert-test-failed-p result)
180 (unwind-protect 211 (ert-fail (cadr (ert-test-result-with-condition-condition result))))))
181 (progn 212
182 (setq file-notify--test-results nil 213(file-notify--deftest-remote file-notify-test02-events
183 file-notify--test-tmpfile (file-notify--test-make-temp-name) 214 "Check file creation/removal notifications for remote files.")
184 file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
185 desc
186 (file-notify-add-watch
187 file-notify--test-tmpfile
188 '(change) 'file-notify--test-event-handler))
189
190 ;; Check creation and removal.
191 (write-region "any text" nil file-notify--test-tmpfile)
192 (delete-file file-notify--test-tmpfile)
193
194 ;; Check copy and rename.
195 (write-region "any text" nil file-notify--test-tmpfile)
196 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
197 (delete-file file-notify--test-tmpfile)
198 (delete-file file-notify--test-tmpfile1)
199
200 (write-region "any text" nil file-notify--test-tmpfile)
201 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
202 (delete-file file-notify--test-tmpfile1))
203
204 ;; Wait for events, and exit.
205 (sit-for 5 'nodisplay)
206 (file-notify-rm-watch desc)
207 (ignore-errors (delete-file file-notify--test-tmpfile))
208 (ignore-errors (delete-file file-notify--test-tmpfile1))))
209
210 (dolist (result file-notify--test-results)
211 ;(message "%s" (ert-test-result-messages result))
212 (when (ert-test-failed-p result)
213 (ert-fail (cadr (ert-test-result-with-condition-condition result))))))
214
215 (file-notify--deftest-remote file-notify-test02-events
216 "Check file creation/removal notifications for remote files.")
217 ) ;; file-notify--test-local-enabled
218 215
219;; autorevert runs only in interactive mode. 216;; autorevert runs only in interactive mode.
220(defvar auto-revert-remote-files) 217(defvar auto-revert-remote-files)
221(setq auto-revert-remote-files t) 218(setq auto-revert-remote-files t)
222(require 'autorevert) 219(require 'autorevert)
223(when (and file-notify--test-local-enabled (null noninteractive))
224 220
225 (ert-deftest file-notify-test03-autorevert () 221(ert-deftest file-notify-test03-autorevert ()
226 "Check autorevert via file notification. 222 "Check autorevert via file notification.
227This test is skipped in batch mode." 223This test is skipped in batch mode."
228 ;; `auto-revert-buffers' runs every 5". And we must wait, until 224 (skip-unless (file-notify--test-local-enabled))
229 ;; the file has been reverted. 225 (skip-unless (not noninteractive))
230 (let ((timeout 10) 226 ;; `auto-revert-buffers' runs every 5". And we must wait, until the
231 buf) 227 ;; file has been reverted.
232 (unwind-protect 228 (let ((timeout 10)
233 (progn 229 buf)
234 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 230 (unwind-protect
235 231 (progn
236 (write-region "any text" nil file-notify--test-tmpfile) 232 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
237 (setq buf (find-file-noselect file-notify--test-tmpfile)) 233
238 (with-current-buffer buf 234 (write-region "any text" nil file-notify--test-tmpfile)
239 (should (string-equal (buffer-string) "any text")) 235 (setq buf (find-file-noselect file-notify--test-tmpfile))
240 (auto-revert-mode 1) 236 (with-current-buffer buf
241 237 (should (string-equal (buffer-string) "any text"))
242 ;; `auto-revert-buffers' runs every 5". 238 (auto-revert-mode 1)
239
240 ;; `auto-revert-buffers' runs every 5".
241 (with-timeout (timeout (ignore))
242 (while (null auto-revert-notify-watch-descriptor)
243 (sit-for 0.1 'nodisplay)))
244
245 ;; Check, that file notification has been used.
246 (should auto-revert-mode)
247 (should auto-revert-use-notify)
248 (should auto-revert-notify-watch-descriptor)
249
250 ;; Modify file. We wait for a second, in order to
251 ;; have another timestamp.
252 (sit-for 1)
253 (shell-command
254 (format "echo -n 'another text' >%s"
255 (or (file-remote-p file-notify--test-tmpfile 'localname)
256 file-notify--test-tmpfile)))
257
258 ;; Check, that the buffer has been reverted.
259 (with-current-buffer (get-buffer-create "*Messages*")
243 (with-timeout (timeout (ignore)) 260 (with-timeout (timeout (ignore))
244 (while (null auto-revert-notify-watch-descriptor) 261 (while
245 (sit-for 0.1 'nodisplay))) 262 (null (string-match
246 263 (format "Reverting buffer `%s'." (buffer-name buf))
247 ;; Check, that file notification has been used. 264 (buffer-string)))
248 (should auto-revert-mode) 265 (sit-for 0.1 'nodisplay))))
249 (should auto-revert-use-notify) 266 (should (string-equal (buffer-string) "another text"))))
250 (should auto-revert-notify-watch-descriptor) 267
251 268 ;; Exit.
252 ;; Modify file. We wait for a second, in order to 269 (ignore-errors (kill-buffer buf))
253 ;; have another timestamp. 270 (ignore-errors (delete-file file-notify--test-tmpfile)))))
254 (sit-for 1) 271
255 (shell-command 272(file-notify--deftest-remote file-notify-test03-autorevert
256 (format "echo -n 'another text' >%s" 273 "Check autorevert via file notification for remote files.
257 (or (file-remote-p file-notify--test-tmpfile 'localname)
258 file-notify--test-tmpfile)))
259
260 ;; Check, that the buffer has been reverted.
261 (with-current-buffer (get-buffer-create "*Messages*")
262 (with-timeout (timeout (ignore))
263 (while
264 (null (string-match
265 (format "Reverting buffer `%s'." (buffer-name buf))
266 (buffer-string)))
267 (sit-for 0.1 'nodisplay))))
268 (should (string-equal (buffer-string) "another text"))))
269
270 ;; Exit.
271 (ignore-errors (kill-buffer buf))
272 (ignore-errors (delete-file file-notify--test-tmpfile)))))
273
274 (file-notify--deftest-remote file-notify-test03-autorevert
275 "Check autorevert via file notification for remote files.
276This test is skipped in batch mode.") 274This test is skipped in batch mode.")
277 ) ;; (and file-notify--test-local-enabled (null noninteractive))
278 275
279(defun file-notify-test-all (&optional interactive) 276(defun file-notify-test-all (&optional interactive)
280 "Run all tests for \\[file-notify]." 277 "Run all tests for \\[file-notify]."
281 (interactive "p") 278 (interactive "p")
282 (when file-notify--test-local-enabled 279 (if interactive
283 (if interactive 280 (ert-run-tests-interactively "^file-notify-")
284 (ert-run-tests-interactively "^file-notify-") 281 (ert-run-tests-batch "^file-notify-")))
285 (ert-run-tests-batch "^file-notify-"))))
286 282
287(provide 'file-notify-tests) 283(provide 'file-notify-tests)
288;;; file-notify-tests.el ends here 284;;; file-notify-tests.el ends here