Re: [PATCH 1/3] test: add functions to count how much times notmuch was called
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Mon, 28 Nov 2011 03:09:17 +0000 (07:09 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:27 +0000 (09:40 -0800)
10/b01b8e55ce42a9b2236136ad464940c7a9fffe [new file with mode: 0644]

diff --git a/10/b01b8e55ce42a9b2236136ad464940c7a9fffe b/10/b01b8e55ce42a9b2236136ad464940c7a9fffe
new file mode 100644 (file)
index 0000000..fd427a4
--- /dev/null
@@ -0,0 +1,206 @@
+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 88328429E25\r
+       for <notmuch@notmuchmail.org>; Sun, 27 Nov 2011 19:09:47 -0800 (PST)\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 vMtol-DKMxT4 for <notmuch@notmuchmail.org>;\r
+       Sun, 27 Nov 2011 19:09:46 -0800 (PST)\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 91DD0431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 27 Nov 2011 19:09:46 -0800 (PST)\r
+Received: by bkaq10 with SMTP id q10so8602745bka.26\r
+       for <notmuch@notmuchmail.org>; Sun, 27 Nov 2011 19:09:42 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type;\r
+       bh=KeFMdFbGBvbKXIt8XpoO8gNi3KnfHnMkbdE3ARz4wXw=;\r
+       b=KC4gjj73iz4ycBYGfmGryEKJrdrNPqtWz9FOcT1s0tYTqD8qYp5qynAeHbOuBvJWnt\r
+       caiLslNsAG2R3KMApEzRK/+zJ47IZ9hnlit4mfwjNhL/Ut0azz/YNoUwsUh0wrKLCulw\r
+       MC1wF767w5Mq8O7XzLE+XzIQXYonlLL03ph6k=\r
+Received: by 10.205.135.6 with SMTP id ie6mr15438198bkc.69.1322449780557;\r
+       Sun, 27 Nov 2011 19:09:40 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id e18sm26645663bkr.15.2011.11.27.19.09.39\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sun, 27 Nov 2011 19:09:39 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/3] test: add functions to count how much times notmuch\r
+       was called\r
+In-Reply-To: <87ipm52cfs.fsf@awakening.csail.mit.edu>\r
+References: <1322271878-32614-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <87ipm52cfs.fsf@awakening.csail.mit.edu>\r
+User-Agent: Notmuch/0.10+45~g5da8b3d (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Mon, 28 Nov 2011 07:09:17 +0400\r
+Message-ID: <877h2leyea.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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: Mon, 28 Nov 2011 03:09:47 -0000\r
+\r
+On Sun, 27 Nov 2011 21:44:23 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:\r
+> > The patch adds two auxiliary functions and a variable:\r
+> > \r
+> >   notmuch_counter_reset\r
+> >   $notmuch_counter\r
+> >   notmuch_counter\r
+> > \r
+> > They allow to count how many times notmuch binary is called.\r
+> > notmuch_counter_reset() function generates a script that counts how\r
+> > many times it is called and resets the counter to zero.  The function\r
+> > sets $notmuch_counter variable to the path to the generated script\r
+> > that should be called instead of notmuch to do the counting.  The\r
+> > notmuch_counter() function returns the current counter value.\r
+> \r
+> Great idea!\r
+> \r
+> > ---\r
+> >  test/README      |   16 ++++++++++++++--\r
+> >  test/test-lib.sh |   32 ++++++++++++++++++++++++++++++++\r
+> >  2 files changed, 46 insertions(+), 2 deletions(-)\r
+> > \r
+> > diff --git a/test/README b/test/README\r
+> > index 2481f16..1570f7c 100644\r
+> > --- a/test/README\r
+> > +++ b/test/README\r
+> > @@ -187,8 +187,8 @@ library for your script to use.\r
+> >     is to summarize successes and failures in the test script and\r
+> >     exit with an appropriate error code.\r
+> >  \r
+> > -There are also a number of mail-specific functions which are useful in\r
+> > -writing tests:\r
+> > +There are also a number of notmuch-specific auxiliary functions and\r
+> > +variables which are useful in writing tests:\r
+> >  \r
+> >    generate_message\r
+> >  \r
+> > @@ -212,3 +212,15 @@ writing tests:\r
+> >      will initialize the mail database to a known state of 50 sample\r
+> >      messages, (culled from the early history of the notmuch mailing\r
+> >      list).\r
+> > +\r
+> > +  notmuch_counter_reset\r
+> > +  $notmuch_counter\r
+> > +  notmuch_counter\r
+> \r
+> From the name, I would expect $notmuch_counter to be the counter value\r
+> (ignoring the difficulty of implementing that).  Perhaps\r
+> $notmuch_counter_command, since it's meant to be bound to\r
+> notmuch-command?\r
+> \r
+\r
+renamed\r
+\r
+> notmuch_counter is okay, but maybe notmuch_counter_value?\r
+> \r
+\r
+renamed\r
+\r
+> > +\r
+> > +    These allow to count how many times notmuch binary is called.\r
+> > +    notmuch_counter_reset() function generates a script that counts\r
+> > +    how many times it is called and resets the counter to zero.  The\r
+> > +    function sets $notmuch_counter variable to the path to the\r
+> > +    generated script that should be called instead of notmuch to do\r
+> > +    the counting.  The notmuch_counter() function returns the current\r
+> > +    counter value.\r
+> \r
+> It doesn't return the counter value, it prints it.\r
+> \r
+\r
+indeed, fixed\r
+\r
+> > diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+> > index 93867b0..e3b85d0 100755\r
+> > --- a/test/test-lib.sh\r
+> > +++ b/test/test-lib.sh\r
+> > @@ -864,6 +864,38 @@ test_emacs () {\r
+> >    emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
+> >  }\r
+> >  \r
+> > +# Creates a script that counts how much time it is executed and calls\r
+> > +# notmuch.  $notmuch_counter is set to the path to the generated\r
+> > +# script.  Use notmuch_counter() function to get the current counter\r
+> > +# value.\r
+> > +notmuch_counter_reset () {\r
+> > +  notmuch_counter="$TMP_DIRECTORY/notmuch_counter"\r
+> > +  if [ ! -x "$notmuch_counter" ]; then\r
+> > +          notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"\r
+> > +          cat <<EOF >"$notmuch_counter"\r
+> \r
+> This is totally a stylistic pet peeve, but consider\r
+>   cat >"$notmuch_counter" <<EOF\r
+> \r
+\r
+fixed\r
+\r
+> > +#!/bin/sh\r
+> > +\r
+> > +count=\$(cat "$notmuch_counter_state_path")\r
+> > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"\r
+> > +\r
+> > +exec notmuch "\$@"\r
+> > +EOF\r
+> > +          chmod +x "$notmuch_counter" || return\r
+> > +  fi\r
+> > +\r
+> > +  echo -n 0 > "$notmuch_counter_state_path" || return\r
+> \r
+> What are the || return's for?\r
+> \r
+\r
+If echo failed by some reason, that is an error.\r
+\r
+Thank you for the reviews.  I will send amended series soon.\r
+\r
+Regards,\r
+  Dmitry\r
+\r
+> > +}\r
+> > +\r
+> > +# Returns the current notmuch counter value.\r
+> > +notmuch_counter () {\r
+> > +  if [ -r "$notmuch_counter_state_path" ]; then\r
+> > +          count=$(cat "$notmuch_counter_state_path")\r
+> > +  else\r
+> > +          count=0\r
+> > +  fi\r
+> > +  echo -n $count\r
+> > +}\r
+> > +\r
+> >  \r
+> >  find_notmuch_path ()\r
+> >  {\r
+> > -- \r
+> > 1.7.7.3\r
+> > \r
+> > _______________________________________________\r
+> > notmuch mailing list\r
+> > notmuch@notmuchmail.org\r
+> > http://notmuchmail.org/mailman/listinfo/notmuch\r
+> > \r