diff options
| author | Michael Albinus | 2016-02-08 10:54:43 +0100 |
|---|---|---|
| committer | Michael Albinus | 2016-02-08 10:54:43 +0100 |
| commit | 37eae51767fc013eec3411c174d27bd8a18e5bc8 (patch) | |
| tree | d4b4d95ea3f95aaca138dd8327aa44e63ad9068e | |
| parent | edc39c92a798821a931f282236f7f4a79c2b25a1 (diff) | |
| download | emacs-37eae51767fc013eec3411c174d27bd8a18e5bc8.tar.gz emacs-37eae51767fc013eec3411c174d27bd8a18e5bc8.zip | |
Some fixes in file-notify-tests.el
* test/automated/file-notify-tests.el
(file-notify--test-with-events-check)
(file-notify--test-with-events-explainer): New defuns.
(file-notify--test-with-events): Use it.
(file-notify-test07-backup): Fix docstring. Some of the
backends fire two `changed' events. Backup by rename doesn't
work for kqueue.
| -rw-r--r-- | test/automated/file-notify-tests.el | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el index 4261507f59f..a8521828c0e 100644 --- a/test/automated/file-notify-tests.el +++ b/test/automated/file-notify-tests.el | |||
| @@ -293,6 +293,26 @@ TIMEOUT is the maximum time to wait for, in seconds." | |||
| 293 | (while (null ,until) | 293 | (while (null ,until) |
| 294 | (read-event nil nil file-notify--test-read-event-timeout)))) | 294 | (read-event nil nil file-notify--test-read-event-timeout)))) |
| 295 | 295 | ||
| 296 | (defun file-notify--test-with-events-check (events) | ||
| 297 | "Check whether received events match one of the EVENTS alternatives." | ||
| 298 | (let (result) | ||
| 299 | (dolist (elt events result) | ||
| 300 | (setq result | ||
| 301 | (or result | ||
| 302 | (equal elt (mapcar #'cadr file-notify--test-events))))))) | ||
| 303 | |||
| 304 | (defun file-notify--test-with-events-explainer (events) | ||
| 305 | "Explain why `file-notify--test-with-events-check' fails." | ||
| 306 | (if (null (cdr events)) | ||
| 307 | (format "Received events `%s' do not match expected events `%s'" | ||
| 308 | (mapcar #'cadr file-notify--test-events) (car events)) | ||
| 309 | (format | ||
| 310 | "Received events `%s' do not match any sequence of expected events `%s'" | ||
| 311 | (mapcar #'cadr file-notify--test-events) events))) | ||
| 312 | |||
| 313 | (put 'file-notify--test-with-events-check 'ert-explainer | ||
| 314 | 'file-notify--test-with-events-explainer) | ||
| 315 | |||
| 296 | (defmacro file-notify--test-with-events (events &rest body) | 316 | (defmacro file-notify--test-with-events (events &rest body) |
| 297 | "Run BODY collecting events and then compare with EVENTS. | 317 | "Run BODY collecting events and then compare with EVENTS. |
| 298 | EVENTS is either a simple list of events, or a list of lists of | 318 | EVENTS is either a simple list of events, or a list of lists of |
| @@ -303,7 +323,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 303 | `(let* ((,outer file-notify--test-events) | 323 | `(let* ((,outer file-notify--test-events) |
| 304 | (events (if (consp (car ,events)) ,events (list ,events))) | 324 | (events (if (consp (car ,events)) ,events (list ,events))) |
| 305 | (max-length (apply 'max (mapcar 'length events))) | 325 | (max-length (apply 'max (mapcar 'length events))) |
| 306 | create-lockfiles result) | 326 | create-lockfiles) |
| 307 | ;; Flush pending events. | 327 | ;; Flush pending events. |
| 308 | (file-notify--wait-for-events | 328 | (file-notify--wait-for-events |
| 309 | (file-notify--test-timeout) | 329 | (file-notify--test-timeout) |
| @@ -315,11 +335,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 315 | (* (ceiling max-length 100) (file-notify--test-timeout)) | 335 | (* (ceiling max-length 100) (file-notify--test-timeout)) |
| 316 | (= max-length (length file-notify--test-events))) | 336 | (= max-length (length file-notify--test-events))) |
| 317 | ;; One of the possible results shall match. | 337 | ;; One of the possible results shall match. |
| 318 | (should | 338 | (should (file-notify--test-with-events-check events)) |
| 319 | (dolist (elt events result) | ||
| 320 | (setq result | ||
| 321 | (or result | ||
| 322 | (equal elt (mapcar #'cadr file-notify--test-events)))))) | ||
| 323 | (setq ,outer (append ,outer file-notify--test-events))) | 339 | (setq ,outer (append ,outer file-notify--test-events))) |
| 324 | (setq file-notify--test-events ,outer)))) | 340 | (setq file-notify--test-events ,outer)))) |
| 325 | 341 | ||
| @@ -849,7 +865,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 849 | "Check that events are not dropped for remote directories.") | 865 | "Check that events are not dropped for remote directories.") |
| 850 | 866 | ||
| 851 | (ert-deftest file-notify-test07-backup () | 867 | (ert-deftest file-notify-test07-backup () |
| 852 | "Check that backup keeps file supervision." | 868 | "Check that backup keeps file notification." |
| 853 | (skip-unless (file-notify--test-local-enabled)) | 869 | (skip-unless (file-notify--test-local-enabled)) |
| 854 | 870 | ||
| 855 | (unwind-protect | 871 | (unwind-protect |
| @@ -862,7 +878,14 @@ longer than timeout seconds for the events to be delivered." | |||
| 862 | file-notify--test-tmpfile | 878 | file-notify--test-tmpfile |
| 863 | '(change) #'file-notify--test-event-handler))) | 879 | '(change) #'file-notify--test-event-handler))) |
| 864 | (should (file-notify-valid-p file-notify--test-desc)) | 880 | (should (file-notify-valid-p file-notify--test-desc)) |
| 865 | (file-notify--test-with-events '(changed) | 881 | (file-notify--test-with-events |
| 882 | (cond | ||
| 883 | ;; For w32notify and in the remote case, there are two | ||
| 884 | ;; `changed' events. | ||
| 885 | ((or (string-equal (file-notify--test-library) "w32notify") | ||
| 886 | (file-remote-p temporary-file-directory)) | ||
| 887 | '(changed changed)) | ||
| 888 | (t '(changed))) | ||
| 866 | ;; There shouldn't be any problem, because the file is kept. | 889 | ;; There shouldn't be any problem, because the file is kept. |
| 867 | (with-temp-buffer | 890 | (with-temp-buffer |
| 868 | (let ((buffer-file-name file-notify--test-tmpfile) | 891 | (let ((buffer-file-name file-notify--test-tmpfile) |
| @@ -881,35 +904,39 @@ longer than timeout seconds for the events to be delivered." | |||
| 881 | 904 | ||
| 882 | (unwind-protect | 905 | (unwind-protect |
| 883 | (progn | 906 | (progn |
| 884 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) | 907 | ;; It doesn't work for kqueue, because we don't use an |
| 885 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) | 908 | ;; implicit directory monitor. |
| 886 | (should | 909 | (unless (string-equal (file-notify--test-library) "kqueue") |
| 887 | (setq file-notify--test-desc | 910 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) |
| 888 | (file-notify-add-watch | 911 | (write-region |
| 889 | file-notify--test-tmpfile | 912 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 890 | '(change) #'file-notify--test-event-handler))) | 913 | (should |
| 891 | (should (file-notify-valid-p file-notify--test-desc)) | 914 | (setq file-notify--test-desc |
| 892 | (file-notify--test-with-events '(renamed created changed) | 915 | (file-notify-add-watch |
| 893 | ;; The file is renamed when creating a backup. It shall | 916 | file-notify--test-tmpfile |
| 894 | ;; still be watched. | 917 | '(change) #'file-notify--test-event-handler))) |
| 895 | (with-temp-buffer | 918 | (should (file-notify-valid-p file-notify--test-desc)) |
| 896 | (let ((buffer-file-name file-notify--test-tmpfile) | 919 | (file-notify--test-with-events '(renamed created changed) |
| 897 | (make-backup-files t) | 920 | ;; The file is renamed when creating a backup. It shall |
| 898 | (backup-by-copying nil) | 921 | ;; still be watched. |
| 899 | (backup-by-copying-when-mismatch nil) | 922 | (with-temp-buffer |
| 900 | (kept-new-versions 1) | 923 | (let ((buffer-file-name file-notify--test-tmpfile) |
| 901 | (delete-old-versions t)) | 924 | (make-backup-files t) |
| 902 | (insert "another text") | 925 | (backup-by-copying nil) |
| 903 | (save-buffer)))) | 926 | (backup-by-copying-when-mismatch nil) |
| 904 | ;; After saving the buffer, the descriptor is still valid. | 927 | (kept-new-versions 1) |
| 905 | (should (file-notify-valid-p file-notify--test-desc)) | 928 | (delete-old-versions t)) |
| 906 | (delete-file file-notify--test-tmpfile)) | 929 | (insert "another text") |
| 930 | (save-buffer)))) | ||
| 931 | ;; After saving the buffer, the descriptor is still valid. | ||
| 932 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 933 | (delete-file file-notify--test-tmpfile))) | ||
| 907 | 934 | ||
| 908 | ;; Cleanup. | 935 | ;; Cleanup. |
| 909 | (file-notify--test-cleanup))) | 936 | (file-notify--test-cleanup))) |
| 910 | 937 | ||
| 911 | (file-notify--deftest-remote file-notify-test07-backup | 938 | (file-notify--deftest-remote file-notify-test07-backup |
| 912 | "Check that backup keeps file supervision for remote files.") | 939 | "Check that backup keeps file notification for remote files.") |
| 913 | 940 | ||
| 914 | (defun file-notify-test-all (&optional interactive) | 941 | (defun file-notify-test-all (&optional interactive) |
| 915 | "Run all tests for \\[file-notify]." | 942 | "Run all tests for \\[file-notify]." |