aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2015-11-18 13:47:25 +0000
committerMichael Albinus2015-11-18 13:47:25 +0000
commit5f08a72c8bf88d4f6f564c5890ec937f59605463 (patch)
tree6fd3a17bad8adaed59c007c3424209293282c194 /test
parentbad2b4dbc6dee26bde4b2da73cf9c295f0a31f97 (diff)
downloademacs-5f08a72c8bf88d4f6f564c5890ec937f59605463.tar.gz
emacs-5f08a72c8bf88d4f6f564c5890ec937f59605463.zip
Further fixes for kqueue.
* lisp/filenotify.el (file-notify-callback): Raise also event if directory name matches. (file-notify-add-watch): Add `create' to the flags for `kqueue'. * src/kqueue.c (kqueue_generate_event): Use watch_object as argument instead of ident. Remove callback argument. Adapt callees. Check actions whether they are monitored flags. * test/automated/file-notify-tests.el (file-notify--test-library): New defun. (file-notify-test00-availability, file-notify-test02-events) (file-notify-test04-file-validity) (file-notify-test05-dir-validity): Use it. (file-notify-test02-events, file-notify-test04-file-validity): Add `read-event' calls between different file actions, in order to give the backends a chance to rais an event. Needed especially for kqueue. In case of deleting a directory, there are two `deleted' events.
Diffstat (limited to 'test')
-rw-r--r--test/automated/file-notify-tests.el59
1 files changed, 42 insertions, 17 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index 67e929a6477..6946541b909 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -133,6 +133,18 @@ being the result.")
133 ;; Return result. 133 ;; Return result.
134 (cdr file-notify--test-remote-enabled-checked)) 134 (cdr file-notify--test-remote-enabled-checked))
135 135
136(defun file-notify--test-library ()
137 "The used libray for the test, as string.
138In the remote case, it is the process name which runs on the
139remote host, or nil."
140 (if (null (file-remote-p temporary-file-directory))
141 (symbol-name file-notify--library)
142 (and (consp file-notify--test-remote-enabled-checked)
143 (processp (cdr file-notify--test-remote-enabled-checked))
144 (replace-regexp-in-string
145 "<[[:digit:]]+>\\'" ""
146 (process-name (cdr file-notify--test-remote-enabled-checked))))))
147
136(defmacro file-notify--deftest-remote (test docstring) 148(defmacro file-notify--deftest-remote (test docstring)
137 "Define ert `TEST-remote' for remote files." 149 "Define ert `TEST-remote' for remote files."
138 (declare (indent 1)) 150 (declare (indent 1))
@@ -150,12 +162,7 @@ being the result.")
150 "Test availability of `file-notify'." 162 "Test availability of `file-notify'."
151 (skip-unless (file-notify--test-local-enabled)) 163 (skip-unless (file-notify--test-local-enabled))
152 ;; Report the native library which has been used. 164 ;; Report the native library which has been used.
153 (if (null (file-remote-p temporary-file-directory)) 165 (message "Library: `%s'" (file-notify--test-library))
154 (message "Local library: `%s'" file-notify--library)
155 (message "Remote command: `%s'"
156 (replace-regexp-in-string
157 "<[[:digit:]]+>\\'" ""
158 (process-name (cdr file-notify--test-remote-enabled-checked)))))
159 (should 166 (should
160 (setq file-notify--test-desc 167 (setq file-notify--test-desc
161 (file-notify-add-watch temporary-file-directory '(change) 'ignore))) 168 (file-notify-add-watch temporary-file-directory '(change) 'ignore)))
@@ -311,6 +318,7 @@ Don't wait longer than timeout seconds for the events to be delivered."
311 (file-notify--test-with-events '(created changed deleted) 318 (file-notify--test-with-events '(created changed deleted)
312 (write-region 319 (write-region
313 "any text" nil file-notify--test-tmpfile nil 'no-message) 320 "any text" nil file-notify--test-tmpfile nil 'no-message)
321 (read-event nil nil 0.1)
314 (delete-file file-notify--test-tmpfile)) 322 (delete-file file-notify--test-tmpfile))
315 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. 323 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it.
316 (let (file-notify--test-events) 324 (let (file-notify--test-events)
@@ -319,7 +327,7 @@ Don't wait longer than timeout seconds for the events to be delivered."
319 ;; Check creation, change and deletion. There must be a 327 ;; Check creation, change and deletion. There must be a
320 ;; `stopped' event when deleting the directory. It doesn't 328 ;; `stopped' event when deleting the directory. It doesn't
321 ;; work for w32notify. 329 ;; work for w32notify.
322 (unless (eq file-notify--library 'w32notify) 330 (unless (string-equal (file-notify--test-library) "w32notify")
323 (make-directory file-notify--test-tmpfile) 331 (make-directory file-notify--test-tmpfile)
324 (setq file-notify--test-desc 332 (setq file-notify--test-desc
325 (file-notify-add-watch 333 (file-notify-add-watch
@@ -327,11 +335,14 @@ Don't wait longer than timeout seconds for the events to be delivered."
327 '(change) 'file-notify--test-event-handler)) 335 '(change) 'file-notify--test-event-handler))
328 (file-notify--test-with-events 336 (file-notify--test-with-events
329 ;; There are two `deleted' events, for the file and for 337 ;; There are two `deleted' events, for the file and for
330 ;; the directory. 338 ;; the directory. Except for kqueue.
331 '(created changed deleted deleted stopped) 339 (if (string-equal (file-notify--test-library) "kqueue")
340 '(created changed deleted stopped)
341 '(created changed deleted deleted stopped))
332 (write-region 342 (write-region
333 "any text" nil (expand-file-name "foo" file-notify--test-tmpfile) 343 "any text" nil (expand-file-name "foo" file-notify--test-tmpfile)
334 nil 'no-message) 344 nil 'no-message)
345 (read-event nil nil 0.1)
335 (delete-directory file-notify--test-tmpfile 'recursive)) 346 (delete-directory file-notify--test-tmpfile 'recursive))
336 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. 347 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it.
337 (let (file-notify--test-events) 348 (let (file-notify--test-events)
@@ -346,17 +357,21 @@ Don't wait longer than timeout seconds for the events to be delivered."
346 (file-notify--test-with-events 357 (file-notify--test-with-events
347 ;; w32notify does not distinguish between `changed' and 358 ;; w32notify does not distinguish between `changed' and
348 ;; `attribute-changed'. 359 ;; `attribute-changed'.
349 (if (eq file-notify--library 'w32notify) 360 (if (string-equal (file-notify--test-library) "w32notify")
350 '(created changed changed deleted) 361 '(created changed changed deleted)
351 '(created changed deleted)) 362 '(created changed deleted))
352 (write-region 363 (write-region
353 "any text" nil file-notify--test-tmpfile nil 'no-message) 364 "any text" nil file-notify--test-tmpfile nil 'no-message)
365 (read-event nil nil 0.1)
354 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) 366 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
355 ;; The next two events shall not be visible. 367 ;; The next two events shall not be visible.
368 (read-event nil nil 0.1)
356 (set-file-modes file-notify--test-tmpfile 000) 369 (set-file-modes file-notify--test-tmpfile 000)
357 (read-event nil nil 0.1) ; In order to distinguish the events. 370 (read-event nil nil 0.1)
358 (set-file-times file-notify--test-tmpfile '(0 0)) 371 (set-file-times file-notify--test-tmpfile '(0 0))
372 (read-event nil nil 0.1)
359 (delete-file file-notify--test-tmpfile) 373 (delete-file file-notify--test-tmpfile)
374 (read-event nil nil 0.1)
360 (delete-file file-notify--test-tmpfile1)) 375 (delete-file file-notify--test-tmpfile1))
361 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. 376 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it.
362 (let (file-notify--test-events) 377 (let (file-notify--test-events)
@@ -371,15 +386,18 @@ Don't wait longer than timeout seconds for the events to be delivered."
371 (file-notify--test-with-events '(created changed renamed) 386 (file-notify--test-with-events '(created changed renamed)
372 (write-region 387 (write-region
373 "any text" nil file-notify--test-tmpfile nil 'no-message) 388 "any text" nil file-notify--test-tmpfile nil 'no-message)
389 (read-event nil nil 0.1)
374 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) 390 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
375 ;; After the rename, we won't get events anymore. 391 ;; After the rename, we won't get events anymore.
392 (read-event nil nil 0.1)
376 (delete-file file-notify--test-tmpfile1)) 393 (delete-file file-notify--test-tmpfile1))
377 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. 394 ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it.
378 (let (file-notify--test-events) 395 (let (file-notify--test-events)
379 (file-notify-rm-watch file-notify--test-desc)) 396 (file-notify-rm-watch file-notify--test-desc))
380 397
381 ;; Check attribute change. It doesn't work for w32notify. 398 ;; Check attribute change. It doesn't work for kqueue and w32notify.
382 (unless (eq file-notify--library 'w32notify) 399 (unless (or (string-equal (file-notify--test-library) "kqueue")
400 (string-equal (file-notify--test-library) "w32notify"))
383 (setq file-notify--test-desc 401 (setq file-notify--test-desc
384 (file-notify-add-watch 402 (file-notify-add-watch
385 file-notify--test-tmpfile 403 file-notify--test-tmpfile
@@ -523,6 +541,7 @@ Don't wait longer than timeout seconds for the events to be delivered."
523 (should (file-notify-valid-p file-notify--test-desc)) 541 (should (file-notify-valid-p file-notify--test-desc))
524 (write-region 542 (write-region
525 "any text" nil file-notify--test-tmpfile nil 'no-message) 543 "any text" nil file-notify--test-tmpfile nil 'no-message)
544 (read-event nil nil 0.1)
526 (delete-file file-notify--test-tmpfile)) 545 (delete-file file-notify--test-tmpfile))
527 ;; After deleting the file, the descriptor is still valid. 546 ;; After deleting the file, the descriptor is still valid.
528 (should (file-notify-valid-p file-notify--test-desc)) 547 (should (file-notify-valid-p file-notify--test-desc))
@@ -537,8 +556,7 @@ Don't wait longer than timeout seconds for the events to be delivered."
537 (unwind-protect 556 (unwind-protect
538 ;; The batch-mode operation of w32notify is fragile (there's no 557 ;; The batch-mode operation of w32notify is fragile (there's no
539 ;; input threads to send the message to). 558 ;; input threads to send the message to).
540 ;(unless (and noninteractive (eq file-notify--library 'w32notify)) 559 (unless (string-equal (file-notify--test-library) "w32notify")
541 (unless (eq file-notify--library 'w32notify)
542 (let ((temporary-file-directory 560 (let ((temporary-file-directory
543 (make-temp-file "file-notify-test-parent" t))) 561 (make-temp-file "file-notify-test-parent" t)))
544 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) 562 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
@@ -546,10 +564,16 @@ Don't wait longer than timeout seconds for the events to be delivered."
546 (file-notify-add-watch 564 (file-notify-add-watch
547 file-notify--test-tmpfile 565 file-notify--test-tmpfile
548 '(change) #'file-notify--test-event-handler)) 566 '(change) #'file-notify--test-event-handler))
549 (file-notify--test-with-events '(created changed deleted stopped) 567 (file-notify--test-with-events
568 ;; There are two `deleted' events, for the file and for
569 ;; the directory. Except for kqueue.
570 (if (string-equal (file-notify--test-library) "kqueue")
571 '(created changed deleted stopped)
572 '(created changed deleted deleted stopped))
550 (should (file-notify-valid-p file-notify--test-desc)) 573 (should (file-notify-valid-p file-notify--test-desc))
551 (write-region 574 (write-region
552 "any text" nil file-notify--test-tmpfile nil 'no-message) 575 "any text" nil file-notify--test-tmpfile nil 'no-message)
576 (read-event nil nil 0.1)
553 (delete-directory temporary-file-directory t)) 577 (delete-directory temporary-file-directory t))
554 ;; After deleting the parent directory, the descriptor must 578 ;; After deleting the parent directory, the descriptor must
555 ;; not be valid anymore. 579 ;; not be valid anymore.
@@ -589,7 +613,8 @@ Don't wait longer than timeout seconds for the events to be delivered."
589 (unwind-protect 613 (unwind-protect
590 ;; The batch-mode operation of w32notify is fragile (there's no 614 ;; The batch-mode operation of w32notify is fragile (there's no
591 ;; input threads to send the message to). 615 ;; input threads to send the message to).
592 (unless (and noninteractive (eq file-notify--library 'w32notify)) 616 (unless (and noninteractive
617 (string-equal (file-notify--test-library) "w32notify"))
593 (setq file-notify--test-tmpfile 618 (setq file-notify--test-tmpfile
594 (file-name-as-directory (file-notify--test-make-temp-name))) 619 (file-name-as-directory (file-notify--test-make-temp-name)))
595 (make-directory file-notify--test-tmpfile) 620 (make-directory file-notify--test-tmpfile)