diff options
| author | Michael Albinus | 2015-07-14 18:23:39 +0200 |
|---|---|---|
| committer | Michael Albinus | 2015-07-14 18:23:39 +0200 |
| commit | 894a90671b9ebc37fb56abfcef6e422e954d6460 (patch) | |
| tree | 4c2f1d6b572e72db969cf5011f3f7bc4e038e470 /test | |
| parent | 2254b6c09cff8f3a83684fd159289d0e305b0e7d (diff) | |
| download | emacs-894a90671b9ebc37fb56abfcef6e422e954d6460.tar.gz emacs-894a90671b9ebc37fb56abfcef6e422e954d6460.zip | |
New autorevert tests.
* test/automated/auto-revert-tests.el: New file.
Diffstat (limited to 'test')
| -rw-r--r-- | test/automated/auto-revert-tests.el | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/test/automated/auto-revert-tests.el b/test/automated/auto-revert-tests.el new file mode 100644 index 00000000000..a98428f7d89 --- /dev/null +++ b/test/automated/auto-revert-tests.el | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | ;;; auto-revert-tests.el --- Tests of auto-revert | ||
| 2 | |||
| 3 | ;; Copyright (C) 2015 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Michael Albinus <michael.albinus@gmx.de> | ||
| 6 | |||
| 7 | ;; This program is free software: you can redistribute it and/or | ||
| 8 | ;; modify it under the terms of the GNU General Public License as | ||
| 9 | ;; published by the Free Software Foundation, either version 3 of the | ||
| 10 | ;; License, or (at your option) any later version. | ||
| 11 | ;; | ||
| 12 | ;; This program is distributed in the hope that it will be useful, but | ||
| 13 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | ;; General Public License for more details. | ||
| 16 | ;; | ||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with this program. If not, see `http://www.gnu.org/licenses/'. | ||
| 19 | |||
| 20 | ;;; Commentary: | ||
| 21 | |||
| 22 | ;; A whole test run can be performed calling the command `auto-revert-test-all'. | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'ert) | ||
| 27 | (require 'autorevert) | ||
| 28 | (setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" | ||
| 29 | auto-revert-stop-on-user-input nil) | ||
| 30 | |||
| 31 | (defvar auto-revert--timeout 10) | ||
| 32 | |||
| 33 | (ert-deftest auto-revert-test00-auto-revert-mode () | ||
| 34 | "Check autorevert for a file." | ||
| 35 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | ||
| 36 | ;; file has been reverted. | ||
| 37 | (let ((tmpfile (make-temp-file "auto-revert-test")) | ||
| 38 | buf) | ||
| 39 | (unwind-protect | ||
| 40 | (progn | ||
| 41 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 42 | (narrow-to-region (point-max) (point-max))) | ||
| 43 | (write-region "any text" nil tmpfile nil 'no-message) | ||
| 44 | (setq buf (find-file-noselect tmpfile)) | ||
| 45 | (with-current-buffer buf | ||
| 46 | (should (string-equal (buffer-string) "any text")) | ||
| 47 | ;; `buffer-stale--default-function' checks for | ||
| 48 | ;; `verify-visited-file-modtime'. We must ensure that it | ||
| 49 | ;; returns nil. | ||
| 50 | (sleep-for 1) | ||
| 51 | (auto-revert-mode 1) | ||
| 52 | (should auto-revert-mode) | ||
| 53 | |||
| 54 | ;; Modify file. We wait for a second, in order to have | ||
| 55 | ;; another timestamp. | ||
| 56 | (sleep-for 1) | ||
| 57 | (write-region "another text" nil tmpfile nil 'no-message) | ||
| 58 | |||
| 59 | ;; Check, that the buffer has been reverted. | ||
| 60 | (with-timeout (auto-revert--timeout nil) | ||
| 61 | (with-current-buffer "*Messages*" | ||
| 62 | (while | ||
| 63 | (null (string-match | ||
| 64 | (format "Reverting buffer `%s'." (buffer-name buf)) | ||
| 65 | (buffer-string))) | ||
| 66 | (read-event nil nil 0.1)))) | ||
| 67 | (should (string-match "another text" (buffer-string))) | ||
| 68 | |||
| 69 | ;; When the buffer is modified, it shall not be reverted. | ||
| 70 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 71 | (narrow-to-region (point-max) (point-max))) | ||
| 72 | (set-buffer-modified-p t) | ||
| 73 | (sleep-for 1) | ||
| 74 | (write-region "any text" nil tmpfile nil 'no-message) | ||
| 75 | |||
| 76 | ;; Check, whether the buffer has been reverted. | ||
| 77 | (with-timeout (auto-revert--timeout nil) | ||
| 78 | (with-current-buffer "*Messages*" | ||
| 79 | (while | ||
| 80 | (null (string-match | ||
| 81 | (format "Reverting buffer `%s'." (buffer-name buf)) | ||
| 82 | (buffer-string))) | ||
| 83 | (read-event nil nil 0.1)))) | ||
| 84 | (should-not (string-match "any text" (buffer-string))))) | ||
| 85 | |||
| 86 | ;; Exit. | ||
| 87 | (with-current-buffer "*Messages*" (widen)) | ||
| 88 | (ignore-errors | ||
| 89 | (with-current-buffer buf (set-buffer-modified-p nil)) | ||
| 90 | (kill-buffer buf)) | ||
| 91 | (ignore-errors (delete-file tmpfile))))) | ||
| 92 | |||
| 93 | (ert-deftest auto-revert-test01-auto-revert-tail-mode () | ||
| 94 | "Check autorevert tail mode." | ||
| 95 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | ||
| 96 | ;; file has been reverted. | ||
| 97 | (let ((tmpfile (make-temp-file "auto-revert-test")) | ||
| 98 | buf) | ||
| 99 | (unwind-protect | ||
| 100 | (progn | ||
| 101 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 102 | (narrow-to-region (point-max) (point-max))) | ||
| 103 | (write-region "any text" nil tmpfile nil 'no-message) | ||
| 104 | (setq buf (find-file-noselect tmpfile)) | ||
| 105 | (with-current-buffer buf | ||
| 106 | ;; `buffer-stale--default-function' checks for | ||
| 107 | ;; `verify-visited-file-modtime'. We must ensure that it | ||
| 108 | ;; returns nil. | ||
| 109 | (sleep-for 1) | ||
| 110 | (auto-revert-tail-mode 1) | ||
| 111 | (should auto-revert-tail-mode) | ||
| 112 | (erase-buffer) | ||
| 113 | (insert "modified text\n") | ||
| 114 | (set-buffer-modified-p nil) | ||
| 115 | |||
| 116 | ;; Modify file. We wait for a second, in order to have | ||
| 117 | ;; another timestamp. | ||
| 118 | (sleep-for 1) | ||
| 119 | (write-region "another text" nil tmpfile 'append 'no-message) | ||
| 120 | |||
| 121 | ;; Check, that the buffer has been reverted. | ||
| 122 | (with-timeout (auto-revert--timeout nil) | ||
| 123 | (with-current-buffer "*Messages*" | ||
| 124 | (while | ||
| 125 | (null (string-match | ||
| 126 | (format "Reverting buffer `%s'." (buffer-name buf)) | ||
| 127 | (buffer-string))) | ||
| 128 | (read-event nil nil 0.1)))) | ||
| 129 | (should | ||
| 130 | (string-match "modified text\nanother text" (buffer-string))))) | ||
| 131 | |||
| 132 | ;; Exit. | ||
| 133 | (with-current-buffer "*Messages*" (widen)) | ||
| 134 | (ignore-errors (kill-buffer buf)) | ||
| 135 | (ignore-errors (delete-file tmpfile))))) | ||
| 136 | |||
| 137 | (ert-deftest auto-revert-test02-auto-revert-mode-dired () | ||
| 138 | "Check autorevert for dired." | ||
| 139 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | ||
| 140 | ;; file has been reverted. | ||
| 141 | (let* ((tmpfile (make-temp-file "auto-revert-test")) | ||
| 142 | (name (file-name-nondirectory tmpfile)) | ||
| 143 | buf) | ||
| 144 | (unwind-protect | ||
| 145 | (progn | ||
| 146 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 147 | (narrow-to-region (point-max) (point-max))) | ||
| 148 | (setq buf (dired-noselect temporary-file-directory)) | ||
| 149 | (with-current-buffer buf | ||
| 150 | ;; `buffer-stale--default-function' checks for | ||
| 151 | ;; `verify-visited-file-modtime'. We must ensure that it | ||
| 152 | ;; returns nil. | ||
| 153 | (sleep-for 1) | ||
| 154 | (auto-revert-mode 1) | ||
| 155 | (should auto-revert-mode) | ||
| 156 | (should | ||
| 157 | (string-match name (substring-no-properties (buffer-string)))) | ||
| 158 | |||
| 159 | ;; Delete file. We wait for a second, in order to have | ||
| 160 | ;; another timestamp. | ||
| 161 | (sleep-for 1) | ||
| 162 | (delete-file tmpfile) | ||
| 163 | |||
| 164 | ;; Check, that the buffer has been reverted. | ||
| 165 | (with-timeout (auto-revert--timeout nil) | ||
| 166 | (with-current-buffer "*Messages*" | ||
| 167 | (while | ||
| 168 | (null (string-match | ||
| 169 | (format "Reverting buffer `%s'." (buffer-name buf)) | ||
| 170 | (buffer-string))) | ||
| 171 | (read-event nil nil 0.1)))) | ||
| 172 | (should | ||
| 173 | (null | ||
| 174 | (string-match name (substring-no-properties (buffer-string))))) | ||
| 175 | |||
| 176 | ;; When the dired buffer is modified, it shall not be | ||
| 177 | ;; reverted. This is questionable, see Bug#20943. | ||
| 178 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 179 | (narrow-to-region (point-max) (point-max))) | ||
| 180 | (set-buffer-modified-p t) | ||
| 181 | (sleep-for 1) | ||
| 182 | (write-region "any text" nil tmpfile nil 'no-message) | ||
| 183 | |||
| 184 | ;; Check, that the buffer hasn't been reverted. | ||
| 185 | (with-timeout (auto-revert--timeout nil) | ||
| 186 | (with-current-buffer "*Messages*" | ||
| 187 | (while | ||
| 188 | (null (string-match | ||
| 189 | (format "Reverting buffer `%s'." (buffer-name buf)) | ||
| 190 | (buffer-string))) | ||
| 191 | (read-event nil nil 0.1)))) | ||
| 192 | (should-not | ||
| 193 | (string-match name (substring-no-properties (buffer-string)))))) | ||
| 194 | |||
| 195 | ;; Exit. | ||
| 196 | (with-current-buffer "*Messages*" (widen)) | ||
| 197 | (ignore-errors | ||
| 198 | (with-current-buffer buf (set-buffer-modified-p nil)) | ||
| 199 | (kill-buffer buf)) | ||
| 200 | (ignore-errors (delete-file tmpfile))))) | ||
| 201 | |||
| 202 | (defun auto-revert-test-all (&optional interactive) | ||
| 203 | "Run all tests for \\[auto-revert]." | ||
| 204 | (interactive "p") | ||
| 205 | (if interactive | ||
| 206 | (ert-run-tests-interactively "^auto-revert-") | ||
| 207 | (ert-run-tests-batch "^auto-revert-"))) | ||
| 208 | |||
| 209 | (provide 'auto-revert-tests) | ||
| 210 | ;;; auto-revert-tests.el ends here | ||