aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2015-09-21 15:07:06 +0200
committerMichael Albinus2015-09-21 15:07:06 +0200
commit01b547529ba81f4f5a64f5017a2c3d6601d0bb95 (patch)
treec52e7ad2b66dca3d7a8f612516d0e738696713bf /test
parent127bafdc6dcbcf4b11bff7ec52960bd941613a1c (diff)
downloademacs-01b547529ba81f4f5a64f5017a2c3d6601d0bb95.tar.gz
emacs-01b547529ba81f4f5a64f5017a2c3d6601d0bb95.zip
Adapt tests and manual for w32notify
* doc/lispref/os.texi (File Notifications): w32notify does not send `attribute-changed' events. * test/automated/file-notify-tests.el (file-notify--test-with-events): Simplify parameters. Adapt all callees. (file-notify-test02-events): w32notify does not send `attribute-changed' events. (file-notify-test04-file-validity, file-notify-test05-dir-validity): Do not skip in case of w32notify. Simply ignore this part of the test.
Diffstat (limited to 'test')
-rw-r--r--test/automated/file-notify-tests.el161
1 files changed, 76 insertions, 85 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el
index 9d66f03ae0c..75e0c24a7e9 100644
--- a/test/automated/file-notify-tests.el
+++ b/test/automated/file-notify-tests.el
@@ -245,17 +245,17 @@ TIMEOUT is the maximum time to wait for, in seconds."
245 (while (null ,until) 245 (while (null ,until)
246 (read-event nil nil 0.1)))) 246 (read-event nil nil 0.1))))
247 247
248(defmacro file-notify--test-with-events (n timeout assert-fn &rest body) 248(defmacro file-notify--test-with-events (timeout events &rest body)
249 "Run BODY collecting N events and then run ASSERT-FN. 249 "Run BODY collecting events and then compare with EVENTS.
250Don't wait longer than TIMEOUT seconds for the events to be delivered." 250Don't wait longer than TIMEOUT seconds for the events to be delivered."
251 (declare (indent 3)) 251 (declare (indent 2))
252 (let ((outer (make-symbol "outer"))) 252 (let ((outer (make-symbol "outer")))
253 `(let ((,outer file-notify--test-events)) 253 `(let ((,outer file-notify--test-events))
254 (let (file-notify--test-events) 254 (let (file-notify--test-events)
255 ,@body 255 ,@body
256 (file-notify--wait-for-events 256 (file-notify--wait-for-events
257 ,timeout (= ,n (length file-notify--test-events))) 257 ,timeout (= (length ,events) (length file-notify--test-events)))
258 (funcall ,assert-fn file-notify--test-events) 258 (should (equal ,events (mapcar #'cadr file-notify--test-events)))
259 (setq ,outer (append ,outer file-notify--test-events))) 259 (setq ,outer (append ,outer file-notify--test-events)))
260 (setq file-notify--test-events ,outer)))) 260 (setq file-notify--test-events ,outer))))
261 261
@@ -274,67 +274,65 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
274 274
275 ;; Check creation, change, and deletion. 275 ;; Check creation, change, and deletion.
276 (file-notify--test-with-events 276 (file-notify--test-with-events
277 3 (file-notify--test-timeout) 277 (file-notify--test-timeout) '(created changed deleted)
278 (lambda (events)
279 (should (equal '(created changed deleted)
280 (mapcar #'cadr events))))
281 (write-region 278 (write-region
282 "any text" nil file-notify--test-tmpfile nil 'no-message) 279 "any text" nil file-notify--test-tmpfile nil 'no-message)
283 (delete-file file-notify--test-tmpfile)) 280 (delete-file file-notify--test-tmpfile))
284 281
285 ;; Check copy. 282 ;; Check copy.
286 (file-notify--test-with-events 283 (file-notify--test-with-events
287 3 (file-notify--test-timeout) 284 (file-notify--test-timeout)
288 (lambda (events) 285 ;; w32notify does not distinguish between `changed' and
289 (should (equal '(created changed deleted) 286 ;; `attribute-changed'.
290 (mapcar #'cadr events)))) 287 (if (eq file-notify--library 'w32notify)
288 '(created changed changed changed deleted)
289 '(created changed deleted))
291 (write-region 290 (write-region
292 "any text" nil file-notify--test-tmpfile nil 'no-message) 291 "any text" nil file-notify--test-tmpfile nil 'no-message)
293 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) 292 (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
294 ;; The next two events shall not be visible. 293 ;; The next two events shall not be visible.
295 (set-file-modes file-notify--test-tmpfile 000) 294 (set-file-modes file-notify--test-tmpfile 000)
295 (read-event nil nil 0.1) ; In order to distinguish the events.
296 (set-file-times file-notify--test-tmpfile '(0 0)) 296 (set-file-times file-notify--test-tmpfile '(0 0))
297 (delete-file file-notify--test-tmpfile) 297 (delete-file file-notify--test-tmpfile)
298 (delete-file file-notify--test-tmpfile1)) 298 (delete-file file-notify--test-tmpfile1))
299 299
300 ;; Check rename. 300 ;; Check rename.
301 (file-notify--test-with-events 301 (file-notify--test-with-events
302 3 (file-notify--test-timeout) 302 (file-notify--test-timeout) '(created changed renamed)
303 (lambda (events)
304 (should (equal '(created changed renamed)
305 (mapcar #'cadr events))))
306 (write-region 303 (write-region
307 "any text" nil file-notify--test-tmpfile nil 'no-message) 304 "any text" nil file-notify--test-tmpfile nil 'no-message)
308 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) 305 (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
309 ;; After the rename, we won't get events anymore. 306 ;; After the rename, we won't get events anymore.
310 (delete-file file-notify--test-tmpfile1)) 307 (delete-file file-notify--test-tmpfile1))
311 308
312 ;; Check attribute change. 309 ;; Check attribute change. It doesn't work for w32notify.
313 (file-notify-rm-watch file-notify--test-desc) 310 (unless (eq file-notify--library 'w32notify)
314 (setq file-notify--test-desc 311 (file-notify-rm-watch file-notify--test-desc)
315 (file-notify-add-watch 312 (setq file-notify--test-desc
316 file-notify--test-tmpfile 313 (file-notify-add-watch
317 '(attribute-change) 'file-notify--test-event-handler)) 314 file-notify--test-tmpfile
318 (file-notify--test-with-events 315 '(attribute-change) 'file-notify--test-event-handler))
319 2 (file-notify--test-timeout) 316 (file-notify--test-with-events
320 (lambda (events) 317 (file-notify--test-timeout) '(attribute-changed attribute-changed)
321 (should (equal '(attribute-changed attribute-changed) 318 (write-region
322 (mapcar #'cadr events)))) 319 "any text" nil file-notify--test-tmpfile nil 'no-message)
323 (write-region 320 (set-file-modes file-notify--test-tmpfile 000)
324 "any text" nil file-notify--test-tmpfile nil 'no-message) 321 (read-event nil nil 0.1) ; In order to distinguish the events.
325 (set-file-modes file-notify--test-tmpfile 000) 322 (set-file-times file-notify--test-tmpfile '(0 0))
326 (read-event nil nil 0.1) ; In order to distinguish the events. 323 (delete-file file-notify--test-tmpfile)))
327 (set-file-times file-notify--test-tmpfile '(0 0))
328 (delete-file file-notify--test-tmpfile))
329 324
330 ;; Check the global sequence again just to make sure that 325 ;; Check the global sequence again just to make sure that
331 ;; `file-notify--test-events' has been set correctly. 326 ;; `file-notify--test-events' has been set correctly.
332 (should (equal (mapcar #'cadr file-notify--test-events) 327 (should (equal (mapcar #'cadr file-notify--test-events)
333 '(created changed deleted 328 (if (eq file-notify--library 'w32notify)
334 created changed deleted 329 '(created changed deleted
335 created changed renamed 330 created changed changed changed deleted
336 attribute-changed attribute-changed))) 331 created changed renamed)
337 332 '(created changed deleted
333 created changed deleted
334 created changed renamed
335 attribute-changed attribute-changed))))
338 (should file-notify--test-results) 336 (should file-notify--test-results)
339 (dolist (result file-notify--test-results) 337 (dolist (result file-notify--test-results)
340 ;;(message "%s" (ert-test-result-messages result)) 338 ;;(message "%s" (ert-test-result-messages result))
@@ -414,15 +412,12 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
414 (unwind-protect 412 (unwind-protect
415 (progn 413 (progn
416 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 414 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
417 (setq file-notify--test-desc (file-notify-add-watch 415 (setq file-notify--test-desc
418 file-notify--test-tmpfile 416 (file-notify-add-watch
419 '(change) 417 file-notify--test-tmpfile
420 #'file-notify--test-event-handler)) 418 '(change) #'file-notify--test-event-handler))
421 (file-notify--test-with-events 419 (file-notify--test-with-events
422 2 (file-notify--test-timeout) 420 (file-notify--test-timeout) '(created changed)
423 (lambda (events)
424 (should (equal '(created changed)
425 (mapcar #'cadr events))))
426 (should (file-notify-valid-p file-notify--test-desc)) 421 (should (file-notify-valid-p file-notify--test-desc))
427 (write-region 422 (write-region
428 "any text" nil file-notify--test-tmpfile nil 'no-message) 423 "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -435,33 +430,30 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
435 ;; Cleanup. 430 ;; Cleanup.
436 (file-notify--test-cleanup)) 431 (file-notify--test-cleanup))
437 432
438 ;; The batch-mode operation of w32notify is fragile (there's no
439 ;; input threads to send the message to).
440 (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify))))
441 (unwind-protect 433 (unwind-protect
442 (let ((temporary-file-directory (make-temp-file 434 ;; The batch-mode operation of w32notify is fragile (there's no
443 "file-notify-test-parent" t))) 435 ;; input threads to send the message to).
444 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) 436 (unless (and noninteractive (eq file-notify--library 'w32notify))
445 (setq file-notify--test-desc (file-notify-add-watch 437 (let ((temporary-file-directory (make-temp-file
446 file-notify--test-tmpfile 438 "file-notify-test-parent" t)))
447 '(change) 439 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
448 #'file-notify--test-event-handler)) 440 (setq file-notify--test-desc
449 (file-notify--test-with-events 441 (file-notify-add-watch
450 2 (file-notify--test-timeout) 442 file-notify--test-tmpfile
451 (lambda (events) 443 '(change) #'file-notify--test-event-handler))
452 (should (equal '(created changed) 444 (file-notify--test-with-events
453 (mapcar #'cadr events)))) 445 (file-notify--test-timeout) '(created changed)
454 (should (file-notify-valid-p file-notify--test-desc)) 446 (should (file-notify-valid-p file-notify--test-desc))
455 (write-region 447 (write-region
456 "any text" nil file-notify--test-tmpfile nil 'no-message) 448 "any text" nil file-notify--test-tmpfile nil 'no-message)
457 (should (file-notify-valid-p file-notify--test-desc))) 449 (should (file-notify-valid-p file-notify--test-desc)))
458 ;; After deleting the parent, the descriptor must not be valid 450 ;; After deleting the parent, the descriptor must not be valid
459 ;; anymore. 451 ;; anymore.
460 (delete-directory temporary-file-directory t) 452 (delete-directory temporary-file-directory t)
461 (file-notify--wait-for-events 453 (file-notify--wait-for-events
462 (file-notify--test-timeout) 454 (file-notify--test-timeout)
463 (not (file-notify-valid-p file-notify--test-desc))) 455 (not (file-notify-valid-p file-notify--test-desc)))
464 (should-not (file-notify-valid-p file-notify--test-desc))) 456 (should-not (file-notify-valid-p file-notify--test-desc))))
465 457
466 ;; Cleanup. 458 ;; Cleanup.
467 (file-notify--test-cleanup))) 459 (file-notify--test-cleanup)))
@@ -478,10 +470,10 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
478 (setq file-notify--test-tmpfile (file-name-as-directory 470 (setq file-notify--test-tmpfile (file-name-as-directory
479 (file-notify--test-make-temp-name))) 471 (file-notify--test-make-temp-name)))
480 (make-directory file-notify--test-tmpfile) 472 (make-directory file-notify--test-tmpfile)
481 (setq file-notify--test-desc (file-notify-add-watch 473 (setq file-notify--test-desc
482 file-notify--test-tmpfile 474 (file-notify-add-watch
483 '(change) 475 file-notify--test-tmpfile
484 #'file-notify--test-event-handler)) 476 '(change) #'file-notify--test-event-handler))
485 (should (file-notify-valid-p file-notify--test-desc)) 477 (should (file-notify-valid-p file-notify--test-desc))
486 ;; After removing the watch, the descriptor must not be valid 478 ;; After removing the watch, the descriptor must not be valid
487 ;; anymore. 479 ;; anymore.
@@ -491,18 +483,17 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
491 ;; Cleanup. 483 ;; Cleanup.
492 (file-notify--test-cleanup)) 484 (file-notify--test-cleanup))
493 485
494 ;; The batch-mode operation of w32notify is fragile (there's no
495 ;; input threads to send the message to).
496 (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify))))
497 (unwind-protect 486 (unwind-protect
498 (progn 487 ;; The batch-mode operation of w32notify is fragile (there's no
488 ;; input threads to send the message to).
489 (unless (and noninteractive (eq file-notify--library 'w32notify))
499 (setq file-notify--test-tmpfile (file-name-as-directory 490 (setq file-notify--test-tmpfile (file-name-as-directory
500 (file-notify--test-make-temp-name))) 491 (file-notify--test-make-temp-name)))
501 (make-directory file-notify--test-tmpfile) 492 (make-directory file-notify--test-tmpfile)
502 (setq file-notify--test-desc (file-notify-add-watch 493 (setq file-notify--test-desc
503 file-notify--test-tmpfile 494 (file-notify-add-watch
504 '(change) 495 file-notify--test-tmpfile
505 #'file-notify--test-event-handler)) 496 '(change) #'file-notify--test-event-handler))
506 (should (file-notify-valid-p file-notify--test-desc)) 497 (should (file-notify-valid-p file-notify--test-desc))
507 ;; After deleting the directory, the descriptor must not be 498 ;; After deleting the directory, the descriptor must not be
508 ;; valid anymore. 499 ;; valid anymore.