Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6A3B9431FD0 for ; Sun, 26 Jun 2011 20:54:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EWcP3vxenp2k for ; Sun, 26 Jun 2011 20:54:32 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id BB1DE429E2E for ; Sun, 26 Jun 2011 20:54:29 -0700 (PDT) Received: by mail-bw0-f53.google.com with SMTP id 12so3975366bwg.26 for ; Sun, 26 Jun 2011 20:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=0kVO65XjIsZBCrElxskjQc3VCs1GUHtR7ueA4x19ncY=; b=Xnq5MJXiNyM4AmLbaOWjzvxPB74AwSugQcoGiqOuM+OUBkUtY9fag5GMXo42sDTpp5 y+03EBL0N08hvI82UKj4dNjbn+MEuClyNB5nRK4y752rp9eHC7qBz9FdqxP9DOgRWZdK QSElsxc3b7eLSPvvpnHitJChHINPDWdV90mys= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=nxgbPRn7ep8+dXvdZ2yxq3EsGN9Aspin5+ZUqbV5Ximk4CpKhabPxh3HsO1mMLtzr7 yHbHpiGOoU1N+6HeglT7FXQtxqnJ8K/0iNbsxqgKgyseHgvMA2EGyyVYThfQ5CN2s/NP hZto6MLUMdiBvil9vb3Dqwtp4cm/GhVgbsoWk= Received: by 10.204.19.70 with SMTP id z6mr3864940bka.204.1309146869077; Sun, 26 Jun 2011 20:54:29 -0700 (PDT) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id n3sm3774843bka.16.2011.06.26.20.54.27 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Jun 2011 20:54:28 -0700 (PDT) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH 2/2] test: use emacsclient(1) for Emacs tests Date: Mon, 27 Jun 2011 07:54:06 +0400 Message-Id: <1309146846-30991-2-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309146846-30991-1-git-send-email-dmitry.kurochkin@gmail.com> References: <1309132379-24089-1-git-send-email-dmitry.kurochkin@gmail.com> <1309146846-30991-1-git-send-email-dmitry.kurochkin@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jun 2011 03:54:36 -0000 Before the change, every Emacs tests 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 or the test is killed by a signal. Several auxiliary scripts useful for debugging and test development are generated instead of the run_emacs script: * emacs_server_start - start Emacs server * emacs_server_stop - stop Emacs server * emacs_start - start Emacs * emacs_run - execute ELisp expressions in running Emacs server Since multiple tests are run in a single Emacs instance, they must not change Emacs environment because it may affect other tests. For now, the only Emacs environment modifications done by the tests are variable settings. Before the change, variables were set with `setq' which affected other tests. The patch changes all variables to use `let', so the scope of the change is limited to a single test. --- test/emacs | 74 +++++++++++++------------- test/test-lib.el | 6 ++ test/test-lib.sh | 149 ++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 161 insertions(+), 68 deletions(-) diff --git a/test/emacs b/test/emacs index 4f16b41..f1939dc 100755 --- a/test/emacs +++ b/test/emacs @@ -12,20 +12,20 @@ test_emacs '(notmuch-hello) test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello test_begin_subtest "Saved search with 0 results" -test_emacs '(setq notmuch-show-empty-saved-searches t) - (setq notmuch-saved-searches - '\''(("inbox" . "tag:inbox") - ("unread" . "tag:unread") - ("empty" . "tag:doesnotexist"))) - (notmuch-hello) - (test-output)' +test_emacs '(let ((notmuch-show-empty-saved-searches t) + (notmuch-saved-searches + '\''(("inbox" . "tag:inbox") + ("unread" . "tag:unread") + ("empty" . "tag:doesnotexist")))) + (notmuch-hello) + (test-output))' test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty test_begin_subtest "No saved searches displayed (all with 0 results)" -test_emacs '(setq notmuch-saved-searches - '\''(("empty" . "tag:doesnotexist"))) - (notmuch-hello) - (test-output)' +test_emacs '(let ((notmuch-saved-searches + '\''(("empty" . "tag:doesnotexist")))) + (notmuch-hello) + (test-output))' test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches test_begin_subtest "Basic notmuch-search view in emacs" @@ -147,9 +147,9 @@ output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_sear test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)" test_begin_subtest "notmuch-fcc-dirs set to nil" -test_emacs "(setq notmuch-fcc-dirs nil) - (notmuch-mua-mail) - (test-output)" +test_emacs "(let ((notmuch-fcc-dirs nil)) + (notmuch-mua-mail) + (test-output))" cat <EXPECTED From: Notmuch Test Suite To: @@ -164,9 +164,9 @@ mkdir -p mail/sent-string/new mkdir -p mail/sent-string/tmp test_begin_subtest "notmuch-fcc-dirs set to a string" -test_emacs "(setq notmuch-fcc-dirs \"sent-string\") - (notmuch-mua-mail) - (test-output)" +test_emacs "(let ((notmuch-fcc-dirs \"sent-string\")) + (notmuch-mua-mail) + (test-output))" cat <EXPECTED From: Notmuch Test Suite To: @@ -185,11 +185,11 @@ mkdir -p mail/failure/new mkdir -p mail/failure/tmp test_begin_subtest "notmuch-fcc-dirs set to a list (with match)" -test_emacs "(setq notmuch-fcc-dirs - '((\"notmuchmail.org\" . \"sent-list-match\") - (\".*\" . \"failure\"))) - (notmuch-mua-mail) - (test-output)" +test_emacs "(let ((notmuch-fcc-dirs + '((\"notmuchmail.org\" . \"sent-list-match\") + (\".*\" . \"failure\")))) + (notmuch-mua-mail) + (test-output))" cat <EXPECTED From: Notmuch Test Suite To: @@ -205,11 +205,11 @@ mkdir -p mail/sent-list-catch-all/new mkdir -p mail/sent-list-catch-all/tmp test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)" -test_emacs "(setq notmuch-fcc-dirs - '((\"example.com\" . \"failure\") - (\".*\" . \"sent-list-catch-all\"))) - (notmuch-mua-mail) - (test-output)" +test_emacs "(let ((notmuch-fcc-dirs + '((\"example.com\" . \"failure\") + (\".*\" . \"sent-list-catch-all\")))) + (notmuch-mua-mail) + (test-output))" cat <EXPECTED From: Notmuch Test Suite To: @@ -220,11 +220,11 @@ EOF test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "notmuch-fcc-dirs set to a list (no match)" -test_emacs "(setq notmuch-fcc-dirs - '((\"example.com\" . \"failure\") - (\"nomatchhere.net\" . \"failure\"))) - (notmuch-mua-mail) - (test-output)" +test_emacs "(let ((notmuch-fcc-dirs + '((\"example.com\" . \"failure\") + (\"nomatchhere.net\" . \"failure\")))) + (notmuch-mua-mail) + (test-output))" cat <EXPECTED From: Notmuch Test Suite To: @@ -253,15 +253,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 -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))' test_expect_equal_file "$EXPECTED/attachment" attachment1.gz 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 "$EXPECTED/attachment" attachment2.gz test_begin_subtest "View raw message within emacs" diff --git a/test/test-lib.el b/test/test-lib.el index 4e7f5cf..a5a3125 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)) diff --git a/test/test-lib.sh b/test/test-lib.sh index ad1506c..1c1581b 100755 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -57,6 +57,9 @@ unset CDPATH unset GREP_OPTIONS +# PID of running Emacs server +emacs_server_pid= + # Convenience # # A regexp to match 5 and 40 hexdigits @@ -174,6 +177,7 @@ test_success=0 die () { code=$? + emacs_server_stop if test -n "$GIT_EXIT_OK" then exit $code @@ -394,19 +398,20 @@ emacs_deliver_message () mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp} ../smtp-dummy sent_message & smtp_dummy_pid=$! - test_emacs "(setq message-send-mail-function 'message-smtpmail-send-it) - (setq smtpmail-smtp-server \"localhost\") - (setq smtpmail-smtp-service \"25025\") - (notmuch-hello) - (notmuch-mua-mail) - (message-goto-to) - (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\") - (message-goto-subject) - (insert \"${subject}\") - (message-goto-body) - (insert \"${body}\") - $@ - (message-send-and-exit)" >/dev/null 2>&1 + test_emacs \ + "(let ((message-send-mail-function 'message-smtpmail-send-it) + (smtpmail-smtp-server \"localhost\") + (smtpmail-smtp-service \"25025\")) + (notmuch-hello) + (notmuch-mua-mail) + (message-goto-to) + (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\") + (message-goto-subject) + (insert \"${subject}\") + (message-goto-body) + (insert \"${body}\") + $@ + (message-send-and-exit))" >/dev/null 2>&1 wait ${smtp_dummy_pid} notmuch new >/dev/null } @@ -828,6 +833,8 @@ test_done () { echo + emacs_server_stop + if [ "$test_failure" = "0" ]; then if [ "$test_broken" = "0" ]; then rm -rf "$remove_tmp" @@ -838,24 +845,26 @@ test_done () { fi } -test_emacs () { - # Construct a little test script here for the benefit of the user, - # (who can easily run "run_emacs" to get the same emacs environment - # for investigating any failures). - cat < run_emacs +# Generate some scripts for running Emacs tests. These scripts are +# used by Emacs tests and help investigating failures. The following +# scripts are generated: +# +# * emacs_server_start - start Emacs server +# * emacs_server_stop - stop Emacs server +# * emacs_start - start Emacs +# * emacs_run - execute ELisp expressions in running Emacs server +emacs_generate_scripts () +{ + server_name="notmuch-test-suite-$$" + + cat < "$TMP_DIRECTORY/emacs_server_start" #!/bin/sh 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: # -# --batch: Quit after given commands and print all (messages) +# --daemon Start Emacs as a daemon # # --no-init-file Don't load users ~/.emacs # @@ -865,13 +874,90 @@ fi # # --load Force loading of notmuch.el and test-lib.el -emacs \$BATCH --no-init-file --no-site-file \ - --directory ../../emacs --load notmuch.el \ - --directory .. --load test-lib.el \ - --eval "(progn \$@)" +emacs --daemon --no-init-file --no-site-file \ + --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \ + --directory "$TEST_DIRECTORY" --load test-lib.el \ + --eval '(setq server-name "$server_name")' +EOF + chmod a+x "$TMP_DIRECTORY/emacs_server_start" + + cat < "$TMP_DIRECTORY/emacs_server_stop" +#!/bin/sh + +dir=\$(dirname "\$0") +"\$dir"/emacs_run '(kill-emacs)' EOF - chmod a+x ./run_emacs - ./run_emacs "$@" + chmod a+x "$TMP_DIRECTORY/emacs_server_stop" + + cat < "$TMP_DIRECTORY/emacs_start" +#!/bin/sh +export PATH=$PATH +export NOTMUCH_CONFIG=$NOTMUCH_CONFIG + +# Here's what we are using here: +# +# --no-init-file Don't load users ~/.emacs +# +# --no-site-file Don't load the site-wide startup stuff +# +# --directory Ensure that the local elisp sources are found +# +# --load Force loading of notmuch.el and test-lib.el + +emacs --no-init-file --no-site-file \ + --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \ + --directory "$TEST_DIRECTORY" --load test-lib.el +EOF + chmod a+x "$TMP_DIRECTORY/emacs_start" + + cat < "$TMP_DIRECTORY/emacs_run" +#!/bin/sh + +# Here's what we are using here: +# +# --socket-name Emacs server name +# +# --eval Evaluate ELisp expressions + +emacsclient --socket-name "$server_name" --eval "(progn \$@)" +EOF + chmod a+x "$TMP_DIRECTORY/emacs_run" +} + +# Start Emacs server if it is not running. +emacs_server_start () +{ + [ -n "$emacs_server_pid" ] && return + + output=$("$TMP_DIRECTORY/emacs_server_start" 2>&1) + if [ "$?" -ne 0 ]; then + echo "$output" + return 1 + fi + + emacs_server_pid=$("$TMP_DIRECTORY/emacs_run" '(emacs-pid)') + [ "$?" -eq 0 -a -n "$emacs_server_pid" ] +} + +# Stop Emacs server if it is running. +emacs_server_stop () +{ + [ -z "$emacs_server_pid" ] && return + + emacs_server_pid= + output=$("$TMP_DIRECTORY/emacs_server_stop" 2>&1) + if [ "$?" -ne 0 ]; then + echo "$output" + return 1 + fi +} + +# Evaluate ELisp expressions in Emacs server. Server is started if it +# is not running. +test_emacs () { + emacs_server_start || return + + "$TMP_DIRECTORY/emacs_run" "$@" } @@ -999,6 +1085,7 @@ primary_email=test_suite@notmuchmail.org other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org EOF +emacs_generate_scripts # Use -P to resolve symlinks in our working directory so that the cwd # in subprocesses like git equals our $PWD (for pathname comparisons). -- 1.7.5.4