(tramp-cleanup-connection
(tramp-dissect-file-name temporary-file-directory) nil 'keep-password)))
+ (when (hash-table-p file-notify-descriptors)
+ (clrhash file-notify-descriptors))
+
(setq file-notify--test-tmpfile nil
file-notify--test-tmpfile1 nil
file-notify--test-desc nil
(file-notify--deftest-remote file-notify-test01-add-watch
"Check `file-notify-add-watch' for remote files.")
+(defun file-notify--test-make-temp-name ()
+ "Create a temporary file name for test."
+ (expand-file-name
+ (make-temp-name "file-notify-test") temporary-file-directory))
+
+;; This test is inspired by Bug#26127.
+(ert-deftest file-notify-test02-rm-watch ()
+ "Check `file-notify-rm-watch'."
+ (skip-unless (file-notify--test-local-enabled))
+
+ (unwind-protect
+ (progn
+ ;; Check, that `file-notify-rm-watch' works.
+ (should
+ (setq file-notify--test-desc
+ (file-notify-add-watch
+ temporary-file-directory '(change) #'ignore)))
+ (file-notify-rm-watch file-notify--test-desc)
+
+ ;; Check, that any parameter is accepted.
+ (condition-case err
+ (progn
+ (file-notify-rm-watch nil)
+ (file-notify-rm-watch 0)
+ (file-notify-rm-watch "foo")
+ (file-notify-rm-watch 'foo))
+ (error (ert-fail err)))
+
+ ;; Check, that no error is returned removing a watch descriptor twice.
+ (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
+ file-notify--test-tmpfile1 (file-notify--test-make-temp-name))
+ (should
+ (setq file-notify--test-desc
+ (file-notify-add-watch
+ file-notify--test-tmpfile '(change) #'ignore)))
+ (should
+ (setq file-notify--test-desc1
+ (file-notify-add-watch
+ file-notify--test-tmpfile1 '(change) #'ignore)))
+ (file-notify-rm-watch file-notify--test-desc)
+ (file-notify-rm-watch file-notify--test-desc)
+ (file-notify-rm-watch file-notify--test-desc1)
+
+ ;; The environment shall be cleaned up.
+ (file-notify--test-cleanup-p))
+
+ ;; Cleanup.
+ (file-notify--test-cleanup)))
+
+(file-notify--deftest-remote file-notify-test02-rm-watch
+ "Check `file-notify-rm-watch' for remote files.")
+
(defun file-notify--test-event-test ()
"Ert test function to be called by `file-notify--test-event-handler'.
We cannot pass arguments, so we assume that `file-notify--test-event'
file-notify--test-results
(append file-notify--test-results `(,result))))))
-(defun file-notify--test-make-temp-name ()
- "Create a temporary file name for test."
- (expand-file-name
- (make-temp-name "file-notify-test") temporary-file-directory))
-
(defun file-notify--test-with-events-check (events)
"Check whether received events match one of the EVENTS alternatives."
(let (result)
;; One of the possible event sequences shall match.
(should (file-notify--test-with-events-check events))))
-(ert-deftest file-notify-test02-events ()
+(ert-deftest file-notify-test03-events ()
"Check file creation/change/removal notifications."
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test02-events
+(file-notify--deftest-remote file-notify-test03-events
"Check file creation/change/removal notifications for remote files.")
(require 'autorevert)
auto-revert-remote-files t
auto-revert-stop-on-user-input nil)
-(ert-deftest file-notify-test03-autorevert ()
+(ert-deftest file-notify-test04-autorevert ()
"Check autorevert via file notification."
(skip-unless (file-notify--test-local-enabled))
(ignore-errors (kill-buffer buf))
(file-notify--test-cleanup))))
-(file-notify--deftest-remote file-notify-test03-autorevert
+(file-notify--deftest-remote file-notify-test04-autorevert
"Check autorevert via file notification for remote files.")
-(ert-deftest file-notify-test04-file-validity ()
+(ert-deftest file-notify-test05-file-validity ()
"Check `file-notify-valid-p' for files."
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test04-file-validity
+(file-notify--deftest-remote file-notify-test05-file-validity
"Check `file-notify-valid-p' via file notification for remote files.")
-(ert-deftest file-notify-test05-dir-validity ()
+(ert-deftest file-notify-test06-dir-validity ()
"Check `file-notify-valid-p' for directories."
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test05-dir-validity
+(file-notify--deftest-remote file-notify-test06-dir-validity
"Check `file-notify-valid-p' via file notification for remote directories.")
-(ert-deftest file-notify-test06-many-events ()
+(ert-deftest file-notify-test07-many-events ()
"Check that events are not dropped."
:tags '(:expensive-test)
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test06-many-events
+(file-notify--deftest-remote file-notify-test07-many-events
"Check that events are not dropped for remote directories.")
-(ert-deftest file-notify-test07-backup ()
+(ert-deftest file-notify-test08-backup ()
"Check that backup keeps file notification."
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test07-backup
+(file-notify--deftest-remote file-notify-test08-backup
"Check that backup keeps file notification for remote files.")
-(ert-deftest file-notify-test08-watched-file-in-watched-dir ()
+(ert-deftest file-notify-test09-watched-file-in-watched-dir ()
"Watches a directory and a file in that directory separately.
Checks that the callbacks are only called with events with
descriptors that were issued when registering the watches. This
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test08-watched-file-in-watched-dir
- "Check `file-notify-test08-watched-file-in-watched-dir' for remote files.")
+(file-notify--deftest-remote file-notify-test09-watched-file-in-watched-dir
+ "Check `file-notify-test09-watched-file-in-watched-dir' for remote files.")
-(ert-deftest file-notify-test09-sufficient-resources ()
+(ert-deftest file-notify-test10-sufficient-resources ()
"Check that file notification does not use too many resources."
:tags '(:expensive-test)
(skip-unless (file-notify--test-local-enabled))
;; Cleanup.
(file-notify--test-cleanup)))
-(file-notify--deftest-remote file-notify-test09-sufficient-resources
- "Check `file-notify-test09-sufficient-resources' for remote files.")
+(file-notify--deftest-remote file-notify-test10-sufficient-resources
+ "Check `file-notify-test10-sufficient-resources' for remote files.")
(defun file-notify-test-all (&optional interactive)
"Run all tests for \\[file-notify]."