From: Michael Albinus Date: Tue, 2 Jun 2015 21:47:17 +0000 (+0200) Subject: Ensure, that autorevert works for remote files in file-notify-tests.el X-Git-Tag: emacs-25.0.90~1892 X-Git-Url: https://code.delx.au/gnu-emacs/commitdiff_plain/420b293c7da575f800a5048e245c25905472697f Ensure, that autorevert works for remote files in file-notify-tests.el * test/automated/file-notify-tests.el (file-notify--test-desc): New defvar. (file-notify--test-remote-enabled) (file-notify-test00-availability, file-notify-test01-add-watch) (file-notify-test02-events): Use it. (file-notify--test-event-test): Check proper descriptor. (file-notify-test03-autorevert): Ensure, that `visited-file-modtime' has changed. Fixes: debbugs:20392 --- diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el index 46d287fe60..a45eff7395 100644 --- a/test/automated/file-notify-tests.el +++ b/test/automated/file-notify-tests.el @@ -57,6 +57,7 @@ (defvar file-notify--test-tmpfile nil) (defvar file-notify--test-tmpfile1 nil) +(defvar file-notify--test-desc nil) (defvar file-notify--test-results nil) (defvar file-notify--test-event nil) @@ -84,20 +85,21 @@ being the result.") (defun file-notify--test-remote-enabled () "Whether remote file notification is enabled." (unless (consp file-notify--test-remote-enabled-checked) - (let (desc) - (unwind-protect - (ignore-errors - (and - (file-remote-p file-notify-test-remote-temporary-file-directory) - (file-directory-p file-notify-test-remote-temporary-file-directory) - (file-writable-p file-notify-test-remote-temporary-file-directory) - (setq desc - (file-notify-add-watch - file-notify-test-remote-temporary-file-directory - '(change) 'ignore)))) - ;; Unwind forms. - (setq file-notify--test-remote-enabled-checked (cons t desc)) - (when desc (file-notify-rm-watch desc))))) + (unwind-protect + (ignore-errors + (and + (file-remote-p file-notify-test-remote-temporary-file-directory) + (file-directory-p file-notify-test-remote-temporary-file-directory) + (file-writable-p file-notify-test-remote-temporary-file-directory) + (setq file-notify--test-desc + (file-notify-add-watch + file-notify-test-remote-temporary-file-directory + '(change) 'ignore)))) + ;; Unwind forms. + (setq file-notify--test-remote-enabled-checked + (cons t file-notify--test-desc)) + (when file-notify--test-desc + (file-notify-rm-watch file-notify--test-desc)))) ;; Return result. (cdr file-notify--test-remote-enabled-checked)) @@ -116,11 +118,11 @@ being the result.") (ert-deftest file-notify-test00-availability () "Test availability of `file-notify'." (skip-unless (file-notify--test-local-enabled)) - (let (desc) - ;; Check, that different valid parameters are accepted. - (should (setq desc (file-notify-add-watch - temporary-file-directory '(change) 'ignore))) - (file-notify-rm-watch desc))) + ;; Check, that different valid parameters are accepted. + (should + (setq file-notify--test-desc + (file-notify-add-watch temporary-file-directory '(change) 'ignore))) + (file-notify-rm-watch file-notify--test-desc)) (file-notify--deftest-remote file-notify-test00-availability "Test availability of `file-notify' for remote files.") @@ -128,34 +130,37 @@ being the result.") (ert-deftest file-notify-test01-add-watch () "Check `file-notify-add-watch'." (skip-unless (file-notify--test-local-enabled)) - (let (desc) - ;; Check, that different valid parameters are accepted. - (should (setq desc (file-notify-add-watch - temporary-file-directory '(change) 'ignore))) - (file-notify-rm-watch desc) - (should (setq desc (file-notify-add-watch - temporary-file-directory - '(attribute-change) 'ignore))) - (file-notify-rm-watch desc) - (should (setq desc (file-notify-add-watch - temporary-file-directory - '(change attribute-change) 'ignore))) - (file-notify-rm-watch desc) - - ;; Check error handling. - (should-error (file-notify-add-watch 1 2 3 4) - :type 'wrong-number-of-arguments) - (should - (equal (should-error (file-notify-add-watch 1 2 3)) - '(wrong-type-argument 1))) - (should - (equal (should-error (file-notify-add-watch - temporary-file-directory 2 3)) - '(wrong-type-argument 2))) - (should - (equal (should-error (file-notify-add-watch - temporary-file-directory '(change) 3)) - '(wrong-type-argument 3))))) + ;; Check, that different valid parameters are accepted. + (should + (setq file-notify--test-desc + (file-notify-add-watch temporary-file-directory '(change) 'ignore))) + (file-notify-rm-watch file-notify--test-desc) + (should + (setq file-notify--test-desc + (file-notify-add-watch + temporary-file-directory '(attribute-change) 'ignore))) + (file-notify-rm-watch file-notify--test-desc) + (should + (setq file-notify--test-desc + (file-notify-add-watch + temporary-file-directory '(change attribute-change) 'ignore))) + (file-notify-rm-watch file-notify--test-desc) + + ;; Check error handling. + (should-error (file-notify-add-watch 1 2 3 4) + :type 'wrong-number-of-arguments) + (should + (equal (should-error + (file-notify-add-watch 1 2 3)) + '(wrong-type-argument 1))) + (should + (equal (should-error + (file-notify-add-watch temporary-file-directory 2 3)) + '(wrong-type-argument 2))) + (should + (equal (should-error + (file-notify-add-watch temporary-file-directory '(change) 3)) + '(wrong-type-argument 3)))) (file-notify--deftest-remote file-notify-test01-add-watch "Check `file-notify-add-watch' for remote files.") @@ -165,6 +170,8 @@ being the result.") We cannot pass arguments, so we assume that `file-notify--test-event' is bound somewhere." ;(message "Event %S" file-notify--test-event) + ;; Check the descriptor. + (should (equal (car file-notify--test-event) file-notify--test-desc)) ;; Check the file name. (should (string-equal (file-notify--event-file-name file-notify--test-event) @@ -199,42 +206,42 @@ TIMEOUT is the maximum time to wait for, in seconds." (ert-deftest file-notify-test02-events () "Check file creation/removal notifications." (skip-unless (file-notify--test-local-enabled)) - (let (desc) - (unwind-protect - (progn - (setq file-notify--test-results nil - file-notify--test-tmpfile (file-notify--test-make-temp-name) - file-notify--test-tmpfile1 (file-notify--test-make-temp-name) - desc - (file-notify-add-watch - file-notify--test-tmpfile - '(change) 'file-notify--test-event-handler)) - - ;; Check creation and removal. - (write-region - "any text" nil file-notify--test-tmpfile nil 'no-message) - (delete-file file-notify--test-tmpfile) - (sleep-for 0.1) - - ;; Check copy and rename. - (write-region - "any text" nil file-notify--test-tmpfile nil 'no-message) - (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) - (delete-file file-notify--test-tmpfile) - (delete-file file-notify--test-tmpfile1) - (sleep-for 0.1) - - (write-region - "any text" nil file-notify--test-tmpfile nil 'no-message) - (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) - (delete-file file-notify--test-tmpfile1) - (sleep-for 0.1)) - - ;; Wait for events, and exit. - (file-notify--wait-for-events 5 file-notify--test-results) - (file-notify-rm-watch desc) - (ignore-errors (delete-file file-notify--test-tmpfile)) - (ignore-errors (delete-file file-notify--test-tmpfile1)))) + (unwind-protect + (progn + (setq file-notify--test-results nil + file-notify--test-tmpfile (file-notify--test-make-temp-name) + file-notify--test-tmpfile1 (file-notify--test-make-temp-name) + file-notify--test-desc + (file-notify-add-watch + file-notify--test-tmpfile + '(change) 'file-notify--test-event-handler)) + (should file-notify--test-desc) + + ;; Check creation and removal. + (write-region + "any text" nil file-notify--test-tmpfile nil 'no-message) + (delete-file file-notify--test-tmpfile) + (sleep-for 0.1) + + ;; Check copy and rename. + (write-region + "any text" nil file-notify--test-tmpfile nil 'no-message) + (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) + (delete-file file-notify--test-tmpfile) + (delete-file file-notify--test-tmpfile1) + (sleep-for 0.1) + + (write-region + "any text" nil file-notify--test-tmpfile nil 'no-message) + (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) + (delete-file file-notify--test-tmpfile1) + (sleep-for 0.1)) + + ;; Wait for events, and exit. + (file-notify--wait-for-events 5 file-notify--test-results) + (file-notify-rm-watch file-notify--test-desc) + (ignore-errors (delete-file file-notify--test-tmpfile)) + (ignore-errors (delete-file file-notify--test-tmpfile1))) (should file-notify--test-results) (dolist (result file-notify--test-results) @@ -245,11 +252,10 @@ TIMEOUT is the maximum time to wait for, in seconds." (file-notify--deftest-remote file-notify-test02-events "Check file creation/removal notifications for remote files.") -(defvar auto-revert-remote-files) -(defvar auto-revert-stop-on-user-input) -(setq auto-revert-remote-files t - auto-revert-stop-on-user-input nil) (require 'autorevert) +(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" + auto-revert-remote-files t + auto-revert-stop-on-user-input nil) (ert-deftest file-notify-test03-autorevert () "Check autorevert via file notification. @@ -257,9 +263,8 @@ This test is skipped in batch mode." (skip-unless (file-notify--test-local-enabled)) ;; `auto-revert-buffers' runs every 5". And we must wait, until the ;; file has been reverted. - (let* ((remote (file-remote-p temporary-file-directory)) - (timeout (if remote 60 10)) - buf) + (let ((timeout (if (file-remote-p temporary-file-directory) 60 10)) + buf) (unwind-protect (progn (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) @@ -269,6 +274,10 @@ This test is skipped in batch mode." (setq buf (find-file-noselect file-notify--test-tmpfile)) (with-current-buffer buf (should (string-equal (buffer-string) "any text")) + ;; `buffer-stale--default-function' checks for + ;; `verify-visited-file-modtime'. We must ensure that it + ;; returns nil. + (sleep-for 1) (auto-revert-mode 1) ;; `auto-revert-buffers' runs every 5". @@ -284,10 +293,8 @@ This test is skipped in batch mode." ;; Modify file. We wait for a second, in order to ;; have another timestamp. (sleep-for 1) - (shell-command - (format "echo -n 'another text' >%s" - (or (file-remote-p file-notify--test-tmpfile 'localname) - file-notify--test-tmpfile))) + (write-region + "another text" nil file-notify--test-tmpfile nil 'no-message) ;; Check, that the buffer has been reverted. (with-current-buffer (get-buffer-create "*Messages*")