Re: [PATCH v4] test: emacs: add test for `notmuch-search-operate-all'
authorPieter Praet <pieter@praet.org>
Wed, 1 Feb 2012 20:32:32 +0000 (21:32 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:54 +0000 (09:43 -0800)
b9/3a683b779cc179dc6515aa5c13dd6384c2bd42 [new file with mode: 0644]

diff --git a/b9/3a683b779cc179dc6515aa5c13dd6384c2bd42 b/b9/3a683b779cc179dc6515aa5c13dd6384c2bd42
new file mode 100644 (file)
index 0000000..71f2693
--- /dev/null
@@ -0,0 +1,260 @@
+Return-Path: <pieter@praet.org>\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 5653B431FAF\r
+       for <notmuch@notmuchmail.org>; Wed,  1 Feb 2012 12:34:38 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 FjafQA4SdCdH for <notmuch@notmuchmail.org>;\r
+       Wed,  1 Feb 2012 12:34:37 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id EFB73431FAE\r
+       for <notmuch@notmuchmail.org>; Wed,  1 Feb 2012 12:34:36 -0800 (PST)\r
+Received: by werb10 with SMTP id b10so1459889wer.26\r
+       for <notmuch@notmuchmail.org>; Wed, 01 Feb 2012 12:34:34 -0800 (PST)\r
+Received: by 10.216.139.25 with SMTP id b25mr10091wej.28.1328128474267;\r
+       Wed, 01 Feb 2012 12:34:34 -0800 (PST)\r
+Received: from localhost ([109.131.39.11])\r
+       by mx.google.com with ESMTPS id di5sm366991wib.3.2012.02.01.12.34.32\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 01 Feb 2012 12:34:33 -0800 (PST)\r
+From: Pieter Praet <pieter@praet.org>\r
+To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+Subject: Re: [PATCH v4] test: emacs: add test for `notmuch-search-operate-all'\r
+In-Reply-To: <87hazamywi.fsf@gmail.com>\r
+References: <1327599289-16865-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327909550-6788-1-git-send-email-pieter@praet.org>\r
+       <87y5spober.fsf@gmail.com> <877h067jn3.fsf@praet.org>\r
+       <87hazamywi.fsf@gmail.com>\r
+User-Agent: Notmuch/0.11+132~ga81001f (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-unknown-linux-gnu)\r
+Date: Wed, 01 Feb 2012 21:32:32 +0100\r
+Message-ID: <87liomb8gv.fsf@praet.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\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: Wed, 01 Feb 2012 20:34:38 -0000\r
+\r
+On Wed, 01 Feb 2012 18:06:05 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:\r
+> On Wed, 01 Feb 2012 14:44:48 +0100, Pieter Praet <pieter@praet.org> wrote:\r
+> > On Mon, 30 Jan 2012 12:13:48 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:\r
+> > > Hi Pieter.\r
+> > > \r
+> > > On Mon, 30 Jan 2012 08:45:50 +0100, Pieter Praet <pieter@praet.org> wrote:\r
+> > > > `notmuch-search-operate-all' (bound to "*") adds and removes tags\r
+> > > > to/from all messages which match the query used to populate the\r
+> > > > current search buffer.\r
+> > > > \r
+> > > > ---\r
+> > > > \r
+> > > > Rebased to current master.\r
+> > > > \r
+> > > > Previous versions (chronologically):\r
+> > > > - id:"1309450108-2793-1-git-send-email-pieter@praet.org"\r
+> > > > - id:"1309762318-4530-5-git-send-email-pieter@praet.org"\r
+> > > > - id:"1310313335-4159-5-git-send-email-pieter@praet.org"\r
+> > > > \r
+> > > \r
+> > > This looks like a useful patch series.  We definitely need more tests\r
+> > > for tagging operations in the Emacs UI.  Do you plan to revive it?\r
+> > > \r
+> > \r
+> > Absolutely.  In fact, it's still alive and kicking on a local branch :)\r
+> > \r
+> > \r
+> > > Note that not so long ago I posted a bunch of tagging-related patches\r
+> > > [1] that would conflict with this patch at least because of\r
+> > > `notmuch-search-operate-all' being renamed to `notmuch-search-tag-all'.\r
+> > > \r
+> > \r
+> > Nice series!  Will probably be pushed in the next few days,\r
+> > so I'll hold off on resubmitting the tests until then.\r
+> > \r
+> > \r
+> > > > \r
+> > > >  test/emacs |   19 +++++++++++++++++++\r
+> > > >  1 files changed, 19 insertions(+), 0 deletions(-)\r
+> > > > \r
+> > > > diff --git a/test/emacs b/test/emacs\r
+> > > > index 8ca4c8a..e94ad94 100755\r
+> > > > --- a/test/emacs\r
+> > > > +++ b/test/emacs\r
+> > > > @@ -124,6 +124,25 @@ test_emacs "(notmuch-show \"$os_x_darwin_thread\")\r
+> > > >  output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)\r
+> > > >  test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"\r
+> > > >  \r
+> > > > +test_begin_subtest "Add/remove tags to/from all matching messages."\r
+> > > > +test_emacs '(notmuch-search "tag:inbox AND tags")\r
+> > > > +          (notmuch-test-wait)\r
+> > > > +          (notmuch-search-operate-all "+matching" "-inbox")\r
+> > > > +          (notmuch-search "tag:matching AND NOT tag:inbox")\r
+> > > > +          (notmuch-test-wait)\r
+> > > > +          (test-output)'\r
+> > > > +cat <<EOF >EXPECTED\r
+> > > > +  2009-11-18 [3/3]   Adrian Perez de Castro, Keith Packard, Carl Worth  [notmuch] Introducing myself (matching signed unread)\r
+> > > > +  2009-11-18 [1/3]   Carl Worth, Israel Herraiz, Keith Packard       [notmuch] New to the list (inbox matching unread)\r
+> > > > +  2009-11-18 [2/2]   Keith Packard, Carl Worth    [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (matching unread)\r
+> > > > +  2009-11-18 [1/2]   Keith Packard, Alexander Botero-Lowry    [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox matching unread)\r
+> > > > +  2009-11-18 [1/1]   Jan Janak            [notmuch] [PATCH] notmuch new: Support for conversion of spool subdirectories into tags (matching unread)\r
+> > > > +  2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH] Fix linking with gcc to use g++ to link in C++ libs. (matching unread)\r
+> > > > +  2009-11-17 [1/2]   Ingmar Vanhassel, Carl Worth  [notmuch] [PATCH] Typsos (inbox matching unread)\r
+> > > > +End of search results.\r
+> > > > +EOF\r
+> > > > +test_expect_equal_file OUTPUT EXPECTED\r
+> > > \r
+> > > I am worried that this test would break because of changes in other\r
+> > > tests.  E.g. if a new test adds a new message which matches "tag:inbox\r
+> > > AND tags", this test would have to be updated.  I think we should avoid\r
+> > > this.  I see the following options here:\r
+> > > \r
+> > > * Search for messages which are less likely to change, e.g. "from:carl".\r
+> > > \r
+> > > * Rework the test to avoid using any fixed expected results, e.g.:\r
+> > > \r
+> > >   - count all messages with tag:inbox\r
+> > > \r
+> > >   - remove inbox tag, add some other distinct tag for all messages with\r
+> > >     tag:inbox\r
+> > > \r
+> > >   - count all messages with tag:inbox again, check that it is 0\r
+> > > \r
+> > >   - add the inbox tag back, remove the previously added tag, check the\r
+> > >     message count\r
+> > > \r
+> > > I like the latter approach because it does not compare Emacs UI output\r
+> > > and hence would not break when that output changes.  What do you think?\r
+> > > \r
+> > > Also, we should leave notmuch db in the same state as it was before the\r
+> > > test if possible.\r
+> > > \r
+> > \r
+> > Good point(s)!\r
+> > \r
+> > How about this:\r
+> > \r
+> >   #+begin_src sh\r
+> >     test_begin_subtest "Add/remove tags to/from all matching messages."\r
+> >     expected=$(notmuch count from:cworth AND tag:inbox)\r
+> >     test "${expected}" == "0" && expected="Need more matches!" # prevent false positives\r
+> >     test_emacs "(notmuch-search \"from:cworth AND tag:inbox\")\r
+> >             (notmuch-test-wait)\r
+> >             (notmuch-search-operate-all \"+matching\" \"-inbox\")"\r
+> >     output=$(notmuch count from:cworth AND tag:matching AND NOT tag:inbox)\r
+> >     notmuch tag -matching +inbox -- from:cworth AND tag:matching AND NOT tag:inbox # restore db state!\r
+> >     test_expect_equal "$output" "$expected"\r
+> >   #+end_src\r
+> > \r
+> \r
+> I think "from:cworth" is not needed here.  In my previous email I meant\r
+> this as an alternative option to testing using counts.\r
+> \r
+\r
+I know, but I decided to include it anyway, on the basis that it\r
+increases the probability of the search buffer containing threads with\r
+matched *as well as* unmatched messages, thus providing more insurance\r
+wrt `notmuch-search-operate-all' doing The Right Thing (TM).\r
+\r
+\r
+> Probably we should add more counts in the test?  E.g.:\r
+> \r
+> * before tagging\r
+>   - count tag:matching, it must be zero\r
+> \r
+> * after -inbox +matching\r
+>   - count tag:matching, it must be equal to $expected\r
+>   - count tag:inbox, it must be zero\r
+> \r
+> * after +inbox -matching\r
+>   - count tag:matching, it must be zero\r
+>   - count tag:inbox, it must be equal to $expected\r
+> \r
+> We can compare it in a single test_expect_equal call.  Actual and\r
+> expected results may be smth like:\r
+> \r
+>   initial tag:matching count: n1\r
+>   tag:inbox count after tagging: n2\r
+>   tag:matching count after tagging: n3\r
+>   tag:inbox count after restoring: n4\r
+>   tag:matching count after restoring: n5\r
+> \r
+> In case of failure, we should get a nice diff.\r
+> \r
+\r
+OK, how about this?:\r
+\r
+  #+begin_src sh\r
+    test_begin_subtest "Add/remove tags to/from all matching messages."\r
+    old="inbox" ; new="xobni" ; filter="AND from:cworth"\r
+    o1=$(notmuch count tag:"${old}" "${filter}") ; n1=$(notmuch count tag:"${new}" "${filter}")\r
+    test "${o1}" == "0" && o1="Need more matches!" # prevent false positives\r
+    test_emacs "(notmuch-search \"tag:${old} ${filter}\")\r
+            (notmuch-test-wait)\r
+            (notmuch-search-operate-all \"+${new}\" \"-${old}\")"\r
+    o2=$(notmuch count tag:"${old}" "${filter}") ; n2=$(notmuch count tag:"${new}" "${filter}")\r
+    notmuch tag -"${new}" +"${old}" -- tag:"${new}" "${filter}" AND NOT tag:"${old}"} # restore db state!\r
+    o3=$(notmuch count tag:"${old}" "${filter}") ; n3=$(notmuch count tag:"${new}" "${filter}")\r
+    output="\r
+    before:   ${old}=$o1 ${new}=$n1\r
+    after:    ${old}=$o2 ${new}=$n2\r
+    restored: ${old}=$o3 ${new}=$n3"\r
+    expected="\r
+    before:   ${old}=$o1 ${new}=0\r
+    after:    ${old}=0 ${new}=$o1\r
+    restored: ${old}=$o1 ${new}=0"\r
+    test_expect_equal "$output" "$expected"\r
+  #+end_src\r
+\r
+\r
+> Regards,\r
+>   Dmitry\r
+> \r
+> > \r
+> > > Regards,\r
+> > >   Dmitry\r
+> > > \r
+> > > [1] id:"1327901644-15799-1-git-send-email-dmitry.kurochkin@gmail.com"\r
+> > > \r
+> > > > +\r
+> > > >  test_begin_subtest "Message with .. in Message-Id:"\r
+> > > >  add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'\r
+> > > >  test_emacs '(notmuch-search "id:\"123..456@example\"")\r
+> > > > -- \r
+> > > > 1.7.8.1\r
+> > > > \r
+> > > _______________________________________________\r
+> > > notmuch mailing list\r
+> > > notmuch@notmuchmail.org\r
+> > > http://notmuchmail.org/mailman/listinfo/notmuch\r
+> > \r
+> > \r
+> > Peace\r
+> > \r
+> > -- \r
+> > Pieter\r
+\r
+\r
+Peace\r
+\r
+-- \r
+Pieter\r