diff options
| author | Paul Eggert | 2016-02-09 14:23:53 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-02-09 14:23:53 -0800 |
| commit | 05595c2e59983db469e620c4f34b2eef5123391b (patch) | |
| tree | 9c72fdb703ebbacb66a9ca08c7a3d4c5bef01049 /test/lisp | |
| parent | 8fa67e959bcc835c359981aae01f0dad3213451a (diff) | |
| parent | 821213572075b3f5a97676f48aeb6733bf437277 (diff) | |
| download | emacs-05595c2e59983db469e620c4f34b2eef5123391b.tar.gz emacs-05595c2e59983db469e620c4f34b2eef5123391b.zip | |
-
Diffstat (limited to 'test/lisp')
| -rw-r--r-- | test/lisp/filenotify-tests.el | 179 |
1 files changed, 139 insertions, 40 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index 5fc4ff8bf42..a8521828c0e 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el | |||
| @@ -62,6 +62,10 @@ | |||
| 62 | (defvar file-notify--test-event nil) | 62 | (defvar file-notify--test-event nil) |
| 63 | (defvar file-notify--test-events nil) | 63 | (defvar file-notify--test-events nil) |
| 64 | 64 | ||
| 65 | (defconst file-notify--test-read-event-timeout 0.02 | ||
| 66 | "Timeout for `read-event' calls. | ||
| 67 | It is different for local and remote file notification libraries.") | ||
| 68 | |||
| 65 | (defun file-notify--test-timeout () | 69 | (defun file-notify--test-timeout () |
| 66 | "Timeout to wait for arriving events, in seconds." | 70 | "Timeout to wait for arriving events, in seconds." |
| 67 | (cond | 71 | (cond |
| @@ -74,19 +78,20 @@ | |||
| 74 | "Cleanup after a test." | 78 | "Cleanup after a test." |
| 75 | (file-notify-rm-watch file-notify--test-desc) | 79 | (file-notify-rm-watch file-notify--test-desc) |
| 76 | 80 | ||
| 77 | (when (and file-notify--test-tmpfile | 81 | (ignore-errors |
| 78 | (file-exists-p file-notify--test-tmpfile)) | 82 | (delete-file (file-newest-backup file-notify--test-tmpfile))) |
| 83 | (ignore-errors | ||
| 79 | (if (file-directory-p file-notify--test-tmpfile) | 84 | (if (file-directory-p file-notify--test-tmpfile) |
| 80 | (delete-directory file-notify--test-tmpfile 'recursive) | 85 | (delete-directory file-notify--test-tmpfile 'recursive) |
| 81 | (delete-file file-notify--test-tmpfile))) | 86 | (delete-file file-notify--test-tmpfile))) |
| 82 | (when (and file-notify--test-tmpfile1 | 87 | (ignore-errors |
| 83 | (file-exists-p file-notify--test-tmpfile1)) | ||
| 84 | (if (file-directory-p file-notify--test-tmpfile1) | 88 | (if (file-directory-p file-notify--test-tmpfile1) |
| 85 | (delete-directory file-notify--test-tmpfile1 'recursive) | 89 | (delete-directory file-notify--test-tmpfile1 'recursive) |
| 86 | (delete-file file-notify--test-tmpfile1))) | 90 | (delete-file file-notify--test-tmpfile1))) |
| 87 | (when (file-remote-p temporary-file-directory) | 91 | (ignore-errors |
| 88 | (tramp-cleanup-connection | 92 | (when (file-remote-p temporary-file-directory) |
| 89 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password)) | 93 | (tramp-cleanup-connection |
| 94 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password))) | ||
| 90 | 95 | ||
| 91 | (setq file-notify--test-tmpfile nil | 96 | (setq file-notify--test-tmpfile nil |
| 92 | file-notify--test-tmpfile1 nil | 97 | file-notify--test-tmpfile1 nil |
| @@ -155,6 +160,7 @@ remote host, or nil." | |||
| 155 | :tags '(:expensive-test) | 160 | :tags '(:expensive-test) |
| 156 | (let* ((temporary-file-directory | 161 | (let* ((temporary-file-directory |
| 157 | file-notify-test-remote-temporary-file-directory) | 162 | file-notify-test-remote-temporary-file-directory) |
| 163 | (file-notify--test-read-event-timeout 0.1) | ||
| 158 | (ert-test (ert-get-test ',test))) | 164 | (ert-test (ert-get-test ',test))) |
| 159 | (skip-unless (file-notify--test-remote-enabled)) | 165 | (skip-unless (file-notify--test-remote-enabled)) |
| 160 | (tramp-cleanup-connection | 166 | (tramp-cleanup-connection |
| @@ -285,7 +291,27 @@ and the event to `file-notify--test-events'." | |||
| 285 | TIMEOUT is the maximum time to wait for, in seconds." | 291 | TIMEOUT is the maximum time to wait for, in seconds." |
| 286 | `(with-timeout (,timeout (ignore)) | 292 | `(with-timeout (,timeout (ignore)) |
| 287 | (while (null ,until) | 293 | (while (null ,until) |
| 288 | (read-event nil nil 0.1)))) | 294 | (read-event nil nil file-notify--test-read-event-timeout)))) |
| 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) | ||
| 289 | 315 | ||
| 290 | (defmacro file-notify--test-with-events (events &rest body) | 316 | (defmacro file-notify--test-with-events (events &rest body) |
| 291 | "Run BODY collecting events and then compare with EVENTS. | 317 | "Run BODY collecting events and then compare with EVENTS. |
| @@ -297,7 +323,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 297 | `(let* ((,outer file-notify--test-events) | 323 | `(let* ((,outer file-notify--test-events) |
| 298 | (events (if (consp (car ,events)) ,events (list ,events))) | 324 | (events (if (consp (car ,events)) ,events (list ,events))) |
| 299 | (max-length (apply 'max (mapcar 'length events))) | 325 | (max-length (apply 'max (mapcar 'length events))) |
| 300 | create-lockfiles result) | 326 | create-lockfiles) |
| 301 | ;; Flush pending events. | 327 | ;; Flush pending events. |
| 302 | (file-notify--wait-for-events | 328 | (file-notify--wait-for-events |
| 303 | (file-notify--test-timeout) | 329 | (file-notify--test-timeout) |
| @@ -309,11 +335,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 309 | (* (ceiling max-length 100) (file-notify--test-timeout)) | 335 | (* (ceiling max-length 100) (file-notify--test-timeout)) |
| 310 | (= max-length (length file-notify--test-events))) | 336 | (= max-length (length file-notify--test-events))) |
| 311 | ;; One of the possible results shall match. | 337 | ;; One of the possible results shall match. |
| 312 | (should | 338 | (should (file-notify--test-with-events-check events)) |
| 313 | (dolist (elt events result) | ||
| 314 | (setq result | ||
| 315 | (or result | ||
| 316 | (equal elt (mapcar #'cadr file-notify--test-events)))))) | ||
| 317 | (setq ,outer (append ,outer file-notify--test-events))) | 339 | (setq ,outer (append ,outer file-notify--test-events))) |
| 318 | (setq file-notify--test-events ,outer)))) | 340 | (setq file-notify--test-events ,outer)))) |
| 319 | 341 | ||
| @@ -342,7 +364,7 @@ longer than timeout seconds for the events to be delivered." | |||
| 342 | (t '(created changed deleted stopped))) | 364 | (t '(created changed deleted stopped))) |
| 343 | (write-region | 365 | (write-region |
| 344 | "another text" nil file-notify--test-tmpfile nil 'no-message) | 366 | "another text" nil file-notify--test-tmpfile nil 'no-message) |
| 345 | (read-event nil nil 0.1) | 367 | (read-event nil nil file-notify--test-read-event-timeout) |
| 346 | (delete-file file-notify--test-tmpfile)) | 368 | (delete-file file-notify--test-tmpfile)) |
| 347 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 369 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 348 | (let (file-notify--test-events) | 370 | (let (file-notify--test-events) |
| @@ -371,10 +393,10 @@ longer than timeout seconds for the events to be delivered." | |||
| 371 | '((changed deleted stopped) | 393 | '((changed deleted stopped) |
| 372 | (changed changed deleted stopped))) | 394 | (changed changed deleted stopped))) |
| 373 | (t '(changed changed deleted stopped))) | 395 | (t '(changed changed deleted stopped))) |
| 374 | (read-event nil nil 0.1) | 396 | (read-event nil nil file-notify--test-read-event-timeout) |
| 375 | (write-region | 397 | (write-region |
| 376 | "another text" nil file-notify--test-tmpfile nil 'no-message) | 398 | "another text" nil file-notify--test-tmpfile nil 'no-message) |
| 377 | (read-event nil nil 0.1) | 399 | (read-event nil nil file-notify--test-read-event-timeout) |
| 378 | (delete-file file-notify--test-tmpfile)) | 400 | (delete-file file-notify--test-tmpfile)) |
| 379 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 401 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 380 | (let (file-notify--test-events) | 402 | (let (file-notify--test-events) |
| @@ -405,10 +427,10 @@ longer than timeout seconds for the events to be delivered." | |||
| 405 | ((string-equal (file-notify--test-library) "kqueue") | 427 | ((string-equal (file-notify--test-library) "kqueue") |
| 406 | '(created changed deleted stopped)) | 428 | '(created changed deleted stopped)) |
| 407 | (t '(created changed deleted deleted stopped))) | 429 | (t '(created changed deleted deleted stopped))) |
| 408 | (read-event nil nil 0.1) | 430 | (read-event nil nil file-notify--test-read-event-timeout) |
| 409 | (write-region | 431 | (write-region |
| 410 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 432 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 411 | (read-event nil nil 0.1) | 433 | (read-event nil nil file-notify--test-read-event-timeout) |
| 412 | (delete-directory temporary-file-directory 'recursive)) | 434 | (delete-directory temporary-file-directory 'recursive)) |
| 413 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 435 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 414 | (let (file-notify--test-events) | 436 | (let (file-notify--test-events) |
| @@ -440,17 +462,17 @@ longer than timeout seconds for the events to be delivered." | |||
| 440 | '(created changed created changed deleted stopped)) | 462 | '(created changed created changed deleted stopped)) |
| 441 | (t '(created changed created changed | 463 | (t '(created changed created changed |
| 442 | deleted deleted deleted stopped))) | 464 | deleted deleted deleted stopped))) |
| 443 | (read-event nil nil 0.1) | 465 | (read-event nil nil file-notify--test-read-event-timeout) |
| 444 | (write-region | 466 | (write-region |
| 445 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 467 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 446 | (read-event nil nil 0.1) | 468 | (read-event nil nil file-notify--test-read-event-timeout) |
| 447 | (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) | 469 | (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) |
| 448 | ;; The next two events shall not be visible. | 470 | ;; The next two events shall not be visible. |
| 449 | (read-event nil nil 0.1) | 471 | (read-event nil nil file-notify--test-read-event-timeout) |
| 450 | (set-file-modes file-notify--test-tmpfile 000) | 472 | (set-file-modes file-notify--test-tmpfile 000) |
| 451 | (read-event nil nil 0.1) | 473 | (read-event nil nil file-notify--test-read-event-timeout) |
| 452 | (set-file-times file-notify--test-tmpfile '(0 0)) | 474 | (set-file-times file-notify--test-tmpfile '(0 0)) |
| 453 | (read-event nil nil 0.1) | 475 | (read-event nil nil file-notify--test-read-event-timeout) |
| 454 | (delete-directory temporary-file-directory 'recursive)) | 476 | (delete-directory temporary-file-directory 'recursive)) |
| 455 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 477 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 456 | (let (file-notify--test-events) | 478 | (let (file-notify--test-events) |
| @@ -480,13 +502,13 @@ longer than timeout seconds for the events to be delivered." | |||
| 480 | ((string-equal (file-notify--test-library) "kqueue") | 502 | ((string-equal (file-notify--test-library) "kqueue") |
| 481 | '(created changed renamed deleted stopped)) | 503 | '(created changed renamed deleted stopped)) |
| 482 | (t '(created changed renamed deleted deleted stopped))) | 504 | (t '(created changed renamed deleted deleted stopped))) |
| 483 | (read-event nil nil 0.1) | 505 | (read-event nil nil file-notify--test-read-event-timeout) |
| 484 | (write-region | 506 | (write-region |
| 485 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 507 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 486 | (read-event nil nil 0.1) | 508 | (read-event nil nil file-notify--test-read-event-timeout) |
| 487 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) | 509 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) |
| 488 | ;; After the rename, we won't get events anymore. | 510 | ;; After the rename, we won't get events anymore. |
| 489 | (read-event nil nil 0.1) | 511 | (read-event nil nil file-notify--test-read-event-timeout) |
| 490 | (delete-directory temporary-file-directory 'recursive)) | 512 | (delete-directory temporary-file-directory 'recursive)) |
| 491 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 513 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 492 | (let (file-notify--test-events) | 514 | (let (file-notify--test-events) |
| @@ -514,14 +536,14 @@ longer than timeout seconds for the events to be delivered." | |||
| 514 | (file-remote-p temporary-file-directory)) | 536 | (file-remote-p temporary-file-directory)) |
| 515 | '(attribute-changed attribute-changed attribute-changed)) | 537 | '(attribute-changed attribute-changed attribute-changed)) |
| 516 | (t '(attribute-changed attribute-changed))) | 538 | (t '(attribute-changed attribute-changed))) |
| 517 | (read-event nil nil 0.1) | 539 | (read-event nil nil file-notify--test-read-event-timeout) |
| 518 | (write-region | 540 | (write-region |
| 519 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 541 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 520 | (read-event nil nil 0.1) | 542 | (read-event nil nil file-notify--test-read-event-timeout) |
| 521 | (set-file-modes file-notify--test-tmpfile 000) | 543 | (set-file-modes file-notify--test-tmpfile 000) |
| 522 | (read-event nil nil 0.1) | 544 | (read-event nil nil file-notify--test-read-event-timeout) |
| 523 | (set-file-times file-notify--test-tmpfile '(0 0)) | 545 | (set-file-times file-notify--test-tmpfile '(0 0)) |
| 524 | (read-event nil nil 0.1) | 546 | (read-event nil nil file-notify--test-read-event-timeout) |
| 525 | (delete-file file-notify--test-tmpfile)) | 547 | (delete-file file-notify--test-tmpfile)) |
| 526 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. | 548 | ;; `file-notify-rm-watch' fires the `stopped' event. Suppress it. |
| 527 | (let (file-notify--test-events) | 549 | (let (file-notify--test-events) |
| @@ -678,10 +700,10 @@ longer than timeout seconds for the events to be delivered." | |||
| 678 | (changed changed deleted stopped))) | 700 | (changed changed deleted stopped))) |
| 679 | (t '(changed changed deleted stopped))) | 701 | (t '(changed changed deleted stopped))) |
| 680 | (should (file-notify-valid-p file-notify--test-desc)) | 702 | (should (file-notify-valid-p file-notify--test-desc)) |
| 681 | (read-event nil nil 0.1) | 703 | (read-event nil nil file-notify--test-read-event-timeout) |
| 682 | (write-region | 704 | (write-region |
| 683 | "another text" nil file-notify--test-tmpfile nil 'no-message) | 705 | "another text" nil file-notify--test-tmpfile nil 'no-message) |
| 684 | (read-event nil nil 0.1) | 706 | (read-event nil nil file-notify--test-read-event-timeout) |
| 685 | (delete-file file-notify--test-tmpfile)) | 707 | (delete-file file-notify--test-tmpfile)) |
| 686 | ;; After deleting the file, the descriptor is not valid anymore. | 708 | ;; After deleting the file, the descriptor is not valid anymore. |
| 687 | (should-not (file-notify-valid-p file-notify--test-desc)) | 709 | (should-not (file-notify-valid-p file-notify--test-desc)) |
| @@ -713,10 +735,10 @@ longer than timeout seconds for the events to be delivered." | |||
| 713 | '(created changed deleted stopped)) | 735 | '(created changed deleted stopped)) |
| 714 | (t '(created changed deleted deleted stopped))) | 736 | (t '(created changed deleted deleted stopped))) |
| 715 | (should (file-notify-valid-p file-notify--test-desc)) | 737 | (should (file-notify-valid-p file-notify--test-desc)) |
| 716 | (read-event nil nil 0.1) | 738 | (read-event nil nil file-notify--test-read-event-timeout) |
| 717 | (write-region | 739 | (write-region |
| 718 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 740 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 719 | (read-event nil nil 0.1) | 741 | (read-event nil nil file-notify--test-read-event-timeout) |
| 720 | (delete-directory temporary-file-directory t)) | 742 | (delete-directory temporary-file-directory t)) |
| 721 | ;; After deleting the parent directory, the descriptor must | 743 | ;; After deleting the parent directory, the descriptor must |
| 722 | ;; not be valid anymore. | 744 | ;; not be valid anymore. |
| @@ -814,9 +836,9 @@ longer than timeout seconds for the events to be delivered." | |||
| 814 | (let ((source-file-list source-file-list) | 836 | (let ((source-file-list source-file-list) |
| 815 | (target-file-list target-file-list)) | 837 | (target-file-list target-file-list)) |
| 816 | (while (and source-file-list target-file-list) | 838 | (while (and source-file-list target-file-list) |
| 817 | (read-event nil nil 0.1) | 839 | (read-event nil nil file-notify--test-read-event-timeout) |
| 818 | (write-region "" nil (pop source-file-list) nil 'no-message) | 840 | (write-region "" nil (pop source-file-list) nil 'no-message) |
| 819 | (read-event nil nil 0.1) | 841 | (read-event nil nil file-notify--test-read-event-timeout) |
| 820 | (write-region "" nil (pop target-file-list) nil 'no-message)))) | 842 | (write-region "" nil (pop target-file-list) nil 'no-message)))) |
| 821 | (file-notify--test-with-events | 843 | (file-notify--test-with-events |
| 822 | (cond | 844 | (cond |
| @@ -829,16 +851,93 @@ longer than timeout seconds for the events to be delivered." | |||
| 829 | (let ((source-file-list source-file-list) | 851 | (let ((source-file-list source-file-list) |
| 830 | (target-file-list target-file-list)) | 852 | (target-file-list target-file-list)) |
| 831 | (while (and source-file-list target-file-list) | 853 | (while (and source-file-list target-file-list) |
| 832 | (rename-file (pop source-file-list) (pop target-file-list) t) | 854 | (read-event nil nil file-notify--test-read-event-timeout) |
| 833 | (read-event nil nil 0.02)))) | 855 | (rename-file (pop source-file-list) (pop target-file-list) t)))) |
| 834 | (file-notify--test-with-events (make-list n 'deleted) | 856 | (file-notify--test-with-events (make-list n 'deleted) |
| 835 | (dolist (file target-file-list) | 857 | (dolist (file target-file-list) |
| 836 | (prog1 (delete-file file) (read-event nil nil 0.02))))) | 858 | (read-event nil nil file-notify--test-read-event-timeout) |
| 859 | (delete-file file) file-notify--test-read-event-timeout))) | ||
| 860 | |||
| 861 | ;; Cleanup. | ||
| 837 | (file-notify--test-cleanup))) | 862 | (file-notify--test-cleanup))) |
| 838 | 863 | ||
| 839 | (file-notify--deftest-remote file-notify-test06-many-events | 864 | (file-notify--deftest-remote file-notify-test06-many-events |
| 840 | "Check that events are not dropped for remote directories.") | 865 | "Check that events are not dropped for remote directories.") |
| 841 | 866 | ||
| 867 | (ert-deftest file-notify-test07-backup () | ||
| 868 | "Check that backup keeps file notification." | ||
| 869 | (skip-unless (file-notify--test-local-enabled)) | ||
| 870 | |||
| 871 | (unwind-protect | ||
| 872 | (progn | ||
| 873 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) | ||
| 874 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) | ||
| 875 | (should | ||
| 876 | (setq file-notify--test-desc | ||
| 877 | (file-notify-add-watch | ||
| 878 | file-notify--test-tmpfile | ||
| 879 | '(change) #'file-notify--test-event-handler))) | ||
| 880 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 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))) | ||
| 889 | ;; There shouldn't be any problem, because the file is kept. | ||
| 890 | (with-temp-buffer | ||
| 891 | (let ((buffer-file-name file-notify--test-tmpfile) | ||
| 892 | (make-backup-files t) | ||
| 893 | (backup-by-copying t) | ||
| 894 | (kept-new-versions 1) | ||
| 895 | (delete-old-versions t)) | ||
| 896 | (insert "another text") | ||
| 897 | (save-buffer)))) | ||
| 898 | ;; After saving the buffer, the descriptor is still valid. | ||
| 899 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 900 | (delete-file file-notify--test-tmpfile)) | ||
| 901 | |||
| 902 | ;; Cleanup. | ||
| 903 | (file-notify--test-cleanup)) | ||
| 904 | |||
| 905 | (unwind-protect | ||
| 906 | (progn | ||
| 907 | ;; It doesn't work for kqueue, because we don't use an | ||
| 908 | ;; implicit directory monitor. | ||
| 909 | (unless (string-equal (file-notify--test-library) "kqueue") | ||
| 910 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) | ||
| 911 | (write-region | ||
| 912 | "any text" nil file-notify--test-tmpfile nil 'no-message) | ||
| 913 | (should | ||
| 914 | (setq file-notify--test-desc | ||
| 915 | (file-notify-add-watch | ||
| 916 | file-notify--test-tmpfile | ||
| 917 | '(change) #'file-notify--test-event-handler))) | ||
| 918 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 919 | (file-notify--test-with-events '(renamed created changed) | ||
| 920 | ;; The file is renamed when creating a backup. It shall | ||
| 921 | ;; still be watched. | ||
| 922 | (with-temp-buffer | ||
| 923 | (let ((buffer-file-name file-notify--test-tmpfile) | ||
| 924 | (make-backup-files t) | ||
| 925 | (backup-by-copying nil) | ||
| 926 | (backup-by-copying-when-mismatch nil) | ||
| 927 | (kept-new-versions 1) | ||
| 928 | (delete-old-versions t)) | ||
| 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))) | ||
| 934 | |||
| 935 | ;; Cleanup. | ||
| 936 | (file-notify--test-cleanup))) | ||
| 937 | |||
| 938 | (file-notify--deftest-remote file-notify-test07-backup | ||
| 939 | "Check that backup keeps file notification for remote files.") | ||
| 940 | |||
| 842 | (defun file-notify-test-all (&optional interactive) | 941 | (defun file-notify-test-all (&optional interactive) |
| 843 | "Run all tests for \\[file-notify]." | 942 | "Run all tests for \\[file-notify]." |
| 844 | (interactive "p") | 943 | (interactive "p") |