2016-06-20 12:41:41 +00:00
|
|
|
;;; filenotify-tests.el --- Tests of file notifications -*- lexical-binding: t; -*-
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2018-01-01 08:21:42 +00:00
|
|
|
;; Copyright (C) 2013-2018 Free Software Foundation, Inc.
|
2013-07-04 09:43:17 +00:00
|
|
|
|
|
|
|
;; Author: Michael Albinus <michael.albinus@gmx.de>
|
|
|
|
|
|
|
|
;; This program is free software: you can redistribute it and/or
|
|
|
|
;; modify it under the terms of the GNU General Public License as
|
|
|
|
;; published by the Free Software Foundation, either version 3 of the
|
|
|
|
;; License, or (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful, but
|
|
|
|
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;; General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with this program. If not, see `https://www.gnu.org/licenses/'.
|
2013-07-04 09:43:17 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2014-04-24 08:21:58 +00:00
|
|
|
;; Some of the tests require access to a remote host files. Since
|
|
|
|
;; this could be problematic, a mock-up connection method "mock" is
|
|
|
|
;; used. Emulating a remote connection, it simply calls "sh -i".
|
2014-04-25 10:35:01 +00:00
|
|
|
;; Tramp's file name handlers still run, so this test is sufficient
|
2014-04-24 08:21:58 +00:00
|
|
|
;; except for connection establishing.
|
|
|
|
|
|
|
|
;; If you want to test a real Tramp connection, set
|
|
|
|
;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order to
|
|
|
|
;; overwrite the default value. If you want to skip tests accessing a
|
|
|
|
;; remote host, set this environment variable to "/dev/null" or
|
|
|
|
;; whatever is appropriate on your system.
|
2013-07-05 14:06:14 +00:00
|
|
|
|
2013-11-27 14:23:32 +00:00
|
|
|
;; A whole test run can be performed calling the command `file-notify-test-all'.
|
2013-07-04 09:43:17 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'ert)
|
2017-02-04 11:36:43 +00:00
|
|
|
(require 'ert-x)
|
2013-07-04 09:43:17 +00:00
|
|
|
(require 'filenotify)
|
2014-04-24 08:21:58 +00:00
|
|
|
(require 'tramp)
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2013-07-05 14:06:14 +00:00
|
|
|
;; There is no default value on w32 systems, which could work out of the box.
|
|
|
|
(defconst file-notify-test-remote-temporary-file-directory
|
2013-11-27 14:23:32 +00:00
|
|
|
(cond
|
|
|
|
((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
|
|
|
|
((eq system-type 'windows-nt) null-device)
|
2014-04-24 08:21:58 +00:00
|
|
|
(t (add-to-list
|
|
|
|
'tramp-methods
|
|
|
|
'("mock"
|
|
|
|
(tramp-login-program "sh")
|
|
|
|
(tramp-login-args (("-i")))
|
|
|
|
(tramp-remote-shell "/bin/sh")
|
|
|
|
(tramp-remote-shell-args ("-c"))
|
|
|
|
(tramp-connection-timeout 10)))
|
2017-07-03 14:12:10 +00:00
|
|
|
(add-to-list
|
|
|
|
'tramp-default-host-alist
|
|
|
|
`("\\`mock\\'" nil ,(system-name)))
|
|
|
|
;; Emacs' Makefile sets $HOME to a nonexistent value. Needed in
|
2018-02-02 17:51:25 +00:00
|
|
|
;; batch mode only, therefore. `temporary-file-directory' might
|
|
|
|
;; be quoted, so we unquote it just in case.
|
2017-07-03 14:12:10 +00:00
|
|
|
(unless (and (null noninteractive) (file-directory-p "~/"))
|
2018-02-02 17:51:25 +00:00
|
|
|
(setenv "HOME" (file-name-unquote temporary-file-directory)))
|
2014-04-24 08:21:58 +00:00
|
|
|
(format "/mock::%s" temporary-file-directory)))
|
2013-07-05 14:06:14 +00:00
|
|
|
"Temporary directory for Tramp tests.")
|
|
|
|
|
2018-01-10 12:39:17 +00:00
|
|
|
(defvar file-notify--test-tmpdir nil)
|
2013-07-05 14:06:14 +00:00
|
|
|
(defvar file-notify--test-tmpfile nil)
|
|
|
|
(defvar file-notify--test-tmpfile1 nil)
|
2015-06-02 21:47:17 +00:00
|
|
|
(defvar file-notify--test-desc nil)
|
2016-02-20 07:33:11 +00:00
|
|
|
(defvar file-notify--test-desc1 nil)
|
2016-02-20 13:04:36 +00:00
|
|
|
(defvar file-notify--test-desc2 nil)
|
2013-07-05 14:06:14 +00:00
|
|
|
(defvar file-notify--test-results nil)
|
|
|
|
(defvar file-notify--test-event nil)
|
2015-09-09 19:46:40 +00:00
|
|
|
(defvar file-notify--test-events nil)
|
2017-01-03 08:50:41 +00:00
|
|
|
(defvar file-notify--test-monitors nil)
|
2015-10-26 15:46:48 +00:00
|
|
|
|
2016-12-29 18:48:17 +00:00
|
|
|
(defun file-notify--test-read-event ()
|
|
|
|
"Read one event.
|
|
|
|
There are different timeouts for local and remote file notification libraries."
|
|
|
|
(read-event
|
|
|
|
nil nil
|
|
|
|
(cond
|
2016-12-31 21:16:12 +00:00
|
|
|
;; gio/gpollfilemonitor.c declares POLL_TIME_SECS 5. So we must
|
|
|
|
;; wait at least this time in the GPollFileMonitor case. A
|
|
|
|
;; similar timeout seems to be needed in the GFamFileMonitor case,
|
|
|
|
;; at least on Cygwin.
|
2016-12-29 18:48:17 +00:00
|
|
|
((and (string-equal (file-notify--test-library) "gfilenotify")
|
2016-12-31 21:16:12 +00:00
|
|
|
(memq (file-notify--test-monitor)
|
|
|
|
'(GFamFileMonitor GPollFileMonitor)))
|
2016-12-29 18:48:17 +00:00
|
|
|
7)
|
2017-01-03 08:50:41 +00:00
|
|
|
((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 1)
|
2016-12-29 18:48:17 +00:00
|
|
|
((file-remote-p temporary-file-directory) 0.1)
|
|
|
|
(t 0.01))))
|
2016-02-07 18:30:01 +00:00
|
|
|
|
2015-09-20 16:44:36 +00:00
|
|
|
(defun file-notify--test-timeout ()
|
2016-12-29 18:48:17 +00:00
|
|
|
"Timeout to wait for arriving a bunch of events, in seconds."
|
2016-01-22 18:56:09 +00:00
|
|
|
(cond
|
|
|
|
((file-remote-p temporary-file-directory) 6)
|
2016-02-23 12:51:36 +00:00
|
|
|
((string-equal (file-notify--test-library) "w32notify") 4)
|
2016-06-06 16:25:28 +00:00
|
|
|
((eq system-type 'cygwin) 6)
|
2016-01-22 18:56:09 +00:00
|
|
|
(t 3)))
|
2013-07-05 14:06:14 +00:00
|
|
|
|
2016-06-06 16:25:28 +00:00
|
|
|
(defmacro file-notify--wait-for-events (timeout until)
|
|
|
|
"Wait for and return file notification events until form UNTIL is true.
|
|
|
|
TIMEOUT is the maximum time to wait for, in seconds."
|
|
|
|
`(with-timeout (,timeout (ignore))
|
|
|
|
(while (null ,until)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event))))
|
2016-06-06 16:25:28 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
(defun file-notify--test-no-descriptors ()
|
|
|
|
"Check that `file-notify-descriptors' is an empty hash table.
|
|
|
|
Return nil when any other file notification watch is still active."
|
|
|
|
;; Give read events a last chance.
|
2016-06-06 16:25:28 +00:00
|
|
|
(file-notify--wait-for-events
|
|
|
|
(file-notify--test-timeout)
|
|
|
|
(zerop (hash-table-count file-notify-descriptors)))
|
2016-06-05 17:49:16 +00:00
|
|
|
;; Now check.
|
|
|
|
(zerop (hash-table-count file-notify-descriptors)))
|
|
|
|
|
|
|
|
(defun file-notify--test-no-descriptors-explainer ()
|
|
|
|
"Explain why `file-notify--test-no-descriptors' fails."
|
|
|
|
(let ((result (list "Watch descriptor(s) existent:")))
|
|
|
|
(maphash
|
|
|
|
(lambda (key value) (push (cons key value) result))
|
|
|
|
file-notify-descriptors)
|
|
|
|
(nreverse result)))
|
|
|
|
|
|
|
|
(put 'file-notify--test-no-descriptors 'ert-explainer
|
|
|
|
'file-notify--test-no-descriptors-explainer)
|
|
|
|
|
|
|
|
(defun file-notify--test-cleanup-p ()
|
|
|
|
"Check, that the test has cleaned up the environment as much as needed."
|
|
|
|
;; `file-notify--test-event' should not be set but bound
|
|
|
|
;; dynamically.
|
|
|
|
(should-not file-notify--test-event)
|
|
|
|
;; The test should have cleaned up this already. Let's check
|
|
|
|
;; nevertheless.
|
|
|
|
(should (file-notify--test-no-descriptors)))
|
|
|
|
|
2015-09-10 15:18:15 +00:00
|
|
|
(defun file-notify--test-cleanup ()
|
|
|
|
"Cleanup after a test."
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2016-02-20 07:33:11 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc1)
|
2016-02-20 13:04:36 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc2)
|
2015-09-10 15:18:15 +00:00
|
|
|
|
2016-02-07 18:30:01 +00:00
|
|
|
(ignore-errors
|
|
|
|
(delete-file (file-newest-backup file-notify--test-tmpfile)))
|
|
|
|
(ignore-errors
|
2015-10-26 15:46:48 +00:00
|
|
|
(if (file-directory-p file-notify--test-tmpfile)
|
2015-09-20 16:44:36 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile 'recursive)
|
2015-09-14 07:52:31 +00:00
|
|
|
(delete-file file-notify--test-tmpfile)))
|
2016-02-07 18:30:01 +00:00
|
|
|
(ignore-errors
|
2015-10-26 15:46:48 +00:00
|
|
|
(if (file-directory-p file-notify--test-tmpfile1)
|
2015-09-20 16:44:36 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile1 'recursive)
|
2015-09-14 07:52:31 +00:00
|
|
|
(delete-file file-notify--test-tmpfile1)))
|
2018-01-10 12:39:17 +00:00
|
|
|
(ignore-errors
|
|
|
|
(delete-directory file-notify--test-tmpdir 'recursive))
|
2016-02-07 18:30:01 +00:00
|
|
|
(ignore-errors
|
|
|
|
(when (file-remote-p temporary-file-directory)
|
|
|
|
(tramp-cleanup-connection
|
|
|
|
(tramp-dissect-file-name temporary-file-directory) nil 'keep-password)))
|
2015-09-10 15:18:15 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(when (hash-table-p file-notify-descriptors)
|
|
|
|
(clrhash file-notify-descriptors))
|
|
|
|
|
2018-01-10 12:39:17 +00:00
|
|
|
(setq file-notify--test-tmpdir nil
|
|
|
|
file-notify--test-tmpfile nil
|
2015-10-25 13:18:17 +00:00
|
|
|
file-notify--test-tmpfile1 nil
|
|
|
|
file-notify--test-desc nil
|
2016-02-20 07:33:11 +00:00
|
|
|
file-notify--test-desc1 nil
|
2016-02-20 13:04:36 +00:00
|
|
|
file-notify--test-desc2 nil
|
2015-10-25 13:18:17 +00:00
|
|
|
file-notify--test-results nil
|
2017-01-03 08:50:41 +00:00
|
|
|
file-notify--test-events nil
|
|
|
|
file-notify--test-monitors nil))
|
2015-09-10 15:18:15 +00:00
|
|
|
|
2014-04-25 10:35:01 +00:00
|
|
|
(setq password-cache-expiry nil
|
|
|
|
tramp-verbose 0
|
2013-07-05 14:06:14 +00:00
|
|
|
tramp-message-show-message nil)
|
2013-11-27 14:23:32 +00:00
|
|
|
|
2017-07-18 16:53:46 +00:00
|
|
|
;; This should happen on hydra only.
|
|
|
|
(when (getenv "EMACS_HYDRA_CI")
|
2018-12-17 18:52:46 +00:00
|
|
|
(require 'tramp-sh)
|
2013-11-08 09:31:15 +00:00
|
|
|
(add-to-list 'tramp-remote-path 'tramp-own-remote-path))
|
2013-07-05 14:06:14 +00:00
|
|
|
|
2013-07-24 13:56:19 +00:00
|
|
|
;; We do not want to try and fail `file-notify-add-watch'.
|
2013-10-24 07:38:45 +00:00
|
|
|
(defun file-notify--test-local-enabled ()
|
|
|
|
"Whether local file notification is enabled.
|
|
|
|
This is needed for local `temporary-file-directory' only, in the
|
2015-05-21 17:04:45 +00:00
|
|
|
remote case we return always t."
|
2013-10-24 07:38:45 +00:00
|
|
|
(or file-notify--library
|
2014-01-21 13:31:39 +00:00
|
|
|
(file-remote-p temporary-file-directory)))
|
2013-10-24 07:38:45 +00:00
|
|
|
|
|
|
|
(defvar file-notify--test-remote-enabled-checked nil
|
|
|
|
"Cached result of `file-notify--test-remote-enabled'.
|
|
|
|
If the function did run, the value is a cons cell, the `cdr'
|
|
|
|
being the result.")
|
2013-07-24 13:56:19 +00:00
|
|
|
|
|
|
|
(defun file-notify--test-remote-enabled ()
|
|
|
|
"Whether remote file notification is enabled."
|
2013-10-24 07:38:45 +00:00
|
|
|
(unless (consp file-notify--test-remote-enabled-checked)
|
2015-06-03 18:03:42 +00:00
|
|
|
(let (desc)
|
|
|
|
(ignore-errors
|
|
|
|
(and
|
|
|
|
(file-remote-p file-notify-test-remote-temporary-file-directory)
|
|
|
|
(file-directory-p file-notify-test-remote-temporary-file-directory)
|
|
|
|
(file-writable-p file-notify-test-remote-temporary-file-directory)
|
|
|
|
(setq desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify-test-remote-temporary-file-directory
|
2016-03-04 14:01:36 +00:00
|
|
|
'(change) #'ignore))))
|
2015-06-03 18:03:42 +00:00
|
|
|
(setq file-notify--test-remote-enabled-checked (cons t desc))
|
|
|
|
(when desc (file-notify-rm-watch desc))))
|
2013-10-24 07:38:45 +00:00
|
|
|
;; Return result.
|
|
|
|
(cdr file-notify--test-remote-enabled-checked))
|
2013-07-24 13:56:19 +00:00
|
|
|
|
2016-01-22 18:56:09 +00:00
|
|
|
(defun file-notify--test-library ()
|
|
|
|
"The used library for the test, as a string.
|
|
|
|
In the remote case, it is the process name which runs on the
|
|
|
|
remote host, or nil."
|
|
|
|
(if (null (file-remote-p temporary-file-directory))
|
|
|
|
(symbol-name file-notify--library)
|
|
|
|
(and (consp file-notify--test-remote-enabled-checked)
|
|
|
|
(processp (cdr file-notify--test-remote-enabled-checked))
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"<[[:digit:]]+>\\'" ""
|
|
|
|
(process-name (cdr file-notify--test-remote-enabled-checked))))))
|
|
|
|
|
2016-12-29 18:48:17 +00:00
|
|
|
(defun file-notify--test-monitor ()
|
2016-12-31 21:16:12 +00:00
|
|
|
"The used monitor for the test, as a symbol.
|
2016-12-29 18:48:17 +00:00
|
|
|
This returns only for the local case and gfilenotify; otherwise it is nil.
|
|
|
|
`file-notify--test-desc' must be a valid watch descriptor."
|
2017-01-03 08:50:41 +00:00
|
|
|
;; We cache the result, because after `file-notify-rm-watch',
|
|
|
|
;; `gfile-monitor-name' does not return a proper result anymore.
|
|
|
|
;; But we still need this information.
|
|
|
|
(unless (file-remote-p temporary-file-directory)
|
|
|
|
(or (cdr (assq file-notify--test-desc file-notify--test-monitors))
|
|
|
|
(when (functionp 'gfile-monitor-name)
|
|
|
|
(add-to-list 'file-notify--test-monitors
|
|
|
|
(cons file-notify--test-desc
|
|
|
|
(gfile-monitor-name file-notify--test-desc)))
|
|
|
|
(cdr (assq file-notify--test-desc file-notify--test-monitors))))))
|
2016-12-29 18:48:17 +00:00
|
|
|
|
2018-12-15 23:04:24 +00:00
|
|
|
(defmacro file-notify--deftest-remote (test docstring &optional expected)
|
2013-07-05 14:06:14 +00:00
|
|
|
"Define ert `TEST-remote' for remote files."
|
2015-06-03 12:07:06 +00:00
|
|
|
(declare (indent 1))
|
2013-10-24 07:38:45 +00:00
|
|
|
`(ert-deftest ,(intern (concat (symbol-name test) "-remote")) ()
|
|
|
|
,docstring
|
2016-01-04 22:28:07 +00:00
|
|
|
:tags '(:expensive-test)
|
2018-12-15 23:04:24 +00:00
|
|
|
:expected-result (or ,expected :passed)
|
2015-06-03 18:03:42 +00:00
|
|
|
(let* ((temporary-file-directory
|
|
|
|
file-notify-test-remote-temporary-file-directory)
|
|
|
|
(ert-test (ert-get-test ',test)))
|
|
|
|
(skip-unless (file-notify--test-remote-enabled))
|
|
|
|
(tramp-cleanup-connection
|
|
|
|
(tramp-dissect-file-name temporary-file-directory) nil 'keep-password)
|
|
|
|
(funcall (ert-test-body ert-test)))))
|
2013-07-05 14:06:14 +00:00
|
|
|
|
|
|
|
(ert-deftest file-notify-test00-availability ()
|
|
|
|
"Test availability of `file-notify'."
|
2013-10-24 07:38:45 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
;; Report the native library which has been used.
|
|
|
|
(message "Library: `%s'" (file-notify--test-library))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
temporary-file-directory '(change) #'ignore)))
|
2016-12-29 18:48:17 +00:00
|
|
|
(when (file-notify--test-monitor)
|
|
|
|
(message "Monitor: `%s'" (file-notify--test-monitor)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
2013-07-24 13:56:19 +00:00
|
|
|
|
|
|
|
(file-notify--deftest-remote file-notify-test00-availability
|
|
|
|
"Test availability of `file-notify' for remote files.")
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2018-01-10 12:39:17 +00:00
|
|
|
(defun file-notify--test-make-temp-name ()
|
|
|
|
"Create a temporary file name for test."
|
|
|
|
(unless (stringp file-notify--test-tmpdir)
|
|
|
|
(setq file-notify--test-tmpdir
|
|
|
|
(expand-file-name
|
|
|
|
(make-temp-name "file-notify-test") temporary-file-directory)))
|
|
|
|
(unless (file-directory-p file-notify--test-tmpdir)
|
|
|
|
(make-directory file-notify--test-tmpdir))
|
|
|
|
(expand-file-name
|
|
|
|
(make-temp-name "file-notify-test") file-notify--test-tmpdir))
|
|
|
|
|
2013-10-24 07:38:45 +00:00
|
|
|
(ert-deftest file-notify-test01-add-watch ()
|
|
|
|
"Check `file-notify-add-watch'."
|
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2015-10-25 13:18:17 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-tmpfile1
|
|
|
|
(format
|
|
|
|
"%s/%s" file-notify--test-tmpfile (md5 (current-time-string))))
|
2015-10-25 13:18:17 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
;; Check, that different valid parameters are accepted.
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2018-01-10 12:39:17 +00:00
|
|
|
file-notify--test-tmpdir '(change) #'ignore)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2018-01-10 12:39:17 +00:00
|
|
|
file-notify--test-tmpdir '(attribute-change) #'ignore)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2018-01-10 12:39:17 +00:00
|
|
|
file-notify--test-tmpdir '(change attribute-change) #'ignore)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2017-03-22 19:33:03 +00:00
|
|
|
|
|
|
|
;; File monitors like kqueue insist, that the watched file
|
|
|
|
;; exists. Directory monitors are not bound to this
|
|
|
|
;; restriction.
|
|
|
|
(when (string-equal (file-notify--test-library) "kqueue")
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message))
|
2016-06-05 17:49:16 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile '(change attribute-change) #'ignore)))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2017-03-22 19:33:03 +00:00
|
|
|
(when (string-equal (file-notify--test-library) "kqueue")
|
|
|
|
(delete-file file-notify--test-tmpfile))
|
2015-06-02 21:47:17 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
;; Check error handling.
|
|
|
|
(should-error (file-notify-add-watch 1 2 3 4)
|
|
|
|
:type 'wrong-number-of-arguments)
|
|
|
|
(should
|
|
|
|
(equal (should-error
|
|
|
|
(file-notify-add-watch 1 2 3))
|
|
|
|
'(wrong-type-argument 1)))
|
|
|
|
(should
|
|
|
|
(equal (should-error
|
2018-01-10 12:39:17 +00:00
|
|
|
(file-notify-add-watch file-notify--test-tmpdir 2 3))
|
2016-06-05 17:49:16 +00:00
|
|
|
'(wrong-type-argument 2)))
|
|
|
|
(should
|
|
|
|
(equal (should-error
|
2018-01-10 12:39:17 +00:00
|
|
|
(file-notify-add-watch file-notify--test-tmpdir '(change) 3))
|
2016-06-05 17:49:16 +00:00
|
|
|
'(wrong-type-argument 3)))
|
|
|
|
;; The upper directory of a file must exist.
|
|
|
|
(should
|
|
|
|
(equal (should-error
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile1
|
|
|
|
'(change attribute-change) #'ignore))
|
|
|
|
`(file-notify-error
|
|
|
|
"Directory does not exist" ,file-notify--test-tmpfile)))
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-10 15:18:15 +00:00
|
|
|
|
2016-06-05 17:49:16 +00:00
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
2013-07-09 07:52:25 +00:00
|
|
|
|
2013-10-24 07:38:45 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test01-add-watch
|
|
|
|
"Check `file-notify-add-watch' for remote files.")
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2017-03-22 13:15:45 +00:00
|
|
|
;; This test is inspired by Bug#26126 and Bug#26127.
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test02-rm-watch ()
|
|
|
|
"Check `file-notify-rm-watch'."
|
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
|
|
|
|
|
|
|
(unwind-protect
|
2017-03-22 13:15:45 +00:00
|
|
|
;; Check, that `file-notify-rm-watch' works.
|
2017-03-17 09:25:46 +00:00
|
|
|
(progn
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
temporary-file-directory '(change) #'ignore)))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
;; Check, that any parameter is accepted.
|
|
|
|
(condition-case err
|
|
|
|
(progn
|
|
|
|
(file-notify-rm-watch nil)
|
|
|
|
(file-notify-rm-watch 0)
|
|
|
|
(file-notify-rm-watch "foo")
|
|
|
|
(file-notify-rm-watch 'foo))
|
|
|
|
(error (ert-fail err)))
|
|
|
|
|
2017-03-22 13:15:45 +00:00
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
;; Check, that no error is returned removing a watch descriptor twice.
|
|
|
|
(progn
|
2017-03-17 09:25:46 +00:00
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-tmpfile1 (file-notify--test-make-temp-name))
|
2017-03-22 19:33:03 +00:00
|
|
|
(write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message)
|
2017-03-17 09:25:46 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile '(change) #'ignore)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc1
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile1 '(change) #'ignore)))
|
2017-03-22 13:15:45 +00:00
|
|
|
;; Remove `file-notify--test-desc' twice.
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
(file-notify-rm-watch file-notify--test-desc1)
|
2017-03-22 19:33:03 +00:00
|
|
|
(delete-file file-notify--test-tmpfile)
|
|
|
|
(delete-file file-notify--test-tmpfile1)
|
2017-03-17 09:25:46 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
2017-03-22 13:15:45 +00:00
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
2017-05-08 19:11:23 +00:00
|
|
|
;; Check, that removing watch descriptors out of order do not
|
|
|
|
;; harm. This fails on Cygwin because of timing issues unless a
|
|
|
|
;; long `sit-for' is added before the call to
|
|
|
|
;; `file-notify--test-read-event'.
|
|
|
|
(if (not (eq system-type 'cygwin))
|
2017-03-22 13:15:45 +00:00
|
|
|
(let (results)
|
|
|
|
(cl-flet ((first-callback (event)
|
|
|
|
(when (eq (nth 1 event) 'deleted) (push 1 results)))
|
|
|
|
(second-callback (event)
|
|
|
|
(when (eq (nth 1 event) 'deleted) (push 2 results))))
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'first-callback)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc1
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'second-callback)))
|
|
|
|
;; Remove first watch.
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
;; Only the second callback shall run.
|
2017-05-01 10:16:15 +00:00
|
|
|
(file-notify--test-read-event)
|
2017-03-22 13:15:45 +00:00
|
|
|
(delete-file file-notify--test-tmpfile)
|
|
|
|
(file-notify--wait-for-events
|
|
|
|
(file-notify--test-timeout) results)
|
|
|
|
(should (equal results (list 2)))
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
2017-05-08 19:11:23 +00:00
|
|
|
(file-notify--test-cleanup-p))))
|
2017-03-22 13:15:45 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
|
|
|
|
|
|
|
(file-notify--deftest-remote file-notify-test02-rm-watch
|
|
|
|
"Check `file-notify-rm-watch' for remote files.")
|
|
|
|
|
2013-07-05 14:06:14 +00:00
|
|
|
(defun file-notify--test-event-test ()
|
|
|
|
"Ert test function to be called by `file-notify--test-event-handler'.
|
|
|
|
We cannot pass arguments, so we assume that `file-notify--test-event'
|
2013-07-04 09:43:17 +00:00
|
|
|
is bound somewhere."
|
2015-06-02 21:47:17 +00:00
|
|
|
;; Check the descriptor.
|
|
|
|
(should (equal (car file-notify--test-event) file-notify--test-desc))
|
2013-07-04 09:43:17 +00:00
|
|
|
;; Check the file name.
|
|
|
|
(should
|
2016-02-22 17:52:37 +00:00
|
|
|
(string-prefix-p
|
|
|
|
(file-notify--event-watched-file file-notify--test-event)
|
|
|
|
(file-notify--event-file-name file-notify--test-event)))
|
2013-07-04 09:43:17 +00:00
|
|
|
;; Check the second file name if exists.
|
2013-07-05 14:06:14 +00:00
|
|
|
(when (eq (nth 1 file-notify--test-event) 'renamed)
|
2013-07-04 09:43:17 +00:00
|
|
|
(should
|
2016-02-22 17:52:37 +00:00
|
|
|
(string-prefix-p
|
|
|
|
(file-notify--event-watched-file file-notify--test-event)
|
|
|
|
(file-notify--event-file1-name file-notify--test-event)))))
|
2013-07-05 14:06:14 +00:00
|
|
|
|
2015-09-10 15:18:15 +00:00
|
|
|
(defun file-notify--test-event-handler (event)
|
2013-07-05 14:06:14 +00:00
|
|
|
"Run a test over FILE-NOTIFY--TEST-EVENT.
|
2015-09-20 16:44:36 +00:00
|
|
|
For later analysis, append the test result to `file-notify--test-results'
|
|
|
|
and the event to `file-notify--test-events'."
|
2015-09-10 15:18:15 +00:00
|
|
|
(let* ((file-notify--test-event event)
|
2015-09-20 16:44:36 +00:00
|
|
|
(result
|
|
|
|
(ert-run-test (make-ert-test :body 'file-notify--test-event-test))))
|
2016-01-22 18:56:09 +00:00
|
|
|
;; Do not add lock files, this would confuse the checks.
|
2015-10-26 15:46:48 +00:00
|
|
|
(unless (string-match
|
|
|
|
(regexp-quote ".#")
|
|
|
|
(file-notify--event-file-name file-notify--test-event))
|
2016-02-21 08:58:55 +00:00
|
|
|
;;(message "file-notify--test-event-handler result: %s event: %S"
|
|
|
|
;;(null (ert-test-failed-p result)) file-notify--test-event)
|
2015-10-26 15:46:48 +00:00
|
|
|
(setq file-notify--test-events
|
|
|
|
(append file-notify--test-events `(,file-notify--test-event))
|
|
|
|
file-notify--test-results
|
|
|
|
(append file-notify--test-results `(,result))))))
|
2013-07-05 14:06:14 +00:00
|
|
|
|
2016-02-08 09:54:43 +00:00
|
|
|
(defun file-notify--test-with-events-check (events)
|
|
|
|
"Check whether received events match one of the EVENTS alternatives."
|
|
|
|
(let (result)
|
|
|
|
(dolist (elt events result)
|
|
|
|
(setq result
|
|
|
|
(or result
|
2016-06-06 16:25:28 +00:00
|
|
|
(if (eq (car elt) :random)
|
2016-06-05 17:49:16 +00:00
|
|
|
(equal (sort (cdr elt) 'string-lessp)
|
|
|
|
(sort (mapcar #'cadr file-notify--test-events)
|
|
|
|
'string-lessp))
|
|
|
|
(equal elt (mapcar #'cadr file-notify--test-events))))))))
|
2016-02-08 09:54:43 +00:00
|
|
|
|
|
|
|
(defun file-notify--test-with-events-explainer (events)
|
|
|
|
"Explain why `file-notify--test-with-events-check' fails."
|
|
|
|
(if (null (cdr events))
|
2016-06-05 17:49:16 +00:00
|
|
|
(format "Received events do not match expected events\n%s\n%s"
|
2016-02-08 09:54:43 +00:00
|
|
|
(mapcar #'cadr file-notify--test-events) (car events))
|
|
|
|
(format
|
2016-06-05 17:49:16 +00:00
|
|
|
"Received events do not match any sequence of expected events\n%s\n%s"
|
2016-02-08 09:54:43 +00:00
|
|
|
(mapcar #'cadr file-notify--test-events) events)))
|
|
|
|
|
|
|
|
(put 'file-notify--test-with-events-check 'ert-explainer
|
|
|
|
'file-notify--test-with-events-explainer)
|
|
|
|
|
2015-11-06 06:33:50 +00:00
|
|
|
(defmacro file-notify--test-with-events (events &rest body)
|
2015-09-21 13:07:06 +00:00
|
|
|
"Run BODY collecting events and then compare with EVENTS.
|
2016-01-22 18:56:09 +00:00
|
|
|
EVENTS is either a simple list of events, or a list of lists of
|
2016-06-05 17:49:16 +00:00
|
|
|
events, which represent different possible results. The first
|
2016-06-06 16:25:28 +00:00
|
|
|
event of a list could be the pseudo event `:random', which is
|
2016-06-05 17:49:16 +00:00
|
|
|
just an indicator for comparison.
|
|
|
|
|
|
|
|
Don't wait longer than timeout seconds for the events to be
|
|
|
|
delivered."
|
2015-11-06 06:33:50 +00:00
|
|
|
(declare (indent 1))
|
2016-02-22 17:52:37 +00:00
|
|
|
`(let* ((events (if (consp (car ,events)) ,events (list ,events)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(max-length
|
|
|
|
(apply
|
|
|
|
'max
|
|
|
|
(mapcar
|
2016-06-06 16:25:28 +00:00
|
|
|
(lambda (x) (length (if (eq (car x) :random) (cdr x) x)))
|
2016-06-05 17:49:16 +00:00
|
|
|
events)))
|
2016-02-22 17:52:37 +00:00
|
|
|
create-lockfiles)
|
|
|
|
;; Flush pending events.
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2016-02-22 17:52:37 +00:00
|
|
|
(file-notify--wait-for-events
|
|
|
|
(file-notify--test-timeout)
|
2016-06-20 12:41:41 +00:00
|
|
|
(not (input-pending-p)))
|
2016-02-22 17:52:37 +00:00
|
|
|
(setq file-notify--test-events nil
|
|
|
|
file-notify--test-results nil)
|
|
|
|
,@body
|
|
|
|
(file-notify--wait-for-events
|
|
|
|
;; More events need more time. Use some fudge factor.
|
|
|
|
(* (ceiling max-length 100) (file-notify--test-timeout))
|
|
|
|
(= max-length (length file-notify--test-events)))
|
|
|
|
;; Check the result sequence just to make sure that all events
|
|
|
|
;; are as expected.
|
|
|
|
(dolist (result file-notify--test-results)
|
|
|
|
(when (ert-test-failed-p result)
|
|
|
|
(ert-fail
|
|
|
|
(cadr (ert-test-result-with-condition-condition result)))))
|
|
|
|
;; One of the possible event sequences shall match.
|
|
|
|
(should (file-notify--test-with-events-check events))))
|
2015-09-10 15:18:15 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test03-events ()
|
2015-09-12 08:37:32 +00:00
|
|
|
"Check file creation/change/removal notifications."
|
2013-10-24 07:38:45 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2015-10-26 15:46:48 +00:00
|
|
|
|
2015-06-02 21:47:17 +00:00
|
|
|
(unwind-protect
|
2018-01-19 13:59:48 +00:00
|
|
|
;; Check file creation, change and deletion. It doesn't work
|
|
|
|
;; for kqueue, because we don't use an implicit directory
|
|
|
|
;; monitor.
|
|
|
|
(unless (string-equal (file-notify--test-library) "kqueue")
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `created' event reliably.
|
|
|
|
((string-equal
|
|
|
|
(file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(created deleted stopped)))
|
|
|
|
;; cygwin does not raise a `changed' event.
|
|
|
|
((eq system-type 'cygwin)
|
|
|
|
'(created deleted stopped))
|
|
|
|
(t '(created changed deleted stopped)))
|
|
|
|
(write-region
|
|
|
|
"another text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-file file-notify--test-tmpfile))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
2016-01-22 18:56:09 +00:00
|
|
|
|
2018-01-19 13:59:48 +00:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
2016-01-22 18:56:09 +00:00
|
|
|
;; Check file change and deletion.
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
2016-03-04 14:01:36 +00:00
|
|
|
'(change) #'file-notify--test-event-handler)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(file-notify--test-with-events
|
2017-01-03 08:50:41 +00:00
|
|
|
(cond
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `changed' event reliably.
|
|
|
|
((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(changed deleted stopped)))
|
|
|
|
;; There could be one or two `changed' events.
|
|
|
|
(t '((changed deleted stopped)
|
|
|
|
(changed changed deleted stopped))))
|
2015-09-10 15:18:15 +00:00
|
|
|
(write-region
|
2016-01-22 18:56:09 +00:00
|
|
|
"another text" nil file-notify--test-tmpfile nil 'no-message)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2015-09-10 15:18:15 +00:00
|
|
|
(delete-file file-notify--test-tmpfile))
|
2016-02-22 17:52:37 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2015-10-26 15:46:48 +00:00
|
|
|
|
2018-01-19 13:59:48 +00:00
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
;; Check file creation, change and deletion when watching a
|
|
|
|
;; directory. There must be a `stopped' event when deleting the
|
|
|
|
;; directory.
|
|
|
|
(let ((file-notify--test-tmpdir
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpdir
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify does not raise `deleted' and `stopped'
|
|
|
|
;; events for the watched directory.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
'(created changed deleted))
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `created' event reliably.
|
|
|
|
((string-equal
|
|
|
|
(file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(created deleted stopped)))
|
|
|
|
;; There are two `deleted' events, for the file and for
|
|
|
|
;; the directory. Except for cygwin and kqueue. And
|
|
|
|
;; cygwin does not raise a `changed' event.
|
|
|
|
((eq system-type 'cygwin)
|
|
|
|
'(created deleted stopped))
|
|
|
|
((string-equal (file-notify--test-library) "kqueue")
|
|
|
|
'(created changed deleted stopped))
|
|
|
|
(t '(created changed deleted deleted stopped)))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-directory file-notify--test-tmpdir 'recursive))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
;; Check copy of files inside a directory.
|
|
|
|
(let ((file-notify--test-tmpdir
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpdir
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify does not distinguish between `changed' and
|
|
|
|
;; `attribute-changed'. It does not raise `deleted' and
|
|
|
|
;; `stopped' events for the watched directory.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
'(created changed created changed
|
|
|
|
changed changed changed
|
|
|
|
deleted deleted))
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `created' event reliably.
|
|
|
|
((string-equal
|
|
|
|
(file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(created created deleted stopped)))
|
|
|
|
;; There are three `deleted' events, for two files and
|
|
|
|
;; for the directory. Except for cygwin and kqueue.
|
|
|
|
((eq system-type 'cygwin)
|
|
|
|
'(created created changed changed deleted stopped))
|
|
|
|
((string-equal (file-notify--test-library) "kqueue")
|
|
|
|
'(created changed created changed deleted stopped))
|
|
|
|
(t '(created changed created changed
|
|
|
|
deleted deleted deleted stopped)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
2018-01-19 13:59:48 +00:00
|
|
|
(file-notify--test-read-event)
|
|
|
|
(copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
|
|
|
|
;; The next two events shall not be visible.
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(set-file-modes file-notify--test-tmpfile 000)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(set-file-times file-notify--test-tmpfile '(0 0))
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-directory file-notify--test-tmpdir 'recursive))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
;; Check rename of files inside a directory.
|
|
|
|
(let ((file-notify--test-tmpdir
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-tmpfile1 (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpdir
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify does not raise `deleted' and `stopped'
|
|
|
|
;; events for the watched directory.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
'(created changed renamed deleted))
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `created' event reliably.
|
|
|
|
((string-equal
|
|
|
|
(file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(created deleted stopped)))
|
|
|
|
;; There are two `deleted' events, for the file and for
|
|
|
|
;; the directory. Except for cygwin and kqueue. And
|
|
|
|
;; cygwin raises `created' and `deleted' events instead
|
|
|
|
;; of a `renamed' event.
|
|
|
|
((eq system-type 'cygwin)
|
|
|
|
'(created created deleted deleted stopped))
|
|
|
|
((string-equal (file-notify--test-library) "kqueue")
|
|
|
|
'(created changed renamed deleted stopped))
|
|
|
|
(t '(created changed renamed deleted deleted stopped)))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
|
|
|
|
;; After the rename, we won't get events anymore.
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-directory file-notify--test-tmpdir 'recursive))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
;; Check attribute change. Does not work for cygwin.
|
|
|
|
(unless (eq system-type 'cygwin)
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(attribute-change) #'file-notify--test-event-handler)))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify does not distinguish between `changed' and
|
|
|
|
;; `attribute-changed'. Under MS Windows 7, we get four
|
|
|
|
;; `changed' events, and under MS Windows 10 just two.
|
|
|
|
;; Strange.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
'((changed changed)
|
|
|
|
(changed changed changed changed)))
|
|
|
|
;; For kqueue and in the remote case, `write-region'
|
|
|
|
;; raises also an `attribute-changed' event.
|
|
|
|
((or (string-equal (file-notify--test-library) "kqueue")
|
|
|
|
(file-remote-p temporary-file-directory))
|
|
|
|
'(attribute-changed attribute-changed attribute-changed))
|
|
|
|
(t '(attribute-changed attribute-changed)))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(set-file-modes file-notify--test-tmpfile 000)
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(set-file-times file-notify--test-tmpfile '(0 0))
|
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-file file-notify--test-tmpfile))
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
2015-09-10 15:18:15 +00:00
|
|
|
(file-notify--test-cleanup)))
|
2013-10-24 07:38:45 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test03-events
|
2015-09-12 08:37:32 +00:00
|
|
|
"Check file creation/change/removal notifications for remote files.")
|
2013-07-04 09:43:17 +00:00
|
|
|
|
|
|
|
(require 'autorevert)
|
2015-06-02 21:47:17 +00:00
|
|
|
(setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded"
|
|
|
|
auto-revert-remote-files t
|
|
|
|
auto-revert-stop-on-user-input nil)
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test04-autorevert ()
|
2015-09-14 20:15:20 +00:00
|
|
|
"Check autorevert via file notification."
|
2013-10-24 07:38:45 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
2013-10-24 07:38:45 +00:00
|
|
|
;; `auto-revert-buffers' runs every 5". And we must wait, until the
|
|
|
|
;; file has been reverted.
|
2015-06-02 21:47:17 +00:00
|
|
|
(let ((timeout (if (file-remote-p temporary-file-directory) 60 10))
|
|
|
|
buf)
|
2013-10-24 07:38:45 +00:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
2017-02-08 18:33:52 +00:00
|
|
|
;; In the remote case, `vc-refresh-state' returns undesired
|
|
|
|
;; error messages. Let's suppress them.
|
|
|
|
(advice-add 'vc-refresh-state :around 'ignore)
|
2013-10-24 07:38:45 +00:00
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
2013-11-13 15:36:12 +00:00
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
2013-10-24 07:38:45 +00:00
|
|
|
(setq buf (find-file-noselect file-notify--test-tmpfile))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(should (string-equal (buffer-string) "any text"))
|
2015-06-02 21:47:17 +00:00
|
|
|
;; `buffer-stale--default-function' checks for
|
|
|
|
;; `verify-visited-file-modtime'. We must ensure that it
|
|
|
|
;; returns nil.
|
|
|
|
(sleep-for 1)
|
2013-10-24 07:38:45 +00:00
|
|
|
(auto-revert-mode 1)
|
|
|
|
|
|
|
|
;; `auto-revert-buffers' runs every 5".
|
|
|
|
(with-timeout (timeout (ignore))
|
|
|
|
(while (null auto-revert-notify-watch-descriptor)
|
2014-02-04 11:41:20 +00:00
|
|
|
(sleep-for 1)))
|
2013-10-24 07:38:45 +00:00
|
|
|
|
2017-01-03 08:50:41 +00:00
|
|
|
;; `file-notify--test-monitor' needs to know
|
|
|
|
;; `file-notify--test-desc' in order to compute proper
|
|
|
|
;; timeouts.
|
|
|
|
(setq file-notify--test-desc auto-revert-notify-watch-descriptor)
|
|
|
|
|
2013-10-24 07:38:45 +00:00
|
|
|
;; Check, that file notification has been used.
|
|
|
|
(should auto-revert-mode)
|
|
|
|
(should auto-revert-use-notify)
|
|
|
|
(should auto-revert-notify-watch-descriptor)
|
|
|
|
|
2015-10-27 15:06:33 +00:00
|
|
|
;; Modify file. We wait for a second, in order to have
|
2017-02-04 11:36:43 +00:00
|
|
|
;; another timestamp.
|
|
|
|
(ert-with-message-capture captured-messages
|
|
|
|
(sleep-for 1)
|
|
|
|
(write-region
|
|
|
|
"another text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
|
|
|
|
;; Check, that the buffer has been reverted.
|
|
|
|
(file-notify--wait-for-events
|
|
|
|
timeout
|
|
|
|
(string-match
|
2015-09-12 08:37:32 +00:00
|
|
|
(format-message "Reverting buffer `%s'." (buffer-name buf))
|
2017-02-04 11:36:43 +00:00
|
|
|
captured-messages))
|
|
|
|
(should (string-match "another text" (buffer-string))))
|
2015-10-27 15:02:26 +00:00
|
|
|
|
|
|
|
;; Stop file notification. Autorevert shall still work via polling.
|
2016-02-23 12:51:36 +00:00
|
|
|
(file-notify-rm-watch auto-revert-notify-watch-descriptor)
|
|
|
|
(file-notify--wait-for-events
|
2018-01-22 08:12:16 +00:00
|
|
|
timeout (null auto-revert-notify-watch-descriptor))
|
|
|
|
(should auto-revert-use-notify)
|
2016-02-23 12:51:36 +00:00
|
|
|
(should-not auto-revert-notify-watch-descriptor)
|
|
|
|
|
|
|
|
;; Modify file. We wait for two seconds, in order to
|
|
|
|
;; have another timestamp. One second seems to be too
|
2018-08-03 14:37:04 +00:00
|
|
|
;; short. And Cygwin sporadically requires more than two.
|
2017-02-04 11:36:43 +00:00
|
|
|
(ert-with-message-capture captured-messages
|
2018-08-03 14:37:04 +00:00
|
|
|
(sleep-for (if (eq system-type 'cygwin) 3 2))
|
2017-02-04 11:36:43 +00:00
|
|
|
(write-region
|
|
|
|
"foo bla" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
|
|
|
|
;; Check, that the buffer has been reverted.
|
|
|
|
(file-notify--wait-for-events
|
|
|
|
timeout
|
|
|
|
(string-match
|
|
|
|
(format-message "Reverting buffer `%s'." (buffer-name buf))
|
|
|
|
captured-messages))
|
2018-01-22 08:12:16 +00:00
|
|
|
(should (string-match "foo bla" (buffer-string))))
|
|
|
|
|
|
|
|
;; Stop autorevert, in order to cleanup descriptor.
|
|
|
|
(auto-revert-mode -1))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2013-10-24 07:38:45 +00:00
|
|
|
|
2015-09-20 16:44:36 +00:00
|
|
|
;; Cleanup.
|
2017-02-08 18:33:52 +00:00
|
|
|
(advice-remove 'vc-refresh-state 'ignore)
|
2013-10-24 07:38:45 +00:00
|
|
|
(ignore-errors (kill-buffer buf))
|
2015-09-10 15:18:15 +00:00
|
|
|
(file-notify--test-cleanup))))
|
2013-10-24 07:38:45 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test04-autorevert
|
2018-12-18 16:25:55 +00:00
|
|
|
"Check autorevert via file notification for remote files.")
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test05-file-validity ()
|
2015-09-14 20:15:20 +00:00
|
|
|
"Check `file-notify-valid-p' for files."
|
2015-09-14 06:03:11 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
2016-01-22 18:56:09 +00:00
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2016-06-05 17:49:16 +00:00
|
|
|
file-notify--test-tmpfile '(change) #'ignore)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
|
|
|
;; After calling `file-notify-rm-watch', the descriptor is not
|
|
|
|
;; valid anymore.
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
(delete-file file-notify--test-tmpfile)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-01-22 18:56:09 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
2016-03-24 17:34:05 +00:00
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
2016-01-22 18:56:09 +00:00
|
|
|
(file-notify--test-with-events
|
2017-01-03 08:50:41 +00:00
|
|
|
(cond
|
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the
|
|
|
|
;; `changed' event reliably.
|
|
|
|
((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(changed deleted stopped)))
|
|
|
|
;; There could be one or two `changed' events.
|
|
|
|
(t '((changed deleted stopped)
|
|
|
|
(changed changed deleted stopped))))
|
2015-09-20 16:44:36 +00:00
|
|
|
(write-region
|
2016-01-22 18:56:09 +00:00
|
|
|
"another text" nil file-notify--test-tmpfile nil 'no-message)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2015-10-26 15:46:48 +00:00
|
|
|
(delete-file file-notify--test-tmpfile))
|
2016-01-22 18:56:09 +00:00
|
|
|
;; After deleting the file, the descriptor is not valid anymore.
|
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
2015-09-14 06:03:11 +00:00
|
|
|
(unwind-protect
|
2018-01-10 12:39:17 +00:00
|
|
|
(let ((file-notify--test-tmpdir
|
2016-02-23 12:51:36 +00:00
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
|
|
|
|
file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2018-01-10 12:39:17 +00:00
|
|
|
file-notify--test-tmpdir
|
2016-02-23 12:51:36 +00:00
|
|
|
'(change) #'file-notify--test-event-handler)))
|
2016-03-24 17:34:05 +00:00
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
2016-02-23 12:51:36 +00:00
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify does not raise `deleted' and `stopped' events
|
|
|
|
;; for the watched directory.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
'(created changed deleted))
|
2017-01-03 08:50:41 +00:00
|
|
|
;; gvfs-monitor-dir on cygwin does not detect the `created'
|
|
|
|
;; event reliably.
|
|
|
|
((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe")
|
|
|
|
'((deleted stopped)
|
|
|
|
(created deleted stopped)))
|
2016-02-23 12:51:36 +00:00
|
|
|
;; There are two `deleted' events, for the file and for the
|
2016-12-26 18:24:43 +00:00
|
|
|
;; directory. Except for cygwin and kqueue. And cygwin
|
|
|
|
;; does not raise a `changed' event.
|
|
|
|
((eq system-type 'cygwin)
|
|
|
|
'(created deleted stopped))
|
2016-02-23 12:51:36 +00:00
|
|
|
((string-equal (file-notify--test-library) "kqueue")
|
|
|
|
'(created changed deleted stopped))
|
|
|
|
(t '(created changed deleted deleted stopped)))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2018-01-10 12:39:17 +00:00
|
|
|
(delete-directory file-notify--test-tmpdir 'recursive))
|
2016-02-23 12:51:36 +00:00
|
|
|
;; After deleting the parent directory, the descriptor must
|
|
|
|
;; not be valid anymore.
|
2016-06-05 17:49:16 +00:00
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc))
|
2017-05-01 10:16:15 +00:00
|
|
|
;; w32notify doesn't generate `stopped' events when the parent
|
2017-01-27 08:28:15 +00:00
|
|
|
;; directory is deleted, which doesn't provide a chance for
|
|
|
|
;; filenotify.el to remove the descriptor from the internal
|
|
|
|
;; hash table it maintains. So we must remove the descriptor
|
|
|
|
;; manually.
|
|
|
|
(if (string-equal (file-notify--test-library) "w32notify")
|
|
|
|
(file-notify--rm-descriptor file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2015-09-20 16:44:36 +00:00
|
|
|
;; Cleanup.
|
2015-09-14 20:15:20 +00:00
|
|
|
(file-notify--test-cleanup)))
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test05-file-validity
|
2015-09-14 20:15:20 +00:00
|
|
|
"Check `file-notify-valid-p' via file notification for remote files.")
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test06-dir-validity ()
|
2015-09-14 06:03:11 +00:00
|
|
|
"Check `file-notify-valid-p' for directories."
|
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
2016-03-04 14:01:36 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2016-06-05 17:49:16 +00:00
|
|
|
file-notify--test-tmpfile '(change) #'ignore)))
|
2015-09-20 16:44:36 +00:00
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
|
|
|
;; After removing the watch, the descriptor must not be valid
|
|
|
|
;; anymore.
|
|
|
|
(file-notify-rm-watch file-notify--test-desc)
|
2015-10-26 15:46:48 +00:00
|
|
|
(file-notify--wait-for-events
|
|
|
|
(file-notify--test-timeout)
|
|
|
|
(not (file-notify-valid-p file-notify--test-desc)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc))
|
2018-01-19 13:59:48 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile 'recursive)
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-20 16:44:36 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
2015-09-14 06:03:11 +00:00
|
|
|
(unwind-protect
|
2016-02-23 12:51:36 +00:00
|
|
|
(progn
|
2016-03-04 14:01:36 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
2016-06-05 17:49:16 +00:00
|
|
|
file-notify--test-tmpfile '(change) #'ignore)))
|
2015-09-14 06:03:11 +00:00
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
2015-09-14 20:15:20 +00:00
|
|
|
;; After deleting the directory, the descriptor must not be
|
2015-09-14 07:52:31 +00:00
|
|
|
;; valid anymore.
|
2018-01-19 13:59:48 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile 'recursive)
|
2015-09-20 16:44:36 +00:00
|
|
|
(file-notify--wait-for-events
|
2016-01-22 18:56:09 +00:00
|
|
|
(file-notify--test-timeout)
|
2015-09-20 16:44:36 +00:00
|
|
|
(not (file-notify-valid-p file-notify--test-desc)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc))
|
2017-01-27 08:28:15 +00:00
|
|
|
(if (string-equal (file-notify--test-library) "w32notify")
|
|
|
|
(file-notify--rm-descriptor file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2015-09-20 16:44:36 +00:00
|
|
|
;; Cleanup.
|
2015-09-14 20:15:20 +00:00
|
|
|
(file-notify--test-cleanup)))
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test06-dir-validity
|
2015-09-14 20:15:20 +00:00
|
|
|
"Check `file-notify-valid-p' via file notification for remote directories.")
|
2015-09-14 06:03:11 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test07-many-events ()
|
2016-01-22 18:56:09 +00:00
|
|
|
"Check that events are not dropped."
|
|
|
|
:tags '(:expensive-test)
|
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
|
|
|
|
2016-03-04 14:01:36 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
2016-03-04 14:01:36 +00:00
|
|
|
'(change) #'file-notify--test-event-handler)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(unwind-protect
|
2016-02-06 19:53:38 +00:00
|
|
|
(let ((n 1000)
|
2016-01-22 18:56:09 +00:00
|
|
|
source-file-list target-file-list
|
|
|
|
(default-directory file-notify--test-tmpfile))
|
|
|
|
(dotimes (i n)
|
|
|
|
;; It matters which direction we rename, at least for
|
|
|
|
;; kqueue. This backend parses directories in alphabetic
|
2016-02-22 17:52:37 +00:00
|
|
|
;; order (x%d before y%d). So we rename into both directions.
|
2016-01-22 18:56:09 +00:00
|
|
|
(if (zerop (mod i 2))
|
|
|
|
(progn
|
|
|
|
(push (expand-file-name (format "x%d" i)) source-file-list)
|
|
|
|
(push (expand-file-name (format "y%d" i)) target-file-list))
|
|
|
|
(push (expand-file-name (format "y%d" i)) source-file-list)
|
|
|
|
(push (expand-file-name (format "x%d" i)) target-file-list)))
|
|
|
|
(file-notify--test-with-events (make-list (+ n n) 'created)
|
|
|
|
(let ((source-file-list source-file-list)
|
|
|
|
(target-file-list target-file-list))
|
|
|
|
(while (and source-file-list target-file-list)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2016-01-22 18:56:09 +00:00
|
|
|
(write-region "" nil (pop source-file-list) nil 'no-message)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2016-01-22 18:56:09 +00:00
|
|
|
(write-region "" nil (pop target-file-list) nil 'no-message))))
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
|
|
|
;; w32notify fires both `deleted' and `renamed' events.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify")
|
|
|
|
(let (r)
|
2018-04-28 20:20:33 +00:00
|
|
|
(dotimes (_i n)
|
|
|
|
(setq r (append '(deleted renamed) r)))
|
|
|
|
r))
|
2016-06-06 16:25:28 +00:00
|
|
|
;; cygwin fires `changed' and `deleted' events, sometimes
|
|
|
|
;; in random order.
|
|
|
|
((eq system-type 'cygwin)
|
2016-12-29 18:48:17 +00:00
|
|
|
(let (r)
|
2018-04-28 20:20:33 +00:00
|
|
|
(dotimes (_i n)
|
|
|
|
(setq r (append '(changed deleted) r)))
|
|
|
|
(cons :random r)))
|
2016-01-22 18:56:09 +00:00
|
|
|
(t (make-list n 'renamed)))
|
|
|
|
(let ((source-file-list source-file-list)
|
|
|
|
(target-file-list target-file-list))
|
|
|
|
(while (and source-file-list target-file-list)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2016-02-07 18:30:01 +00:00
|
|
|
(rename-file (pop source-file-list) (pop target-file-list) t))))
|
2016-01-22 18:56:09 +00:00
|
|
|
(file-notify--test-with-events (make-list n 'deleted)
|
|
|
|
(dolist (file target-file-list)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
|
|
|
(delete-file file)))
|
2016-06-05 17:49:16 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile)
|
2017-01-27 08:28:15 +00:00
|
|
|
(if (string-equal (file-notify--test-library) "w32notify")
|
|
|
|
(file-notify--rm-descriptor file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-02-07 18:30:01 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
2016-01-22 18:56:09 +00:00
|
|
|
(file-notify--test-cleanup)))
|
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test07-many-events
|
2016-01-22 18:56:09 +00:00
|
|
|
"Check that events are not dropped for remote directories.")
|
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test08-backup ()
|
2016-02-08 09:54:43 +00:00
|
|
|
"Check that backup keeps file notification."
|
2016-02-07 18:30:01 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
|
|
|
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
2016-02-08 09:54:43 +00:00
|
|
|
(file-notify--test-with-events
|
2016-06-20 12:41:41 +00:00
|
|
|
;; There could be one or two `changed' events.
|
|
|
|
'((changed)
|
|
|
|
(changed changed))
|
2016-02-07 18:30:01 +00:00
|
|
|
;; There shouldn't be any problem, because the file is kept.
|
|
|
|
(with-temp-buffer
|
|
|
|
(let ((buffer-file-name file-notify--test-tmpfile)
|
|
|
|
(make-backup-files t)
|
|
|
|
(backup-by-copying t)
|
|
|
|
(kept-new-versions 1)
|
|
|
|
(delete-old-versions t))
|
|
|
|
(insert "another text")
|
|
|
|
(save-buffer))))
|
|
|
|
;; After saving the buffer, the descriptor is still valid.
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
2016-06-05 17:49:16 +00:00
|
|
|
(delete-file file-notify--test-tmpfile)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-02-07 18:30:01 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup))
|
|
|
|
|
|
|
|
(unwind-protect
|
2016-06-05 17:49:16 +00:00
|
|
|
;; It doesn't work for kqueue, because we don't use an implicit
|
|
|
|
;; directory monitor.
|
|
|
|
(unless (string-equal (file-notify--test-library) "kqueue")
|
|
|
|
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile nil 'no-message)
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
|
|
|
'(change) #'file-notify--test-event-handler)))
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
|
|
|
(file-notify--test-with-events
|
2016-05-27 18:55:34 +00:00
|
|
|
(cond
|
2016-06-20 12:41:41 +00:00
|
|
|
;; On cygwin we only get the `changed' event.
|
2016-05-27 18:55:34 +00:00
|
|
|
((eq system-type 'cygwin) '(changed))
|
|
|
|
(t '(renamed created changed)))
|
2016-06-05 17:49:16 +00:00
|
|
|
;; The file is renamed when creating a backup. It shall
|
|
|
|
;; still be watched.
|
|
|
|
(with-temp-buffer
|
|
|
|
(let ((buffer-file-name file-notify--test-tmpfile)
|
|
|
|
(make-backup-files t)
|
|
|
|
(backup-by-copying nil)
|
|
|
|
(backup-by-copying-when-mismatch nil)
|
|
|
|
(kept-new-versions 1)
|
|
|
|
(delete-old-versions t))
|
|
|
|
(insert "another text")
|
|
|
|
(save-buffer))))
|
|
|
|
;; After saving the buffer, the descriptor is still valid.
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc))
|
|
|
|
(delete-file file-notify--test-tmpfile)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-02-07 18:30:01 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test08-backup
|
2018-12-15 23:04:24 +00:00
|
|
|
"Check that backup keeps file notification for remote files."
|
|
|
|
(if (getenv "EMACS_HYDRA_CI") :failed :passed)) ; fixme bug#33735
|
2016-02-07 18:30:01 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test09-watched-file-in-watched-dir ()
|
2016-02-20 07:33:11 +00:00
|
|
|
"Watches a directory and a file in that directory separately.
|
|
|
|
Checks that the callbacks are only called with events with
|
|
|
|
descriptors that were issued when registering the watches. This
|
|
|
|
test caters for the situation in bug#22736 where the callback for
|
|
|
|
the directory received events for the file with the descriptor of
|
|
|
|
the file watch."
|
2016-02-20 13:04:36 +00:00
|
|
|
:tags '(:expensive-test)
|
2016-02-20 07:33:11 +00:00
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
|
|
|
|
2016-02-22 17:52:37 +00:00
|
|
|
;; A directory to be watched.
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
;; A file to be watched.
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile1
|
2018-01-10 12:39:17 +00:00
|
|
|
(let ((file-notify--test-tmpdir file-notify--test-tmpfile))
|
2016-02-22 17:52:37 +00:00
|
|
|
(file-notify--test-make-temp-name))))
|
|
|
|
(write-region "any text" nil file-notify--test-tmpfile1 nil 'no-message)
|
2016-02-20 07:33:11 +00:00
|
|
|
(unwind-protect
|
2016-02-22 17:52:37 +00:00
|
|
|
(cl-flet (;; Directory monitor.
|
|
|
|
(dir-callback (event)
|
|
|
|
(let ((file-notify--test-desc file-notify--test-desc1))
|
|
|
|
(file-notify--test-event-handler event)))
|
|
|
|
;; File monitor.
|
|
|
|
(file-callback (event)
|
|
|
|
(let ((file-notify--test-desc file-notify--test-desc2))
|
|
|
|
(file-notify--test-event-handler event))))
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc1
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile
|
2017-01-03 08:50:41 +00:00
|
|
|
'(change) #'dir-callback)
|
|
|
|
;; This is needed for `file-notify--test-monitor'.
|
|
|
|
file-notify--test-desc file-notify--test-desc1))
|
2016-02-22 17:52:37 +00:00
|
|
|
(should
|
|
|
|
(setq file-notify--test-desc2
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile1
|
|
|
|
'(change) #'file-callback)))
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc1))
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc2))
|
|
|
|
(should-not (equal file-notify--test-desc1 file-notify--test-desc2))
|
2016-06-20 12:41:41 +00:00
|
|
|
(let ((n 100))
|
|
|
|
;; Run the test.
|
|
|
|
(file-notify--test-with-events
|
|
|
|
;; There could be one or two `changed' events.
|
2016-06-20 13:05:52 +00:00
|
|
|
(list
|
2016-12-29 18:48:17 +00:00
|
|
|
;; cygwin.
|
|
|
|
(append
|
|
|
|
'(:random)
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
(make-list (/ n 2) 'created)
|
|
|
|
(make-list (/ n 2) 'changed))
|
2016-06-20 13:05:52 +00:00
|
|
|
(append
|
|
|
|
'(:random)
|
|
|
|
;; Directory monitor and file monitor.
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
;; Just the directory monitor.
|
|
|
|
(make-list (/ n 2) 'created)
|
|
|
|
(make-list (/ n 2) 'changed))
|
|
|
|
(append
|
|
|
|
'(:random)
|
|
|
|
;; Directory monitor and file monitor.
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
(make-list (/ n 2) 'changed)
|
|
|
|
;; Just the directory monitor.
|
|
|
|
(make-list (/ n 2) 'created)
|
|
|
|
(make-list (/ n 2) 'changed)))
|
2016-06-20 12:41:41 +00:00
|
|
|
(dotimes (i n)
|
2016-12-29 18:48:17 +00:00
|
|
|
(file-notify--test-read-event)
|
2016-06-20 12:41:41 +00:00
|
|
|
(if (zerop (mod i 2))
|
|
|
|
(write-region
|
|
|
|
"any text" nil file-notify--test-tmpfile1 t 'no-message)
|
2018-01-10 12:39:17 +00:00
|
|
|
(let ((file-notify--test-tmpdir file-notify--test-tmpfile))
|
2016-06-20 12:41:41 +00:00
|
|
|
(write-region
|
|
|
|
"any text" nil
|
|
|
|
(file-notify--test-make-temp-name) nil 'no-message))))))
|
2016-02-22 17:52:37 +00:00
|
|
|
|
|
|
|
;; If we delete the file, the directory monitor shall still be
|
|
|
|
;; active. We receive the `deleted' event from both the
|
|
|
|
;; directory and the file monitor. The `stopped' event is
|
|
|
|
;; from the file monitor. It's undecided in which order the
|
|
|
|
;; the directory and the file monitor are triggered.
|
2016-06-06 16:25:28 +00:00
|
|
|
(file-notify--test-with-events '(:random deleted deleted stopped)
|
2016-02-22 17:52:37 +00:00
|
|
|
(delete-file file-notify--test-tmpfile1))
|
|
|
|
(should (file-notify-valid-p file-notify--test-desc1))
|
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc2))
|
2016-02-20 13:04:36 +00:00
|
|
|
|
2016-02-22 17:52:37 +00:00
|
|
|
;; Now we delete the directory.
|
|
|
|
(file-notify--test-with-events
|
|
|
|
(cond
|
2016-12-29 18:48:17 +00:00
|
|
|
;; In kqueue and for cygwin, just one `deleted' event for
|
|
|
|
;; the directory is received.
|
|
|
|
((or (eq system-type 'cygwin)
|
|
|
|
(string-equal (file-notify--test-library) "kqueue"))
|
2016-02-22 17:52:37 +00:00
|
|
|
'(deleted stopped))
|
|
|
|
(t (append
|
|
|
|
;; The directory monitor raises a `deleted' event for
|
|
|
|
;; every file contained in the directory, we must
|
|
|
|
;; count them.
|
|
|
|
(make-list
|
|
|
|
(length
|
|
|
|
(directory-files
|
|
|
|
file-notify--test-tmpfile nil
|
|
|
|
directory-files-no-dot-files-regexp 'nosort))
|
|
|
|
'deleted)
|
|
|
|
;; The events of the directory itself.
|
2016-02-23 12:51:36 +00:00
|
|
|
(cond
|
|
|
|
;; w32notify does not raise `deleted' and `stopped'
|
|
|
|
;; events for the watched directory.
|
|
|
|
((string-equal (file-notify--test-library) "w32notify") '())
|
|
|
|
(t '(deleted stopped))))))
|
2016-02-22 17:52:37 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile 'recursive))
|
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc1))
|
2016-06-05 17:49:16 +00:00
|
|
|
(should-not (file-notify-valid-p file-notify--test-desc2))
|
2017-01-27 08:28:15 +00:00
|
|
|
(when (string-equal (file-notify--test-library) "w32notify")
|
|
|
|
(file-notify--rm-descriptor file-notify--test-desc1)
|
|
|
|
(file-notify--rm-descriptor file-notify--test-desc2))
|
2016-06-05 17:49:16 +00:00
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-02-20 07:33:11 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
|
|
|
|
2017-07-03 14:12:10 +00:00
|
|
|
;(file-notify--deftest-remote file-notify-test09-watched-file-in-watched-dir
|
|
|
|
; "Check `file-notify-test09-watched-file-in-watched-dir' for remote files.")
|
2016-02-20 07:33:11 +00:00
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(ert-deftest file-notify-test10-sufficient-resources ()
|
2016-04-04 06:16:35 +00:00
|
|
|
"Check that file notification does not use too many resources."
|
2016-03-04 14:01:36 +00:00
|
|
|
:tags '(:expensive-test)
|
|
|
|
(skip-unless (file-notify--test-local-enabled))
|
|
|
|
;; This test is intended for kqueue only.
|
|
|
|
(skip-unless (string-equal (file-notify--test-library) "kqueue"))
|
|
|
|
|
|
|
|
(should
|
|
|
|
(setq file-notify--test-tmpfile
|
|
|
|
(make-temp-file "file-notify-test-parent" t)))
|
|
|
|
(unwind-protect
|
2018-01-10 12:39:17 +00:00
|
|
|
(let ((file-notify--test-tmpdir file-notify--test-tmpfile)
|
2016-03-04 14:01:36 +00:00
|
|
|
descs)
|
|
|
|
(should-error
|
|
|
|
(while t
|
|
|
|
;; We watch directories, because we want to reach the upper
|
|
|
|
;; limit. Watching a file might not be sufficient, because
|
|
|
|
;; most of the libraries implement this as watching the
|
|
|
|
;; upper directory.
|
|
|
|
(setq file-notify--test-tmpfile1
|
|
|
|
(make-temp-file "file-notify-test-parent" t)
|
|
|
|
descs
|
|
|
|
(cons
|
|
|
|
(should
|
|
|
|
(file-notify-add-watch
|
|
|
|
file-notify--test-tmpfile1 '(change) #'ignore))
|
|
|
|
descs)))
|
|
|
|
:type 'file-notify-error)
|
|
|
|
;; Remove watches. If we don't do it prior removing
|
|
|
|
;; directories, Emacs crashes in batch mode.
|
|
|
|
(dolist (desc descs)
|
|
|
|
(file-notify-rm-watch desc))
|
|
|
|
;; Remove directories.
|
2016-06-05 17:49:16 +00:00
|
|
|
(delete-directory file-notify--test-tmpfile 'recursive)
|
|
|
|
|
|
|
|
;; The environment shall be cleaned up.
|
|
|
|
(file-notify--test-cleanup-p))
|
2016-03-04 14:01:36 +00:00
|
|
|
|
|
|
|
;; Cleanup.
|
|
|
|
(file-notify--test-cleanup)))
|
|
|
|
|
2017-03-17 09:25:46 +00:00
|
|
|
(file-notify--deftest-remote file-notify-test10-sufficient-resources
|
|
|
|
"Check `file-notify-test10-sufficient-resources' for remote files.")
|
2016-03-04 14:01:36 +00:00
|
|
|
|
2013-07-04 09:43:17 +00:00
|
|
|
(defun file-notify-test-all (&optional interactive)
|
|
|
|
"Run all tests for \\[file-notify]."
|
|
|
|
(interactive "p")
|
2013-10-24 07:38:45 +00:00
|
|
|
(if interactive
|
|
|
|
(ert-run-tests-interactively "^file-notify-")
|
|
|
|
(ert-run-tests-batch "^file-notify-")))
|
2013-07-04 09:43:17 +00:00
|
|
|
|
2015-10-26 15:46:48 +00:00
|
|
|
;; TODO:
|
|
|
|
|
2016-02-23 12:51:36 +00:00
|
|
|
;; * kqueue does not send all expected `deleted' events. Maybe due to
|
|
|
|
;; the missing directory monitor.
|
|
|
|
;; * For w32notify, no `deleted' and `stopped' events arrive when a
|
|
|
|
;; directory is removed.
|
2016-12-26 18:24:43 +00:00
|
|
|
;; * For cygwin and w32notify, no `attribute-changed' events arrive.
|
|
|
|
;; They send `changed' events instead.
|
|
|
|
;; * cygwin does not send all expected `changed' and `deleted' events.
|
|
|
|
;; Probably due to timing issues.
|
2015-10-26 15:46:48 +00:00
|
|
|
|
2013-07-04 09:43:17 +00:00
|
|
|
(provide 'file-notify-tests)
|
2016-06-20 12:41:41 +00:00
|
|
|
;;; filenotify-tests.el ends here
|