]> code.delx.au - gnu-emacs/blob - test/src/inotify-tests.el
Merge from origin/emacs-25
[gnu-emacs] / test / src / inotify-tests.el
1 ;;; inotify-tests.el --- Test suite for inotify. -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
4
5 ;; Author: RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
6 ;; Keywords: internal
7 ;; Human-Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Code:
25
26 (require 'ert)
27
28 (declare-function inotify-add-watch "inotify.c" (file-name aspect callback))
29 (declare-function inotify-rm-watch "inotify.c" (watch-descriptor))
30
31 ;; (ert-deftest filewatch-file-watch-aspects-check ()
32 ;; "Test whether `file-watch' properly checks the aspects."
33 ;; (let ((temp-file (make-temp-file "filewatch-aspects")))
34 ;; (should (stringp temp-file))
35 ;; (should-error (file-watch temp-file 'wrong nil)
36 ;; :type 'error)
37 ;; (should-error (file-watch temp-file '(modify t) nil)
38 ;; :type 'error)
39 ;; (should-error (file-watch temp-file '(modify all-modify) nil)
40 ;; :type 'error)
41 ;; (should-error (file-watch temp-file '(access wrong modify) nil)
42 ;; :type 'error)))
43
44 (ert-deftest inotify-file-watch-simple ()
45 "Test if watching a normal file works."
46
47 (skip-unless (featurep 'inotify))
48 (let ((temp-file (make-temp-file "inotify-simple"))
49 (events 0))
50 (let ((wd
51 (inotify-add-watch temp-file t (lambda (_ev)
52 (setq events (1+ events))))))
53 (unwind-protect
54 (progn
55 (with-temp-file temp-file
56 (insert "Foo\n"))
57 (read-event nil nil 5)
58 (should (> events 0)))
59 (inotify-rm-watch wd)
60 (delete-file temp-file)))))
61
62 (provide 'inotify-tests)
63
64 ;;; inotify-tests.el ends here.