aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/test-lib.el
diff options
context:
space:
mode:
authorGravatar Dmitry Kurochkin <dmitry.kurochkin@gmail.com>2011-06-28 08:56:17 +0400
committerGravatar Carl Worth <cworth@cworth.org>2011-06-28 17:10:55 -0700
commita854d06e92645350b7ec3f6cd1a10a2f6933104f (patch)
tree652225103630b0f9af84a90d6a191ea9acd826dd /test/test-lib.el
parent6ea26cfb81c68526b157a213d00b593d4e7b1335 (diff)
test: use emacsclient(1) for Emacs tests
Before the change, every Emacs test ran in a separate Emacs instance. Starting Emacs many times wastes considerable time and it gets worse as the test suite grows. The patch solves this by using a single Emacs server and emacsclient(1) to run multiple tests. Emacs server is started on the first test_emacs call and stopped when test_done is called. We take care not to leave orphan Emacs processes behind when test is terminated by whatever reason: Emacs server runs a watchdog that periodically checks that the test is still running. Some tests need to provide user input. Before the change, this was done using echo(1) to Emacs stdin. This no longer works and instead `standard-input' variable is set accordingly to make `read' return the appropriate string.
Diffstat (limited to 'test/test-lib.el')
-rw-r--r--test/test-lib.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/test-lib.el b/test/test-lib.el
index 4e7f5cfc..a7839368 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -23,6 +23,12 @@
;; avoid crazy 10-column default of --batch
(set-frame-width (window-frame (get-buffer-window)) 80)
+;; `read-file-name' by default uses `completing-read' function to read
+;; user input. It does not respect `standard-input' variable which we
+;; use in tests to provide user input. So replace it with a plain
+;; `read' call.
+(setq read-file-name-function (lambda (&rest _) (read)))
+
(defun notmuch-test-wait ()
"Wait for process completion."
(while (get-buffer-process (current-buffer))
@@ -51,3 +57,10 @@ FILENAME is OUTPUT."
(setq str (concat str (buffer-substring start next-pos))))
(setq start next-pos)))
str))
+
+(defun orphan-watchdog (pid)
+ "Periodically check that the process with id PID is still
+running, quit if it terminated."
+ (if (not (process-attributes pid))
+ (kill-emacs)
+ (run-at-time "1 min" nil 'orphan-watchdog pid)))