From: Olof-Joachim Frahm Date: Fri, 16 Jan 2015 00:16:55 +0000 (+0000) Subject: Add some more test cases, fix for `UNWATCH`. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=fe57a17e5e8e860dbba2aa0d9e3b179c92fb96d2;p=cl-inotify.git Add some more test cases, fix for `UNWATCH`. --- diff --git a/src/inotify.lisp b/src/inotify.lisp index a2ad5e8..eb2919f 100644 --- a/src/inotify.lisp +++ b/src/inotify.lisp @@ -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) diff --git a/tests/inotify.lisp b/tests/inotify.lisp index 4787dd2..5515f6e 100644 --- a/tests/inotify.lisp +++ b/tests/inotify.lisp @@ -48,3 +48,40 @@ (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))))