emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 3a76484 2/5: Don't use internal filenotify function


From: Mattias Engdegård
Subject: [Emacs-diffs] master 3a76484 2/5: Don't use internal filenotify function in test
Date: Wed, 24 Jul 2019 06:06:46 -0400 (EDT)

branch: master
commit 3a764848650365a9794839c5e98fa74bceb76c47
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Don't use internal filenotify function in test
    
    * test/lisp/filenotify-tests.el
    (file-notify--test-file, file-notify--test-add-watch): New.
    (file-notify--test-event-test, file-notify--test-event-handler)
    (file-notify-test02-rm-watch, file-notify-test03-events)
    (file-notify-test05-file-validity, file-notify-test07-many-events)
    (file-notify-test08-backup, file-notify-test09-watched-file-in-watched-dir):
    Avoid using the internal `file-notify--event-watched-file' so that it
    can be removed from filenotify.el.
    Instead, pass the file name to the callback as an extra argument;
    use `file-notify--test-add-watch' instead of `file-notify-add-watch'.
---
 test/lisp/filenotify-tests.el | 49 ++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index 2c77681..7c8c195 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -93,6 +93,7 @@
 (defvar file-notify--test-desc2 nil)
 (defvar file-notify--test-results nil)
 (defvar file-notify--test-event nil)
+(defvar file-notify--test-file nil)
 (defvar file-notify--test-events nil)
 (defvar file-notify--test-monitors nil)
 
@@ -204,6 +205,11 @@ Return nil when any other file notification watch is still 
active."
 (when (getenv "EMACS_HYDRA_CI")
   (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
 
+(defun file-notify--test-add-watch (file flags callback)
+  "Like `file-notify-add-watch', but also passing FILE to CALLBACK."
+  (file-notify-add-watch file flags
+                         (lambda (event) (funcall callback event file))))
+
 ;; We do not want to try and fail `file-notify-add-watch'.
 (defun file-notify--test-local-enabled ()
   "Whether local file notification is enabled.
@@ -494,26 +500,27 @@ If UNSTABLE is non-nil, the test is tagged as 
`:unstable'."
 (defun file-notify--test-event-test ()
   "Ert test function to be called by `file-notify--test-event-handler'.
 We cannot pass arguments, so we assume that `file-notify--test-event'
-is bound somewhere."
+and `file-notify--test-file' are bound somewhere."
   ;; Check the descriptor.
   (should (equal (car file-notify--test-event) file-notify--test-desc))
   ;; Check the file name.
   (should
    (string-prefix-p
-    (file-notify--event-watched-file file-notify--test-event)
+    file-notify--test-file
     (file-notify--test-event-file file-notify--test-event)))
   ;; Check the second file name if exists.
   (when (eq (nth 1 file-notify--test-event) 'renamed)
     (should
      (string-prefix-p
-      (file-notify--event-watched-file file-notify--test-event)
+      file-notify--test-file
       (file-notify--test-event-file1 file-notify--test-event)))))
 
-(defun file-notify--test-event-handler (event)
+(defun file-notify--test-event-handler (event file)
   "Run a test over FILE-NOTIFY--TEST-EVENT.
 For later analysis, append the test result to `file-notify--test-results'
 and the event to `file-notify--test-events'."
   (let* ((file-notify--test-event event)
+         (file-notify--test-file file)
          (result
           (ert-run-test (make-ert-test :body 'file-notify--test-event-test))))
     ;; Do not add lock files, this would confuse the checks.
@@ -603,7 +610,7 @@ delivered."
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
         (should
          (setq file-notify--test-desc
-               (file-notify-add-watch
+               (file-notify--test-add-watch
                 file-notify--test-tmpfile
                 '(change) #'file-notify--test-event-handler)))
         (file-notify--test-with-events
@@ -637,7 +644,7 @@ delivered."
         (write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
        (should
         (setq file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpfile
                '(change) #'file-notify--test-event-handler)))
         (file-notify--test-with-events
@@ -671,7 +678,7 @@ delivered."
        (should
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
               file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpdir
                '(change) #'file-notify--test-event-handler)))
        (file-notify--test-with-events
@@ -718,7 +725,7 @@ delivered."
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
               file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
               file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpdir
                '(change) #'file-notify--test-event-handler)))
        (file-notify--test-with-events
@@ -775,7 +782,7 @@ delivered."
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
               file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
               file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpdir
                '(change) #'file-notify--test-event-handler)))
        (file-notify--test-with-events
@@ -826,7 +833,7 @@ delivered."
         "any text" nil file-notify--test-tmpfile nil 'no-message)
        (should
         (setq file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpfile
                '(attribute-change) #'file-notify--test-event-handler)))
        (file-notify--test-with-events
@@ -991,7 +998,7 @@ delivered."
        (write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
        (should
         (setq file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpfile
                '(change) #'file-notify--test-event-handler)))
        (should (file-notify-valid-p file-notify--test-desc))
@@ -1028,7 +1035,7 @@ delivered."
          (should
           (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
                 file-notify--test-desc
-                (file-notify-add-watch
+                (file-notify--test-add-watch
                  file-notify--test-tmpdir
                  '(change) #'file-notify--test-event-handler)))
          (should (file-notify-valid-p file-notify--test-desc))
@@ -1146,7 +1153,7 @@ delivered."
         (make-temp-file "file-notify-test-parent" t)))
   (should
    (setq file-notify--test-desc
-        (file-notify-add-watch
+        (file-notify--test-add-watch
          file-notify--test-tmpfile
          '(change) #'file-notify--test-event-handler)))
   (unwind-protect
@@ -1222,7 +1229,7 @@ delivered."
        (write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
        (should
         (setq file-notify--test-desc
-              (file-notify-add-watch
+              (file-notify--test-add-watch
                file-notify--test-tmpfile
                '(change) #'file-notify--test-event-handler)))
         (should (file-notify-valid-p file-notify--test-desc))
@@ -1258,7 +1265,7 @@ delivered."
          "any text" nil file-notify--test-tmpfile nil 'no-message)
         (should
          (setq file-notify--test-desc
-               (file-notify-add-watch
+               (file-notify--test-add-watch
                 file-notify--test-tmpfile
                 '(change) #'file-notify--test-event-handler)))
         (should (file-notify-valid-p file-notify--test-desc))
@@ -1314,23 +1321,23 @@ the file watch."
   (write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message)
   (unwind-protect
       (cl-flet (;; Directory monitor.
-                (dir-callback (event)
+                (dir-callback (event file)
                  (let ((file-notify--test-desc file-notify--test-desc1))
-                   (file-notify--test-event-handler event)))
+                   (file-notify--test-event-handler event file)))
                 ;; File monitor.
-                (file-callback (event)
+                (file-callback (event file)
                  (let ((file-notify--test-desc file-notify--test-desc2))
-                   (file-notify--test-event-handler event))))
+                   (file-notify--test-event-handler event file))))
         (should
          (setq file-notify--test-desc1
-               (file-notify-add-watch
+               (file-notify--test-add-watch
                 file-notify--test-tmpfile
                 '(change) #'dir-callback)
                ;; This is needed for `file-notify--test-monitor'.
                file-notify--test-desc file-notify--test-desc1))
         (should
          (setq file-notify--test-desc2
-               (file-notify-add-watch
+               (file-notify--test-add-watch
                 file-notify--test-tmpfile1
                 '(change) #'file-callback)))
         (should (file-notify-valid-p file-notify--test-desc1))



reply via email to

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