1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-04 08:47:11 +00:00

Adapt tests in auto-revert-tests.el

* test/automated/auto-revert-tests.el (auto-revert--timeout):
Make it a defconst.
(auto-revert--wait-for-revert): New defun.
(auto-revert-test00-auto-revert-mode)
(auto-revert-test01-auto-revert-tail-mode)
(auto-revert-test02-auto-revert-mode-dired): Use it.
This commit is contained in:
Michael Albinus 2015-09-15 20:12:34 +02:00
parent 6d98299e76
commit 5c182636b1

View File

@ -28,7 +28,18 @@
(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" (setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
auto-revert-stop-on-user-input nil) auto-revert-stop-on-user-input nil)
(defvar auto-revert--timeout 10) (defconst auto-revert--timeout 10
"Time to wait until a message appears in the *Messages* buffer.")
(defun auto-revert--wait-for-revert (buffer)
"Wait until the *Messages* buffer reports reversion of BUFFER."
(with-timeout (auto-revert--timeout nil)
(with-current-buffer "*Messages*"
(while
(null (string-match
(format-message "Reverting buffer `%s'." (buffer-name buffer))
(buffer-string)))
(read-event nil nil 0.1)))))
(ert-deftest auto-revert-test00-auto-revert-mode () (ert-deftest auto-revert-test00-auto-revert-mode ()
"Check autorevert for a file." "Check autorevert for a file."
@ -57,13 +68,7 @@
(write-region "another text" nil tmpfile nil 'no-message) (write-region "another text" nil tmpfile nil 'no-message)
;; Check, that the buffer has been reverted. ;; Check, that the buffer has been reverted.
(with-timeout (auto-revert--timeout nil) (auto-revert--wait-for-revert buf)
(with-current-buffer "*Messages*"
(while
(null (string-match
(format "Reverting buffer `%s'." (buffer-name buf))
(buffer-string)))
(read-event nil nil 0.1))))
(should (string-match "another text" (buffer-string))) (should (string-match "another text" (buffer-string)))
;; When the buffer is modified, it shall not be reverted. ;; When the buffer is modified, it shall not be reverted.
@ -73,14 +78,8 @@
(sleep-for 1) (sleep-for 1)
(write-region "any text" nil tmpfile nil 'no-message) (write-region "any text" nil tmpfile nil 'no-message)
;; Check, whether the buffer has been reverted. ;; Check, that the buffer hasn't been reverted.
(with-timeout (auto-revert--timeout nil) (auto-revert--wait-for-revert buf)
(with-current-buffer "*Messages*"
(while
(null (string-match
(format "Reverting buffer `%s'." (buffer-name buf))
(buffer-string)))
(read-event nil nil 0.1))))
(should-not (string-match "any text" (buffer-string))))) (should-not (string-match "any text" (buffer-string)))))
;; Exit. ;; Exit.
@ -119,13 +118,7 @@
(write-region "another text" nil tmpfile 'append 'no-message) (write-region "another text" nil tmpfile 'append 'no-message)
;; Check, that the buffer has been reverted. ;; Check, that the buffer has been reverted.
(with-timeout (auto-revert--timeout nil) (auto-revert--wait-for-revert buf)
(with-current-buffer "*Messages*"
(while
(null (string-match
(format "Reverting buffer `%s'." (buffer-name buf))
(buffer-string)))
(read-event nil nil 0.1))))
(should (should
(string-match "modified text\nanother text" (buffer-string))))) (string-match "modified text\nanother text" (buffer-string)))))
@ -162,16 +155,9 @@
(delete-file tmpfile) (delete-file tmpfile)
;; Check, that the buffer has been reverted. ;; Check, that the buffer has been reverted.
(with-timeout (auto-revert--timeout nil) (auto-revert--wait-for-revert buf)
(with-current-buffer "*Messages*" (should-not
(while (string-match name (substring-no-properties (buffer-string))))
(null (string-match
(format "Reverting buffer `%s'." (buffer-name buf))
(buffer-string)))
(read-event nil nil 0.1))))
(should
(null
(string-match name (substring-no-properties (buffer-string)))))
;; Make dired buffer modified. Check, that the buffer has ;; Make dired buffer modified. Check, that the buffer has
;; been still reverted. ;; been still reverted.
@ -181,14 +167,8 @@
(sleep-for 1) (sleep-for 1)
(write-region "any text" nil tmpfile nil 'no-message) (write-region "any text" nil tmpfile nil 'no-message)
;; Check, that the buffer hasn't been reverted. ;; Check, that the buffer has been reverted.
(with-timeout (auto-revert--timeout nil) (auto-revert--wait-for-revert buf)
(with-current-buffer "*Messages*"
(while
(null (string-match
(format "Reverting buffer `%s'." (buffer-name buf))
(buffer-string)))
(read-event nil nil 0.1))))
(should (should
(string-match name (substring-no-properties (buffer-string)))))) (string-match name (substring-no-properties (buffer-string))))))