aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2017-03-17 10:25:46 +0100
committerMichael Albinus2017-03-17 10:25:46 +0100
commit6b2f3ba02ab1cf54e2bdbb0207843cf86de48191 (patch)
treec319b1e53f21d040708058296e386f6f4a7af7ff
parent938e7826ff849c14cb092dec8e2c1198413c7462 (diff)
downloademacs-6b2f3ba02ab1cf54e2bdbb0207843cf86de48191.tar.gz
emacs-6b2f3ba02ab1cf54e2bdbb0207843cf86de48191.zip
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.
-rw-r--r--lisp/filenotify.el7
-rw-r--r--test/lisp/filenotify-tests.el96
2 files changed, 77 insertions, 26 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 1de5420f1e7..7eb6229976a 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -62,9 +62,10 @@ If it is registered in `file-notify-descriptors', a stopped event is sent."
62 62
63 (when (consp registered) 63 (when (consp registered)
64 ;; Send `stopped' event. 64 ;; Send `stopped' event.
65 (funcall 65 (when (consp (assoc file (cdr registered)))
66 (cdr (assoc file (cdr registered))) 66 (funcall
67 `(,descriptor stopped ,(if file (expand-file-name file dir) dir))) 67 (cdr (assoc file (cdr registered)))
68 `(,descriptor stopped ,(if file (expand-file-name file dir) dir))))
68 69
69 ;; Modify `file-notify-descriptors'. 70 ;; Modify `file-notify-descriptors'.
70 (if (not file) 71 (if (not file)
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index dcd83a3ef3b..72080322379 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -150,6 +150,9 @@ Return nil when any other file notification watch is still active."
150 (tramp-cleanup-connection 150 (tramp-cleanup-connection
151 (tramp-dissect-file-name temporary-file-directory) nil 'keep-password))) 151 (tramp-dissect-file-name temporary-file-directory) nil 'keep-password)))
152 152
153 (when (hash-table-p file-notify-descriptors)
154 (clrhash file-notify-descriptors))
155
153 (setq file-notify--test-tmpfile nil 156 (setq file-notify--test-tmpfile nil
154 file-notify--test-tmpfile1 nil 157 file-notify--test-tmpfile1 nil
155 file-notify--test-desc nil 158 file-notify--test-desc nil
@@ -332,6 +335,58 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
332(file-notify--deftest-remote file-notify-test01-add-watch 335(file-notify--deftest-remote file-notify-test01-add-watch
333 "Check `file-notify-add-watch' for remote files.") 336 "Check `file-notify-add-watch' for remote files.")
334 337
338(defun file-notify--test-make-temp-name ()
339 "Create a temporary file name for test."
340 (expand-file-name
341 (make-temp-name "file-notify-test") temporary-file-directory))
342
343;; This test is inspired by Bug#26127.
344(ert-deftest file-notify-test02-rm-watch ()
345 "Check `file-notify-rm-watch'."
346 (skip-unless (file-notify--test-local-enabled))
347
348 (unwind-protect
349 (progn
350 ;; Check, that `file-notify-rm-watch' works.
351 (should
352 (setq file-notify--test-desc
353 (file-notify-add-watch
354 temporary-file-directory '(change) #'ignore)))
355 (file-notify-rm-watch file-notify--test-desc)
356
357 ;; Check, that any parameter is accepted.
358 (condition-case err
359 (progn
360 (file-notify-rm-watch nil)
361 (file-notify-rm-watch 0)
362 (file-notify-rm-watch "foo")
363 (file-notify-rm-watch 'foo))
364 (error (ert-fail err)))
365
366 ;; Check, that no error is returned removing a watch descriptor twice.
367 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
368 file-notify--test-tmpfile1 (file-notify--test-make-temp-name))
369 (should
370 (setq file-notify--test-desc
371 (file-notify-add-watch
372 file-notify--test-tmpfile '(change) #'ignore)))
373 (should
374 (setq file-notify--test-desc1
375 (file-notify-add-watch
376 file-notify--test-tmpfile1 '(change) #'ignore)))
377 (file-notify-rm-watch file-notify--test-desc)
378 (file-notify-rm-watch file-notify--test-desc)
379 (file-notify-rm-watch file-notify--test-desc1)
380
381 ;; The environment shall be cleaned up.
382 (file-notify--test-cleanup-p))
383
384 ;; Cleanup.
385 (file-notify--test-cleanup)))
386
387(file-notify--deftest-remote file-notify-test02-rm-watch
388 "Check `file-notify-rm-watch' for remote files.")
389
335(defun file-notify--test-event-test () 390(defun file-notify--test-event-test ()
336 "Ert test function to be called by `file-notify--test-event-handler'. 391 "Ert test function to be called by `file-notify--test-event-handler'.
337We cannot pass arguments, so we assume that `file-notify--test-event' 392We cannot pass arguments, so we assume that `file-notify--test-event'
@@ -368,11 +423,6 @@ and the event to `file-notify--test-events'."
368 file-notify--test-results 423 file-notify--test-results
369 (append file-notify--test-results `(,result)))))) 424 (append file-notify--test-results `(,result))))))
370 425
371(defun file-notify--test-make-temp-name ()
372 "Create a temporary file name for test."
373 (expand-file-name
374 (make-temp-name "file-notify-test") temporary-file-directory))
375
376(defun file-notify--test-with-events-check (events) 426(defun file-notify--test-with-events-check (events)
377 "Check whether received events match one of the EVENTS alternatives." 427 "Check whether received events match one of the EVENTS alternatives."
378 (let (result) 428 (let (result)
@@ -436,7 +486,7 @@ delivered."
436 ;; One of the possible event sequences shall match. 486 ;; One of the possible event sequences shall match.
437 (should (file-notify--test-with-events-check events)))) 487 (should (file-notify--test-with-events-check events))))
438 488
439(ert-deftest file-notify-test02-events () 489(ert-deftest file-notify-test03-events ()
440 "Check file creation/change/removal notifications." 490 "Check file creation/change/removal notifications."
441 (skip-unless (file-notify--test-local-enabled)) 491 (skip-unless (file-notify--test-local-enabled))
442 492
@@ -658,7 +708,7 @@ delivered."
658 ;; Cleanup. 708 ;; Cleanup.
659 (file-notify--test-cleanup))) 709 (file-notify--test-cleanup)))
660 710
661(file-notify--deftest-remote file-notify-test02-events 711(file-notify--deftest-remote file-notify-test03-events
662 "Check file creation/change/removal notifications for remote files.") 712 "Check file creation/change/removal notifications for remote files.")
663 713
664(require 'autorevert) 714(require 'autorevert)
@@ -666,7 +716,7 @@ delivered."
666 auto-revert-remote-files t 716 auto-revert-remote-files t
667 auto-revert-stop-on-user-input nil) 717 auto-revert-stop-on-user-input nil)
668 718
669(ert-deftest file-notify-test03-autorevert () 719(ert-deftest file-notify-test04-autorevert ()
670 "Check autorevert via file notification." 720 "Check autorevert via file notification."
671 (skip-unless (file-notify--test-local-enabled)) 721 (skip-unless (file-notify--test-local-enabled))
672 722
@@ -752,10 +802,10 @@ delivered."
752 (ignore-errors (kill-buffer buf)) 802 (ignore-errors (kill-buffer buf))
753 (file-notify--test-cleanup)))) 803 (file-notify--test-cleanup))))
754 804
755(file-notify--deftest-remote file-notify-test03-autorevert 805(file-notify--deftest-remote file-notify-test04-autorevert
756 "Check autorevert via file notification for remote files.") 806 "Check autorevert via file notification for remote files.")
757 807
758(ert-deftest file-notify-test04-file-validity () 808(ert-deftest file-notify-test05-file-validity ()
759 "Check `file-notify-valid-p' for files." 809 "Check `file-notify-valid-p' for files."
760 (skip-unless (file-notify--test-local-enabled)) 810 (skip-unless (file-notify--test-local-enabled))
761 811
@@ -864,10 +914,10 @@ delivered."
864 ;; Cleanup. 914 ;; Cleanup.
865 (file-notify--test-cleanup))) 915 (file-notify--test-cleanup)))
866 916
867(file-notify--deftest-remote file-notify-test04-file-validity 917(file-notify--deftest-remote file-notify-test05-file-validity
868 "Check `file-notify-valid-p' via file notification for remote files.") 918 "Check `file-notify-valid-p' via file notification for remote files.")
869 919
870(ert-deftest file-notify-test05-dir-validity () 920(ert-deftest file-notify-test06-dir-validity ()
871 "Check `file-notify-valid-p' for directories." 921 "Check `file-notify-valid-p' for directories."
872 (skip-unless (file-notify--test-local-enabled)) 922 (skip-unless (file-notify--test-local-enabled))
873 923
@@ -922,10 +972,10 @@ delivered."
922 ;; Cleanup. 972 ;; Cleanup.
923 (file-notify--test-cleanup))) 973 (file-notify--test-cleanup)))
924 974
925(file-notify--deftest-remote file-notify-test05-dir-validity 975(file-notify--deftest-remote file-notify-test06-dir-validity
926 "Check `file-notify-valid-p' via file notification for remote directories.") 976 "Check `file-notify-valid-p' via file notification for remote directories.")
927 977
928(ert-deftest file-notify-test06-many-events () 978(ert-deftest file-notify-test07-many-events ()
929 "Check that events are not dropped." 979 "Check that events are not dropped."
930 :tags '(:expensive-test) 980 :tags '(:expensive-test)
931 (skip-unless (file-notify--test-local-enabled)) 981 (skip-unless (file-notify--test-local-enabled))
@@ -993,10 +1043,10 @@ delivered."
993 ;; Cleanup. 1043 ;; Cleanup.
994 (file-notify--test-cleanup))) 1044 (file-notify--test-cleanup)))
995 1045
996(file-notify--deftest-remote file-notify-test06-many-events 1046(file-notify--deftest-remote file-notify-test07-many-events
997 "Check that events are not dropped for remote directories.") 1047 "Check that events are not dropped for remote directories.")
998 1048
999(ert-deftest file-notify-test07-backup () 1049(ert-deftest file-notify-test08-backup ()
1000 "Check that backup keeps file notification." 1050 "Check that backup keeps file notification."
1001 (skip-unless (file-notify--test-local-enabled)) 1051 (skip-unless (file-notify--test-local-enabled))
1002 1052
@@ -1072,10 +1122,10 @@ delivered."
1072 ;; Cleanup. 1122 ;; Cleanup.
1073 (file-notify--test-cleanup))) 1123 (file-notify--test-cleanup)))
1074 1124
1075(file-notify--deftest-remote file-notify-test07-backup 1125(file-notify--deftest-remote file-notify-test08-backup
1076 "Check that backup keeps file notification for remote files.") 1126 "Check that backup keeps file notification for remote files.")
1077 1127
1078(ert-deftest file-notify-test08-watched-file-in-watched-dir () 1128(ert-deftest file-notify-test09-watched-file-in-watched-dir ()
1079 "Watches a directory and a file in that directory separately. 1129 "Watches a directory and a file in that directory separately.
1080Checks that the callbacks are only called with events with 1130Checks that the callbacks are only called with events with
1081descriptors that were issued when registering the watches. This 1131descriptors that were issued when registering the watches. This
@@ -1205,10 +1255,10 @@ the file watch."
1205 ;; Cleanup. 1255 ;; Cleanup.
1206 (file-notify--test-cleanup))) 1256 (file-notify--test-cleanup)))
1207 1257
1208(file-notify--deftest-remote file-notify-test08-watched-file-in-watched-dir 1258(file-notify--deftest-remote file-notify-test09-watched-file-in-watched-dir
1209 "Check `file-notify-test08-watched-file-in-watched-dir' for remote files.") 1259 "Check `file-notify-test09-watched-file-in-watched-dir' for remote files.")
1210 1260
1211(ert-deftest file-notify-test09-sufficient-resources () 1261(ert-deftest file-notify-test10-sufficient-resources ()
1212 "Check that file notification does not use too many resources." 1262 "Check that file notification does not use too many resources."
1213 :tags '(:expensive-test) 1263 :tags '(:expensive-test)
1214 (skip-unless (file-notify--test-local-enabled)) 1264 (skip-unless (file-notify--test-local-enabled))
@@ -1249,8 +1299,8 @@ the file watch."
1249 ;; Cleanup. 1299 ;; Cleanup.
1250 (file-notify--test-cleanup))) 1300 (file-notify--test-cleanup)))
1251 1301
1252(file-notify--deftest-remote file-notify-test09-sufficient-resources 1302(file-notify--deftest-remote file-notify-test10-sufficient-resources
1253 "Check `file-notify-test09-sufficient-resources' for remote files.") 1303 "Check `file-notify-test10-sufficient-resources' for remote files.")
1254 1304
1255(defun file-notify-test-all (&optional interactive) 1305(defun file-notify-test-all (&optional interactive)
1256 "Run all tests for \\[file-notify]." 1306 "Run all tests for \\[file-notify]."