;; of a respective command. The first command found is used. In
;; order to use a dedicated one, the environment variable
;; $REMOTE_FILE_NOTIFY_LIBRARY shall be set, possible values are
-;; "inotifywait", "gio-monitor" and "gvfs-monitor-dir".
+;; "inotifywait", "gio" and "smb-notify".
;; Local file-notify libraries are auto-detected during Emacs
;; configuration. This can be changed with a respective configuration
(require 'ert-x)
(require 'autorevert)
-(setq auto-revert-debug nil
+(setq auth-source-cache-expiry nil
+ auth-source-save-behavior nil
+ auto-revert-debug nil
auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
auto-revert-stop-on-user-input nil
+ ert-temp-file-prefix "auto-revert-test"
+ ert-temp-file-suffix ""
file-notify-debug nil
- tramp-verbose 0)
+ password-cache-expiry nil
+ remote-file-name-inhibit-cache nil
+ tramp-allow-unsafe-temporary-files t
+ tramp-cache-read-persistent-data t ;; For auth-sources.
+ tramp-verbose 0
+ ;; When the remote user id is 0, Tramp refuses unsafe temporary files.
+ tramp-allow-unsafe-temporary-files
+ (or tramp-allow-unsafe-temporary-files noninteractive))
(defun auto-revert--timeout ()
"Time to wait for a message."
- (+ auto-revert-interval 0.1))
+ (+ auto-revert-interval 1))
(defvar auto-revert--messages nil
"Used to collect messages issued during a section of a test.")
;; Filter suppressed remote file-notify libraries.
(when (stringp (getenv "REMOTE_FILE_NOTIFY_LIBRARY"))
- (dolist (lib '("inotifywait" "gio-monitor" "gvfs-monitor-dir"))
+ (dolist (lib '("inotifywait" "gio" "smb-notify"))
(unless (string-equal (getenv "REMOTE_FILE_NOTIFY_LIBRARY") lib)
(add-to-list 'tramp-connection-properties `(nil ,lib nil)))))
(cons
t (ignore-errors
(and
- (not (getenv "EMACS_HYDRA_CI"))
(file-remote-p ert-remote-temporary-file-directory)
(file-directory-p ert-remote-temporary-file-directory)
(file-writable-p ert-remote-temporary-file-directory))))))
This expects `auto-revert--messages' to be bound by
`ert-with-message-capture' before calling."
;; Remote files do not cooperate well with timers. So we count ourselves.
- (let ((ct (current-time)))
+ (let ((ct (current-time))
+ (text-quoting-style 'grave))
(while (and (< (float-time (time-subtract nil ct))
(auto-revert--timeout))
- (null (string-match
- (format-message
- "Reverting buffer `%s'" (buffer-name buffer))
+ (null (string-match-p
+ (rx bol "Reverting buffer `"
+ (literal (buffer-name buffer)) "'" eol)
(or auto-revert--messages ""))))
(if (and (or file-notify--library
(file-remote-p temporary-file-directory))
(defmacro auto-revert--deftest-remote (test docstring)
"Define ert `TEST-remote' for remote files."
- (declare (indent 1))
+ (declare (indent 1) (debug (symbolp stringp)))
`(ert-deftest ,(intern (concat (symbol-name test) "-remote")) ()
,docstring
- :tags '(:expensive-test :unstable)
+ :tags '(:expensive-test)
(let ((temporary-file-directory
ert-remote-temporary-file-directory)
(auto-revert-remote-files t)
(error (message "%s" err) (signal (car err) (cdr err)))))))
(defmacro with-auto-revert-test (&rest body)
+ (declare (debug t))
`(let ((auto-revert-interval-orig auto-revert-interval)
(auto-revert--lockout-interval-orig auto-revert--lockout-interval))
(unwind-protect
(progn
- (customize-set-variable 'auto-revert-interval 0.1)
- (setq auto-revert--lockout-interval 0.05)
+ (unless (file-remote-p temporary-file-directory)
+ (customize-set-variable 'auto-revert-interval 0.1)
+ (setq auto-revert--lockout-interval 0.05))
,@body)
(customize-set-variable 'auto-revert-interval auto-revert-interval-orig)
(setq auto-revert--lockout-interval auto-revert--lockout-interval-orig))))
(ert-deftest auto-revert-test00-auto-revert-mode ()
"Check autorevert for a file."
+ (file-notify-rm-all-watches)
+
;; `auto-revert-buffers' runs every 5". And we must wait, until the
;; file has been reverted.
(with-auto-revert-test
(setq buf (find-file-noselect tmpfile))
(with-current-buffer buf
(ert-with-message-capture auto-revert--messages
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
;; `buffer-stale--default-function' checks for
;; `verify-visited-file-modtime'. We must ensure that it
- ;; returns nil.
+ ;; returns nil. We also clean up.
(auto-revert-mode 1)
(should auto-revert-mode)
+ ;; There was already an initial call of
+ ;; `auto-revert-handler', which locks file
+ ;; notification. Reset this lock.
+ (setq auto-revert--last-time 0)
+ (auto-revert-test--wait-for
+ (lambda () (null auto-revert--lockout-timer))
+ (auto-revert--timeout))
- (auto-revert-tests--write-file "another text" tmpfile (pop times))
+ (auto-revert-tests--write-file
+ "another text" tmpfile (pop times))
;; Check, that the buffer has been reverted.
(auto-revert--wait-for-revert buf))
- (should (string-match "another text" (buffer-string)))
+ (should
+ (string-match-p
+ "another text" (substring-no-properties (buffer-string))))
;; When the buffer is modified, it shall not be reverted.
(ert-with-message-capture auto-revert--messages
;; Check, that the buffer hasn't been reverted.
(auto-revert--wait-for-revert buf))
- (should-not (string-match "any text" (buffer-string)))))
+ (should-not
+ (string-match-p
+ "any text" (substring-no-properties (buffer-string))))))
;; Exit.
(ignore-errors
(ert-deftest auto-revert-test01-auto-revert-several-files ()
"Check autorevert for several files at once."
(skip-unless (executable-find "cp" (file-remote-p temporary-file-directory)))
+ (file-notify-rm-all-watches)
- (ert-with-temp-directory tmpdir1
- (ert-with-temp-directory tmpdir2
- (ert-with-temp-file tmpfile1
- :prefix (expand-file-name "auto-revert-test" tmpdir1)
- (ert-with-temp-file tmpfile2
- :prefix (expand-file-name "auto-revert-test" tmpdir1)
- (with-auto-revert-test
- (let* ((cp (executable-find "cp" (file-remote-p temporary-file-directory)))
+ (with-auto-revert-test
+ (ert-with-temp-directory tmpdir1
+ :prefix "auto-revert-test-parent"
+ (ert-with-temp-directory tmpdir2
+ :prefix "auto-revert-test-parent"
+ (ert-with-temp-file tmpfile1
+ :prefix (expand-file-name "auto-revert-test" tmpdir1)
+ (ert-with-temp-file tmpfile2
+ :prefix (expand-file-name "auto-revert-test" tmpdir1)
+ (let* ((cp (executable-find
+ "cp" (file-remote-p temporary-file-directory)))
(times '(120 60 30 15))
buf1 buf2)
(unwind-protect
(ert-with-message-capture auto-revert--messages
- (auto-revert-tests--write-file "any text" tmpfile1 (pop times))
+ (auto-revert-tests--write-file
+ "any text" tmpfile1 (pop times))
(setq buf1 (find-file-noselect tmpfile1))
- (auto-revert-tests--write-file "any text" tmpfile2 (pop times))
+ (auto-revert-tests--write-file
+ "any text" tmpfile2 (pop times))
(setq buf2 (find-file-noselect tmpfile2))
(dolist (buf (list buf1 buf2))
(with-current-buffer buf
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
;; `buffer-stale--default-function' checks for
;; `verify-visited-file-modtime'. We must ensure that
;; it returns nil.
;; The following shell command is not portable on all
;; platforms, unfortunately.
(shell-command
- (format "%s -f %s/* %s"
- cp (file-local-name tmpdir2) (file-local-name tmpdir1)))
+ (format "%s -f %s/* %s" cp
+ (file-local-name tmpdir2) (file-local-name tmpdir1)))
;; Check, that the buffers have been reverted.
(dolist (buf (list buf1 buf2))
(with-current-buffer buf
(auto-revert--wait-for-revert buf)
- (should (string-match "another text" (buffer-string))))))
+ (should
+ (string-match-p
+ "another text"
+ (substring-no-properties (buffer-string)))))))
;; Exit.
(ignore-errors
;; This is inspired by Bug#23276.
(ert-deftest auto-revert-test02-auto-revert-deleted-file ()
"Check autorevert for a deleted file."
- ;; Repeated unpredictable failures, bug#32645.
- :tags '(:unstable)
- ;; Unlikely to be hydra-specific?
- ;; (skip-when (getenv "EMACS_HYDRA_CI"))
+ (file-notify-rm-all-watches)
+
(with-auto-revert-test
(ert-with-temp-file tmpfile
- (let (;; Try to catch bug#32645.
- (auto-revert-debug (getenv "EMACS_HYDRA_CI"))
- (file-notify-debug (getenv "EMACS_HYDRA_CI"))
- (times '(120 60 30 15))
+ (let ((times '(120 60 30 15))
buf desc)
(unwind-protect
(progn
(with-current-buffer buf
(should-not
(file-notify-valid-p auto-revert-notify-watch-descriptor))
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
;; `buffer-stale--default-function' checks for
;; `verify-visited-file-modtime'. We must ensure that
;; it returns nil.
'before-revert-hook
(lambda ()
(when auto-revert-debug
- (message "%s deleted" buffer-file-name))
+ (message "before-revert-hook %s deleted" buffer-file-name))
(delete-file buffer-file-name))
nil t)
(ert-with-message-capture auto-revert--messages
- (auto-revert-tests--write-file "another text" tmpfile (pop times))
+ (auto-revert-tests--write-file
+ "another text" tmpfile (pop times))
(should (eq desc auto-revert-notify-watch-descriptor))
(auto-revert--wait-for-revert buf))
;; Check, that the buffer hasn't been reverted. File
;; notification should be disabled, falling back to
;; polling.
- (should (string-match "any text" (buffer-string)))
- ;; With w32notify, and on emba, the `stopped' events are not sent.
- (or (eq file-notify--library 'w32notify)
- (getenv "EMACS_EMBA_CI")
- (should-not
- ;; The auto-revert timer is wont to establish a new
- ;; watch soon after the previous descriptor is
- ;; destroyed, which not unnaturally interferes with
- ;; our testing for its destruction, since descriptor
- ;; IDs are reused. Therefore, test the identity of
- ;; the previous descriptor, not just its validity.
- (and (eq desc auto-revert-notify-watch-descriptor)
- (file-notify-valid-p auto-revert-notify-watch-descriptor))))
+ (should
+ (string-match-p
+ "any text" (substring-no-properties (buffer-string))))
;; Once the file has been recreated, the buffer shall be
;; reverted.
(kill-local-variable 'before-revert-hook)
(ert-with-message-capture auto-revert--messages
- (auto-revert-tests--write-file "another text" tmpfile (pop times))
+ (auto-revert-tests--write-file
+ "another text" tmpfile (pop times))
(auto-revert--wait-for-revert buf))
;; Check, that the buffer has been reverted.
- (should (string-match "another text" (buffer-string)))
+ (should
+ (string-match-p
+ "another text" (substring-no-properties (buffer-string))))
;; When file notification is used, it must be reenabled
;; after recreation of the file. We cannot expect that
;; the descriptor is the same, so we just check the
;; existence.
- (should (eq (null desc) (null auto-revert-notify-watch-descriptor)))
+ (should
+ (eq (null desc) (null auto-revert-notify-watch-descriptor)))
;; An empty file shall still be reverted.
(ert-with-message-capture auto-revert--messages
(auto-revert-tests--write-file "" tmpfile (pop times))
(auto-revert--wait-for-revert buf))
;; Check, that the buffer has been reverted.
- (should (string-equal "" (buffer-string)))))
+ (should
+ (string-equal "" (substring-no-properties (buffer-string))))))
;; Exit.
(ignore-errors
(ert-deftest auto-revert-test03-auto-revert-tail-mode ()
"Check autorevert tail mode."
+ (file-notify-rm-all-watches)
+
+ (with-auto-revert-test
;; `auto-revert-buffers' runs every 5". And we must wait, until the
;; file has been reverted.
(ert-with-temp-file tmpfile
(set-buffer-modified-p nil)
;; Modify file.
- (auto-revert-tests--write-file "another text" tmpfile (pop times) 'append)
+ (auto-revert-tests--write-file
+ "another text" tmpfile (pop times) 'append)
;; Check, that the buffer has been reverted.
(auto-revert--wait-for-revert buf)
(should
- (string-match "modified text\nanother text" (buffer-string)))))
+ (string-match-p
+ "modified text\nanother text"
+ (substring-no-properties (buffer-string))))))
;; Exit.
- (ignore-errors (kill-buffer buf))))))
+ (ignore-errors (kill-buffer buf)))))))
(auto-revert--deftest-remote auto-revert-test03-auto-revert-tail-mode
"Check remote autorevert tail mode.")
(ert-deftest auto-revert-test04-auto-revert-mode-dired ()
"Check autorevert for dired."
+ (file-notify-rm-all-watches)
+
;; `auto-revert-buffers' runs every 5". And we must wait, until the
;; file has been reverted.
(with-auto-revert-test
- (ert-with-temp-file tmpfile
- (let* ((name (file-name-nondirectory tmpfile))
- (times '(30))
- buf)
- (unwind-protect
- (progn
- (setq buf (dired-noselect temporary-file-directory))
- (with-current-buffer buf
- ;; `buffer-stale--default-function' checks for
- ;; `verify-visited-file-modtime'. We must ensure that it
- ;; returns nil.
- (auto-revert-mode 1)
- (should auto-revert-mode)
- (should
- (string-match name (substring-no-properties (buffer-string))))
- ;; If we don't sleep for a while, this test fails on
- ;; MS-Windows.
- (if (eq system-type 'windows-nt)
- (sleep-for 0.5))
-
- (ert-with-message-capture auto-revert--messages
- ;; Delete file.
- (delete-file tmpfile)
- (auto-revert--wait-for-revert buf))
- (if (eq system-type 'windows-nt)
- (sleep-for 1))
- ;; Check, that the buffer has been reverted.
- (should-not
- (string-match name (substring-no-properties (buffer-string))))
-
- (ert-with-message-capture auto-revert--messages
- ;; Make dired buffer modified. Check, that the buffer has
- ;; been still reverted.
- (set-buffer-modified-p t)
- (auto-revert-tests--write-file "any text" tmpfile (pop times))
+ (ert-with-temp-directory tmpdir
+ :prefix "auto-revert-test-parent"
+ (ert-with-temp-file tmpfile
+ :prefix (expand-file-name "auto-revert-test" tmpdir)
+ (let* ((name (file-name-nondirectory tmpfile))
+ (times '(30))
+ buf)
+ (unwind-protect
+ (progn
+ (setq buf (dired-noselect tmpdir))
+ (with-current-buffer buf
+ ;; `buffer-stale--default-function' checks for
+ ;; `verify-visited-file-modtime'. We must ensure that
+ ;; it returns nil.
+ (auto-revert-mode 1)
+ (should auto-revert-mode)
+ (should
+ (string-match-p
+ (rx bow (literal name) eow)
+ (substring-no-properties (buffer-string))))
+ ;; If we don't sleep for a while, this test fails on
+ ;; MS-Windows.
+ (if (eq system-type 'windows-nt)
+ (sleep-for 0.5))
+
+ ;; File stamps of remote files have an accuracy of 1
+ ;; second. Wait a little bit.
+ (when (file-remote-p tmpfile)
+ (sleep-for (auto-revert--timeout)))
+ (ert-with-message-capture auto-revert--messages
+ ;; Delete file.
+ (delete-file tmpfile)
+ (auto-revert--wait-for-revert buf))
+ (if (eq system-type 'windows-nt)
+ (sleep-for 1))
+ ;; Check, that the buffer has been reverted.
+ (should-not
+ (string-match-p
+ (rx bow (literal name) eow)
+ (substring-no-properties (buffer-string))))
+
+ ;; File stamps of remote files have an accuracy of 1
+ ;; second. Wait a little bit.
+ (when (file-remote-p tmpfile)
+ (sleep-for (auto-revert--timeout)))
+ (ert-with-message-capture auto-revert--messages
+ ;; Make dired buffer modified. Check, that the
+ ;; buffer has been still reverted.
+ (set-buffer-modified-p t)
+ (auto-revert-tests--write-file "any text" tmpfile (pop times))
+ (auto-revert--wait-for-revert buf))
+ ;; Check, that the buffer has been reverted.
+ (should
+ (string-match-p
+ (rx bow (literal name) eow)
+ (substring-no-properties (buffer-string))))))
- (auto-revert--wait-for-revert buf))
- ;; Check, that the buffer has been reverted.
- (should
- (string-match name (substring-no-properties (buffer-string))))))
-
- ;; Exit.
- (ignore-errors
- (with-current-buffer buf (set-buffer-modified-p nil))
- (kill-buffer buf)))))))
+ ;; Exit.
+ (ignore-errors
+ (with-current-buffer buf (set-buffer-modified-p nil))
+ (kill-buffer buf))))))))
(auto-revert--deftest-remote auto-revert-test04-auto-revert-mode-dired
"Check remote autorevert for dired.")
(defun auto-revert-test--buffer-string (buffer)
"Contents of BUFFER as a string."
(with-current-buffer buffer
- (buffer-string)))
+ (substring-no-properties (buffer-string))))
(defun auto-revert-test--wait-for (pred max-wait)
"Wait until PRED is true, or MAX-WAIT seconds elapsed."
'kill-buffer-hook
(lambda ()
(message
- "%s killed\n%s" (current-buffer) (with-output-to-string (backtrace))))
+ "%S killed\n%s" (current-buffer) (with-output-to-string (backtrace))))
nil 'local))))
(ert-deftest auto-revert-test05-global-notify ()
"Test `global-auto-revert-mode' without polling."
(skip-unless (or file-notify--library
(file-remote-p temporary-file-directory)))
+ (file-notify-rm-all-watches)
+
(with-auto-revert-test
(ert-with-temp-file file-1
(ert-with-temp-file file-2
(auto-revert-test--instrument-kill-buffer-hook buf-1)
(setq buf-2 (find-file-noselect file-2))
(auto-revert-test--instrument-kill-buffer-hook buf-2)
+ ;; File stamps of remote files have an accuracy of 1
+ ;; second. Wait a little bit.
+ (when (file-remote-p file-1)
+ (sleep-for (auto-revert--timeout)))
(auto-revert-test--write-file "1-a" file-1)
- (should (equal (auto-revert-test--buffer-string buf-1) ""))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-1) ""))
(global-auto-revert-mode 1) ; Turn it on.
(should (buffer-local-value
'auto-revert-notify-watch-descriptor buf-2))
+ ;; Allow for some time to handle notification events.
+ (auto-revert-test--wait-for-buffer-text
+ buf-1 "1-a" (auto-revert--timeout))
;; buf-1 should have been reverted immediately when the mode
;; was enabled.
- (should (equal (auto-revert-test--buffer-string buf-1) "1-a"))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-1) "1-a"))
;; Alter a file.
(auto-revert-test--write-file "2-a" file-2)
;; Allow for some time to handle notification events.
(auto-revert-test--wait-for-buffer-text buf-2 "2-a" 1)
- (should (equal (auto-revert-test--buffer-string buf-2) "2-a"))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-2) "2-a"))
;; Visit a file, and modify it on disk.
(setq buf-3 (find-file-noselect file-3))
'auto-revert-notify-watch-descriptor buf-3))
(auto-revert-test--write-file "3-a" file-3)
(auto-revert-test--wait-for-buffer-text buf-3 "3-a" 1)
- (should (equal (auto-revert-test--buffer-string buf-3) "3-a"))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-3) "3-a"))
;; Delete a visited file, and re-create it with new contents.
(delete-file file-1)
- (should (equal (auto-revert-test--buffer-string buf-1) "1-a"))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-1) "1-a"))
(auto-revert-test--write-file "1-b" file-1)
;; Since the file is deleted, it needs at least
;; `auto-revert-interval' to recognize the new file,
(should (buffer-local-value
'auto-revert-notify-watch-descriptor buf-1))
- ;; Write a buffer to a new file, then modify the new file on disk.
+ ;; Write a buffer to a new file, then modify the new
+ ;; file on disk.
(with-current-buffer buf-2
(write-file file-2b))
- (should (equal (auto-revert-test--buffer-string buf-2) "2-a"))
+ (should
+ (string-equal (auto-revert-test--buffer-string buf-2) "2-a"))
(auto-revert-test--write-file "2-b" file-2b)
(auto-revert-test--wait-for-buffer-text
buf-2 "2-b" (auto-revert--timeout))
"Verify that notification follows `write-file' correctly."
(skip-unless (or file-notify--library
(file-remote-p temporary-file-directory)))
+ (file-notify-rm-all-watches)
+
(with-auto-revert-test
(ert-with-temp-file file-1
(let* ((auto-revert-use-notify t)
(insert "B")
(write-file file-2)
+ ;; File stamps of remote files have an accuracy of 1
+ ;; second. Wait a little bit.
+ (when (file-remote-p file-1)
+ (sleep-for (auto-revert--timeout)))
(auto-revert-test--write-file "C" file-2)
(auto-revert-test--wait-for-buffer-text
buf "C" (auto-revert--timeout))
- (should (equal (buffer-string) "C"))))
+ (should
+ (string-equal (substring-no-properties (buffer-string)) "C"))))
;; Clean up.
(ignore-errors (kill-buffer buf))
"Check autorevert for several buffers visiting the same file."
(skip-unless (or file-notify--library
(file-remote-p temporary-file-directory)))
- ;; (with-auto-revert-test
+ (file-notify-rm-all-watches)
+
+ (with-auto-revert-test
(ert-with-temp-file tmpfile
(let ((auto-revert-use-notify t)
(times '(120 60 30 15))
(auto-revert-tests--write-file "any text" tmpfile (pop times))
(push (find-file-noselect tmpfile) buffers)
(with-current-buffer (car buffers)
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
;; `buffer-stale--default-function' checks for
;; `verify-visited-file-modtime'. We must ensure that
;; it returns nil.
(setq buffers (nreverse buffers))
(dolist (buf buffers)
(with-current-buffer buf
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
(if (string-suffix-p "-nil" (buffer-name buf))
(should-not auto-revert-mode)
(should auto-revert-mode))))
(auto-revert--wait-for-revert (car buffers))
(dolist (buf buffers)
(with-current-buffer buf
- (should (string-equal (buffer-string) "another text"))))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "another text"))))
;; Disabling autorevert in an indirect buffer does not
;; disable autorevert in the corresponding base buffer.
(dolist (buf buffers)
(with-current-buffer buf
(insert-file-contents tmpfile 'visit)
- (should (string-equal (buffer-string) "any text"))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "any text"))
(auto-revert-mode 1)
(should auto-revert-mode)))
(dolist (buf buffers)
(auto-revert--wait-for-revert buf)
(with-current-buffer buf
- (should (string-equal (buffer-string) "another text")))))
+ (should
+ (string-equal
+ (substring-no-properties (buffer-string)) "another text")))))
;; Exit.
(ignore-errors
(dolist (buf buffers)
(with-current-buffer buf (set-buffer-modified-p nil))
- (kill-buffer buf)))))));)
+ (kill-buffer buf))))))))
(auto-revert--deftest-remote auto-revert-test07-auto-revert-several-buffers
"Check autorevert for several buffers visiting the same remote file.")
(ert-deftest auto-revert-test08-auto-revert-inhibit-auto-revert ()
"Check the power of `inhibit-auto-revert'."
+ (file-notify-rm-all-watches)
+
;; `auto-revert-buffers' runs every 5". And we must wait, until the
;; file has been reverted.
(with-auto-revert-test
(auto-revert-mode 1)
(should auto-revert-mode)
- (auto-revert-tests--write-file "another text" tmpfile (pop times))
+ (auto-revert-tests--write-file
+ "another text" tmpfile (pop times))
;; Check, that the buffer hasn't been reverted.
(auto-revert--wait-for-revert buf)
- (should-not (string-match "another text" (buffer-string))))
+ (should-not
+ (string-match-p
+ "another text" (substring-no-properties (buffer-string)))))
;; Check, that the buffer has been reverted.
(auto-revert--wait-for-revert buf)
- (should (string-match "another text" (buffer-string))))))
+ (should
+ (string-match-p
+ "another text" (substring-no-properties (buffer-string)))))))
;; Exit.
(ignore-errors
;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper
;; value less than 10 could help.
-;; This test suite obeys the environment variables $EMACS_HYDRA_CI and
-;; $EMACS_EMBA_CI, used on the Emacs CI/CD platforms.
+;; This test suite obeys the environment variable $EMACS_EMBA_CI, used
+;; on the Emacs CI/CD platforms.
;; The following test tags are used: `:expensive-test',
;; `:tramp-asynchronous-processes' and `:unstable'.
(require 'dired-aux)
(require 'tramp)
(require 'ert-x)
+(require 'filenotify)
(require 'tar-mode)
(require 'trace)
(require 'vc)
(unless (and (null noninteractive) (file-directory-p "~/"))
(setenv "HOME" temporary-file-directory))
(format "/mock::%s" temporary-file-directory)))
- "Temporary directory for remote file tests.")
-
- ;; This should happen on hydra only.
- (when (getenv "EMACS_HYDRA_CI")
- (add-to-list 'tramp-remote-path 'tramp-own-remote-path))))
+ "Temporary directory for remote file tests.")))
;; Beautify batch mode.
(when noninteractive
;; Bug#10085.
(when (tramp--test-enabled) ;; Packages like tramp-gvfs.el might be disabled.
(dolist (non-essential '(nil t))
- ;; We must clear `tramp-default-method'. On hydra, it is "ftp",
- ;; which ruins the tests.
+ ;; We must clear `tramp-default-method'.
(let ((tramp-default-method
(file-remote-p ert-remote-temporary-file-directory 'method))
(host-port
(unwind-protect
(progn
;; We cannot use "/bin/true" and "/bin/false"; those paths
- ;; do not exist on hydra and on MS Windows.
+ ;; do not exist on MS Windows.
(should (zerop (process-file "true")))
(should-not (zerop (process-file "false")))
(should-not (zerop (process-file "binary-does-not-exist")))
(ert-deftest tramp-test41-special-characters ()
"Check special characters in file names."
(skip-unless (tramp--test-enabled))
- (skip-unless (not (getenv "EMACS_HYDRA_CI"))) ; SLOW ~ 245s
(skip-unless (not (tramp--test-rsync-p)))
(skip-unless (not (tramp--test-rclone-p)))
(skip-unless (not (or (eq system-type 'darwin) (tramp--test-macos-p))))
(ert-deftest tramp-test42-utf8 ()
"Check UTF8 encoding in file names and file contents."
(skip-unless (tramp--test-enabled))
- (skip-unless (not (getenv "EMACS_HYDRA_CI"))) ; SLOW ~ 620s
(skip-unless (not (tramp--test-container-p)))
(skip-unless (not (tramp--test-rsync-p)))
(skip-unless (not (tramp--test-windows-nt-and-out-of-band-p)))
(cond
((ignore-errors
(string-to-number (getenv "REMOTE_PARALLEL_PROCESSES"))))
- ((getenv "EMACS_HYDRA_CI") 5)
(t 10)))
;; PuTTY-based methods can only share up to 10 connections.
(tramp-use-connection-share
(if (and (tramp--test-putty-p) (>= number-proc 10))
'suppress (bound-and-true-p tramp-use-connection-share)))
- ;; On hydra, timings are bad.
- (timer-repeat
- (cond
- ((getenv "EMACS_HYDRA_CI") 10)
- (t 1)))
+ (timer-repeat 1)
;; This is when all timers start. We check inside the
;; timer function, that we don't exceed timeout.
(timer-start (current-time))
(delete-directory tmp-name)
(delete-file (concat tmp-name ".tar.gz"))))
+;; More exhaustive tests are performed in filenotify-tests.el,
+;; selector "remote".
+(ert-deftest tramp-test46-file-notifications ()
+ "Check that Tramp handles file notifications."
+ (skip-unless (tramp--test-enabled))
+
+ (let* ((tmp-name (tramp--test-make-temp-name))
+ ;(file-notify-debug t)
+ (desc1
+ (ignore-error file-notify-error
+ (file-notify-add-watch
+ tmp-name '(change attribute-change) #'ignore)))
+ (desc2
+ (ignore-error file-notify-error
+ (file-notify-add-watch
+ ert-remote-temporary-file-directory
+ '(change attribute-change) #'ignore))))
+ (skip-unless (and desc1 desc2))
+
+ (unwind-protect
+ (progn
+ (tramp--test-message "%S" desc1)
+ (should-not (file-exists-p tmp-name))
+ (should (file-notify-valid-p desc1))
+ (should (file-notify-valid-p desc2))
+
+ ;; Create the file.
+ (write-region "foo" nil tmp-name)
+ (should (file-exists-p tmp-name))
+ ;; Modify.
+ (write-region "foo" nil tmp-name)
+ (should (file-exists-p tmp-name))
+ ;; Delete.
+ (delete-file tmp-name)
+ (should-not (file-exists-p tmp-name))
+
+ (while (read-event nil nil 0.1))
+ ;; This has been stopped because the file was deleted.
+ (should-not (file-notify-valid-p desc1))
+
+ ;; This is still valid.
+ (should (file-notify-valid-p desc2))
+ (file-notify-rm-watch desc2)
+ (should-not (file-notify-valid-p desc2)))
+
+ ;; Cleanup.
+ (ignore-errors (delete-file tmp-name))
+ ;; `file-notify-rm-all-watches' exists since Emacs 30.1.
+ ;; We don't want to see compiler warnings for older Emacsen.
+ (when (fboundp 'file-notify-rm-all-watches)
+ (with-no-warnings (file-notify-rm-all-watches))))))
+
(ert-deftest tramp-test47-read-password ()
"Check Tramp password handling."
:tags '(:expensive-test)
;; * Check, why direct async processes do not work for
;; `tramp-test45-asynchronous-requests'.
+;; Starting with Emacs 29, use `ert-with-temp-file' and
+;; `ert-with-temp-directory'.
+
(provide 'tramp-tests)
;;; tramp-tests.el ends here