[PATCH 05/10] test: save buffer content to file instead of printing it in Emacs tests
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Tue, 28 Jun 2011 04:45:06 +0000 (08:45 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:45 +0000 (09:38 -0800)
88/b5a90c84d719e866bba35ad4209f5a91bc90c2 [new file with mode: 0644]

diff --git a/88/b5a90c84d719e866bba35ad4209f5a91bc90c2 b/88/b5a90c84d719e866bba35ad4209f5a91bc90c2
new file mode 100644 (file)
index 0000000..233187a
--- /dev/null
@@ -0,0 +1,351 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E5268429E55\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:51 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id YYSjoTYwqnx0 for <notmuch@notmuchmail.org>;\r
+       Mon, 27 Jun 2011 21:45:48 -0700 (PDT)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 0F758429E5F\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:39 -0700 (PDT)\r
+Received: by mail-bw0-f53.google.com with SMTP id 12so4889638bwg.26\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Jun 2011 21:45:39 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer\r
+       :in-reply-to:references;\r
+       bh=pm0aFxaQum1kNeC/55I0oVNIZz07fa4L4p2a+KOIdTs=;\r
+       b=YN1VSYGMdyWWI/9w2RP60s/kYvvm5e7mUf7PVSoKLUy3LL8KNbcv9MkzSsOVyZIYSv\r
+       5nm9gIcYFJ91ach8dOjMIv/LS4mTTYGBBbl4rgH/R7EYsq8FvevuaQ6lSs5hN8kS5Dlj\r
+       9k2RPQrgHVawSxq3aqaDEpmubVjLAihGJc8sY=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       b=Wl3jMaZOtQUuw40On/qRN+4OlxtUJMIcOGHPp0PitX4vAwpMqy4aV8AddOKPbZm5ZM\r
+       RYbp8QYGUgXjpB3+cTZUJTerNgYBOZoOxitBwBFPhIN2UNpaDypEsrHhQv4Lr9kEgnB3\r
+       IoSQXfioSI4/llNsTRuVM6lcM1Imehh960s40=\r
+Received: by 10.204.40.80 with SMTP id j16mr5093916bke.107.1309236338656;\r
+       Mon, 27 Jun 2011 21:45:38 -0700 (PDT)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id l24sm4742272bkw.15.2011.06.27.21.45.37\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 27 Jun 2011 21:45:38 -0700 (PDT)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 05/10] test: save buffer content to file instead of printing\r
+       it in Emacs tests\r
+Date: Tue, 28 Jun 2011 08:45:06 +0400\r
+Message-Id: <1309236311-2162-5-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1309236311-2162-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1309236311-2162-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 28 Jun 2011 04:45:52 -0000\r
+\r
+Before the change, the common Emacs test scheme was to print\r
+buffer content to stdout and redirect it to a file or capture it\r
+in a shell variable.  This does not work if we switch to using\r
+emacsclient(1) for running the tests, because you can not print\r
+to the stdout in this case. (Actually, you can print to stdout\r
+from Emacs server, but you can not capture the output on\r
+emacsclient(1)).\r
+\r
+The patch introduces new Emacs test auxiliary functions:\r
+`test-output' and `test-visible-output'.  These functions are\r
+used to save buffer content to a file directly from Emacs.  For\r
+most tests the changes are trivial, because Emacs stdout output\r
+was redirected to a file anyway.  But some tests captured the\r
+output in a shell variable and compare it with the expected\r
+output using test_expect_equal.  These tests are changed to use\r
+files and test_expect_equal_file instead.\r
+\r
+Note: even if we do not switch Emacs tests to emacsclient(1), the\r
+patch makes tests cleaner and is an improvement.\r
+---\r
+ test/emacs                     |   71 ++++++++++++++++++++-------------------\r
+ test/emacs-large-search-buffer |   23 +++++++++----\r
+ test/test-lib.el               |   10 ++++++\r
+ 3 files changed, 62 insertions(+), 42 deletions(-)\r
+\r
+diff --git a/test/emacs b/test/emacs\r
+index fddb4a1..8f8b841 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -8,7 +8,7 @@ add_email_corpus\r
\r
+ test_begin_subtest "Basic notmuch-hello view in emacs"\r
+ test_emacs '(notmuch-hello)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello\r
\r
+ test_begin_subtest "Saved search with 0 results"\r
+@@ -18,20 +18,20 @@ test_emacs '(setq notmuch-show-empty-saved-searches t)\r
+                      ("unread" . "tag:unread")\r
+                      ("empty" . "tag:doesnotexist")))\r
+           (notmuch-hello)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty\r
\r
+ test_begin_subtest "No saved searches displayed (all with 0 results)"\r
+ test_emacs '(setq notmuch-saved-searches\r
+                 '\''(("empty" . "tag:doesnotexist")))\r
+           (notmuch-hello)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches\r
\r
+ test_begin_subtest "Basic notmuch-search view in emacs"\r
+ test_emacs '(notmuch-search "tag:inbox")\r
+           (notmuch-test-wait)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox\r
\r
+ test_begin_subtest "Navigation of notmuch-hello to search results"\r
+@@ -40,27 +40,30 @@ test_emacs '(notmuch-hello)\r
+           (re-search-forward "inbox")\r
+           (widget-button-press (point))\r
+           (notmuch-test-wait)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox\r
\r
+ test_begin_subtest "Basic notmuch-show view in emacs"\r
+ maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)\r
+ test_emacs "(notmuch-show \"$maildir_storage_thread\")\r
+-          (princ (buffer-string))" >OUTPUT\r
++          (test-output)"\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage\r
\r
+ test_begin_subtest "notmuch-show for message with invalid From"\r
+ add_message "[subject]=\"message-with-invalid-from\"" \\r
+           "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""\r
+ thread=$(notmuch search --output=threads subject:message-with-invalid-from)\r
+-output=$(test_emacs "(notmuch-show \"$thread\") (princ (buffer-string))")\r
+-test_expect_equal "$output" \\r
+-'"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)\r
++test_emacs "(notmuch-show \"$thread\")\r
++          (test-output)"\r
++cat <<EOF >EXPECTED\r
++"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)\r
+ Subject: message-with-invalid-from\r
+ To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ Date: Tue, 05 Jan 2001 15:43:57 -0000\r
\r
+-This is just a test message (#1)'\r
++This is just a test message (#1)\r
++EOF\r
++test_expect_equal_file OUTPUT EXPECTED\r
\r
+ test_begin_subtest "Navigation of notmuch-search to thread view"\r
+ test_emacs '(notmuch-search "tag:inbox")\r
+@@ -69,7 +72,7 @@ test_emacs '(notmuch-search "tag:inbox")\r
+           (re-search-forward "Working with Maildir")\r
+           (notmuch-search-show-thread)\r
+           (notmuch-test-wait)\r
+-          (princ (buffer-string))' >OUTPUT\r
++          (test-output)'\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage\r
\r
+ test_begin_subtest "Add tag from search view"\r
+@@ -162,7 +165,7 @@ test_expect_equal "$output" "thread:XXX   1974-03-29 [1/1] Notmuch Test Suite; T\r
+ test_begin_subtest "notmuch-fcc-dirs set to nil"\r
+ test_emacs "(setq notmuch-fcc-dirs nil)\r
+           (notmuch-mua-mail)\r
+-          (princ (buffer-string))" > OUTPUT\r
++          (test-output)"\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: \r
+@@ -179,7 +182,7 @@ mkdir -p mail/sent-string/tmp\r
+ test_begin_subtest "notmuch-fcc-dirs set to a string"\r
+ test_emacs "(setq notmuch-fcc-dirs \"sent-string\")\r
+           (notmuch-mua-mail)\r
+-          (princ (buffer-string))" > OUTPUT\r
++          (test-output)"\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: \r
+@@ -202,7 +205,7 @@ test_emacs "(setq notmuch-fcc-dirs\r
+                 '((\"notmuchmail.org\" . \"sent-list-match\")\r
+                   (\".*\" . \"failure\")))\r
+           (notmuch-mua-mail)\r
+-          (princ (buffer-string))" > OUTPUT\r
++          (test-output)"\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: \r
+@@ -222,7 +225,7 @@ test_emacs "(setq notmuch-fcc-dirs\r
+                 '((\"example.com\" . \"failure\")\r
+                   (\".*\" . \"sent-list-catch-all\")))\r
+           (notmuch-mua-mail)\r
+-          (princ (buffer-string))" > OUTPUT\r
++          (test-output)"\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: \r
+@@ -237,7 +240,7 @@ test_emacs "(setq notmuch-fcc-dirs\r
+                 '((\"example.com\" . \"failure\")\r
+                   (\"nomatchhere.net\" . \"failure\")))\r
+           (notmuch-mua-mail)\r
+-          (princ (buffer-string))" > OUTPUT\r
++          (test-output)"\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: \r
+@@ -252,9 +255,9 @@ test_begin_subtest "Reply within emacs"\r
+ test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")\r
+           (notmuch-test-wait)\r
+           (notmuch-search-reply-to-thread)\r
+-          (princ (buffer-string))' |\r
+-sed -ne '/^From/,$ p' |\r
+-sed -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' >OUTPUT\r
++          (test-output)'\r
++sed -i -ne '/^From/,$ p' OUTPUT\r
++sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT\r
+ cat <<EOF >EXPECTED\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ To: user@example.com\r
+@@ -284,8 +287,8 @@ test_begin_subtest "View raw message within emacs"\r
+ first_line=$(head -n1 $EXPECTED/raw-message-cf0c4d-52ad0a)\r
+ test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")\r
+           (notmuch-show-view-raw-message)\r
+-          (princ (buffer-string))' |\r
+-sed -ne "/$first_line/,\$ p" >OUTPUT\r
++          (test-output)'\r
++sed -i -ne "/$first_line/,\$ p" OUTPUT\r
+ test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a\r
\r
+ test_begin_subtest "Hiding/showing signature in notmuch-show view"\r
+@@ -295,7 +298,7 @@ test_emacs "(notmuch-show \"$maildir_storage_thread\")\r
+           (button-activate (button-at (point)))\r
+           (search-backward \"Click/Enter to hide.\")\r
+           (button-activate (button-at (point)))\r
+-          (princ (buffer-string))" >OUTPUT\r
++          (test-output)"\r
+ test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage\r
\r
+ test_begin_subtest "Detection and hiding of top-post quoting of message"\r
+@@ -323,7 +326,7 @@ Q: Why is top-posting such a bad thing?\r
+ A: Top-posting.\r
+ Q: What is the most annoying thing in e-mail?"'\r
+ test_emacs "(notmuch-show \"top-posting\")\r
+-          (princ (visible-buffer-string))" >OUTPUT\r
++          (test-visible-output)"\r
+ echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)\r
+ Subject: The problem with top-posting\r
+ To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+@@ -346,19 +349,17 @@ Thanks for the advice! I will be sure to put it to good use.\r
+ test_expect_equal_file OUTPUT EXPECTED\r
\r
+ test_begin_subtest "Hiding message in notmuch-show view"\r
+-output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")\r
+-                   (notmuch-show-toggle-message)\r
+-                   (princ (visible-buffer-string))')\r
+-expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)\r
+-test_expect_equal "$output" "$expected"\r
++test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")\r
++          (notmuch-show-toggle-message)\r
++          (test-visible-output)'\r
++test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages\r
\r
+ test_begin_subtest "Hiding message with visible citation in notmuch-show view"\r
+-output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")\r
+-                   (search-forward "Click/Enter to show.")\r
+-                   (button-activate (button-at (point)))\r
+-                   (notmuch-show-toggle-message)\r
+-                   (princ (visible-buffer-string))')\r
+-expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)\r
+-test_expect_equal "$output" "$expected"\r
++test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")\r
++          (search-forward "Click/Enter to show.")\r
++          (button-activate (button-at (point)))\r
++          (notmuch-show-toggle-message)\r
++          (test-visible-output)'\r
++test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages\r
\r
+ test_done\r
+diff --git a/test/emacs-large-search-buffer b/test/emacs-large-search-buffer\r
+index c78ce33..6095e9d 100755\r
+--- a/test/emacs-large-search-buffer\r
++++ b/test/emacs-large-search-buffer\r
+@@ -19,16 +19,25 @@ done\r
+ notmuch new > /dev/null\r
\r
+ test_begin_subtest "Ensure that emacs doesn't drop results"\r
+-expected="$(notmuch search '*' | sed -e 's/^thread:[0-9a-f]*  //' -e 's/;//' -e  's/xx*/[BLOB]/')\r
+-End of search results."\r
++notmuch search '*' > EXPEXTED\r
++sed -i -e 's/^thread:[0-9a-f]*  //' -e 's/;//' -e 's/xx*/[BLOB]/' EXPEXTED\r
++echo 'End of search results.' >> EXPEXTED\r
\r
+-output=$(test_emacs '(notmuch-search "*") (notmuch-test-wait) (princ (buffer-string))' | sed -e s',  *, ,g' -e 's/xxx*/[BLOB]/g')\r
+-test_expect_equal "$output" "$expected"\r
++test_emacs '(notmuch-search "*")\r
++          (notmuch-test-wait)\r
++          (test-output)'\r
++sed -i -e s',  *, ,g' -e 's/xxx*/[BLOB]/g' OUTPUT\r
++test_expect_equal_file OUTPUT EXPEXTED\r
\r
+ test_begin_subtest "Ensure that emacs doesn't drop error messages"\r
+-output=$(test_emacs '(notmuch-search "--this-option-does-not-exist") (notmuch-test-wait) (princ (buffer-string))')\r
+-test_expect_equal "$output" "Error: Unexpected output from notmuch search:\r
++test_emacs '(notmuch-search "--this-option-does-not-exist")\r
++          (notmuch-test-wait)\r
++          (test-output)'\r
++cat <<EOF >EXPEXTED\r
++Error: Unexpected output from notmuch search:\r
+ Unrecognized option: --this-option-does-not-exist\r
+-End of search results. (process returned 1)"\r
++End of search results. (process returned 1)\r
++EOF\r
++test_expect_equal_file OUTPUT EXPEXTED\r
\r
+ test_done\r
+diff --git a/test/test-lib.el b/test/test-lib.el\r
+index 344a02e..4e7f5cf 100644\r
+--- a/test/test-lib.el\r
++++ b/test/test-lib.el\r
+@@ -28,6 +28,16 @@\r
+   (while (get-buffer-process (current-buffer))\r
+     (sleep-for 0.1)))\r
\r
++(defun test-output (&optional filename)\r
++  "Save current buffer to file FILENAME.  Default FILENAME is OUTPUT."\r
++  (write-region (point-min) (point-max) (or filename "OUTPUT")))\r
++\r
++(defun test-visible-output (&optional filename)\r
++  "Save visible text in current buffer to file FILENAME.  Default\r
++FILENAME is OUTPUT."\r
++  (let ((text (visible-buffer-string)))\r
++    (with-temp-file (or filename "OUTPUT") (insert text))))\r
++\r
+ (defun visible-buffer-string ()\r
+   "Same as `buffer-string', but excludes invisible text."\r
+   (visible-buffer-substring (point-min) (point-max)))\r
+-- \r
+1.7.5.4\r
+\r