]> git.eshelyaron.com Git - emacs.git/commitdiff
New filenotify tests
authorMichael Albinus <michael.albinus@gmx.de>
Thu, 12 Oct 2023 09:02:53 +0000 (11:02 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Thu, 12 Oct 2023 09:02:53 +0000 (11:02 +0200)
* 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.

src/inotify.c
test/lisp/filenotify-tests.el

index 247d9f03055587e701172125337fd4f36686aae7..f50b9ddcaa752f21ce1fc848ea2f0385ea243d33 100644 (file)
@@ -517,12 +517,14 @@ it invalid.  */)
 #ifdef INOTIFY_DEBUG
 DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0,
        doc: /* Return a copy of the internal watch_list.  */)
+  (void)
 {
   return Fcopy_sequence (watch_list);
 }
 
 DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0,
        doc: /* Return non-nil, if an inotify instance is allocated.  */)
+  (void)
 {
   return inotifyfd < 0 ? Qnil : Qt;
 }
index 57099add08b9f912a56c7e125874bf6fc62a4c1a..eb485a10a92ea78086efe97ca1a0b44aa6a86474 100644 (file)
@@ -973,8 +973,7 @@ delivered."
             (setq file-notify--test-desc auto-revert-notify-watch-descriptor)
 
            ;; GKqueueFileMonitor does not report the `changed' event.
-           (skip-unless
-             (not (eq (file-notify--test-monitor) 'GKqueueFileMonitor)))
+           (skip-when (eq (file-notify--test-monitor) 'GKqueueFileMonitor))
 
            ;; Check, that file notification has been used.
            (should auto-revert-mode)
@@ -1708,6 +1707,71 @@ the file watch."
 (file-notify--deftest-remote file-notify-test11-symlinks
   "Check `file-notify-test11-symlinks' for remote files.")
 
+(ert-deftest file-notify-test12-unmount ()
+  "Check that file notification stop after unmounting the filesystem."
+  :tags '(:expensive-test)
+  (skip-unless (file-notify--test-local-enabled))
+  ;; This test does not work for w32notify.
+  (skip-when (string-equal (file-notify--test-library) "w32notify"))
+
+  (unwind-protect
+      (progn
+       (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
+       ;; File monitors like kqueue insist, that the watched file
+       ;; exists.  Directory monitors are not bound to this
+       ;; restriction.
+       (when (string-equal (file-notify--test-library) "kqueue")
+         (write-region
+          "any text" nil file-notify--test-tmpfile nil 'no-message))
+
+       (should
+        (setq file-notify--test-desc
+              (file-notify--test-add-watch
+                file-notify--test-tmpfile
+                '(attribute-change change) #'file-notify--test-event-handler)))
+        (should (file-notify-valid-p file-notify--test-desc))
+
+        ;; Unmounting the filesystem should stop watching.
+        (file-notify--test-with-actions '(stopped)
+          ;; We emulate unmounting by calling
+          ;; `file-notify-handle-event' with a corresponding event.
+          (file-notify-handle-event
+           (make-file-notify
+            :-event
+            (list file-notify--test-desc
+                  (pcase (file-notify--test-library)
+                    ((or "inotify" "inotifywait") '(unmount isdir))
+                    ((or "gfilenotify" "gio") '(unmounted))
+                    ("kqueue" '(revoke))
+                    (err (ert-fail (format "Library %s not supported" err))))
+                  (pcase (file-notify--test-library)
+                    ("kqueue" (file-local-name file-notify--test-tmpfile))
+                    (_ (file-local-name file-notify--test-tmpdir)))
+                  ;; In the inotify case, there is a 4th slot `cookie'.
+                  ;; Since it is unused for `unmount', we ignore it.
+                  )
+            :-callback
+            (pcase (file-notify--test-library)
+              ("inotify" #'file-notify--callback-inotify)
+              ("gfilenotify" #'file-notify--callback-gfilenotify)
+              ("kqueue" #'file-notify--callback-kqueue)
+              ((or "inotifywait" "gio") #'file-notify-callback)
+              (err (ert-fail (format "Library %s not supported" err)))))))
+
+        ;; The watch has been stopped.
+        (should-not (file-notify-valid-p file-notify--test-desc))
+
+        ;; The environment shall be cleaned up.
+        (when (string-equal (file-notify--test-library) "kqueue")
+          (delete-file file-notify--test-tmpfile))
+        (file-notify--test-cleanup-p))
+
+    ;; Cleanup.
+    (file-notify--test-cleanup)))
+
+(file-notify--deftest-remote file-notify-test12-unmount
+  "Check `file-notify-test12-unmount' for remote files.")
+
 (defun file-notify-test-all (&optional interactive)
   "Run all tests for \\[file-notify]."
   (interactive "p")