diff options
| author | Michael Albinus | 2019-05-03 17:18:13 +0200 |
|---|---|---|
| committer | Michael Albinus | 2019-05-03 17:18:13 +0200 |
| commit | d0fe28cb1d33daa059990d62556a8de20a385387 (patch) | |
| tree | ae2dab44a36a6497d034d4a4dc4e08411bcbd9c9 /test | |
| parent | 24a1d5a0b5c0debd8256d71242bfa6f8448bf5af (diff) | |
| download | emacs-d0fe28cb1d33daa059990d62556a8de20a385387.tar.gz emacs-d0fe28cb1d33daa059990d62556a8de20a385387.zip | |
Add tests for remote files in auto-revert-tests
* lisp/autorevert.el (auto-revert-debug): New defvar.
(auto-revert-notify-handler): Write traces.
* lisp/filenotify.el (file-notify-debug): New defvar.
(file-notify-handle-event, file-notify-callback): Write traces.
* lisp/net/tramp-sh.el (tramp-sh-handle-vc-registered):
Handle nil `vc-handled-backends'.
* test/lisp/autorevert-tests.el
(auto-revert-test-remote-temporary-file-directory): New defconst.
Handle also $REMOTE_FILE_NOTIFY_LIBRARY.
(auto-revert--test-enabled-remote-checked): New defvar.
(auto-revert--test-enabled-remote): New defun.
(auto-revert--wait-for-revert): Rewrite without timeout.
(auto-revert--deftest-remote): New defmacro.
(auto-revert-test01-auto-revert-several-files):
(auto-revert-test02-auto-revert-deleted-file): Adapt for remote files.
(auto-revert-test02-auto-revert-deleted-file):
Use `auto-revert-debug' for debug messages.
(auto-revert-test00-auto-revert-mode-remote)
(auto-revert-test01-auto-revert-several-files-mode-remote)
(auto-revert-test02-auto-revert-deleted-file-mode-remote)
(auto-revert-test03-auto-revert-tail-mode-mode-remote)
(auto-revert-test04-auto-revert-mode-dired-mode-remote): New tests.
* test/lisp/filenotify-tests.el (file-notify--test-event-handler):
Use `file-notify-debug' for debug messages.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/autorevert-tests.el | 145 | ||||
| -rw-r--r-- | test/lisp/filenotify-tests.el | 8 |
2 files changed, 138 insertions, 15 deletions
diff --git a/test/lisp/autorevert-tests.el b/test/lisp/autorevert-tests.el index 6e8219d238d..d98c11658fe 100644 --- a/test/lisp/autorevert-tests.el +++ b/test/lisp/autorevert-tests.el | |||
| @@ -19,6 +19,33 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Commentary: | 20 | ;;; Commentary: |
| 21 | 21 | ||
| 22 | ;; Some of the tests require access to a remote host files. Since | ||
| 23 | ;; this could be problematic, a mock-up connection method "mock" is | ||
| 24 | ;; used. Emulating a remote connection, it simply calls "sh -i". | ||
| 25 | ;; Tramp's file name handlers still run, so this test is sufficient | ||
| 26 | ;; except for connection establishing. | ||
| 27 | |||
| 28 | ;; If you want to test a real Tramp connection, set | ||
| 29 | ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order to | ||
| 30 | ;; overwrite the default value. If you want to skip tests accessing a | ||
| 31 | ;; remote host, set this environment variable to "/dev/null" or | ||
| 32 | ;; whatever is appropriate on your system. | ||
| 33 | |||
| 34 | ;; For the remote file-notify library, Tramp checks for the existence | ||
| 35 | ;; of a respective command. The first command found is used. In | ||
| 36 | ;; order to use a dedicated one, the environment variable | ||
| 37 | ;; $REMOTE_FILE_NOTIFY_LIBRARY shall be set, possible values are | ||
| 38 | ;; "inotifywait", "gio-monitor" and "gvfs-monitor-dir". | ||
| 39 | |||
| 40 | ;; Local file-notify libraries are auto-detected during Emacs | ||
| 41 | ;; configuration. This can be changed with a respective configuration | ||
| 42 | ;; argument, like | ||
| 43 | ;; | ||
| 44 | ;; --with-file-notification=inotify | ||
| 45 | ;; --with-file-notification=kqueue | ||
| 46 | ;; --with-file-notification=gfile | ||
| 47 | ;; --with-file-notification=w32 | ||
| 48 | |||
| 22 | ;; A whole test run can be performed calling the command `auto-revert-test-all'. | 49 | ;; A whole test run can be performed calling the command `auto-revert-test-all'. |
| 23 | 50 | ||
| 24 | ;;; Code: | 51 | ;;; Code: |
| @@ -26,8 +53,14 @@ | |||
| 26 | (require 'ert) | 53 | (require 'ert) |
| 27 | (require 'ert-x) | 54 | (require 'ert-x) |
| 28 | (require 'autorevert) | 55 | (require 'autorevert) |
| 29 | (setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" | 56 | (require 'tramp) |
| 30 | auto-revert-stop-on-user-input nil) | 57 | |
| 58 | (setq auto-revert-debug nil | ||
| 59 | auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" | ||
| 60 | auto-revert-stop-on-user-input nil | ||
| 61 | file-notify-debug nil | ||
| 62 | tramp-verbose 0 | ||
| 63 | tramp-message-show-message nil) | ||
| 31 | 64 | ||
| 32 | (defconst auto-revert--timeout 10 | 65 | (defconst auto-revert--timeout 10 |
| 33 | "Time to wait for a message.") | 66 | "Time to wait for a message.") |
| @@ -35,19 +68,88 @@ | |||
| 35 | (defvar auto-revert--messages nil | 68 | (defvar auto-revert--messages nil |
| 36 | "Used to collect messages issued during a section of a test.") | 69 | "Used to collect messages issued during a section of a test.") |
| 37 | 70 | ||
| 71 | ;; There is no default value on w32 systems, which could work out of the box. | ||
| 72 | (defconst auto-revert-test-remote-temporary-file-directory | ||
| 73 | (cond | ||
| 74 | ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY")) | ||
| 75 | ((eq system-type 'windows-nt) null-device) | ||
| 76 | (t (add-to-list | ||
| 77 | 'tramp-methods | ||
| 78 | '("mock" | ||
| 79 | (tramp-login-program "sh") | ||
| 80 | (tramp-login-args (("-i"))) | ||
| 81 | (tramp-remote-shell "/bin/sh") | ||
| 82 | (tramp-remote-shell-args ("-c")) | ||
| 83 | (tramp-connection-timeout 10))) | ||
| 84 | (add-to-list | ||
| 85 | 'tramp-default-host-alist | ||
| 86 | `("\\`mock\\'" nil ,(system-name))) | ||
| 87 | ;; Emacs' Makefile sets $HOME to a nonexistent value. Needed in | ||
| 88 | ;; batch mode only, therefore. `temporary-file-directory' might | ||
| 89 | ;; be quoted, so we unquote it just in case. | ||
| 90 | (unless (and (null noninteractive) (file-directory-p "~/")) | ||
| 91 | (setenv "HOME" (file-name-unquote temporary-file-directory))) | ||
| 92 | (format "/mock::%s" temporary-file-directory))) | ||
| 93 | "Temporary directory for Tramp tests.") | ||
| 94 | |||
| 95 | ;; Filter suppressed remote file-notify libraries. | ||
| 96 | (when (stringp (getenv "REMOTE_FILE_NOTIFY_LIBRARY")) | ||
| 97 | (dolist (lib '("inotifywait" "gio-monitor" "gvfs-monitor-dir")) | ||
| 98 | (unless (string-equal (getenv "REMOTE_FILE_NOTIFY_LIBRARY") lib) | ||
| 99 | (add-to-list 'tramp-connection-properties `(nil ,lib nil))))) | ||
| 100 | |||
| 101 | (defvar auto-revert--test-enabled-remote-checked nil | ||
| 102 | "Cached result of `auto-revert--test-enabled-remote'. | ||
| 103 | If the function did run, the value is a cons cell, the `cdr' | ||
| 104 | being the result.") | ||
| 105 | |||
| 106 | (defun auto-revert--test-enabled-remote () | ||
| 107 | "Whether remote file access is enabled." | ||
| 108 | (unless (consp auto-revert--test-enabled-remote-checked) | ||
| 109 | (setq | ||
| 110 | auto-revert--test-enabled-remote-checked | ||
| 111 | (cons | ||
| 112 | t (ignore-errors | ||
| 113 | (and | ||
| 114 | (file-remote-p auto-revert-test-remote-temporary-file-directory) | ||
| 115 | (file-directory-p auto-revert-test-remote-temporary-file-directory) | ||
| 116 | (file-writable-p | ||
| 117 | auto-revert-test-remote-temporary-file-directory)))))) | ||
| 118 | ;; Return result. | ||
| 119 | (cdr auto-revert--test-enabled-remote-checked)) | ||
| 120 | |||
| 38 | (defun auto-revert--wait-for-revert (buffer) | 121 | (defun auto-revert--wait-for-revert (buffer) |
| 39 | "Wait until a message reports reversion of BUFFER. | 122 | "Wait until a message reports reversion of BUFFER. |
| 40 | This expects `auto-revert--messages' to be bound by | 123 | This expects `auto-revert--messages' to be bound by |
| 41 | `ert-with-message-capture' before calling." | 124 | `ert-with-message-capture' before calling." |
| 42 | (with-timeout (auto-revert--timeout nil) | 125 | ;; Remote files do not cooperate well with timers. So we count ourselves. |
| 43 | (while | 126 | (let ((ct (current-time))) |
| 44 | (null (string-match | 127 | (while (and (< (float-time (time-subtract (current-time) ct)) |
| 45 | (format-message "Reverting buffer `%s'." (buffer-name buffer)) | 128 | auto-revert--timeout) |
| 46 | auto-revert--messages)) | 129 | (null (string-match |
| 130 | (format-message | ||
| 131 | "Reverting buffer `%s'\\." (buffer-name buffer)) | ||
| 132 | auto-revert--messages))) | ||
| 47 | (if (with-current-buffer buffer auto-revert-use-notify) | 133 | (if (with-current-buffer buffer auto-revert-use-notify) |
| 48 | (read-event nil nil 0.1) | 134 | (read-event nil nil 0.1) |
| 49 | (sleep-for 0.1))))) | 135 | (sleep-for 0.1))))) |
| 50 | 136 | ||
| 137 | (defmacro auto-revert--deftest-remote (test docstring) | ||
| 138 | "Define ert `TEST-remote' for remote files." | ||
| 139 | (declare (indent 1)) | ||
| 140 | `(ert-deftest ,(intern (concat (symbol-name test) "-remote")) () | ||
| 141 | ,docstring | ||
| 142 | :tags '(:expensive-test) | ||
| 143 | (let ((temporary-file-directory | ||
| 144 | auto-revert-test-remote-temporary-file-directory) | ||
| 145 | (auto-revert-remote-files t) | ||
| 146 | (ert-test (ert-get-test ',test)) | ||
| 147 | vc-handled-backends) | ||
| 148 | (skip-unless (auto-revert--test-enabled-remote)) | ||
| 149 | (tramp-cleanup-connection | ||
| 150 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password) | ||
| 151 | (funcall (ert-test-body ert-test))))) | ||
| 152 | |||
| 51 | (ert-deftest auto-revert-test00-auto-revert-mode () | 153 | (ert-deftest auto-revert-test00-auto-revert-mode () |
| 52 | "Check autorevert for a file." | 154 | "Check autorevert for a file." |
| 53 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | 155 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the |
| @@ -93,13 +195,16 @@ This expects `auto-revert--messages' to be bound by | |||
| 93 | (kill-buffer buf)) | 195 | (kill-buffer buf)) |
| 94 | (ignore-errors (delete-file tmpfile))))) | 196 | (ignore-errors (delete-file tmpfile))))) |
| 95 | 197 | ||
| 198 | (auto-revert--deftest-remote auto-revert-test00-auto-revert-mode | ||
| 199 | "Check autorevert for a remote file.") | ||
| 200 | |||
| 96 | ;; This is inspired by Bug#21841. | 201 | ;; This is inspired by Bug#21841. |
| 97 | (ert-deftest auto-revert-test01-auto-revert-several-files () | 202 | (ert-deftest auto-revert-test01-auto-revert-several-files () |
| 98 | "Check autorevert for several files at once." | 203 | "Check autorevert for several files at once." |
| 99 | :tags '(:expensive-test) | 204 | :tags '(:expensive-test) |
| 100 | (skip-unless (executable-find "cp")) | 205 | (skip-unless (executable-find "cp" (file-remote-p temporary-file-directory))) |
| 101 | 206 | ||
| 102 | (let* ((cp (executable-find "cp")) | 207 | (let* ((cp (executable-find "cp" (file-remote-p temporary-file-directory))) |
| 103 | (tmpdir1 (make-temp-file "auto-revert-test" 'dir)) | 208 | (tmpdir1 (make-temp-file "auto-revert-test" 'dir)) |
| 104 | (tmpdir2 (make-temp-file "auto-revert-test" 'dir)) | 209 | (tmpdir2 (make-temp-file "auto-revert-test" 'dir)) |
| 105 | (tmpfile1 | 210 | (tmpfile1 |
| @@ -139,7 +244,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 139 | ;; Strange, that `copy-directory' does not work as expected. | 244 | ;; Strange, that `copy-directory' does not work as expected. |
| 140 | ;; The following shell command is not portable on all | 245 | ;; The following shell command is not portable on all |
| 141 | ;; platforms, unfortunately. | 246 | ;; platforms, unfortunately. |
| 142 | (shell-command (format "%s -f %s/* %s" cp tmpdir2 tmpdir1)) | 247 | (shell-command |
| 248 | (format "%s -f %s/* %s" | ||
| 249 | cp (file-local-name tmpdir2) (file-local-name tmpdir1))) | ||
| 143 | 250 | ||
| 144 | ;; Check, that the buffers have been reverted. | 251 | ;; Check, that the buffers have been reverted. |
| 145 | (dolist (buf (list buf1 buf2)) | 252 | (dolist (buf (list buf1 buf2)) |
| @@ -155,6 +262,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 155 | (ignore-errors (delete-directory tmpdir1 'recursive)) | 262 | (ignore-errors (delete-directory tmpdir1 'recursive)) |
| 156 | (ignore-errors (delete-directory tmpdir2 'recursive))))) | 263 | (ignore-errors (delete-directory tmpdir2 'recursive))))) |
| 157 | 264 | ||
| 265 | (auto-revert--deftest-remote auto-revert-test01-auto-revert-several-files | ||
| 266 | "Check autorevert for several remote files at once.") | ||
| 267 | |||
| 158 | ;; This is inspired by Bug#23276. | 268 | ;; This is inspired by Bug#23276. |
| 159 | (ert-deftest auto-revert-test02-auto-revert-deleted-file () | 269 | (ert-deftest auto-revert-test02-auto-revert-deleted-file () |
| 160 | "Check autorevert for a deleted file." | 270 | "Check autorevert for a deleted file." |
| @@ -185,8 +295,8 @@ This expects `auto-revert--messages' to be bound by | |||
| 185 | (add-hook | 295 | (add-hook |
| 186 | 'before-revert-hook | 296 | 'before-revert-hook |
| 187 | (lambda () | 297 | (lambda () |
| 188 | ;; Temporarily. | 298 | (when auto-revert-debug |
| 189 | (message "%s deleted" buffer-file-name) | 299 | (message "%s deleted" buffer-file-name)) |
| 190 | (delete-file buffer-file-name)) | 300 | (delete-file buffer-file-name)) |
| 191 | nil t) | 301 | nil t) |
| 192 | 302 | ||
| @@ -199,7 +309,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 199 | ;; polling. | 309 | ;; polling. |
| 200 | (should (string-match "any text" (buffer-string))) | 310 | (should (string-match "any text" (buffer-string))) |
| 201 | ;; With w32notify, the 'stopped' events are not sent. | 311 | ;; With w32notify, the 'stopped' events are not sent. |
| 312 | ;; Same for remote file name handlers. Why? | ||
| 202 | (or (eq file-notify--library 'w32notify) | 313 | (or (eq file-notify--library 'w32notify) |
| 314 | (file-remote-p temporary-file-directory) | ||
| 203 | (should-not auto-revert-notify-watch-descriptor)) | 315 | (should-not auto-revert-notify-watch-descriptor)) |
| 204 | 316 | ||
| 205 | ;; Once the file has been recreated, the buffer shall be | 317 | ;; Once the file has been recreated, the buffer shall be |
| @@ -231,6 +343,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 231 | (kill-buffer buf)) | 343 | (kill-buffer buf)) |
| 232 | (ignore-errors (delete-file tmpfile))))) | 344 | (ignore-errors (delete-file tmpfile))))) |
| 233 | 345 | ||
| 346 | (auto-revert--deftest-remote auto-revert-test02-auto-revert-deleted-file | ||
| 347 | "Check autorevert for a deleted remote file.") | ||
| 348 | |||
| 234 | (ert-deftest auto-revert-test03-auto-revert-tail-mode () | 349 | (ert-deftest auto-revert-test03-auto-revert-tail-mode () |
| 235 | "Check autorevert tail mode." | 350 | "Check autorevert tail mode." |
| 236 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | 351 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the |
| @@ -266,6 +381,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 266 | (ignore-errors (kill-buffer buf)) | 381 | (ignore-errors (kill-buffer buf)) |
| 267 | (ignore-errors (delete-file tmpfile))))) | 382 | (ignore-errors (delete-file tmpfile))))) |
| 268 | 383 | ||
| 384 | (auto-revert--deftest-remote auto-revert-test03-auto-revert-tail-mode | ||
| 385 | "Check remote autorevert tail mode.") | ||
| 386 | |||
| 269 | (ert-deftest auto-revert-test04-auto-revert-mode-dired () | 387 | (ert-deftest auto-revert-test04-auto-revert-mode-dired () |
| 270 | "Check autorevert for dired." | 388 | "Check autorevert for dired." |
| 271 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the | 389 | ;; `auto-revert-buffers' runs every 5". And we must wait, until the |
| @@ -314,6 +432,9 @@ This expects `auto-revert--messages' to be bound by | |||
| 314 | (kill-buffer buf)) | 432 | (kill-buffer buf)) |
| 315 | (ignore-errors (delete-file tmpfile))))) | 433 | (ignore-errors (delete-file tmpfile))))) |
| 316 | 434 | ||
| 435 | (auto-revert--deftest-remote auto-revert-test04-auto-revert-mode-dired | ||
| 436 | "Check remote autorevert for dired.") | ||
| 437 | |||
| 317 | (defun auto-revert-test-all (&optional interactive) | 438 | (defun auto-revert-test-all (&optional interactive) |
| 318 | "Run all tests for \\[auto-revert]." | 439 | "Run all tests for \\[auto-revert]." |
| 319 | (interactive "p") | 440 | (interactive "p") |
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index a40dc720786..af2d0b33e08 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el | |||
| @@ -195,7 +195,8 @@ Return nil when any other file notification watch is still active." | |||
| 195 | file-notify--test-events nil | 195 | file-notify--test-events nil |
| 196 | file-notify--test-monitors nil)) | 196 | file-notify--test-monitors nil)) |
| 197 | 197 | ||
| 198 | (setq password-cache-expiry nil | 198 | (setq file-notify-debug nil |
| 199 | password-cache-expiry nil | ||
| 199 | tramp-verbose 0 | 200 | tramp-verbose 0 |
| 200 | tramp-message-show-message nil) | 201 | tramp-message-show-message nil) |
| 201 | 202 | ||
| @@ -515,8 +516,9 @@ and the event to `file-notify--test-events'." | |||
| 515 | (unless (string-match | 516 | (unless (string-match |
| 516 | (regexp-quote ".#") | 517 | (regexp-quote ".#") |
| 517 | (file-notify--event-file-name file-notify--test-event)) | 518 | (file-notify--event-file-name file-notify--test-event)) |
| 518 | ;;(message "file-notify--test-event-handler result: %s event: %S" | 519 | (when file-notify-debug |
| 519 | ;;(null (ert-test-failed-p result)) file-notify--test-event) | 520 | (message "file-notify--test-event-handler result: %s event: %S" |
| 521 | (null (ert-test-failed-p result)) file-notify--test-event)) | ||
| 520 | (setq file-notify--test-events | 522 | (setq file-notify--test-events |
| 521 | (append file-notify--test-events `(,file-notify--test-event)) | 523 | (append file-notify--test-events `(,file-notify--test-event)) |
| 522 | file-notify--test-results | 524 | file-notify--test-results |