Fix Bug#26127

* lisp/filenotify.el (file-notify--rm-descriptor): Check, that
there is a function which could be called.  (Bug#26127)

* test/lisp/filenotify-tests.el (file-notify--test-cleanup):
Clear also `file-notify-descriptors'.
(file-notify--test-make-temp-name): Move up.
(file-notify-test02-rm-watch): New test.
(file-notify-test03-events, file-notify-test04-autorevert)
(file-notify-test05-file-validity)
(file-notify-test06-dir-validity)
(file-notify-test07-many-events, file-notify-test08-backup)
(file-notify-test09-watched-file-in-watched-dir)
(file-notify-test10-sufficient-resources): Rename.
This commit is contained in:
Michael Albinus 2017-03-17 10:25:46 +01:00
parent 938e7826ff
commit 6b2f3ba02a
2 changed files with 77 additions and 26 deletions

View file

@ -62,9 +62,10 @@ If it is registered in `file-notify-descriptors', a stopped event is sent."
(when (consp registered)
;; Send `stopped' event.
(funcall
(cdr (assoc file (cdr registered)))
`(,descriptor stopped ,(if file (expand-file-name file dir) dir)))
(when (consp (assoc file (cdr registered)))
(funcall
(cdr (assoc file (cdr registered)))
`(,descriptor stopped ,(if file (expand-file-name file dir) dir))))
;; Modify `file-notify-descriptors'.
(if (not file)

View file

@ -150,6 +150,9 @@ Return nil when any other file notification watch is still active."
(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
@ -332,6 +335,58 @@ This returns only for the local case and gfilenotify; otherwise it is 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'
@ -368,11 +423,6 @@ and the event to `file-notify--test-events'."
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)
@ -436,7 +486,7 @@ delivered."
;; 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))
@ -658,7 +708,7 @@ delivered."
;; 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)
@ -666,7 +716,7 @@ delivered."
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))
@ -752,10 +802,10 @@ delivered."
(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))
@ -864,10 +914,10 @@ delivered."
;; 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))
@ -922,10 +972,10 @@ delivered."
;; 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))
@ -993,10 +1043,10 @@ delivered."
;; 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))
@ -1072,10 +1122,10 @@ delivered."
;; 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
@ -1205,10 +1255,10 @@ the file watch."
;; 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))
@ -1249,8 +1299,8 @@ the file watch."
;; 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]."