1 ;; test-lib.el --- auxiliary stuff for Notmuch Emacs tests.
3 ;; Copyright © Carl Worth
4 ;; Copyright © David Edmondson
6 ;; This file is part of Notmuch test suit.
8 ;; Notmuch is free software: you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; Notmuch is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
21 ;; Authors: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
23 ;; `read-file-name' by default uses `completing-read' function to read
24 ;; user input. It does not respect `standard-input' variable which we
25 ;; use in tests to provide user input. So replace it with a plain
27 (setq read-file-name-function (lambda (&rest _) (read)))
29 (defun notmuch-test-wait ()
30 "Wait for process completion."
31 (while (get-buffer-process (current-buffer))
34 (defun test-output (&optional filename)
35 "Save current buffer to file FILENAME. Default FILENAME is OUTPUT."
36 (write-region (point-min) (point-max) (or filename "OUTPUT")))
38 (defun test-visible-output (&optional filename)
39 "Save visible text in current buffer to file FILENAME. Default
41 (let ((text (visible-buffer-string)))
42 (with-temp-file (or filename "OUTPUT") (insert text))))
44 (defun visible-buffer-string ()
45 "Same as `buffer-string', but excludes invisible text."
46 (visible-buffer-substring (point-min) (point-max)))
48 (defun visible-buffer-substring (start end)
49 "Same as `buffer-substring', but excludes invisible text."
52 (let ((next-pos (next-char-property-change start end)))
53 (when (not (invisible-p start))
54 (setq str (concat str (buffer-substring start next-pos))))
55 (setq start next-pos)))
58 (defun orphan-watchdog (pid)
59 "Periodically check that the process with id PID is still
60 running, quit if it terminated."
61 (if (not (process-attributes pid))
63 (run-at-time "1 min" nil 'orphan-watchdog pid)))