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 97FC3429E25 for ; Sun, 27 Nov 2011 18:42:20 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 gRplxTeb3adG for ; Sun, 27 Nov 2011 18:42:19 -0800 (PST) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id C088B431FB6 for ; Sun, 27 Nov 2011 18:42:19 -0800 (PST) X-AuditID: 1209190e-b7f4a6d0000008e5-ef-4ed2f50bc965 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 9B.87.02277.B05F2DE4; Sun, 27 Nov 2011 21:42:19 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id pAS2gIs7007692; Sun, 27 Nov 2011 21:42:19 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pAS2gHKv023245 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 27 Nov 2011 21:42:18 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RUrCh-0000RK-Lj; Sun, 27 Nov 2011 21:44:23 -0500 From: Austin Clements To: Dmitry Kurochkin , notmuch@notmuchmail.org Subject: Re: [PATCH 1/3] test: add functions to count how much times notmuch was called In-Reply-To: <1322271878-32614-1-git-send-email-dmitry.kurochkin@gmail.com> References: <1322271878-32614-1-git-send-email-dmitry.kurochkin@gmail.com> User-Agent: Notmuch/0.9+77~gfdb7dac (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) Date: Sun, 27 Nov 2011 21:44:23 -0500 Message-ID: <87ipm52cfs.fsf@awakening.csail.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLIsWRmVeSWpSXmKPExsUixG6nosv99ZKfwcH/EhZXt/azW1y/OZPZ gclj56y77B7PVt1iDmCK4rJJSc3JLEst0rdL4Mp49m4TS8Fa+YrN/V/YGhjfSXQxcnJICJhI fNiwkRHCFpO4cG89G4gtJLCPUWLOUr4uRi4gewOjxI9b81khnJNMEg/OvGeBqFrCKNF4ORrE ZhPQkNi2fznYJBEBL4lP1zuYQWxhgXCJXfdXAzVzcHAKeEv8/80CYgoBlUxZzgpSISoQK/F2 9kRmkDCLgKrEozP2IGFeoNM2fD7AAmELSpyc+QTMZhbQkrjx7yXTBEaBWUhSs5CkFjAyrWKU Tcmt0s1NzMwpTk3WLU5OzMtLLdI11svNLNFLTSndxAgKRU5Jvh2MXw8qHWIU4GBU4uHluHbJ T4g1say4MvcQoyQHk5Io7+XPQCG+pPyUyozE4oz4otKc1OJDjBIczEoivD1HgXK8KYmVValF +TApaQ4WJXHe1Tsc/IQE0hNLUrNTUwtSi2CyMhwcShK8fl+AGgWLUtNTK9Iyc0oQ0kwcnCDD eYCGd4Es5i0uSMwtzkyHyJ9iVJQS5w0HaRYASWSU5sH1wlLFK0ZxoFeEeZ1BqniAaQau+xXQ YCagwRwzL4AMLklESEk1MIafXG0e/zpAw6pFrKZk0V8xqU29DyX+VfesKSjxM/939aud06N1 jZ3z1+d09Oyb+Gzn5Aneb5Z++f/OKmeHj3mPoURjWYHNk2qHrc/v3T2etsbWoCA1MGfitcJ5 MdcOS/f/WPVyZpzJUSODCwI/nrZ9bX60u/zkGRdhn/qLUusN5/wNYzk+97wSS3FGoqEWc1Fx IgDEzyk08AIAAA== 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, 28 Nov 2011 02:42:20 -0000 On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin wrote: > The patch adds two auxiliary functions and a variable: > > notmuch_counter_reset > $notmuch_counter > notmuch_counter > > They allow to count how many times notmuch binary is called. > notmuch_counter_reset() function generates a script that counts how > many times it is called and resets the counter to zero. The function > sets $notmuch_counter variable to the path to the generated script > that should be called instead of notmuch to do the counting. The > notmuch_counter() function returns the current counter value. Great idea! > --- > test/README | 16 ++++++++++++++-- > test/test-lib.sh | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 46 insertions(+), 2 deletions(-) > > diff --git a/test/README b/test/README > index 2481f16..1570f7c 100644 > --- a/test/README > +++ b/test/README > @@ -187,8 +187,8 @@ library for your script to use. > is to summarize successes and failures in the test script and > exit with an appropriate error code. > > -There are also a number of mail-specific functions which are useful in > -writing tests: > +There are also a number of notmuch-specific auxiliary functions and > +variables which are useful in writing tests: > > generate_message > > @@ -212,3 +212,15 @@ writing tests: > will initialize the mail database to a known state of 50 sample > messages, (culled from the early history of the notmuch mailing > list). > + > + notmuch_counter_reset > + $notmuch_counter > + notmuch_counter >From the name, I would expect $notmuch_counter to be the counter value (ignoring the difficulty of implementing that). Perhaps $notmuch_counter_command, since it's meant to be bound to notmuch-command? notmuch_counter is okay, but maybe notmuch_counter_value? > + > + These allow to count how many times notmuch binary is called. > + notmuch_counter_reset() function generates a script that counts > + how many times it is called and resets the counter to zero. The > + function sets $notmuch_counter variable to the path to the > + generated script that should be called instead of notmuch to do > + the counting. The notmuch_counter() function returns the current > + counter value. It doesn't return the counter value, it prints it. > diff --git a/test/test-lib.sh b/test/test-lib.sh > index 93867b0..e3b85d0 100755 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -864,6 +864,38 @@ test_emacs () { > emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)" > } > > +# Creates a script that counts how much time it is executed and calls > +# notmuch. $notmuch_counter is set to the path to the generated > +# script. Use notmuch_counter() function to get the current counter > +# value. > +notmuch_counter_reset () { > + notmuch_counter="$TMP_DIRECTORY/notmuch_counter" > + if [ ! -x "$notmuch_counter" ]; then > + notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state" > + cat <"$notmuch_counter" This is totally a stylistic pet peeve, but consider cat >"$notmuch_counter" < +#!/bin/sh > + > +count=\$(cat "$notmuch_counter_state_path") > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path" > + > +exec notmuch "\$@" > +EOF > + chmod +x "$notmuch_counter" || return > + fi > + > + echo -n 0 > "$notmuch_counter_state_path" || return What are the || return's for? > +} > + > +# Returns the current notmuch counter value. > +notmuch_counter () { > + if [ -r "$notmuch_counter_state_path" ]; then > + count=$(cat "$notmuch_counter_state_path") > + else > + count=0 > + fi > + echo -n $count > +} > + > > find_notmuch_path () > { > -- > 1.7.7.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch >