Re: [PATCH] test: whitespace-cleanup for most test/* files
[notmuch-archives.git] / d1 / d545aa79c4366d579510b24eb9f15faeefa2ef
1 Return-Path: <tomi.ollila@nixu.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id A9885429E21\r
6         for <notmuch@notmuchmail.org>; Mon, 28 Nov 2011 12:42:56 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id OnhbzEugVe5F for <notmuch@notmuchmail.org>;\r
16         Mon, 28 Nov 2011 12:42:55 -0800 (PST)\r
17 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 60D44431FB6\r
21         for <notmuch@notmuchmail.org>; Mon, 28 Nov 2011 12:42:55 -0800 (PST)\r
22 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31])\r
23         by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id\r
24         pASKgp8a018102; Mon, 28 Nov 2011 22:42:52 +0200\r
25 From: Tomi Ollila <tomi.ollila@iki.fi>\r
26 To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>, notmuch@notmuchmail.org\r
27 Subject: Re: [PATCH 1/3] test: add functions to count how much times notmuch\r
28         was called\r
29 In-Reply-To: <1322450895-32523-2-git-send-email-dmitry.kurochkin@gmail.com>\r
30 References: <1322271878-32614-1-git-send-email-dmitry.kurochkin@gmail.com>\r
31         <1322450895-32523-1-git-send-email-dmitry.kurochkin@gmail.com>\r
32         <1322450895-32523-2-git-send-email-dmitry.kurochkin@gmail.com>\r
33 User-Agent: Notmuch/0.10+15~gb5803e9 (http://notmuchmail.org) Emacs/23.3.1\r
34         (i686-pc-linux-gnu)\r
35 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
36         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
37         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
38 Date: Mon, 28 Nov 2011 22:42:50 +0200\r
39 Message-ID: <yf6aa7gj7w5.fsf@taco2.nixu.fi>\r
40 MIME-Version: 1.0\r
41 Content-Type: text/plain; charset=us-ascii\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Mon, 28 Nov 2011 20:42:56 -0000\r
55 \r
56 On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:\r
57 \r
58 [...]\r
59 > +\r
60 > +    These allow to count how many times notmuch binary is called.\r
61 > +    notmuch_counter_reset() function generates a script that counts\r
62 > +    how many times it is called and resets the counter to zero.  The\r
63 > +    function sets $notmuch_counter_command variable to the path to the\r
64 > +    generated script that should be called instead of notmuch to do\r
65 > +    the counting.  The notmuch_counter_value() function prints the\r
66 > +    current counter value.\r
67 > diff --git a/test/test-lib.sh b/test/test-lib.sh\r
68 > index 076f929..880bed9 100644\r
69 > --- a/test/test-lib.sh\r
70 > +++ b/test/test-lib.sh\r
71 > @@ -868,6 +868,38 @@ test_emacs () {\r
72 >       emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
73 >  }\r
74 >  \r
75 > +# Creates a script that counts how much time it is executed and calls\r
76 > +# notmuch.  $notmuch_counter_command is set to the path to the\r
77 > +# generated script.  Use notmuch_counter_value() function to get the\r
78 > +# current counter value.\r
79 > +notmuch_counter_reset () {\r
80 > +     notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"\r
81 > +     if [ ! -x "$notmuch_counter_command" ]; then\r
82 > +             notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"\r
83 > +             cat >"$notmuch_counter_command" <<EOF || return\r
84 > +#!/bin/sh\r
85 > +\r
86 > +count=\$(cat "$notmuch_counter_state_path")\r
87 > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"\r
88 > +\r
89 > +exec notmuch "\$@"\r
90 > +EOF\r
91 > +             chmod +x "$notmuch_counter_command" || return\r
92 > +     fi\r
93 > +\r
94 > +     echo -n 0 > "$notmuch_counter_state_path"\r
95 > +}\r
96 > +\r
97 > +# Returns the current notmuch counter value.\r
98 > +notmuch_counter_value () {\r
99 > +     if [ -r "$notmuch_counter_state_path" ]; then\r
100 > +             count=$(cat "$notmuch_counter_state_path")\r
101 > +     else\r
102 > +             count=0\r
103 > +     fi\r
104 > +     echo -n $count\r
105 > +}\r
106 > +\r
107 \r
108 Good work! It would be nice if the state file contained newline after\r
109 count number. Also some optimizations could be done:\r
110 \r
111                 cat >"$notmuch_counter_command" <<EOF || return\r
112 #!/bin/sh\r
113 \r
114 read count < "$notmuch_counter_state_path"\r
115 echo \$((count + 1)) > "$notmuch_counter_state_path"\r
116 \r
117 exec notmuch "\$@"\r
118 EOF\r
119                 chmod +x "$notmuch_counter_command" || return\r
120         fi\r
121 \r
122         echo 0 > "$notmuch_counter_state_path"\r
123 }\r
124 \r
125 # Returns the current notmuch counter value.\r
126 notmuch_counter_value () {\r
127         if [ -r "$notmuch_counter_state_path" ]; then\r
128                 read count < "$notmuch_counter_state_path"\r
129         else\r
130                 count=0\r
131         fi\r
132         echo -n $count\r
133 }\r
134 \r
135 \r
136 Tomi\r