diff options
| author | Michael Albinus | 2016-04-19 11:05:55 +0200 |
|---|---|---|
| committer | Michael Albinus | 2016-04-19 11:05:55 +0200 |
| commit | ed54b3ff9760e7b73172aa296949dfcc7aba106e (patch) | |
| tree | 07f13d97c30229d493233c7259707dd726b49791 /test | |
| parent | c456627ffaf4e73e979883b56117cb91f164936b (diff) | |
| download | emacs-ed54b3ff9760e7b73172aa296949dfcc7aba106e.tar.gz emacs-ed54b3ff9760e7b73172aa296949dfcc7aba106e.zip | |
autorevert: Resume with polling if file is deleted
* lisp/autorevert.el: Use consistent wording in comments and
docstrings.
(auto-revert-mode): Add local function to `kill-buffer-hook'.
(auto-revert-notify-handler): Improve handling of `stopped' event.
* test/lisp/autorevert-tests.el
(auto-revert-test02-auto-revert-deleted-file): New test.
(auto-revert-test03-auto-revert-tail-mode)
(auto-revert-test04-auto-revert-mode-dired): Rename them.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/autorevert-tests.el | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/test/lisp/autorevert-tests.el b/test/lisp/autorevert-tests.el index a6f8cb29563..2f951c0c9aa 100644 --- a/test/lisp/autorevert-tests.el +++ b/test/lisp/autorevert-tests.el | |||
| @@ -156,7 +156,76 @@ | |||
| 156 | (ignore-errors (delete-directory tmpdir1 'recursive)) | 156 | (ignore-errors (delete-directory tmpdir1 'recursive)) |
| 157 | (ignore-errors (delete-directory tmpdir2 'recursive))))) | 157 | (ignore-errors (delete-directory tmpdir2 'recursive))))) |
| 158 | 158 | ||
| 159 | (ert-deftest auto-revert-test02-auto-revert-tail-mode () | 159 | ;; This is inspired by Bug#23276. |
| 160 | (ert-deftest auto-revert-test02-auto-revert-deleted-file () | ||
| 161 | "Check autorevert for a deleted file." | ||
| 162 | :tags '(:expensive-test) | ||
| 163 | |||
| 164 | (let ((tmpfile (make-temp-file "auto-revert-test")) | ||
| 165 | buf) | ||
| 166 | (unwind-protect | ||
| 167 | (progn | ||
| 168 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 169 | (narrow-to-region (point-max) (point-max))) | ||
| 170 | (write-region "any text" nil tmpfile nil 'no-message) | ||
| 171 | (setq buf (find-file-noselect tmpfile)) | ||
| 172 | (with-current-buffer buf | ||
| 173 | (should (string-equal (buffer-string) "any text")) | ||
| 174 | ;; `buffer-stale--default-function' checks for | ||
| 175 | ;; `verify-visited-file-modtime'. We must ensure that | ||
| 176 | ;; it returns nil. | ||
| 177 | (sleep-for 1) | ||
| 178 | (auto-revert-mode 1) | ||
| 179 | (should auto-revert-mode) | ||
| 180 | |||
| 181 | ;; Remove file while reverting. We simulate this by | ||
| 182 | ;; modifying `before-revert-hook'. | ||
| 183 | (add-hook | ||
| 184 | 'before-revert-hook | ||
| 185 | (lambda () (delete-file buffer-file-name)) | ||
| 186 | nil t) | ||
| 187 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 188 | (narrow-to-region (point-max) (point-max))) | ||
| 189 | (sleep-for 1) | ||
| 190 | (write-region "another text" nil tmpfile nil 'no-message) | ||
| 191 | |||
| 192 | ;; Check, that the buffer hasn't been reverted. File | ||
| 193 | ;; notification should be disabled, falling back to | ||
| 194 | ;; polling. | ||
| 195 | (auto-revert--wait-for-revert buf) | ||
| 196 | (should (string-match "any text" (buffer-string))) | ||
| 197 | (should-not auto-revert-use-notify) | ||
| 198 | |||
| 199 | ;; Once the file has been recreated, the buffer shall be | ||
| 200 | ;; reverted. | ||
| 201 | (kill-local-variable 'before-revert-hook) | ||
| 202 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 203 | (narrow-to-region (point-max) (point-max))) | ||
| 204 | (sleep-for 1) | ||
| 205 | (write-region "another text" nil tmpfile nil 'no-message) | ||
| 206 | |||
| 207 | ;; Check, that the buffer has been reverted. | ||
| 208 | (auto-revert--wait-for-revert buf) | ||
| 209 | (should (string-match "another text" (buffer-string))) | ||
| 210 | |||
| 211 | ;; An empty file shall still be reverted. | ||
| 212 | (with-current-buffer (get-buffer-create "*Messages*") | ||
| 213 | (narrow-to-region (point-max) (point-max))) | ||
| 214 | (sleep-for 1) | ||
| 215 | (write-region "" nil tmpfile nil 'no-message) | ||
| 216 | |||
| 217 | ;; Check, that the buffer has been reverted. | ||
| 218 | (auto-revert--wait-for-revert buf) | ||
| 219 | (should (string-equal "" (buffer-string))))) | ||
| 220 | |||
| 221 | ;; Exit. | ||
| 222 | (with-current-buffer "*Messages*" (widen)) | ||
| 223 | (ignore-errors | ||
| 224 | (with-current-buffer buf (set-buffer-modified-p nil)) | ||
| 225 | (kill-buffer buf)) | ||
| 226 | (ignore-errors (delete-file tmpfile))))) | ||
| 227 | |||
| 228 | (ert-deftest auto-revert-test03-auto-revert-tail-mode () | ||
| 160 | "Check autorevert tail mode." | 229 | "Check autorevert tail mode." |
| 161 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | 230 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the |
| 162 | ;; file has been reverted. | 231 | ;; file has been reverted. |
| @@ -194,7 +263,7 @@ | |||
| 194 | (ignore-errors (kill-buffer buf)) | 263 | (ignore-errors (kill-buffer buf)) |
| 195 | (ignore-errors (delete-file tmpfile))))) | 264 | (ignore-errors (delete-file tmpfile))))) |
| 196 | 265 | ||
| 197 | (ert-deftest auto-revert-test03-auto-revert-mode-dired () | 266 | (ert-deftest auto-revert-test04-auto-revert-mode-dired () |
| 198 | "Check autorevert for dired." | 267 | "Check autorevert for dired." |
| 199 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | 268 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the |
| 200 | ;; file has been reverted. | 269 | ;; file has been reverted. |