aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2016-02-23 13:51:36 +0100
committerMichael Albinus2016-02-23 13:51:36 +0100
commitc582def527fa905dce9abe87232849746aedc6a3 (patch)
tree978ee7eef7004b754fdbbc508163002f229d61a4 /test
parenta1585e18c05d031307c8dcb05f1ac1165858f270 (diff)
downloademacs-c582def527fa905dce9abe87232849746aedc6a3.tar.gz
emacs-c582def527fa905dce9abe87232849746aedc6a3.zip
Further adaptions in file-notify-tests.el for w32notify
* test/automated/file-notify-tests.el (file-notify--test-read-event-timeout, file-notify--test-timeout): Decrease values. (file-notify-test03-autorevert) (file-notify-test04-file-validity) (file-notify-test05-dir-validity): Run tests also for w32notify. (file-notify-test08-watched-file-in-watched-dir): Adapt expected events for w32notify.
Diffstat (limited to 'test')
-rw-r--r--test/automated/file-notify-tests.el145
1 files changed, 76 insertions, 69 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index a16de7fb058..9f0c0ed0dc1 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -64,7 +64,7 @@
64(defvar file-notify--test-event nil) 64(defvar file-notify--test-event nil)
65(defvar file-notify--test-events nil) 65(defvar file-notify--test-events nil)
66 66
67(defconst file-notify--test-read-event-timeout 0.02 67(defconst file-notify--test-read-event-timeout 0.01
68 "Timeout for `read-event' calls. 68 "Timeout for `read-event' calls.
69It is different for local and remote file notification libraries.") 69It is different for local and remote file notification libraries.")
70 70
@@ -72,7 +72,7 @@ It is different for local and remote file notification libraries.")
72 "Timeout to wait for arriving events, in seconds." 72 "Timeout to wait for arriving events, in seconds."
73 (cond 73 (cond
74 ((file-remote-p temporary-file-directory) 6) 74 ((file-remote-p temporary-file-directory) 6)
75 ((string-equal (file-notify--test-library) "w32notify") 10) 75 ((string-equal (file-notify--test-library) "w32notify") 4)
76 ((eq system-type 'cygwin) 10) 76 ((eq system-type 'cygwin) 10)
77 (t 3))) 77 (t 3)))
78 78
@@ -417,8 +417,8 @@ longer than timeout seconds for the events to be delivered."
417 '(change) 'file-notify--test-event-handler))) 417 '(change) 'file-notify--test-event-handler)))
418 (file-notify--test-with-events 418 (file-notify--test-with-events
419 (cond 419 (cond
420 ;; w32notify does raise a `stopped' event when a 420 ;; w32notify does not raise `deleted' and `stopped'
421 ;; watched directory is deleted. 421 ;; events for the watched directory.
422 ((string-equal (file-notify--test-library) "w32notify") 422 ((string-equal (file-notify--test-library) "w32notify")
423 '(created changed deleted)) 423 '(created changed deleted))
424 ;; cygwin recognizes only `deleted' and `stopped' events. 424 ;; cygwin recognizes only `deleted' and `stopped' events.
@@ -449,9 +449,11 @@ longer than timeout seconds for the events to be delivered."
449 (file-notify--test-with-events 449 (file-notify--test-with-events
450 (cond 450 (cond
451 ;; w32notify does not distinguish between `changed' and 451 ;; w32notify does not distinguish between `changed' and
452 ;; `attribute-changed'. 452 ;; `attribute-changed'. It does not raise `deleted'
453 ;; and `stopped' events for the watched directory.
453 ((string-equal (file-notify--test-library) "w32notify") 454 ((string-equal (file-notify--test-library) "w32notify")
454 '(created changed created changed changed changed changed 455 '(created changed created changed
456 changed changed changed
455 deleted deleted)) 457 deleted deleted))
456 ;; cygwin recognizes only `deleted' and `stopped' events. 458 ;; cygwin recognizes only `deleted' and `stopped' events.
457 ((eq system-type 'cygwin) 459 ((eq system-type 'cygwin)
@@ -488,8 +490,8 @@ longer than timeout seconds for the events to be delivered."
488 '(change) 'file-notify--test-event-handler))) 490 '(change) 'file-notify--test-event-handler)))
489 (file-notify--test-with-events 491 (file-notify--test-with-events
490 (cond 492 (cond
491 ;; w32notify does not distinguish between `changed' and 493 ;; w32notify does not raise `deleted' and `stopped'
492 ;; `attribute-changed'. 494 ;; events for the watched directory.
493 ((string-equal (file-notify--test-library) "w32notify") 495 ((string-equal (file-notify--test-library) "w32notify")
494 '(created changed renamed deleted)) 496 '(created changed renamed deleted))
495 ;; cygwin recognizes only `deleted' and `stopped' events. 497 ;; cygwin recognizes only `deleted' and `stopped' events.
@@ -604,31 +606,29 @@ longer than timeout seconds for the events to be delivered."
604 (should (string-match "another text" (buffer-string))) 606 (should (string-match "another text" (buffer-string)))
605 607
606 ;; Stop file notification. Autorevert shall still work via polling. 608 ;; Stop file notification. Autorevert shall still work via polling.
607 ;; It doesn't work for w32notify. 609 (file-notify-rm-watch auto-revert-notify-watch-descriptor)
608 (unless (string-equal (file-notify--test-library) "w32notify") 610 (file-notify--wait-for-events
609 (file-notify-rm-watch auto-revert-notify-watch-descriptor) 611 timeout (null auto-revert-use-notify))
612 (should-not auto-revert-use-notify)
613 (should-not auto-revert-notify-watch-descriptor)
614
615 ;; Modify file. We wait for two seconds, in order to
616 ;; have another timestamp. One second seems to be too
617 ;; short.
618 (with-current-buffer (get-buffer-create "*Messages*")
619 (narrow-to-region (point-max) (point-max)))
620 (sleep-for 2)
621 (write-region
622 "foo bla" nil file-notify--test-tmpfile nil 'no-message)
623
624 ;; Check, that the buffer has been reverted.
625 (with-current-buffer (get-buffer-create "*Messages*")
610 (file-notify--wait-for-events 626 (file-notify--wait-for-events
611 timeout (null auto-revert-use-notify)) 627 timeout
612 (should-not auto-revert-use-notify) 628 (string-match
613 (should-not auto-revert-notify-watch-descriptor) 629 (format-message "Reverting buffer `%s'." (buffer-name buf))
614 630 (buffer-string))))
615 ;; Modify file. We wait for two seconds, in order to 631 (should (string-match "foo bla" (buffer-string)))))
616 ;; have another timestamp. One second seems to be too
617 ;; short.
618 (with-current-buffer (get-buffer-create "*Messages*")
619 (narrow-to-region (point-max) (point-max)))
620 (sleep-for 2)
621 (write-region
622 "foo bla" nil file-notify--test-tmpfile nil 'no-message)
623
624 ;; Check, that the buffer has been reverted.
625 (with-current-buffer (get-buffer-create "*Messages*")
626 (file-notify--wait-for-events
627 timeout
628 (string-match
629 (format-message "Reverting buffer `%s'." (buffer-name buf))
630 (buffer-string))))
631 (should (string-match "foo bla" (buffer-string))))))
632 632
633 ;; Cleanup. 633 ;; Cleanup.
634 (with-current-buffer "*Messages*" (widen)) 634 (with-current-buffer "*Messages*" (widen))
@@ -699,36 +699,37 @@ longer than timeout seconds for the events to be delivered."
699 (file-notify--test-cleanup)) 699 (file-notify--test-cleanup))
700 700
701 (unwind-protect 701 (unwind-protect
702 ;; w32notify does not send a `stopped' event when deleting a 702 (let ((temporary-file-directory
703 ;; directory. The test does not work, therefore. 703 (make-temp-file "file-notify-test-parent" t)))
704 (unless (string-equal (file-notify--test-library) "w32notify") 704 (should
705 (let ((temporary-file-directory 705 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
706 (make-temp-file "file-notify-test-parent" t))) 706 file-notify--test-desc
707 (should 707 (file-notify-add-watch
708 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) 708 temporary-file-directory
709 file-notify--test-desc 709 '(change) #'file-notify--test-event-handler)))
710 (file-notify-add-watch 710 (file-notify--test-with-events
711 temporary-file-directory 711 (cond
712 '(change) #'file-notify--test-event-handler))) 712 ;; w32notify does not raise `deleted' and `stopped' events
713 (file-notify--test-with-events 713 ;; for the watched directory.
714 (cond 714 ((string-equal (file-notify--test-library) "w32notify")
715 ;; cygwin recognizes only `deleted' and `stopped' events. 715 '(created changed deleted))
716 ((eq system-type 'cygwin) 716 ;; cygwin recognizes only `deleted' and `stopped' events.
717 '(deleted stopped)) 717 ((eq system-type 'cygwin)
718 ;; There are two `deleted' events, for the file and for 718 '(deleted stopped))
719 ;; the directory. Except for kqueue. 719 ;; There are two `deleted' events, for the file and for the
720 ((string-equal (file-notify--test-library) "kqueue") 720 ;; directory. Except for kqueue.
721 '(created changed deleted stopped)) 721 ((string-equal (file-notify--test-library) "kqueue")
722 (t '(created changed deleted deleted stopped))) 722 '(created changed deleted stopped))
723 (should (file-notify-valid-p file-notify--test-desc)) 723 (t '(created changed deleted deleted stopped)))
724 (read-event nil nil file-notify--test-read-event-timeout) 724 (should (file-notify-valid-p file-notify--test-desc))
725 (write-region 725 (read-event nil nil file-notify--test-read-event-timeout)
726 "any text" nil file-notify--test-tmpfile nil 'no-message) 726 (write-region
727 (read-event nil nil file-notify--test-read-event-timeout) 727 "any text" nil file-notify--test-tmpfile nil 'no-message)
728 (delete-directory temporary-file-directory t)) 728 (read-event nil nil file-notify--test-read-event-timeout)
729 ;; After deleting the parent directory, the descriptor must 729 (delete-directory temporary-file-directory t))
730 ;; not be valid anymore. 730 ;; After deleting the parent directory, the descriptor must
731 (should-not (file-notify-valid-p file-notify--test-desc)))) 731 ;; not be valid anymore.
732 (should-not (file-notify-valid-p file-notify--test-desc)))
732 733
733 ;; Cleanup. 734 ;; Cleanup.
734 (file-notify--test-cleanup))) 735 (file-notify--test-cleanup)))
@@ -763,11 +764,8 @@ longer than timeout seconds for the events to be delivered."
763 (file-notify--test-cleanup)) 764 (file-notify--test-cleanup))
764 765
765 (unwind-protect 766 (unwind-protect
766 ;; The batch-mode operation of w32notify is fragile (there's no 767 (progn
767 ;; input threads to send the message to). 768 (setq file-notify--test-tmpfile
768 (unless (and noninteractive
769 (string-equal (file-notify--test-library) "w32notify"))
770 (setq file-notify--test-tmpfile
771 (file-name-as-directory (file-notify--test-make-temp-name))) 769 (file-name-as-directory (file-notify--test-make-temp-name)))
772 (make-directory file-notify--test-tmpfile) 770 (make-directory file-notify--test-tmpfile)
773 (should 771 (should
@@ -1045,7 +1043,11 @@ the file watch."
1045 directory-files-no-dot-files-regexp 'nosort)) 1043 directory-files-no-dot-files-regexp 'nosort))
1046 'deleted) 1044 'deleted)
1047 ;; The events of the directory itself. 1045 ;; The events of the directory itself.
1048 '(deleted stopped)))) 1046 (cond
1047 ;; w32notify does not raise `deleted' and `stopped'
1048 ;; events for the watched directory.
1049 ((string-equal (file-notify--test-library) "w32notify") '())
1050 (t '(deleted stopped))))))
1049 (delete-directory file-notify--test-tmpfile 'recursive)) 1051 (delete-directory file-notify--test-tmpfile 'recursive))
1050 (should-not (file-notify-valid-p file-notify--test-desc1)) 1052 (should-not (file-notify-valid-p file-notify--test-desc1))
1051 (should-not (file-notify-valid-p file-notify--test-desc2))) 1053 (should-not (file-notify-valid-p file-notify--test-desc2)))
@@ -1065,7 +1067,12 @@ the file watch."
1065 1067
1066;; TODO: 1068;; TODO:
1067 1069
1068;; * For w32notify, no stopped events arrive when a directory is removed. 1070;; * kqueue does not send all expected `deleted' events. Maybe due to
1071;; the missing directory monitor.
1072;; * For w32notify, no `deleted' and `stopped' events arrive when a
1073;; directory is removed.
1074;; * For w32notify, no `attribute-changed' events arrive. Its sends
1075;; `changed' events instead.
1069;; * Check, why cygwin recognizes only `deleted' and `stopped' events. 1076;; * Check, why cygwin recognizes only `deleted' and `stopped' events.
1070 1077
1071(provide 'file-notify-tests) 1078(provide 'file-notify-tests)