diff options
| author | Tassilo Horn | 2015-09-09 21:46:40 +0200 |
|---|---|---|
| committer | Tassilo Horn | 2015-09-09 22:02:43 +0200 |
| commit | 1c5b7ba8761af7aa2f476d98abcd653cdb966301 (patch) | |
| tree | eacc60dbc54674321c96ccc839035c4b735ee0dd | |
| parent | 5a3122e1679575a8b4e24d3d965f6d6684ae118e (diff) | |
| download | emacs-1c5b7ba8761af7aa2f476d98abcd653cdb966301.tar.gz emacs-1c5b7ba8761af7aa2f476d98abcd653cdb966301.zip | |
Start checking event types in file-notify tests
* test/automated/file-notify-tests.el (file-notify--test-events): New
variable.
(file-notify--test-event-handler): Append received event to
file-notify--test-events for later analysis.
(file-notify-test02-events): Assert that the expected notifications have
arrived in the expected order.
| -rw-r--r-- | test/automated/file-notify-tests.el | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el index 11589b99295..4fe79558dcf 100644 --- a/test/automated/file-notify-tests.el +++ b/test/automated/file-notify-tests.el | |||
| @@ -60,6 +60,7 @@ | |||
| 60 | (defvar file-notify--test-desc nil) | 60 | (defvar file-notify--test-desc nil) |
| 61 | (defvar file-notify--test-results nil) | 61 | (defvar file-notify--test-results nil) |
| 62 | (defvar file-notify--test-event nil) | 62 | (defvar file-notify--test-event nil) |
| 63 | (defvar file-notify--test-events nil) | ||
| 63 | 64 | ||
| 64 | (setq password-cache-expiry nil | 65 | (setq password-cache-expiry nil |
| 65 | tramp-verbose 0 | 66 | tramp-verbose 0 |
| @@ -166,7 +167,7 @@ being the result.") | |||
| 166 | "Ert test function to be called by `file-notify--test-event-handler'. | 167 | "Ert test function to be called by `file-notify--test-event-handler'. |
| 167 | We cannot pass arguments, so we assume that `file-notify--test-event' | 168 | We cannot pass arguments, so we assume that `file-notify--test-event' |
| 168 | is bound somewhere." | 169 | is bound somewhere." |
| 169 | ;(message "Event %S" file-notify--test-event) | 170 | ;;(message "Event %S" file-notify--test-event) |
| 170 | ;; Check the descriptor. | 171 | ;; Check the descriptor. |
| 171 | (should (equal (car file-notify--test-event) file-notify--test-desc)) | 172 | (should (equal (car file-notify--test-event) file-notify--test-desc)) |
| 172 | ;; Check the file name. | 173 | ;; Check the file name. |
| @@ -182,9 +183,13 @@ is bound somewhere." | |||
| 182 | 183 | ||
| 183 | (defun file-notify--test-event-handler (file-notify--test-event) | 184 | (defun file-notify--test-event-handler (file-notify--test-event) |
| 184 | "Run a test over FILE-NOTIFY--TEST-EVENT. | 185 | "Run a test over FILE-NOTIFY--TEST-EVENT. |
| 185 | Save the result in `file-notify--test-results', for later analysis." | 186 | For later analysis, append the test result to |
| 187 | `file-notify--test-results' and the event to | ||
| 188 | `file-notify--test-events'." | ||
| 186 | (let ((result | 189 | (let ((result |
| 187 | (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) | 190 | (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) |
| 191 | (setq file-notify--test-events | ||
| 192 | (append file-notify--test-events `(,file-notify--test-event))) | ||
| 188 | (setq file-notify--test-results | 193 | (setq file-notify--test-results |
| 189 | (append file-notify--test-results `(,result))))) | 194 | (append file-notify--test-results `(,result))))) |
| 190 | 195 | ||
| @@ -194,7 +199,7 @@ Save the result in `file-notify--test-results', for later analysis." | |||
| 194 | (make-temp-name "file-notify-test") temporary-file-directory)) | 199 | (make-temp-name "file-notify-test") temporary-file-directory)) |
| 195 | 200 | ||
| 196 | (defmacro file-notify--wait-for-events (timeout until) | 201 | (defmacro file-notify--wait-for-events (timeout until) |
| 197 | "Wait for file notification events until form UNTIL is true. | 202 | "Wait for and return file notification events until form UNTIL is true. |
| 198 | TIMEOUT is the maximum time to wait for, in seconds." | 203 | TIMEOUT is the maximum time to wait for, in seconds." |
| 199 | `(with-timeout (,timeout (ignore)) | 204 | `(with-timeout (,timeout (ignore)) |
| 200 | (while (null ,until) | 205 | (while (null ,until) |
| @@ -206,6 +211,7 @@ TIMEOUT is the maximum time to wait for, in seconds." | |||
| 206 | (unwind-protect | 211 | (unwind-protect |
| 207 | (progn | 212 | (progn |
| 208 | (setq file-notify--test-results nil | 213 | (setq file-notify--test-results nil |
| 214 | file-notify--test-events nil | ||
| 209 | file-notify--test-tmpfile (file-notify--test-make-temp-name) | 215 | file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 210 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 216 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 211 | file-notify--test-desc | 217 | file-notify--test-desc |
| @@ -214,7 +220,7 @@ TIMEOUT is the maximum time to wait for, in seconds." | |||
| 214 | '(change) 'file-notify--test-event-handler)) | 220 | '(change) 'file-notify--test-event-handler)) |
| 215 | (should file-notify--test-desc) | 221 | (should file-notify--test-desc) |
| 216 | 222 | ||
| 217 | ;; Check creation and removal. | 223 | ;; Check creation, change, and deletion. |
| 218 | (write-region | 224 | (write-region |
| 219 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 225 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 220 | (delete-file file-notify--test-tmpfile) | 226 | (delete-file file-notify--test-tmpfile) |
| @@ -236,13 +242,17 @@ TIMEOUT is the maximum time to wait for, in seconds." | |||
| 236 | 242 | ||
| 237 | ;; Wait for events, and exit. | 243 | ;; Wait for events, and exit. |
| 238 | (file-notify--wait-for-events 5 file-notify--test-results) | 244 | (file-notify--wait-for-events 5 file-notify--test-results) |
| 245 | (should (equal (mapcar #'second file-notify--test-events) | ||
| 246 | '(created changed deleted | ||
| 247 | created changed deleted | ||
| 248 | created changed renamed))) | ||
| 239 | (file-notify-rm-watch file-notify--test-desc) | 249 | (file-notify-rm-watch file-notify--test-desc) |
| 240 | (ignore-errors (delete-file file-notify--test-tmpfile)) | 250 | (ignore-errors (delete-file file-notify--test-tmpfile)) |
| 241 | (ignore-errors (delete-file file-notify--test-tmpfile1))) | 251 | (ignore-errors (delete-file file-notify--test-tmpfile1))) |
| 242 | 252 | ||
| 243 | (should file-notify--test-results) | 253 | (should file-notify--test-results) |
| 244 | (dolist (result file-notify--test-results) | 254 | (dolist (result file-notify--test-results) |
| 245 | ;(message "%s" (ert-test-result-messages result)) | 255 | ;;(message "%s" (ert-test-result-messages result)) |
| 246 | (when (ert-test-failed-p result) | 256 | (when (ert-test-failed-p result) |
| 247 | (ert-fail (cadr (ert-test-result-with-condition-condition result)))))) | 257 | (ert-fail (cadr (ert-test-result-with-condition-condition result)))))) |
| 248 | 258 | ||