Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 9e / 78eef0742edfd45306f352098fae13db1310a8
1 Return-Path: <dmitry.kurochkin@gmail.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 16E4A429E36\r
6         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 05:06:38 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id m3TCdw6Rmngp for <notmuch@notmuchmail.org>;\r
17         Thu, 17 Nov 2011 05:06:35 -0800 (PST)\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
19         [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id BBEE9429E2F\r
22         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 05:06:33 -0800 (PST)\r
23 Received: by mail-bw0-f53.google.com with SMTP id q10so2108290bka.26\r
24         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 05:06:33 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=sgvjV8pNBcbjF8VaZx4MhRFstc/3JADC8zbMoeNmZCI=;\r
28         b=Qag1+F5Firi3m2JPS4wEAHcTNroOYdG5nj+NI6HyB7tnubBCCYlbNX4rFBtLgeJQLc\r
29         ZFI7qdar1Kwe+vFBhLdIq09BCHbbQ896O+1Njr70EkgoUALFa60oBMHT4PLlXdwpEV9G\r
30         f+t2wsiiq4Nxxfpyw/vx36jba5m+QRchZogL4=\r
31 Received: by 10.205.132.16 with SMTP id hs16mr33395740bkc.7.1321535193486;\r
32         Thu, 17 Nov 2011 05:06:33 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21])\r
34         by mx.google.com with ESMTPS id o7sm31264515bkw.16.2011.11.17.05.06.32\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Thu, 17 Nov 2011 05:06:32 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2 04/10] test: add support for external executable\r
40         dependencies\r
41 Date: Thu, 17 Nov 2011 17:05:57 +0400\r
42 Message-Id: <1321535163-4895-5-git-send-email-dmitry.kurochkin@gmail.com>\r
43 X-Mailer: git-send-email 1.7.7.2\r
44 In-Reply-To: <1321535163-4895-1-git-send-email-dmitry.kurochkin@gmail.com>\r
45 References: <1321535163-4895-1-git-send-email-dmitry.kurochkin@gmail.com>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Thu, 17 Nov 2011 13:06:38 -0000\r
59 \r
60 There is existing support for general prerequisites in the test suite.\r
61 But it is not very convenient to use: every test case has to keep\r
62 track for it's dependencies and they have to be explicitly listed.\r
63 \r
64 The patch aims to add better support for a particular type of external\r
65 dependencies: external executables.  The main idea is to replace\r
66 missing external binaries with shell functions that have the same\r
67 name.  These functions always fail and keep track of missing\r
68 dependencies for a subtest.  The result reporting functions later can\r
69 check that an external binaries are missing and correctly report SKIP\r
70 result instead of FAIL.  The primary benefit is that the test cases do\r
71 not need to declare their dependencies or be changed in any way.\r
72 ---\r
73  test/test-lib.sh |   49 +++++++++++++++++++++++++++++++++++++++++--------\r
74  1 files changed, 41 insertions(+), 8 deletions(-)\r
75 \r
76 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
77 index f21e45e..625d19b 100755\r
78 --- a/test/test-lib.sh\r
79 +++ b/test/test-lib.sh\r
80 @@ -526,40 +526,53 @@ notmuch_json_show_sanitize ()\r
81  # - Implicitly by specifying the prerequisite tag in the calls to\r
82  #   test_expect_{success,failure,code}.\r
83  #\r
84  # The single parameter is the prerequisite tag (a simple word, in all\r
85  # capital letters by convention).\r
86  \r
87  test_set_prereq () {\r
88         satisfied="$satisfied$1 "\r
89  }\r
90  satisfied=" "\r
91  \r
92  test_have_prereq () {\r
93         case $satisfied in\r
94         *" $1 "*)\r
95                 : yes, have it ;;\r
96         *)\r
97                 ! : nope ;;\r
98         esac\r
99  }\r
100  \r
101 +# declare prerequisite for the given external binary\r
102 +test_declare_external_prereq () {\r
103 +       binary="$1"\r
104 +       test "$#" = 2 && name=$2 || name="$binary(1)"\r
105 +\r
106 +       hash $binary 2>/dev/null || eval "\r
107 +$binary () {\r
108 +       echo -n \"\$test_subtest_missing_external_prereqs_\" | grep -e \" $name \" ||\r
109 +       test_subtest_missing_external_prereqs_=\"$test_subtest_missing_external_prereqs_ $name\"\r
110 +       false\r
111 +}"\r
112 +}\r
113 +\r
114  # You are not expected to call test_ok_ and test_failure_ directly, use\r
115  # the text_expect_* functions instead.\r
116  \r
117  test_ok_ () {\r
118         if test "$test_subtest_known_broken_" = "t"; then\r
119                 test_known_broken_ok_ "$@"\r
120                 return\r
121         fi\r
122         test_success=$(($test_success + 1))\r
123         say_color pass "%-6s" "PASS"\r
124         echo " $@"\r
125  }\r
126  \r
127  test_failure_ () {\r
128         if test "$test_subtest_known_broken_" = "t"; then\r
129                 test_known_broken_failure_ "$@"\r
130                 return\r
131         fi\r
132         test_failure=$(($test_failure + 1))\r
133         test_failure_message_ "FAIL" "$@"\r
134 @@ -602,82 +615,101 @@ test_run_ () {\r
135         return 0\r
136  }\r
137  \r
138  test_skip () {\r
139         test_count=$(($test_count+1))\r
140         to_skip=\r
141         for skp in $NOTMUCH_SKIP_TESTS\r
142         do\r
143                 case $this_test.$test_count in\r
144                 $skp)\r
145                         to_skip=t\r
146                 esac\r
147         done\r
148         if test -z "$to_skip" && test -n "$prereq" &&\r
149            ! test_have_prereq "$prereq"\r
150         then\r
151                 to_skip=t\r
152         fi\r
153         case "$to_skip" in\r
154         t)\r
155 -               test_reset_state_\r
156 -               say_color skip >&3 "skipping test: $@"\r
157 -               say_color skip "%-6s" "SKIP"\r
158 -               echo " $1"\r
159 -               : true\r
160 +               test_report_skip_ "$@"\r
161                 ;;\r
162         *)\r
163 -               false\r
164 +               test_check_missing_external_prereqs_ "$@"\r
165                 ;;\r
166         esac\r
167  }\r
168  \r
169 +test_check_missing_external_prereqs_ () {\r
170 +       if test -n "$test_subtest_missing_external_prereqs_"; then\r
171 +               say_color skip >&3 "missing prerequisites:"\r
172 +               echo "$test_subtest_missing_external_prereqs_" >&3\r
173 +               test_report_skip_ "$@"\r
174 +       else\r
175 +               false\r
176 +       fi\r
177 +}\r
178 +\r
179 +test_report_skip_ () {\r
180 +       test_reset_state_\r
181 +       say_color skip >&3 "skipping test: $@"\r
182 +       say_color skip "%-6s" "SKIP"\r
183 +       echo " $1"\r
184 +}\r
185 +\r
186  test_subtest_known_broken () {\r
187         test_subtest_known_broken_=t\r
188  }\r
189  \r
190  test_expect_success () {\r
191         test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
192         test "$#" = 2 ||\r
193         error "bug in the test script: not 2 or 3 parameters to test-expect-success"\r
194         test_reset_state_\r
195         if ! test_skip "$@"\r
196         then\r
197                 test_run_ "$2"\r
198 -               if [ "$?" = 0 -a "$eval_ret" = 0 ]\r
199 +               run_ret="$?"\r
200 +               # test_run_ may update missing external prerequisites\r
201 +               test_check_missing_external_prereqs_ "$@" ||\r
202 +               if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]\r
203                 then\r
204                         test_ok_ "$1"\r
205                 else\r
206                         test_failure_ "$@"\r
207                 fi\r
208         fi\r
209  }\r
210  \r
211  test_expect_code () {\r
212         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
213         test "$#" = 3 ||\r
214         error "bug in the test script: not 3 or 4 parameters to test-expect-code"\r
215         test_reset_state_\r
216         if ! test_skip "$@"\r
217         then\r
218                 test_run_ "$3"\r
219 -               if [ "$?" = 0 -a "$eval_ret" = "$1" ]\r
220 +               run_ret="$?"\r
221 +               # test_run_ may update missing external prerequisites,\r
222 +               test_check_missing_external_prereqs_ "$@" ||\r
223 +               if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]\r
224                 then\r
225                         test_ok_ "$2"\r
226                 else\r
227                         test_failure_ "$@"\r
228                 fi\r
229         fi\r
230  }\r
231  \r
232  # test_external runs external test scripts that provide continuous\r
233  # test output about their progress, and succeeds/fails on\r
234  # zero/non-zero exit code.  It outputs the test output on stdout even\r
235  # in non-verbose mode, and announces the external script with "* run\r
236  # <n>: ..." before running it.  When providing relative paths, keep in\r
237  # mind that all scripts run in "trash directory".\r
238  # Usage: test_external description command arguments...\r
239  # Example: test_external 'Perl API' perl ../path/to/test.pl\r
240  test_external () {\r
241         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
242         test "$#" = 3 ||\r
243         error >&5 "bug in the test script: not 3 or 4 parameters to test_external"\r
244 @@ -848,40 +880,41 @@ test_emacs () {\r
245                 # user's TERM is given to dtach which assumes a minimally\r
246                 # VT100-compatible terminal -- and emacs inherits that\r
247                 TERM=$ORIGINAL_TERM dtach -n "$TMP_DIRECTORY/emacs-dtach-socket.$$" \\r
248                         sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \\r
249                                 --no-window-system \\r
250                                 --eval '(setq server-name \"$server_name\")' \\r
251                                 --eval '(server-start)' \\r
252                                 --eval '(orphan-watchdog $$)'" || return\r
253                 EMACS_SERVER="$server_name"\r
254                 # wait until the emacs server is up\r
255                 until test_emacs '()' 2>/dev/null; do\r
256                         sleep 1\r
257                 done\r
258         fi\r
259  \r
260         emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
261  }\r
262  \r
263  test_reset_state_ () {\r
264         test_subtest_known_broken_=\r
265 +       test_subtest_missing_external_prereqs_=\r
266  }\r
267  \r
268  \r
269  find_notmuch_path ()\r
270  {\r
271      dir="$1"\r
272  \r
273      while [ -n "$dir" ]; do\r
274         bin="$dir/notmuch"\r
275         if [ -x "$bin" ]; then\r
276             echo "$dir"\r
277             return\r
278         fi\r
279         dir="$(dirname "$dir")"\r
280         if [ "$dir" = "/" ]; then\r
281             break\r
282         fi\r
283      done\r
284  }\r
285  \r
286 -- \r
287 1.7.7.2\r
288 \r