aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2021-03-25 15:36:33 +0100
committerMichael Albinus2021-03-25 15:36:33 +0100
commit720a8b17f8f48f2bc7d59dc71be1d5fc35f0964b (patch)
tree03a6973fa58b9fbca6400085b1010833e93b7aaf /test
parentdeef5efafb70f4b171265b896505b92b6eef24e6 (diff)
downloademacs-720a8b17f8f48f2bc7d59dc71be1d5fc35f0964b.tar.gz
emacs-720a8b17f8f48f2bc7d59dc71be1d5fc35f0964b.zip
Fix filenotify-tests.el for Solaris (bug#47262), do not merge
* test/lisp/filenotify-tests.el (file-notify--test-read-event): Check also for GFamDirectoryMonitor. (file-notify--test-timeout): Increase cygwin timeout. (file-notify--test-monitor): Use `alist-get'. (file-notify--test-event-actions): New defun. (file-notify--test-with-actions-explainer): Use it. (file-notify--test-with-actions-check): Use it. If file-notify-debug is non-nil, trace received events instead of checking them. (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): Handle GFamFileMonitor and GFamDirectoryMonitor.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/filenotify-tests.el170
1 files changed, 102 insertions, 68 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index a7ceeddb416..3a297f0a961 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -105,11 +105,10 @@ There are different timeouts for local and remote file notification libraries."
105 (cond 105 (cond
106 ;; gio/gpollfilemonitor.c declares POLL_TIME_SECS 5. So we must 106 ;; gio/gpollfilemonitor.c declares POLL_TIME_SECS 5. So we must
107 ;; wait at least this time in the GPollFileMonitor case. A 107 ;; wait at least this time in the GPollFileMonitor case. A
108 ;; similar timeout seems to be needed in the GFamFileMonitor case, 108 ;; similar timeout seems to be needed in the
109 ;; at least on Cygwin. 109 ;; GFam{File,Directory}Monitor case.
110 ((and (string-equal (file-notify--test-library) "gfilenotify") 110 ((memq (file-notify--test-monitor)
111 (memq (file-notify--test-monitor) 111 '(GFamFileMonitor GFamDirectoryMonitor GPollFileMonitor))
112 '(GFamFileMonitor GPollFileMonitor)))
113 7) 112 7)
114 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 1) 113 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 1)
115 ((file-remote-p temporary-file-directory) 0.1) 114 ((file-remote-p temporary-file-directory) 0.1)
@@ -120,7 +119,7 @@ There are different timeouts for local and remote file notification libraries."
120 (cond 119 (cond
121 ((file-remote-p temporary-file-directory) 6) 120 ((file-remote-p temporary-file-directory) 6)
122 ((string-equal (file-notify--test-library) "w32notify") 4) 121 ((string-equal (file-notify--test-library) "w32notify") 4)
123 ((eq system-type 'cygwin) 6) 122 ((eq system-type 'cygwin) 7)
124 (t 3))) 123 (t 3)))
125 124
126(defmacro file-notify--test-wait-for-events (timeout until) 125(defmacro file-notify--test-wait-for-events (timeout until)
@@ -263,12 +262,12 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
263 ;; `gfile-monitor-name' does not return a proper result anymore. 262 ;; `gfile-monitor-name' does not return a proper result anymore.
264 ;; But we still need this information. 263 ;; But we still need this information.
265 (unless (file-remote-p temporary-file-directory) 264 (unless (file-remote-p temporary-file-directory)
266 (or (cdr (assq file-notify--test-desc file-notify--test-monitors)) 265 (or (alist-get file-notify--test-desc file-notify--test-monitors)
267 (when (functionp 'gfile-monitor-name) 266 (when (functionp 'gfile-monitor-name)
268 (add-to-list 'file-notify--test-monitors 267 (add-to-list 'file-notify--test-monitors
269 (cons file-notify--test-desc 268 (cons file-notify--test-desc
270 (gfile-monitor-name file-notify--test-desc))) 269 (gfile-monitor-name file-notify--test-desc)))
271 (cdr (assq file-notify--test-desc file-notify--test-monitors)))))) 270 (alist-get file-notify--test-desc file-notify--test-monitors)))))
272 271
273(defmacro file-notify--deftest-remote (test docstring &optional unstable) 272(defmacro file-notify--deftest-remote (test docstring &optional unstable)
274 "Define ert `TEST-remote' for remote files. 273 "Define ert `TEST-remote' for remote files.
@@ -455,7 +454,7 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'."
455 454
456 (unwind-protect 455 (unwind-protect
457 ;; Check, that removing watch descriptors out of order do not 456 ;; Check, that removing watch descriptors out of order do not
458 ;; harm. This fails on Cygwin because of timing issues unless a 457 ;; harm. This fails on cygwin because of timing issues unless a
459 ;; long `sit-for' is added before the call to 458 ;; long `sit-for' is added before the call to
460 ;; `file-notify--test-read-event'. 459 ;; `file-notify--test-read-event'.
461 (unless (eq system-type 'cygwin) 460 (unless (eq system-type 'cygwin)
@@ -542,6 +541,10 @@ and the event to `file-notify--test-events'."
542 file-notify--test-results 541 file-notify--test-results
543 (append file-notify--test-results `(,result)))))) 542 (append file-notify--test-results `(,result))))))
544 543
544(defun file-notify--test-event-actions ()
545 "Helper function to return retrieved actions, as list."
546 (mapcar #'file-notify--test-event-action file-notify--test-events))
547
545(defun file-notify--test-with-actions-check (actions) 548(defun file-notify--test-with-actions-check (actions)
546 "Check whether received actions match one of the ACTIONS alternatives." 549 "Check whether received actions match one of the ACTIONS alternatives."
547 (let (result) 550 (let (result)
@@ -550,22 +553,25 @@ and the event to `file-notify--test-events'."
550 (or result 553 (or result
551 (if (eq (car elt) :random) 554 (if (eq (car elt) :random)
552 (equal (sort (cdr elt) 'string-lessp) 555 (equal (sort (cdr elt) 'string-lessp)
553 (sort (mapcar #'file-notify--test-event-action 556 (sort (file-notify--test-event-actions)
554 file-notify--test-events)
555 'string-lessp)) 557 'string-lessp))
556 (equal elt (mapcar #'file-notify--test-event-action 558 (equal elt (file-notify--test-event-actions))))))
557 file-notify--test-events)))))))) 559 ;; Do not report result in case we debug. Write messages instead.
560 (if file-notify-debug
561 (prog1 t
562 (if result
563 (message "Success\n%s" (file-notify--test-event-actions))
564 (message (file-notify--test-with-actions-explainer actions))))
565 result)))
558 566
559(defun file-notify--test-with-actions-explainer (actions) 567(defun file-notify--test-with-actions-explainer (actions)
560 "Explain why `file-notify--test-with-actions-check' fails." 568 "Explain why `file-notify--test-with-actions-check' fails."
561 (if (null (cdr actions)) 569 (if (null (cdr actions))
562 (format "Received actions do not match expected actions\n%s\n%s" 570 (format "Received actions do not match expected actions\n%s\n%s"
563 (mapcar #'file-notify--test-event-action file-notify--test-events) 571 (file-notify--test-event-actions) (car actions))
564 (car actions))
565 (format 572 (format
566 "Received actions do not match any sequence of expected actions\n%s\n%s" 573 "Received actions do not match any sequence of expected actions\n%s\n%s"
567 (mapcar #'file-notify--test-event-action file-notify--test-events) 574 (file-notify--test-event-actions) actions)))
568 actions)))
569 575
570(put 'file-notify--test-with-actions-check 'ert-explainer 576(put 'file-notify--test-with-actions-check 'ert-explainer
571 'file-notify--test-with-actions-explainer) 577 'file-notify--test-with-actions-explainer)
@@ -632,9 +638,10 @@ delivered."
632 (file-notify--test-library) "gvfs-monitor-dir.exe") 638 (file-notify--test-library) "gvfs-monitor-dir.exe")
633 '((deleted stopped) 639 '((deleted stopped)
634 (created deleted stopped))) 640 (created deleted stopped)))
635 ;; cygwin does not raise a `changed' event. 641 ;; GFam{File,Directory}Monitor do not report the `changed' event.
636 ((eq system-type 'cygwin) 642 ((memq (file-notify--test-monitor)
637 '(created deleted stopped)) 643 '(GFamFileMonitor GFamDirectoryMonitor))
644 '(created deleted stopped))
638 (t '(created changed deleted stopped))) 645 (t '(created changed deleted stopped)))
639 (write-region 646 (write-region
640 "another text" nil file-notify--test-tmpfile nil 'no-message) 647 "another text" nil file-notify--test-tmpfile nil 'no-message)
@@ -665,6 +672,12 @@ delivered."
665 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 672 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe")
666 '((deleted stopped) 673 '((deleted stopped)
667 (changed deleted stopped))) 674 (changed deleted stopped)))
675 ;; GFam{File,Directory}Monitor do not detect the
676 ;; `changed' event reliably.
677 ((memq (file-notify--test-monitor)
678 '(GFamFileMonitor GFamDirectoryMonitor))
679 '((deleted stopped)
680 (changed deleted stopped)))
668 ;; There could be one or two `changed' events. 681 ;; There could be one or two `changed' events.
669 (t '((changed deleted stopped) 682 (t '((changed deleted stopped)
670 (changed changed deleted stopped)))) 683 (changed changed deleted stopped))))
@@ -709,9 +722,11 @@ delivered."
709 ((getenv "EMACS_EMBA_CI") 722 ((getenv "EMACS_EMBA_CI")
710 '(created changed deleted)) 723 '(created changed deleted))
711 ;; There are two `deleted' events, for the file and for 724 ;; There are two `deleted' events, for the file and for
712 ;; the directory. Except for cygwin and kqueue. And 725 ;; the directory. Except for GFam{File,Directory}Monitor
713 ;; cygwin does not raise a `changed' event. 726 ;; and kqueue. And GFam{File,Directory}Monitor do not
714 ((eq system-type 'cygwin) 727 ;; raise a `changed' event.
728 ((memq (file-notify--test-monitor)
729 '(GFamFileMonitor GFamDirectoryMonitor))
715 '(created deleted stopped)) 730 '(created deleted stopped))
716 ((string-equal (file-notify--test-library) "kqueue") 731 ((string-equal (file-notify--test-library) "kqueue")
717 '(created changed deleted stopped)) 732 '(created changed deleted stopped))
@@ -755,8 +770,10 @@ delivered."
755 '((deleted stopped) 770 '((deleted stopped)
756 (created created deleted stopped))) 771 (created created deleted stopped)))
757 ;; There are three `deleted' events, for two files and 772 ;; There are three `deleted' events, for two files and
758 ;; for the directory. Except for cygwin and kqueue. 773 ;; for the directory. Except for
759 ((eq system-type 'cygwin) 774 ;; GFam{File,Directory}Monitor and kqueue.
775 ((memq (file-notify--test-monitor)
776 '(GFamFileMonitor GFamDirectoryMonitor))
760 '(created created changed changed deleted stopped)) 777 '(created created changed changed deleted stopped))
761 ((string-equal (file-notify--test-library) "kqueue") 778 ((string-equal (file-notify--test-library) "kqueue")
762 '(created changed created changed deleted stopped)) 779 '(created changed created changed deleted stopped))
@@ -813,10 +830,12 @@ delivered."
813 ((getenv "EMACS_EMBA_CI") 830 ((getenv "EMACS_EMBA_CI")
814 '(created changed renamed deleted)) 831 '(created changed renamed deleted))
815 ;; There are two `deleted' events, for the file and for 832 ;; There are two `deleted' events, for the file and for
816 ;; the directory. Except for cygwin and kqueue. And 833 ;; the directory. Except for GFam{File,Directory}Monitor
817 ;; cygwin raises `created' and `deleted' events instead 834 ;; and kqueue. And GFam{File,Directory}Monitor raise
818 ;; of a `renamed' event. 835 ;; `created' and `deleted' events instead of a `renamed'
819 ((eq system-type 'cygwin) 836 ;; event.
837 ((memq (file-notify--test-monitor)
838 '(GFamFileMonitor GFamDirectoryMonitor))
820 '(created created deleted deleted stopped)) 839 '(created created deleted deleted stopped))
821 ((string-equal (file-notify--test-library) "kqueue") 840 ((string-equal (file-notify--test-library) "kqueue")
822 '(created changed renamed deleted stopped)) 841 '(created changed renamed deleted stopped))
@@ -837,8 +856,8 @@ delivered."
837 (file-notify--test-cleanup)) 856 (file-notify--test-cleanup))
838 857
839 (unwind-protect 858 (unwind-protect
840 ;; Check attribute change. Does not work for cygwin. 859 ;; Check attribute change. Does not work for GFam{File,Directory}Monitor.
841 (unless (eq system-type 'cygwin) 860 (progn
842 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 861 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
843 (write-region 862 (write-region
844 "any text" nil file-notify--test-tmpfile nil 'no-message) 863 "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -847,29 +866,31 @@ delivered."
847 (file-notify--test-add-watch 866 (file-notify--test-add-watch
848 file-notify--test-tmpfile 867 file-notify--test-tmpfile
849 '(attribute-change) #'file-notify--test-event-handler))) 868 '(attribute-change) #'file-notify--test-event-handler)))
850 (file-notify--test-with-actions 869 (unless (memq (file-notify--test-monitor)
851 (cond 870 '(GFamFileMonitor GFamDirectoryMonitor))
852 ;; w32notify does not distinguish between `changed' and 871 (file-notify--test-with-actions
853 ;; `attribute-changed'. Under MS Windows 7, we get four 872 (cond
854 ;; `changed' events, and under MS Windows 10 just two. 873 ;; w32notify does not distinguish between `changed' and
855 ;; Strange. 874 ;; `attribute-changed'. Under MS Windows 7, we get
856 ((string-equal (file-notify--test-library) "w32notify") 875 ;; four `changed' events, and under MS Windows 10 just
857 '((changed changed) 876 ;; two. Strange.
858 (changed changed changed changed))) 877 ((string-equal (file-notify--test-library) "w32notify")
859 ;; For kqueue and in the remote case, `write-region' 878 '((changed changed)
860 ;; raises also an `attribute-changed' event. 879 (changed changed changed changed)))
861 ((or (string-equal (file-notify--test-library) "kqueue") 880 ;; For kqueue and in the remote case, `write-region'
862 (file-remote-p temporary-file-directory)) 881 ;; raises also an `attribute-changed' event.
863 '(attribute-changed attribute-changed attribute-changed)) 882 ((or (string-equal (file-notify--test-library) "kqueue")
864 (t '(attribute-changed attribute-changed))) 883 (file-remote-p temporary-file-directory))
865 (write-region 884 '(attribute-changed attribute-changed attribute-changed))
866 "any text" nil file-notify--test-tmpfile nil 'no-message) 885 (t '(attribute-changed attribute-changed)))
867 (file-notify--test-read-event) 886 (write-region
868 (set-file-modes file-notify--test-tmpfile 000) 887 "any text" nil file-notify--test-tmpfile nil 'no-message)
869 (file-notify--test-read-event) 888 (file-notify--test-read-event)
870 (set-file-times file-notify--test-tmpfile '(0 0)) 889 (set-file-modes file-notify--test-tmpfile 000)
871 (file-notify--test-read-event) 890 (file-notify--test-read-event)
872 (delete-file file-notify--test-tmpfile)) 891 (set-file-times file-notify--test-tmpfile '(0 0))
892 (file-notify--test-read-event)
893 (delete-file file-notify--test-tmpfile)))
873 (file-notify-rm-watch file-notify--test-desc) 894 (file-notify-rm-watch file-notify--test-desc)
874 895
875 ;; The environment shall be cleaned up. 896 ;; The environment shall be cleaned up.
@@ -951,7 +972,7 @@ delivered."
951 972
952 ;; Modify file. We wait for two seconds, in order to 973 ;; Modify file. We wait for two seconds, in order to
953 ;; have another timestamp. One second seems to be too 974 ;; have another timestamp. One second seems to be too
954 ;; short. And Cygwin sporadically requires more than two. 975 ;; short. And cygwin sporadically requires more than two.
955 (ert-with-message-capture captured-messages 976 (ert-with-message-capture captured-messages
956 (sleep-for (if (eq system-type 'cygwin) 3 2)) 977 (sleep-for (if (eq system-type 'cygwin) 3 2))
957 (write-region 978 (write-region
@@ -1021,6 +1042,12 @@ delivered."
1021 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 1042 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe")
1022 '((deleted stopped) 1043 '((deleted stopped)
1023 (changed deleted stopped))) 1044 (changed deleted stopped)))
1045 ;; GFam{File,Directory}Monitor do not detect the
1046 ;; `changed' event reliably.
1047 ((memq (file-notify--test-monitor)
1048 '(GFamFileMonitor GFamDirectoryMonitor))
1049 '((deleted stopped)
1050 (changed deleted stopped)))
1024 ;; There could be one or two `changed' events. 1051 ;; There could be one or two `changed' events.
1025 (t '((changed deleted stopped) 1052 (t '((changed deleted stopped)
1026 (changed changed deleted stopped)))) 1053 (changed changed deleted stopped))))
@@ -1064,9 +1091,12 @@ delivered."
1064 '((deleted stopped) 1091 '((deleted stopped)
1065 (created deleted stopped))) 1092 (created deleted stopped)))
1066 ;; There are two `deleted' events, for the file and for 1093 ;; There are two `deleted' events, for the file and for
1067 ;; the directory. Except for cygwin and kqueue. And 1094 ;; the directory. Except for
1068 ;; cygwin does not raise a `changed' event. 1095 ;; GFam{File,Directory}Monitor and kqueue. And
1069 ((eq system-type 'cygwin) 1096 ;; GFam{File,Directory}Monitor do not raise a `changed'
1097 ;; event.
1098 ((memq (file-notify--test-monitor)
1099 '(GFamFileMonitor GFamDirectoryMonitor))
1070 '(created deleted stopped)) 1100 '(created deleted stopped))
1071 ((string-equal (file-notify--test-library) "kqueue") 1101 ((string-equal (file-notify--test-library) "kqueue")
1072 '(created changed deleted stopped)) 1102 '(created changed deleted stopped))
@@ -1198,9 +1228,10 @@ delivered."
1198 (dotimes (_i n) 1228 (dotimes (_i n)
1199 (setq r (append '(deleted renamed) r))) 1229 (setq r (append '(deleted renamed) r)))
1200 r)) 1230 r))
1201 ;; cygwin fires `changed' and `deleted' events, sometimes 1231 ;; GFam{File,Directory}Monitor fire `changed' and
1202 ;; in random order. 1232 ;; `deleted' events, sometimes in random order.
1203 ((eq system-type 'cygwin) 1233 ((memq (file-notify--test-monitor)
1234 '(GFamFileMonitor GFamDirectoryMonitor))
1204 (let (r) 1235 (let (r)
1205 (dotimes (_i n) 1236 (dotimes (_i n)
1206 (setq r (append '(changed deleted) r))) 1237 (setq r (append '(changed deleted) r)))
@@ -1283,9 +1314,10 @@ delivered."
1283 (should (file-notify-valid-p file-notify--test-desc)) 1314 (should (file-notify-valid-p file-notify--test-desc))
1284 (file-notify--test-with-actions 1315 (file-notify--test-with-actions
1285 (cond 1316 (cond
1286 ;; On cygwin we only get the `changed' event. 1317 ;; GFam{File,Directory}Monitor report only the `changed' event.
1287 ((eq system-type 'cygwin) 1318 ((memq (file-notify--test-monitor)
1288 '(changed)) 1319 '(GFamFileMonitor GFamDirectoryMonitor))
1320 '(changed))
1289 (t '(renamed created changed))) 1321 (t '(renamed created changed)))
1290 ;; The file is renamed when creating a backup. It shall 1322 ;; The file is renamed when creating a backup. It shall
1291 ;; still be watched. 1323 ;; still be watched.
@@ -1407,10 +1439,12 @@ the file watch."
1407 ;; Now we delete the directory. 1439 ;; Now we delete the directory.
1408 (file-notify--test-with-actions 1440 (file-notify--test-with-actions
1409 (cond 1441 (cond
1410 ;; In kqueue and for cygwin, just one `deleted' event for 1442 ;; GFam{File,Directory}Monitor and kqueue raise just one
1411 ;; the directory is received. 1443 ;; `deleted' event for the directory.
1412 ((or (eq system-type 'cygwin) 1444 ((memq (file-notify--test-monitor)
1413 (string-equal (file-notify--test-library) "kqueue")) 1445 '(GFamFileMonitor GFamDirectoryMonitor))
1446 '(deleted stopped))
1447 ((string-equal (file-notify--test-library) "kqueue")
1414 '(deleted stopped)) 1448 '(deleted stopped))
1415 (t (append 1449 (t (append
1416 ;; The directory monitor raises a `deleted' event for 1450 ;; The directory monitor raises a `deleted' event for