aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2023-10-12 11:02:53 +0200
committerMichael Albinus2023-10-12 11:02:53 +0200
commit088dd67f891553e1a27e65c97e386d0dd8dc4f64 (patch)
tree5f56001e7c8dca79990ebc6276fa0747327a7082
parent963ccc05acf2939c95524de9175a1fc3053b0f6f (diff)
downloademacs-088dd67f891553e1a27e65c97e386d0dd8dc4f64.tar.gz
emacs-088dd67f891553e1a27e65c97e386d0dd8dc4f64.zip
New filenotify tests
* src/inotify.c (Finotify_watch_list, Finotify_allocated_p): Fix argument list. * test/lisp/filenotify-tests.el (file-notify-test04-autorevert): Use `skip-when'. (file-notify-test12-unmount, file-notify-test12-unmount-remote): New tests.
-rw-r--r--src/inotify.c2
-rw-r--r--test/lisp/filenotify-tests.el68
2 files changed, 68 insertions, 2 deletions
diff --git a/src/inotify.c b/src/inotify.c
index 247d9f03055..f50b9ddcaa7 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -517,12 +517,14 @@ it invalid. */)
517#ifdef INOTIFY_DEBUG 517#ifdef INOTIFY_DEBUG
518DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0, 518DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0,
519 doc: /* Return a copy of the internal watch_list. */) 519 doc: /* Return a copy of the internal watch_list. */)
520 (void)
520{ 521{
521 return Fcopy_sequence (watch_list); 522 return Fcopy_sequence (watch_list);
522} 523}
523 524
524DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0, 525DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0,
525 doc: /* Return non-nil, if an inotify instance is allocated. */) 526 doc: /* Return non-nil, if an inotify instance is allocated. */)
527 (void)
526{ 528{
527 return inotifyfd < 0 ? Qnil : Qt; 529 return inotifyfd < 0 ? Qnil : Qt;
528} 530}
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index 57099add08b..eb485a10a92 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -973,8 +973,7 @@ delivered."
973 (setq file-notify--test-desc auto-revert-notify-watch-descriptor) 973 (setq file-notify--test-desc auto-revert-notify-watch-descriptor)
974 974
975 ;; GKqueueFileMonitor does not report the `changed' event. 975 ;; GKqueueFileMonitor does not report the `changed' event.
976 (skip-unless 976 (skip-when (eq (file-notify--test-monitor) 'GKqueueFileMonitor))
977 (not (eq (file-notify--test-monitor) 'GKqueueFileMonitor)))
978 977
979 ;; Check, that file notification has been used. 978 ;; Check, that file notification has been used.
980 (should auto-revert-mode) 979 (should auto-revert-mode)
@@ -1708,6 +1707,71 @@ the file watch."
1708(file-notify--deftest-remote file-notify-test11-symlinks 1707(file-notify--deftest-remote file-notify-test11-symlinks
1709 "Check `file-notify-test11-symlinks' for remote files.") 1708 "Check `file-notify-test11-symlinks' for remote files.")
1710 1709
1710(ert-deftest file-notify-test12-unmount ()
1711 "Check that file notification stop after unmounting the filesystem."
1712 :tags '(:expensive-test)
1713 (skip-unless (file-notify--test-local-enabled))
1714 ;; This test does not work for w32notify.
1715 (skip-when (string-equal (file-notify--test-library) "w32notify"))
1716
1717 (unwind-protect
1718 (progn
1719 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
1720 ;; File monitors like kqueue insist, that the watched file
1721 ;; exists. Directory monitors are not bound to this
1722 ;; restriction.
1723 (when (string-equal (file-notify--test-library) "kqueue")
1724 (write-region
1725 "any text" nil file-notify--test-tmpfile nil 'no-message))
1726
1727 (should
1728 (setq file-notify--test-desc
1729 (file-notify--test-add-watch
1730 file-notify--test-tmpfile
1731 '(attribute-change change) #'file-notify--test-event-handler)))
1732 (should (file-notify-valid-p file-notify--test-desc))
1733
1734 ;; Unmounting the filesystem should stop watching.
1735 (file-notify--test-with-actions '(stopped)
1736 ;; We emulate unmounting by calling
1737 ;; `file-notify-handle-event' with a corresponding event.
1738 (file-notify-handle-event
1739 (make-file-notify
1740 :-event
1741 (list file-notify--test-desc
1742 (pcase (file-notify--test-library)
1743 ((or "inotify" "inotifywait") '(unmount isdir))
1744 ((or "gfilenotify" "gio") '(unmounted))
1745 ("kqueue" '(revoke))
1746 (err (ert-fail (format "Library %s not supported" err))))
1747 (pcase (file-notify--test-library)
1748 ("kqueue" (file-local-name file-notify--test-tmpfile))
1749 (_ (file-local-name file-notify--test-tmpdir)))
1750 ;; In the inotify case, there is a 4th slot `cookie'.
1751 ;; Since it is unused for `unmount', we ignore it.
1752 )
1753 :-callback
1754 (pcase (file-notify--test-library)
1755 ("inotify" #'file-notify--callback-inotify)
1756 ("gfilenotify" #'file-notify--callback-gfilenotify)
1757 ("kqueue" #'file-notify--callback-kqueue)
1758 ((or "inotifywait" "gio") #'file-notify-callback)
1759 (err (ert-fail (format "Library %s not supported" err)))))))
1760
1761 ;; The watch has been stopped.
1762 (should-not (file-notify-valid-p file-notify--test-desc))
1763
1764 ;; The environment shall be cleaned up.
1765 (when (string-equal (file-notify--test-library) "kqueue")
1766 (delete-file file-notify--test-tmpfile))
1767 (file-notify--test-cleanup-p))
1768
1769 ;; Cleanup.
1770 (file-notify--test-cleanup)))
1771
1772(file-notify--deftest-remote file-notify-test12-unmount
1773 "Check `file-notify-test12-unmount' for remote files.")
1774
1711(defun file-notify-test-all (&optional interactive) 1775(defun file-notify-test-all (&optional interactive)
1712 "Run all tests for \\[file-notify]." 1776 "Run all tests for \\[file-notify]."
1713 (interactive "p") 1777 (interactive "p")