Add some more test cases, fix for `UNWATCH`.
authorOlof-Joachim Frahm <olof@macrolet.net>
Fri, 16 Jan 2015 00:16:55 +0000 (00:16 +0000)
committerOlof-Joachim Frahm <olof@macrolet.net>
Fri, 16 Jan 2015 00:49:32 +0000 (00:49 +0000)
src/inotify.lisp
tests/inotify.lisp

index a2ad5e8..eb2919f 100644 (file)
@@ -341,14 +341,15 @@ may be one from a given EVENT) or PATHNAME."
     (error "either PATHNAME, EVENT or HANDLE have to be specified"))
   (when event
     (setf handle (slot-value event 'wd)))
-  (if handle
-      (unwatch-raw inotify handle)
-      (let ((handle (car (pathname-handle/flags inotify pathname))))
-        (unless handle
-          (error "PATHNAME ~S isn't being watched" pathname))
-        ;; remove even if unwatch-raw throws an error (which can happen if :oneshot is specified)
-        (remhash pathname (inotify-watched inotify))
-        (unwatch-raw inotify handle)))
+  (let ((handle (or handle
+                    (car (pathname-handle/flags inotify pathname))
+                    (error "PATHNAME ~S isn't being watched" pathname)))
+        (pathname (or pathname
+                      (event-pathname/flags inotify NIL handle)
+                      (error "No PATHNAME found for HANDLE ~S" handle))))
+    ;; remove even if unwatch-raw throws an error (which can happen if :oneshot is specified)
+    (remhash pathname (inotify-watched inotify))
+    (unwatch-raw inotify handle))
   (values))
 
 (defun list-watched (inotify)
index 4787dd2..5515f6e 100644 (file)
                  (is-true event "No event was read")
                  (is (equal "foo" (inotify-event-name event))))))
         (osicat:delete-directory-and-files tmp)))))
+
+(def-test watch.recorded ()
+  "A single watch is recorded and the returned handle is valid."
+  (with-inotify (inotify)
+    (is (null (list-watched inotify)))
+    (is (integerp (watch inotify #P"." :all-events)))
+    (is (equal '(#P".") (list-watched inotify)))))
+
+(def-test unwatch.pathname ()
+  "Unwatching by pathname works."
+  (with-inotify (inotify)
+    (is (null (list-watched inotify)))
+    (watch inotify #P"." :all-events)
+    (is (not (null (list-watched inotify))))
+    (unwatch inotify :pathname #P".")
+    (is (null (list-watched inotify)))))
+
+(def-test unwatch.handle ()
+  "Unwatching by handle works."
+  (with-inotify (inotify)
+    (is (null (list-watched inotify)))
+    (let ((handle (watch inotify #P"." :all-events)))
+      (is (not (null (list-watched inotify))))
+      (unwatch inotify :handle handle))
+    (is (null (list-watched inotify)))))
+
+(def-test unwatch.no-arguments ()
+  "Unwatching needs exactly one of three keywords."
+  (with-inotify (inotify)
+    (signals error
+      (unwatch inotify))))
+
+(def-test unwatch.two-arguments ()
+  "Unwatching needs exactly one of three keywords."
+  (with-inotify (inotify)
+    (signals error
+      (unwatch inotify :pathname #P"." :handle 42))))