diff options
| author | Michael Albinus | 2018-01-10 13:39:17 +0100 |
|---|---|---|
| committer | Michael Albinus | 2018-01-10 13:39:17 +0100 |
| commit | 3efb1e7defc6bc4eeebbf05d9d4bf2d0deb5a4c1 (patch) | |
| tree | c2f1a22061365533307c0a5c7bdc8a8c060a5e61 | |
| parent | a9b884c60f5d17d55e18039b73020a1c726dd048 (diff) | |
| download | emacs-3efb1e7defc6bc4eeebbf05d9d4bf2d0deb5a4c1.tar.gz emacs-3efb1e7defc6bc4eeebbf05d9d4bf2d0deb5a4c1.zip | |
Fix Bug#30057
* test/lisp/filenotify-tests.el (file-notify--test-tmpdir): New defvar.
(file-notify--test-cleanup, file-notify--test-make-temp-name)
(file-notify-test01-add-watch, file-notify-test03-events)
(file-notify-test05-file-validity)
(file-notify-test09-watched-file-in-watched-dir)
(file-notify-test10-sufficient-resources): Use it. (Bug#30057)
| -rw-r--r-- | test/lisp/filenotify-tests.el | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index d8fae4df592..feb1f19cb5c 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el | |||
| @@ -63,6 +63,7 @@ | |||
| 63 | (format "/mock::%s" temporary-file-directory))) | 63 | (format "/mock::%s" temporary-file-directory))) |
| 64 | "Temporary directory for Tramp tests.") | 64 | "Temporary directory for Tramp tests.") |
| 65 | 65 | ||
| 66 | (defvar file-notify--test-tmpdir nil) | ||
| 66 | (defvar file-notify--test-tmpfile nil) | 67 | (defvar file-notify--test-tmpfile nil) |
| 67 | (defvar file-notify--test-tmpfile1 nil) | 68 | (defvar file-notify--test-tmpfile1 nil) |
| 68 | (defvar file-notify--test-desc nil) | 69 | (defvar file-notify--test-desc nil) |
| @@ -153,6 +154,8 @@ Return nil when any other file notification watch is still active." | |||
| 153 | (delete-directory file-notify--test-tmpfile1 'recursive) | 154 | (delete-directory file-notify--test-tmpfile1 'recursive) |
| 154 | (delete-file file-notify--test-tmpfile1))) | 155 | (delete-file file-notify--test-tmpfile1))) |
| 155 | (ignore-errors | 156 | (ignore-errors |
| 157 | (delete-directory file-notify--test-tmpdir 'recursive)) | ||
| 158 | (ignore-errors | ||
| 156 | (when (file-remote-p temporary-file-directory) | 159 | (when (file-remote-p temporary-file-directory) |
| 157 | (tramp-cleanup-connection | 160 | (tramp-cleanup-connection |
| 158 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password))) | 161 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password))) |
| @@ -160,7 +163,8 @@ Return nil when any other file notification watch is still active." | |||
| 160 | (when (hash-table-p file-notify-descriptors) | 163 | (when (hash-table-p file-notify-descriptors) |
| 161 | (clrhash file-notify-descriptors)) | 164 | (clrhash file-notify-descriptors)) |
| 162 | 165 | ||
| 163 | (setq file-notify--test-tmpfile nil | 166 | (setq file-notify--test-tmpdir nil |
| 167 | file-notify--test-tmpfile nil | ||
| 164 | file-notify--test-tmpfile1 nil | 168 | file-notify--test-tmpfile1 nil |
| 165 | file-notify--test-desc nil | 169 | file-notify--test-desc nil |
| 166 | file-notify--test-desc1 nil | 170 | file-notify--test-desc1 nil |
| @@ -274,6 +278,17 @@ This returns only for the local case and gfilenotify; otherwise it is nil. | |||
| 274 | (file-notify--deftest-remote file-notify-test00-availability | 278 | (file-notify--deftest-remote file-notify-test00-availability |
| 275 | "Test availability of `file-notify' for remote files.") | 279 | "Test availability of `file-notify' for remote files.") |
| 276 | 280 | ||
| 281 | (defun file-notify--test-make-temp-name () | ||
| 282 | "Create a temporary file name for test." | ||
| 283 | (unless (stringp file-notify--test-tmpdir) | ||
| 284 | (setq file-notify--test-tmpdir | ||
| 285 | (expand-file-name | ||
| 286 | (make-temp-name "file-notify-test") temporary-file-directory))) | ||
| 287 | (unless (file-directory-p file-notify--test-tmpdir) | ||
| 288 | (make-directory file-notify--test-tmpdir)) | ||
| 289 | (expand-file-name | ||
| 290 | (make-temp-name "file-notify-test") file-notify--test-tmpdir)) | ||
| 291 | |||
| 277 | (ert-deftest file-notify-test01-add-watch () | 292 | (ert-deftest file-notify-test01-add-watch () |
| 278 | "Check `file-notify-add-watch'." | 293 | "Check `file-notify-add-watch'." |
| 279 | (skip-unless (file-notify--test-local-enabled)) | 294 | (skip-unless (file-notify--test-local-enabled)) |
| @@ -289,17 +304,17 @@ This returns only for the local case and gfilenotify; otherwise it is nil. | |||
| 289 | (should | 304 | (should |
| 290 | (setq file-notify--test-desc | 305 | (setq file-notify--test-desc |
| 291 | (file-notify-add-watch | 306 | (file-notify-add-watch |
| 292 | temporary-file-directory '(change) #'ignore))) | 307 | file-notify--test-tmpdir '(change) #'ignore))) |
| 293 | (file-notify-rm-watch file-notify--test-desc) | 308 | (file-notify-rm-watch file-notify--test-desc) |
| 294 | (should | 309 | (should |
| 295 | (setq file-notify--test-desc | 310 | (setq file-notify--test-desc |
| 296 | (file-notify-add-watch | 311 | (file-notify-add-watch |
| 297 | temporary-file-directory '(attribute-change) #'ignore))) | 312 | file-notify--test-tmpdir '(attribute-change) #'ignore))) |
| 298 | (file-notify-rm-watch file-notify--test-desc) | 313 | (file-notify-rm-watch file-notify--test-desc) |
| 299 | (should | 314 | (should |
| 300 | (setq file-notify--test-desc | 315 | (setq file-notify--test-desc |
| 301 | (file-notify-add-watch | 316 | (file-notify-add-watch |
| 302 | temporary-file-directory '(change attribute-change) #'ignore))) | 317 | file-notify--test-tmpdir '(change attribute-change) #'ignore))) |
| 303 | (file-notify-rm-watch file-notify--test-desc) | 318 | (file-notify-rm-watch file-notify--test-desc) |
| 304 | 319 | ||
| 305 | ;; File monitors like kqueue insist, that the watched file | 320 | ;; File monitors like kqueue insist, that the watched file |
| @@ -325,11 +340,11 @@ This returns only for the local case and gfilenotify; otherwise it is nil. | |||
| 325 | '(wrong-type-argument 1))) | 340 | '(wrong-type-argument 1))) |
| 326 | (should | 341 | (should |
| 327 | (equal (should-error | 342 | (equal (should-error |
| 328 | (file-notify-add-watch temporary-file-directory 2 3)) | 343 | (file-notify-add-watch file-notify--test-tmpdir 2 3)) |
| 329 | '(wrong-type-argument 2))) | 344 | '(wrong-type-argument 2))) |
| 330 | (should | 345 | (should |
| 331 | (equal (should-error | 346 | (equal (should-error |
| 332 | (file-notify-add-watch temporary-file-directory '(change) 3)) | 347 | (file-notify-add-watch file-notify--test-tmpdir '(change) 3)) |
| 333 | '(wrong-type-argument 3))) | 348 | '(wrong-type-argument 3))) |
| 334 | ;; The upper directory of a file must exist. | 349 | ;; The upper directory of a file must exist. |
| 335 | (should | 350 | (should |
| @@ -349,11 +364,6 @@ This returns only for the local case and gfilenotify; otherwise it is nil. | |||
| 349 | (file-notify--deftest-remote file-notify-test01-add-watch | 364 | (file-notify--deftest-remote file-notify-test01-add-watch |
| 350 | "Check `file-notify-add-watch' for remote files.") | 365 | "Check `file-notify-add-watch' for remote files.") |
| 351 | 366 | ||
| 352 | (defun file-notify--test-make-temp-name () | ||
| 353 | "Create a temporary file name for test." | ||
| 354 | (expand-file-name | ||
| 355 | (make-temp-name "file-notify-test") temporary-file-directory)) | ||
| 356 | |||
| 357 | ;; This test is inspired by Bug#26126 and Bug#26127. | 367 | ;; This test is inspired by Bug#26126 and Bug#26127. |
| 358 | (ert-deftest file-notify-test02-rm-watch () | 368 | (ert-deftest file-notify-test02-rm-watch () |
| 359 | "Check `file-notify-rm-watch'." | 369 | "Check `file-notify-rm-watch'." |
| @@ -612,13 +622,13 @@ delivered." | |||
| 612 | ;; Check file creation, change and deletion when watching a | 622 | ;; Check file creation, change and deletion when watching a |
| 613 | ;; directory. There must be a `stopped' event when deleting | 623 | ;; directory. There must be a `stopped' event when deleting |
| 614 | ;; the directory. | 624 | ;; the directory. |
| 615 | (let ((temporary-file-directory | 625 | (let ((file-notify--test-tmpdir |
| 616 | (make-temp-file "file-notify-test-parent" t))) | 626 | (make-temp-file "file-notify-test-parent" t))) |
| 617 | (should | 627 | (should |
| 618 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 628 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 619 | file-notify--test-desc | 629 | file-notify--test-desc |
| 620 | (file-notify-add-watch | 630 | (file-notify-add-watch |
| 621 | temporary-file-directory | 631 | file-notify--test-tmpdir |
| 622 | '(change) #'file-notify--test-event-handler))) | 632 | '(change) #'file-notify--test-event-handler))) |
| 623 | (file-notify--test-with-events | 633 | (file-notify--test-with-events |
| 624 | (cond | 634 | (cond |
| @@ -643,18 +653,18 @@ delivered." | |||
| 643 | (write-region | 653 | (write-region |
| 644 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 654 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 645 | (file-notify--test-read-event) | 655 | (file-notify--test-read-event) |
| 646 | (delete-directory temporary-file-directory 'recursive)) | 656 | (delete-directory file-notify--test-tmpdir 'recursive)) |
| 647 | (file-notify-rm-watch file-notify--test-desc)) | 657 | (file-notify-rm-watch file-notify--test-desc)) |
| 648 | 658 | ||
| 649 | ;; Check copy of files inside a directory. | 659 | ;; Check copy of files inside a directory. |
| 650 | (let ((temporary-file-directory | 660 | (let ((file-notify--test-tmpdir |
| 651 | (make-temp-file "file-notify-test-parent" t))) | 661 | (make-temp-file "file-notify-test-parent" t))) |
| 652 | (should | 662 | (should |
| 653 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 663 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 654 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 664 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 655 | file-notify--test-desc | 665 | file-notify--test-desc |
| 656 | (file-notify-add-watch | 666 | (file-notify-add-watch |
| 657 | temporary-file-directory | 667 | file-notify--test-tmpdir |
| 658 | '(change) #'file-notify--test-event-handler))) | 668 | '(change) #'file-notify--test-event-handler))) |
| 659 | (file-notify--test-with-events | 669 | (file-notify--test-with-events |
| 660 | (cond | 670 | (cond |
| @@ -689,18 +699,18 @@ delivered." | |||
| 689 | (file-notify--test-read-event) | 699 | (file-notify--test-read-event) |
| 690 | (set-file-times file-notify--test-tmpfile '(0 0)) | 700 | (set-file-times file-notify--test-tmpfile '(0 0)) |
| 691 | (file-notify--test-read-event) | 701 | (file-notify--test-read-event) |
| 692 | (delete-directory temporary-file-directory 'recursive)) | 702 | (delete-directory file-notify--test-tmpdir 'recursive)) |
| 693 | (file-notify-rm-watch file-notify--test-desc)) | 703 | (file-notify-rm-watch file-notify--test-desc)) |
| 694 | 704 | ||
| 695 | ;; Check rename of files inside a directory. | 705 | ;; Check rename of files inside a directory. |
| 696 | (let ((temporary-file-directory | 706 | (let ((file-notify--test-tmpdir |
| 697 | (make-temp-file "file-notify-test-parent" t))) | 707 | (make-temp-file "file-notify-test-parent" t))) |
| 698 | (should | 708 | (should |
| 699 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 709 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 700 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 710 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 701 | file-notify--test-desc | 711 | file-notify--test-desc |
| 702 | (file-notify-add-watch | 712 | (file-notify-add-watch |
| 703 | temporary-file-directory | 713 | file-notify--test-tmpdir |
| 704 | '(change) #'file-notify--test-event-handler))) | 714 | '(change) #'file-notify--test-event-handler))) |
| 705 | (file-notify--test-with-events | 715 | (file-notify--test-with-events |
| 706 | (cond | 716 | (cond |
| @@ -729,7 +739,7 @@ delivered." | |||
| 729 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) | 739 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) |
| 730 | ;; After the rename, we won't get events anymore. | 740 | ;; After the rename, we won't get events anymore. |
| 731 | (file-notify--test-read-event) | 741 | (file-notify--test-read-event) |
| 732 | (delete-directory temporary-file-directory 'recursive)) | 742 | (delete-directory file-notify--test-tmpdir 'recursive)) |
| 733 | (file-notify-rm-watch file-notify--test-desc)) | 743 | (file-notify-rm-watch file-notify--test-desc)) |
| 734 | 744 | ||
| 735 | ;; Check attribute change. Does not work for cygwin. | 745 | ;; Check attribute change. Does not work for cygwin. |
| @@ -930,13 +940,13 @@ delivered." | |||
| 930 | (file-notify--test-cleanup)) | 940 | (file-notify--test-cleanup)) |
| 931 | 941 | ||
| 932 | (unwind-protect | 942 | (unwind-protect |
| 933 | (let ((temporary-file-directory | 943 | (let ((file-notify--test-tmpdir |
| 934 | (make-temp-file "file-notify-test-parent" t))) | 944 | (make-temp-file "file-notify-test-parent" t))) |
| 935 | (should | 945 | (should |
| 936 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 946 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 937 | file-notify--test-desc | 947 | file-notify--test-desc |
| 938 | (file-notify-add-watch | 948 | (file-notify-add-watch |
| 939 | temporary-file-directory | 949 | file-notify--test-tmpdir |
| 940 | '(change) #'file-notify--test-event-handler))) | 950 | '(change) #'file-notify--test-event-handler))) |
| 941 | (should (file-notify-valid-p file-notify--test-desc)) | 951 | (should (file-notify-valid-p file-notify--test-desc)) |
| 942 | (file-notify--test-with-events | 952 | (file-notify--test-with-events |
| @@ -961,7 +971,7 @@ delivered." | |||
| 961 | (write-region | 971 | (write-region |
| 962 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 972 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 963 | (file-notify--test-read-event) | 973 | (file-notify--test-read-event) |
| 964 | (delete-directory temporary-file-directory t)) | 974 | (delete-directory file-notify--test-tmpdir 'recursive)) |
| 965 | ;; After deleting the parent directory, the descriptor must | 975 | ;; After deleting the parent directory, the descriptor must |
| 966 | ;; not be valid anymore. | 976 | ;; not be valid anymore. |
| 967 | (should-not (file-notify-valid-p file-notify--test-desc)) | 977 | (should-not (file-notify-valid-p file-notify--test-desc)) |
| @@ -1207,7 +1217,7 @@ the file watch." | |||
| 1207 | ;; A file to be watched. | 1217 | ;; A file to be watched. |
| 1208 | (should | 1218 | (should |
| 1209 | (setq file-notify--test-tmpfile1 | 1219 | (setq file-notify--test-tmpfile1 |
| 1210 | (let ((temporary-file-directory file-notify--test-tmpfile)) | 1220 | (let ((file-notify--test-tmpdir file-notify--test-tmpfile)) |
| 1211 | (file-notify--test-make-temp-name)))) | 1221 | (file-notify--test-make-temp-name)))) |
| 1212 | (write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message) | 1222 | (write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message) |
| 1213 | (unwind-protect | 1223 | (unwind-protect |
| @@ -1268,7 +1278,7 @@ the file watch." | |||
| 1268 | (if (zerop (mod i 2)) | 1278 | (if (zerop (mod i 2)) |
| 1269 | (write-region | 1279 | (write-region |
| 1270 | "any text" nil file-notify--test-tmpfile1 t 'no-message) | 1280 | "any text" nil file-notify--test-tmpfile1 t 'no-message) |
| 1271 | (let ((temporary-file-directory file-notify--test-tmpfile)) | 1281 | (let ((file-notify--test-tmpdir file-notify--test-tmpfile)) |
| 1272 | (write-region | 1282 | (write-region |
| 1273 | "any text" nil | 1283 | "any text" nil |
| 1274 | (file-notify--test-make-temp-name) nil 'no-message)))))) | 1284 | (file-notify--test-make-temp-name) nil 'no-message)))))) |
| @@ -1334,7 +1344,7 @@ the file watch." | |||
| 1334 | (setq file-notify--test-tmpfile | 1344 | (setq file-notify--test-tmpfile |
| 1335 | (make-temp-file "file-notify-test-parent" t))) | 1345 | (make-temp-file "file-notify-test-parent" t))) |
| 1336 | (unwind-protect | 1346 | (unwind-protect |
| 1337 | (let ((temporary-file-directory file-notify--test-tmpfile) | 1347 | (let ((file-notify--test-tmpdir file-notify--test-tmpfile) |
| 1338 | descs) | 1348 | descs) |
| 1339 | (should-error | 1349 | (should-error |
| 1340 | (while t | 1350 | (while t |