diff options
| author | Mattias EngdegÄrd | 2019-05-19 17:57:19 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-07-24 11:52:44 +0200 |
| commit | 3a764848650365a9794839c5e98fa74bceb76c47 (patch) | |
| tree | 3993bd2d0716ce64940f25964e6e990ccdacbced | |
| parent | 5cfd8c508ea59739eea6093771f0f747ebd64885 (diff) | |
| download | emacs-3a764848650365a9794839c5e98fa74bceb76c47.tar.gz emacs-3a764848650365a9794839c5e98fa74bceb76c47.zip | |
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'.
| -rw-r--r-- | test/lisp/filenotify-tests.el | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index 2c776815e3b..7c8c1953c4f 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el | |||
| @@ -93,6 +93,7 @@ | |||
| 93 | (defvar file-notify--test-desc2 nil) | 93 | (defvar file-notify--test-desc2 nil) |
| 94 | (defvar file-notify--test-results nil) | 94 | (defvar file-notify--test-results nil) |
| 95 | (defvar file-notify--test-event nil) | 95 | (defvar file-notify--test-event nil) |
| 96 | (defvar file-notify--test-file nil) | ||
| 96 | (defvar file-notify--test-events nil) | 97 | (defvar file-notify--test-events nil) |
| 97 | (defvar file-notify--test-monitors nil) | 98 | (defvar file-notify--test-monitors nil) |
| 98 | 99 | ||
| @@ -204,6 +205,11 @@ Return nil when any other file notification watch is still active." | |||
| 204 | (when (getenv "EMACS_HYDRA_CI") | 205 | (when (getenv "EMACS_HYDRA_CI") |
| 205 | (add-to-list 'tramp-remote-path 'tramp-own-remote-path)) | 206 | (add-to-list 'tramp-remote-path 'tramp-own-remote-path)) |
| 206 | 207 | ||
| 208 | (defun file-notify--test-add-watch (file flags callback) | ||
| 209 | "Like `file-notify-add-watch', but also passing FILE to CALLBACK." | ||
| 210 | (file-notify-add-watch file flags | ||
| 211 | (lambda (event) (funcall callback event file)))) | ||
| 212 | |||
| 207 | ;; We do not want to try and fail `file-notify-add-watch'. | 213 | ;; We do not want to try and fail `file-notify-add-watch'. |
| 208 | (defun file-notify--test-local-enabled () | 214 | (defun file-notify--test-local-enabled () |
| 209 | "Whether local file notification is enabled. | 215 | "Whether local file notification is enabled. |
| @@ -494,26 +500,27 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'." | |||
| 494 | (defun file-notify--test-event-test () | 500 | (defun file-notify--test-event-test () |
| 495 | "Ert test function to be called by `file-notify--test-event-handler'. | 501 | "Ert test function to be called by `file-notify--test-event-handler'. |
| 496 | We cannot pass arguments, so we assume that `file-notify--test-event' | 502 | We cannot pass arguments, so we assume that `file-notify--test-event' |
| 497 | is bound somewhere." | 503 | and `file-notify--test-file' are bound somewhere." |
| 498 | ;; Check the descriptor. | 504 | ;; Check the descriptor. |
| 499 | (should (equal (car file-notify--test-event) file-notify--test-desc)) | 505 | (should (equal (car file-notify--test-event) file-notify--test-desc)) |
| 500 | ;; Check the file name. | 506 | ;; Check the file name. |
| 501 | (should | 507 | (should |
| 502 | (string-prefix-p | 508 | (string-prefix-p |
| 503 | (file-notify--event-watched-file file-notify--test-event) | 509 | file-notify--test-file |
| 504 | (file-notify--test-event-file file-notify--test-event))) | 510 | (file-notify--test-event-file file-notify--test-event))) |
| 505 | ;; Check the second file name if exists. | 511 | ;; Check the second file name if exists. |
| 506 | (when (eq (nth 1 file-notify--test-event) 'renamed) | 512 | (when (eq (nth 1 file-notify--test-event) 'renamed) |
| 507 | (should | 513 | (should |
| 508 | (string-prefix-p | 514 | (string-prefix-p |
| 509 | (file-notify--event-watched-file file-notify--test-event) | 515 | file-notify--test-file |
| 510 | (file-notify--test-event-file1 file-notify--test-event))))) | 516 | (file-notify--test-event-file1 file-notify--test-event))))) |
| 511 | 517 | ||
| 512 | (defun file-notify--test-event-handler (event) | 518 | (defun file-notify--test-event-handler (event file) |
| 513 | "Run a test over FILE-NOTIFY--TEST-EVENT. | 519 | "Run a test over FILE-NOTIFY--TEST-EVENT. |
| 514 | For later analysis, append the test result to `file-notify--test-results' | 520 | For later analysis, append the test result to `file-notify--test-results' |
| 515 | and the event to `file-notify--test-events'." | 521 | and the event to `file-notify--test-events'." |
| 516 | (let* ((file-notify--test-event event) | 522 | (let* ((file-notify--test-event event) |
| 523 | (file-notify--test-file file) | ||
| 517 | (result | 524 | (result |
| 518 | (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) | 525 | (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) |
| 519 | ;; Do not add lock files, this would confuse the checks. | 526 | ;; Do not add lock files, this would confuse the checks. |
| @@ -603,7 +610,7 @@ delivered." | |||
| 603 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) | 610 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) |
| 604 | (should | 611 | (should |
| 605 | (setq file-notify--test-desc | 612 | (setq file-notify--test-desc |
| 606 | (file-notify-add-watch | 613 | (file-notify--test-add-watch |
| 607 | file-notify--test-tmpfile | 614 | file-notify--test-tmpfile |
| 608 | '(change) #'file-notify--test-event-handler))) | 615 | '(change) #'file-notify--test-event-handler))) |
| 609 | (file-notify--test-with-events | 616 | (file-notify--test-with-events |
| @@ -637,7 +644,7 @@ delivered." | |||
| 637 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) | 644 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 638 | (should | 645 | (should |
| 639 | (setq file-notify--test-desc | 646 | (setq file-notify--test-desc |
| 640 | (file-notify-add-watch | 647 | (file-notify--test-add-watch |
| 641 | file-notify--test-tmpfile | 648 | file-notify--test-tmpfile |
| 642 | '(change) #'file-notify--test-event-handler))) | 649 | '(change) #'file-notify--test-event-handler))) |
| 643 | (file-notify--test-with-events | 650 | (file-notify--test-with-events |
| @@ -671,7 +678,7 @@ delivered." | |||
| 671 | (should | 678 | (should |
| 672 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 679 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 673 | file-notify--test-desc | 680 | file-notify--test-desc |
| 674 | (file-notify-add-watch | 681 | (file-notify--test-add-watch |
| 675 | file-notify--test-tmpdir | 682 | file-notify--test-tmpdir |
| 676 | '(change) #'file-notify--test-event-handler))) | 683 | '(change) #'file-notify--test-event-handler))) |
| 677 | (file-notify--test-with-events | 684 | (file-notify--test-with-events |
| @@ -718,7 +725,7 @@ delivered." | |||
| 718 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 725 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 719 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 726 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 720 | file-notify--test-desc | 727 | file-notify--test-desc |
| 721 | (file-notify-add-watch | 728 | (file-notify--test-add-watch |
| 722 | file-notify--test-tmpdir | 729 | file-notify--test-tmpdir |
| 723 | '(change) #'file-notify--test-event-handler))) | 730 | '(change) #'file-notify--test-event-handler))) |
| 724 | (file-notify--test-with-events | 731 | (file-notify--test-with-events |
| @@ -775,7 +782,7 @@ delivered." | |||
| 775 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 782 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 776 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 783 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 777 | file-notify--test-desc | 784 | file-notify--test-desc |
| 778 | (file-notify-add-watch | 785 | (file-notify--test-add-watch |
| 779 | file-notify--test-tmpdir | 786 | file-notify--test-tmpdir |
| 780 | '(change) #'file-notify--test-event-handler))) | 787 | '(change) #'file-notify--test-event-handler))) |
| 781 | (file-notify--test-with-events | 788 | (file-notify--test-with-events |
| @@ -826,7 +833,7 @@ delivered." | |||
| 826 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 833 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 827 | (should | 834 | (should |
| 828 | (setq file-notify--test-desc | 835 | (setq file-notify--test-desc |
| 829 | (file-notify-add-watch | 836 | (file-notify--test-add-watch |
| 830 | file-notify--test-tmpfile | 837 | file-notify--test-tmpfile |
| 831 | '(attribute-change) #'file-notify--test-event-handler))) | 838 | '(attribute-change) #'file-notify--test-event-handler))) |
| 832 | (file-notify--test-with-events | 839 | (file-notify--test-with-events |
| @@ -991,7 +998,7 @@ delivered." | |||
| 991 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) | 998 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 992 | (should | 999 | (should |
| 993 | (setq file-notify--test-desc | 1000 | (setq file-notify--test-desc |
| 994 | (file-notify-add-watch | 1001 | (file-notify--test-add-watch |
| 995 | file-notify--test-tmpfile | 1002 | file-notify--test-tmpfile |
| 996 | '(change) #'file-notify--test-event-handler))) | 1003 | '(change) #'file-notify--test-event-handler))) |
| 997 | (should (file-notify-valid-p file-notify--test-desc)) | 1004 | (should (file-notify-valid-p file-notify--test-desc)) |
| @@ -1028,7 +1035,7 @@ delivered." | |||
| 1028 | (should | 1035 | (should |
| 1029 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) | 1036 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 1030 | file-notify--test-desc | 1037 | file-notify--test-desc |
| 1031 | (file-notify-add-watch | 1038 | (file-notify--test-add-watch |
| 1032 | file-notify--test-tmpdir | 1039 | file-notify--test-tmpdir |
| 1033 | '(change) #'file-notify--test-event-handler))) | 1040 | '(change) #'file-notify--test-event-handler))) |
| 1034 | (should (file-notify-valid-p file-notify--test-desc)) | 1041 | (should (file-notify-valid-p file-notify--test-desc)) |
| @@ -1146,7 +1153,7 @@ delivered." | |||
| 1146 | (make-temp-file "file-notify-test-parent" t))) | 1153 | (make-temp-file "file-notify-test-parent" t))) |
| 1147 | (should | 1154 | (should |
| 1148 | (setq file-notify--test-desc | 1155 | (setq file-notify--test-desc |
| 1149 | (file-notify-add-watch | 1156 | (file-notify--test-add-watch |
| 1150 | file-notify--test-tmpfile | 1157 | file-notify--test-tmpfile |
| 1151 | '(change) #'file-notify--test-event-handler))) | 1158 | '(change) #'file-notify--test-event-handler))) |
| 1152 | (unwind-protect | 1159 | (unwind-protect |
| @@ -1222,7 +1229,7 @@ delivered." | |||
| 1222 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) | 1229 | (write-region "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 1223 | (should | 1230 | (should |
| 1224 | (setq file-notify--test-desc | 1231 | (setq file-notify--test-desc |
| 1225 | (file-notify-add-watch | 1232 | (file-notify--test-add-watch |
| 1226 | file-notify--test-tmpfile | 1233 | file-notify--test-tmpfile |
| 1227 | '(change) #'file-notify--test-event-handler))) | 1234 | '(change) #'file-notify--test-event-handler))) |
| 1228 | (should (file-notify-valid-p file-notify--test-desc)) | 1235 | (should (file-notify-valid-p file-notify--test-desc)) |
| @@ -1258,7 +1265,7 @@ delivered." | |||
| 1258 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 1265 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 1259 | (should | 1266 | (should |
| 1260 | (setq file-notify--test-desc | 1267 | (setq file-notify--test-desc |
| 1261 | (file-notify-add-watch | 1268 | (file-notify--test-add-watch |
| 1262 | file-notify--test-tmpfile | 1269 | file-notify--test-tmpfile |
| 1263 | '(change) #'file-notify--test-event-handler))) | 1270 | '(change) #'file-notify--test-event-handler))) |
| 1264 | (should (file-notify-valid-p file-notify--test-desc)) | 1271 | (should (file-notify-valid-p file-notify--test-desc)) |
| @@ -1314,23 +1321,23 @@ the file watch." | |||
| 1314 | (write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message) | 1321 | (write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message) |
| 1315 | (unwind-protect | 1322 | (unwind-protect |
| 1316 | (cl-flet (;; Directory monitor. | 1323 | (cl-flet (;; Directory monitor. |
| 1317 | (dir-callback (event) | 1324 | (dir-callback (event file) |
| 1318 | (let ((file-notify--test-desc file-notify--test-desc1)) | 1325 | (let ((file-notify--test-desc file-notify--test-desc1)) |
| 1319 | (file-notify--test-event-handler event))) | 1326 | (file-notify--test-event-handler event file))) |
| 1320 | ;; File monitor. | 1327 | ;; File monitor. |
| 1321 | (file-callback (event) | 1328 | (file-callback (event file) |
| 1322 | (let ((file-notify--test-desc file-notify--test-desc2)) | 1329 | (let ((file-notify--test-desc file-notify--test-desc2)) |
| 1323 | (file-notify--test-event-handler event)))) | 1330 | (file-notify--test-event-handler event file)))) |
| 1324 | (should | 1331 | (should |
| 1325 | (setq file-notify--test-desc1 | 1332 | (setq file-notify--test-desc1 |
| 1326 | (file-notify-add-watch | 1333 | (file-notify--test-add-watch |
| 1327 | file-notify--test-tmpfile | 1334 | file-notify--test-tmpfile |
| 1328 | '(change) #'dir-callback) | 1335 | '(change) #'dir-callback) |
| 1329 | ;; This is needed for `file-notify--test-monitor'. | 1336 | ;; This is needed for `file-notify--test-monitor'. |
| 1330 | file-notify--test-desc file-notify--test-desc1)) | 1337 | file-notify--test-desc file-notify--test-desc1)) |
| 1331 | (should | 1338 | (should |
| 1332 | (setq file-notify--test-desc2 | 1339 | (setq file-notify--test-desc2 |
| 1333 | (file-notify-add-watch | 1340 | (file-notify--test-add-watch |
| 1334 | file-notify--test-tmpfile1 | 1341 | file-notify--test-tmpfile1 |
| 1335 | '(change) #'file-callback))) | 1342 | '(change) #'file-callback))) |
| 1336 | (should (file-notify-valid-p file-notify--test-desc1)) | 1343 | (should (file-notify-valid-p file-notify--test-desc1)) |