]> code.delx.au - gnu-emacs/commitdiff
Adapt tests in auto-revert-tests.el
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 15 Sep 2015 18:12:34 +0000 (20:12 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 15 Sep 2015 18:12:34 +0000 (20:12 +0200)
* 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.

test/automated/auto-revert-tests.el

index 204e03d423df95e4d54216bcc19828a43b0479e5..86184d613fc5f028994c85a43260b02f55bd6d42 100644 (file)
 (setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
       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 ()
   "Check autorevert for a file."
             (write-region "another text" nil tmpfile nil 'no-message)
 
            ;; Check, that the buffer has been reverted.
-            (with-timeout (auto-revert--timeout nil)
-              (with-current-buffer "*Messages*"
-                (while
-                    (null (string-match
-                           (format "Reverting buffer `%s'." (buffer-name buf))
-                           (buffer-string)))
-                  (read-event nil nil 0.1))))
+            (auto-revert--wait-for-revert buf)
             (should (string-match "another text" (buffer-string)))
 
             ;; When the buffer is modified, it shall not be reverted.
            (sleep-for 1)
             (write-region "any text" nil tmpfile nil 'no-message)
 
-           ;; Check, whether the buffer has been reverted.
-            (with-timeout (auto-revert--timeout nil)
-              (with-current-buffer "*Messages*"
-                (while
-                    (null (string-match
-                           (format "Reverting buffer `%s'." (buffer-name buf))
-                           (buffer-string)))
-                  (read-event nil nil 0.1))))
+           ;; Check, that the buffer hasn't been reverted.
+            (auto-revert--wait-for-revert buf)
             (should-not (string-match "any text" (buffer-string)))))
 
       ;; Exit.
             (write-region "another text" nil tmpfile 'append 'no-message)
 
            ;; Check, that the buffer has been reverted.
-            (with-timeout (auto-revert--timeout nil)
-              (with-current-buffer "*Messages*"
-                (while
-                    (null (string-match
-                           (format "Reverting buffer `%s'." (buffer-name buf))
-                           (buffer-string)))
-                  (read-event nil nil 0.1))))
+            (auto-revert--wait-for-revert buf)
             (should
              (string-match "modified text\nanother text" (buffer-string)))))
 
             (delete-file tmpfile)
 
            ;; Check, that the buffer has been reverted.
-            (with-timeout (auto-revert--timeout nil)
-              (with-current-buffer "*Messages*"
-                (while
-                    (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)))))
+            (auto-revert--wait-for-revert buf)
+            (should-not
+             (string-match name (substring-no-properties (buffer-string))))
 
             ;; Make dired buffer modified.  Check, that the buffer has
             ;; been still reverted.
            (sleep-for 1)
             (write-region "any text" nil tmpfile nil 'no-message)
 
-           ;; Check, that the buffer hasn't been reverted.
-            (with-timeout (auto-revert--timeout nil)
-              (with-current-buffer "*Messages*"
-                (while
-                    (null (string-match
-                           (format "Reverting buffer `%s'." (buffer-name buf))
-                           (buffer-string)))
-                  (read-event nil nil 0.1))))
+           ;; Check, that the buffer has been reverted.
+            (auto-revert--wait-for-revert buf)
             (should
              (string-match name (substring-no-properties (buffer-string))))))