]> git.notmuchmail.org Git - notmuch/commitdiff
test: use emacsclient(1) for Emacs tests
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Tue, 28 Jun 2011 04:56:17 +0000 (08:56 +0400)
committerCarl Worth <cworth@cworth.org>
Wed, 29 Jun 2011 00:10:55 +0000 (17:10 -0700)
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.

test/emacs
test/test-lib.el
test/test-lib.sh

index 3034a5a6c765f1f367cb5c6e16d79a1a6346a57a..e59de47c57afae4089c27b1c722fe22332f6d750 100755 (executable)
@@ -259,15 +259,15 @@ test_expect_equal_file OUTPUT EXPECTED
 
 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
 # save as archive to test that Emacs does not re-compress .gz
 
 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
 # save as archive to test that Emacs does not re-compress .gz
-echo ./attachment1.gz |
-test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
-           (notmuch-show-save-attachments)' > /dev/null 2>&1
+test_emacs '(let ((standard-input "\"attachment1.gz\""))
+             (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
+             (notmuch-show-save-attachments))' > /dev/null 2>&1
 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
 
 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
 # save as archive to test that Emacs does not re-compress .gz
 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
 
 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
 # save as archive to test that Emacs does not re-compress .gz
-echo ./attachment2.gz |
-test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1
+test_emacs '(let ((standard-input "\"attachment2.gz\""))
+             (notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5))' > /dev/null 2>&1
 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
 
 test_begin_subtest "View raw message within emacs"
 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
 
 test_begin_subtest "View raw message within emacs"
index 4e7f5cfc30a7538011124717884b026a19fc2f06..a78393684c4e4b308f3e822e6eae1c593ebfb89a 100644 (file)
 ;; avoid crazy 10-column default of --batch
 (set-frame-width (window-frame (get-buffer-window)) 80)
 
 ;; 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))
 (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))
          (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)))
index 7d39d27b1d210a11196ad5aec99644d388dc2798..079d7dba7d2c6eddc3d2e1b596bf3d03839aaea4 100755 (executable)
@@ -831,6 +831,8 @@ test_done () {
 
        echo
 
 
        echo
 
+       [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
+
        if [ "$test_failure" = "0" ]; then
            if [ "$test_broken" = "0" ]; then       
                rm -rf "$remove_tmp"
        if [ "$test_failure" = "0" ]; then
            if [ "$test_broken" = "0" ]; then       
                rm -rf "$remove_tmp"
@@ -850,16 +852,8 @@ emacs_generate_script () {
 export PATH=$PATH
 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
 
 export PATH=$PATH
 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
 
-# We assume that the user will give a command-line argument only if
-# wanting to run in batch mode.
-if [ \$# -gt 0 ]; then
-       BATCH=--batch
-fi
-
 # Here's what we are using here:
 #
 # Here's what we are using here:
 #
-# --batch:             Quit after given commands and print all (messages)
-#
 # --no-init-file       Don't load users ~/.emacs
 #
 # --no-site-file       Don't load the site-wide startup stuff
 # --no-init-file       Don't load users ~/.emacs
 #
 # --no-site-file       Don't load the site-wide startup stuff
@@ -868,16 +862,24 @@ fi
 #
 # --load               Force loading of notmuch.el and test-lib.el
 
 #
 # --load               Force loading of notmuch.el and test-lib.el
 
-emacs \$BATCH --no-init-file --no-site-file \
+emacs --no-init-file --no-site-file \
        --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
        --directory "$TEST_DIRECTORY" --load test-lib.el \
        --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
        --directory "$TEST_DIRECTORY" --load test-lib.el \
-       --eval "(progn \$@)"
+       "\$@"
 EOF
        chmod a+x "$TMP_DIRECTORY/run_emacs"
 }
 
 test_emacs () {
 EOF
        chmod a+x "$TMP_DIRECTORY/run_emacs"
 }
 
 test_emacs () {
-       "$TMP_DIRECTORY/run_emacs" "$@"
+       if [ -z "$EMACS_SERVER" ]; then
+               EMACS_SERVER="notmuch-test-suite-$$"
+               "$TMP_DIRECTORY/run_emacs" \
+                       --daemon \
+                       --eval "(setq server-name \"$EMACS_SERVER\")" \
+                       --eval "(orphan-watchdog $$)" || return
+       fi
+
+       emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
 }
 
 
 }