(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)
(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))
(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.")
(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.")
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)
(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)
(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.
(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))
(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".
;; 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*")