* admin/automerge: Quieten initial pull if start with reset.
[emacs.git] / test / src / inotify-tests.el
blobb46014e2734a2d0eb542a69efa2da5db42e7cbf6
1 ;;; inotify-tests.el --- Test suite for inotify. -*- lexical-binding: t -*-
3 ;; Copyright (C) 2012-2018 Free Software Foundation, Inc.
5 ;; Author: RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
6 ;; Keywords: internal
7 ;; Human-Keywords: internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;;; Code:
26 (require 'ert)
28 (declare-function inotify-add-watch "inotify.c" (file-name aspect callback))
29 (declare-function inotify-rm-watch "inotify.c" (watch-descriptor))
31 (ert-deftest inotify-valid-p-simple ()
32 "Simple tests for `inotify-valid-p'."
33 (skip-unless (featurep 'inotify))
34 (should-not (inotify-valid-p 0))
35 (should-not (inotify-valid-p nil))
36 (should-not (inotify-valid-p '(0 . 0))))
38 ;; (ert-deftest filewatch-file-watch-aspects-check ()
39 ;; "Test whether `file-watch' properly checks the aspects."
40 ;; (let ((temp-file (make-temp-file "filewatch-aspects")))
41 ;; (should (stringp temp-file))
42 ;; (should-error (file-watch temp-file 'wrong nil)
43 ;; :type 'error)
44 ;; (should-error (file-watch temp-file '(modify t) nil)
45 ;; :type 'error)
46 ;; (should-error (file-watch temp-file '(modify all-modify) nil)
47 ;; :type 'error)
48 ;; (should-error (file-watch temp-file '(access wrong modify) nil)
49 ;; :type 'error)))
51 (ert-deftest inotify-file-watch-simple ()
52 "Test if watching a normal file works."
54 (skip-unless (featurep 'inotify))
55 (let ((temp-file (make-temp-file "inotify-simple"))
56 (events 0))
57 (let ((wd
58 (inotify-add-watch temp-file t (lambda (_ev)
59 (setq events (1+ events))))))
60 (unwind-protect
61 (progn
62 (with-temp-file temp-file
63 (insert "Foo\n"))
64 (read-event nil nil 5)
65 (should (> events 0)))
66 (should (inotify-valid-p wd))
67 (inotify-rm-watch wd)
68 (should-not (inotify-valid-p wd))
69 (delete-file temp-file)))))
71 (provide 'inotify-tests)
73 ;;; inotify-tests.el ends here.