emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 01b5475: Adapt tests and manual for w32notify


From: Michael Albinus
Subject: [Emacs-diffs] master 01b5475: Adapt tests and manual for w32notify
Date: Mon, 21 Sep 2015 13:07:15 +0000

branch: master
commit 01b547529ba81f4f5a64f5017a2c3d6601d0bb95
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    Adapt tests and manual for w32notify
    
    * doc/lispref/os.texi (File Notifications): w32notify does not
    send `attribute-changed' events.
    
    * test/automated/file-notify-tests.el (file-notify--test-with-events):
    Simplify parameters.  Adapt all callees.
    (file-notify-test02-events): w32notify does not send
    `attribute-changed' events.
    (file-notify-test04-file-validity, file-notify-test05-dir-validity):
    Do not skip in case of w32notify.  Simply ignore this part of the test.
---
 doc/lispref/os.texi                 |    7 ++-
 test/automated/file-notify-tests.el |  161 ++++++++++++++++------------------
 2 files changed, 82 insertions(+), 86 deletions(-)

diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index f5eecb2..1d0723e 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -2565,7 +2565,7 @@ specification prior to @samp{"1.0"}.
 
 Several operating systems support watching of filesystems for changes
 of files.  If configured properly, Emacs links a respective library
-like @file{gfilenotify}, @file{inotify}, or  @file{w32notify}
+like @file{gfilenotify}, @file{inotify}, or @file{w32notify}
 statically.  These libraries enable watching of filesystems on the
 local machine.
 
@@ -2632,6 +2632,11 @@ any one of the following symbols:
 a @var{file} attribute was changed
 @end table
 
+Note that the @file{w32notify} library does not report
address@hidden events.  Even in case a file attribute has
+changed, like permissions or modification time, this library reports a
address@hidden event.
+
 @var{file} and @var{file1} are the name of the file(s) whose event is
 being reported.  For example:
 
diff --git a/test/automated/file-notify-tests.el 
b/test/automated/file-notify-tests.el
index 9d66f03..75e0c24 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -245,17 +245,17 @@ TIMEOUT is the maximum time to wait for, in seconds."
      (while (null ,until)
        (read-event nil nil 0.1))))
 
-(defmacro file-notify--test-with-events (n timeout assert-fn &rest body)
-  "Run BODY collecting N events and then run ASSERT-FN.
+(defmacro file-notify--test-with-events (timeout events &rest body)
+  "Run BODY collecting events and then compare with EVENTS.
 Don't wait longer than TIMEOUT seconds for the events to be delivered."
-  (declare (indent 3))
+  (declare (indent 2))
   (let ((outer (make-symbol "outer")))
     `(let ((,outer file-notify--test-events))
        (let (file-notify--test-events)
          ,@body
          (file-notify--wait-for-events
-          ,timeout (= ,n (length file-notify--test-events)))
-         (funcall ,assert-fn file-notify--test-events)
+          ,timeout (= (length ,events) (length file-notify--test-events)))
+         (should (equal ,events (mapcar #'cadr file-notify--test-events)))
          (setq ,outer (append ,outer file-notify--test-events)))
        (setq file-notify--test-events ,outer))))
 
@@ -274,67 +274,65 @@ Don't wait longer than TIMEOUT seconds for the events to 
be delivered."
 
         ;; Check creation, change, and deletion.
         (file-notify--test-with-events
-            3 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(created changed deleted)
-                             (mapcar #'cadr events))))
+            (file-notify--test-timeout) '(created changed deleted)
           (write-region
            "any text" nil file-notify--test-tmpfile nil 'no-message)
           (delete-file file-notify--test-tmpfile))
 
         ;; Check copy.
         (file-notify--test-with-events
-            3 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(created changed deleted)
-                             (mapcar #'cadr events))))
+            (file-notify--test-timeout)
+            ;; w32notify does not distinguish between `changed' and
+            ;; `attribute-changed'.
+            (if (eq file-notify--library 'w32notify)
+                '(created changed changed changed deleted)
+              '(created changed deleted))
           (write-region
            "any text" nil file-notify--test-tmpfile nil 'no-message)
           (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
           ;; The next two events shall not be visible.
           (set-file-modes file-notify--test-tmpfile 000)
+          (read-event nil nil 0.1) ; In order to distinguish the events.
           (set-file-times file-notify--test-tmpfile '(0 0))
           (delete-file file-notify--test-tmpfile)
           (delete-file file-notify--test-tmpfile1))
 
         ;; Check rename.
         (file-notify--test-with-events
-            3 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(created changed renamed)
-                             (mapcar #'cadr events))))
+            (file-notify--test-timeout) '(created changed renamed)
           (write-region
            "any text" nil file-notify--test-tmpfile nil 'no-message)
           (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
           ;; After the rename, we won't get events anymore.
           (delete-file file-notify--test-tmpfile1))
 
-        ;; Check attribute change.
-        (file-notify-rm-watch file-notify--test-desc)
-        (setq file-notify--test-desc
-              (file-notify-add-watch
-               file-notify--test-tmpfile
-               '(attribute-change) 'file-notify--test-event-handler))
-        (file-notify--test-with-events
-            2 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(attribute-changed attribute-changed)
-                             (mapcar #'cadr events))))
-          (write-region
-           "any text" nil file-notify--test-tmpfile nil 'no-message)
-          (set-file-modes file-notify--test-tmpfile 000)
-          (read-event nil nil 0.1) ; In order to distinguish the events.
-          (set-file-times file-notify--test-tmpfile '(0 0))
-          (delete-file file-notify--test-tmpfile))
+        ;; Check attribute change.  It doesn't work for w32notify.
+        (unless (eq file-notify--library 'w32notify)
+          (file-notify-rm-watch file-notify--test-desc)
+          (setq file-notify--test-desc
+                (file-notify-add-watch
+                 file-notify--test-tmpfile
+                 '(attribute-change) 'file-notify--test-event-handler))
+          (file-notify--test-with-events
+              (file-notify--test-timeout) '(attribute-changed 
attribute-changed)
+            (write-region
+             "any text" nil file-notify--test-tmpfile nil 'no-message)
+            (set-file-modes file-notify--test-tmpfile 000)
+            (read-event nil nil 0.1) ; In order to distinguish the events.
+            (set-file-times file-notify--test-tmpfile '(0 0))
+            (delete-file file-notify--test-tmpfile)))
 
         ;; Check the global sequence again just to make sure that
         ;; `file-notify--test-events' has been set correctly.
         (should (equal (mapcar #'cadr file-notify--test-events)
-                       '(created changed deleted
-                                 created changed deleted
-                                 created changed renamed
-                                 attribute-changed attribute-changed)))
-
+                       (if (eq file-notify--library 'w32notify)
+                           '(created changed deleted
+                                     created changed changed changed deleted
+                                     created changed renamed)
+                         '(created changed deleted
+                                   created changed deleted
+                                   created changed renamed
+                                   attribute-changed attribute-changed))))
         (should file-notify--test-results)
         (dolist (result file-notify--test-results)
           ;;(message "%s" (ert-test-result-messages result))
@@ -414,15 +412,12 @@ Don't wait longer than TIMEOUT seconds for the events to 
be delivered."
   (unwind-protect
       (progn
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
-        (setq file-notify--test-desc (file-notify-add-watch
-                                      file-notify--test-tmpfile
-                                      '(change)
-                                      #'file-notify--test-event-handler))
+        (setq file-notify--test-desc
+              (file-notify-add-watch
+               file-notify--test-tmpfile
+               '(change) #'file-notify--test-event-handler))
         (file-notify--test-with-events
-            2 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(created changed)
-                             (mapcar #'cadr events))))
+            (file-notify--test-timeout) '(created changed)
           (should (file-notify-valid-p file-notify--test-desc))
           (write-region
            "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -435,33 +430,30 @@ Don't wait longer than TIMEOUT seconds for the events to 
be delivered."
     ;; Cleanup.
     (file-notify--test-cleanup))
 
-  ;; The batch-mode operation of w32notify is fragile (there's no
-  ;; input threads to send the message to).
-  (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify))))
   (unwind-protect
-      (let ((temporary-file-directory (make-temp-file
-                                       "file-notify-test-parent" t)))
-        (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
-        (setq file-notify--test-desc (file-notify-add-watch
-                                      file-notify--test-tmpfile
-                                      '(change)
-                                      #'file-notify--test-event-handler))
-        (file-notify--test-with-events
-            2 (file-notify--test-timeout)
-            (lambda (events)
-              (should (equal '(created changed)
-                             (mapcar #'cadr events))))
-          (should (file-notify-valid-p file-notify--test-desc))
-          (write-region
-           "any text" nil file-notify--test-tmpfile nil 'no-message)
-          (should (file-notify-valid-p file-notify--test-desc)))
-        ;; After deleting the parent, the descriptor must not be valid
-        ;; anymore.
-        (delete-directory temporary-file-directory t)
-        (file-notify--wait-for-events
-         (file-notify--test-timeout)
-        (not (file-notify-valid-p file-notify--test-desc)))
-        (should-not (file-notify-valid-p file-notify--test-desc)))
+      ;; The batch-mode operation of w32notify is fragile (there's no
+      ;; input threads to send the message to).
+      (unless (and noninteractive (eq file-notify--library 'w32notify))
+        (let ((temporary-file-directory (make-temp-file
+                                         "file-notify-test-parent" t)))
+          (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
+          (setq file-notify--test-desc
+                (file-notify-add-watch
+                 file-notify--test-tmpfile
+                 '(change) #'file-notify--test-event-handler))
+          (file-notify--test-with-events
+              (file-notify--test-timeout) '(created changed)
+            (should (file-notify-valid-p file-notify--test-desc))
+            (write-region
+             "any text" nil file-notify--test-tmpfile nil 'no-message)
+            (should (file-notify-valid-p file-notify--test-desc)))
+          ;; After deleting the parent, the descriptor must not be valid
+          ;; anymore.
+          (delete-directory temporary-file-directory t)
+          (file-notify--wait-for-events
+           (file-notify--test-timeout)
+           (not (file-notify-valid-p file-notify--test-desc)))
+          (should-not (file-notify-valid-p file-notify--test-desc))))
 
     ;; Cleanup.
     (file-notify--test-cleanup)))
@@ -478,10 +470,10 @@ Don't wait longer than TIMEOUT seconds for the events to 
be delivered."
         (setq file-notify--test-tmpfile (file-name-as-directory
                                          (file-notify--test-make-temp-name)))
         (make-directory file-notify--test-tmpfile)
-        (setq file-notify--test-desc (file-notify-add-watch
-                                      file-notify--test-tmpfile
-                                      '(change)
-                                      #'file-notify--test-event-handler))
+        (setq file-notify--test-desc
+              (file-notify-add-watch
+               file-notify--test-tmpfile
+               '(change) #'file-notify--test-event-handler))
         (should (file-notify-valid-p file-notify--test-desc))
         ;; After removing the watch, the descriptor must not be valid
         ;; anymore.
@@ -491,18 +483,17 @@ Don't wait longer than TIMEOUT seconds for the events to 
be delivered."
     ;; Cleanup.
     (file-notify--test-cleanup))
 
-  ;; The batch-mode operation of w32notify is fragile (there's no
-  ;; input threads to send the message to).
-  (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify))))
   (unwind-protect
-      (progn
+      ;; The batch-mode operation of w32notify is fragile (there's no
+      ;; input threads to send the message to).
+      (unless (and noninteractive (eq file-notify--library 'w32notify))
         (setq file-notify--test-tmpfile (file-name-as-directory
                                          (file-notify--test-make-temp-name)))
         (make-directory file-notify--test-tmpfile)
-        (setq file-notify--test-desc (file-notify-add-watch
-                                      file-notify--test-tmpfile
-                                      '(change)
-                                      #'file-notify--test-event-handler))
+        (setq file-notify--test-desc
+              (file-notify-add-watch
+               file-notify--test-tmpfile
+               '(change) #'file-notify--test-event-handler))
         (should (file-notify-valid-p file-notify--test-desc))
         ;; After deleting the directory, the descriptor must not be
         ;; valid anymore.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]