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 7274D429E2E
\r
6 for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:57:07 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 aa18-wP9EFfC for <notmuch@notmuchmail.org>;
\r
17 Wed, 16 Nov 2011 17:57:04 -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 BD6C3429E39
\r
22 for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:56:56 -0800 (PST)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id q10so1456807bka.26
\r
24 for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:56:56 -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=LGlH135A5PBHZD5TmjaxaIQwi1a4gGc2zhsQSt4gfHo=;
\r
28 b=fLNqGh+6xhD0OIe9RWFoVuWp98yni4Tjpe2bJaQktM0WIvsy3eqv3HzKjFw2osqzyR
\r
29 hjYvNAcnQvYghz+ldu5U6trNrYnCZITiVnSWYBPz4z9wTeFMksH43348zxYB9Cbpkkip
\r
30 K6rZ1LGtaLM6VpeYPOx0MXBM692eSwbKCctBc=
\r
31 Received: by 10.205.130.1 with SMTP id hk1mr14119258bkc.68.1321495016273;
\r
32 Wed, 16 Nov 2011 17:56:56 -0800 (PST)
\r
33 Received: from localhost ([91.144.186.21])
\r
34 by mx.google.com with ESMTPS id cc2sm37989464bkb.8.2011.11.16.17.56.55
\r
35 (version=TLSv1/SSLv3 cipher=OTHER);
\r
36 Wed, 16 Nov 2011 17:56:55 -0800 (PST)
\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 4/9] test: add support for external executable dependencies
\r
40 Date: Thu, 17 Nov 2011 05:56:21 +0400
\r
41 Message-Id: <1321494986-18998-5-git-send-email-dmitry.kurochkin@gmail.com>
\r
42 X-Mailer: git-send-email 1.7.7.2
\r
43 In-Reply-To: <1321494986-18998-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
44 References: <1321494986-18998-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
45 X-BeenThere: notmuch@notmuchmail.org
\r
46 X-Mailman-Version: 2.1.13
\r
48 List-Id: "Use and development of the notmuch mail system."
\r
49 <notmuch.notmuchmail.org>
\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
53 List-Post: <mailto:notmuch@notmuchmail.org>
\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
57 X-List-Received-Date: Thu, 17 Nov 2011 01:57:07 -0000
\r
59 There is existing support for general prerequisites in the test suite.
\r
60 But it is not very convenient to use: every test case has to keep
\r
61 track for it's dependencies and they have to be explicitly listed.
\r
63 The patch aims to add better support for a particular type of external
\r
64 dependencies: external executables. The main idea is to replace
\r
65 missing external binaries with shell functions that have the same
\r
66 name. These functions always fail and keep track of missing
\r
67 dependencies for a subtest. The result reporting functions later can
\r
68 check that an external binaries are missing and correctly report SKIP
\r
69 result instead of FAIL. The primary benefit is that the test cases do
\r
70 not need to declare their dependencies or be changed in any way.
\r
72 test/test-lib.sh | 49 +++++++++++++++++++++++++++++++++++++++++--------
\r
73 1 files changed, 41 insertions(+), 8 deletions(-)
\r
75 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
76 index f21e45e..ab8c6fd 100755
\r
77 --- a/test/test-lib.sh
\r
78 +++ b/test/test-lib.sh
\r
79 @@ -526,40 +526,53 @@ notmuch_json_show_sanitize ()
\r
80 # - Implicitly by specifying the prerequisite tag in the calls to
\r
81 # test_expect_{success,failure,code}.
\r
83 # The single parameter is the prerequisite tag (a simple word, in all
\r
84 # capital letters by convention).
\r
86 test_set_prereq () {
\r
87 satisfied="$satisfied$1 "
\r
91 test_have_prereq () {
\r
100 +# declare prerequisite for the given external binary
\r
101 +test_declare_external_prereq () {
\r
103 + test "$#" = 2 && name=$2 || name="$binary(1)"
\r
105 + hash $binary 2>/dev/null || eval "
\r
107 + echo -n \"\$test_subtest_missing_external_prereqs_\" | grep -e \" $name \" ||
\r
108 + test_subtest_missing_external_prereqs_=\"$test_subtest_missing_external_prereqs_ $name\"
\r
113 # You are not expected to call test_ok_ and test_failure_ directly, use
\r
114 # the text_expect_* functions instead.
\r
117 if test "$test_subtest_known_broken_" = "t"; then
\r
118 test_known_broken_ok_ "$@"
\r
121 test_success=$(($test_success + 1))
\r
122 say_color pass "%-6s" "PASS"
\r
127 if test "$test_subtest_known_broken_" = "t"; then
\r
128 test_known_broken_failure_ "$@"
\r
131 test_failure=$(($test_failure + 1))
\r
132 test_failure_message_ "FAIL" "$@"
\r
133 @@ -602,82 +615,101 @@ test_run_ () {
\r
138 test_count=$(($test_count+1))
\r
140 for skp in $NOTMUCH_SKIP_TESTS
\r
142 case $this_test.$test_count in
\r
147 if test -z "$to_skip" && test -n "$prereq" &&
\r
148 ! test_have_prereq "$prereq"
\r
154 - test_reset_state_
\r
155 - say_color skip >&3 "skipping test: $@"
\r
156 - say_color skip "%-6s" "SKIP"
\r
159 + test_report_skip_ "$@"
\r
163 + test_check_missing_external_prereqs_ "$@"
\r
168 +test_check_missing_external_prereqs_ () {
\r
169 + if test -n "$test_subtest_missing_external_prereqs_"; then
\r
170 + say_color skip >&3 "missing prerequisites:"
\r
171 + echo "$test_subtest_missing_external_prereqs_" >&3
\r
172 + test_report_skip_ "$@"
\r
178 +test_report_skip_ () {
\r
179 + test_reset_state_
\r
180 + say_color skip >&3 "skipping test: $@"
\r
181 + say_color skip "%-6s" "SKIP"
\r
185 test_subtest_known_broken () {
\r
186 test_subtest_known_broken_=t
\r
189 test_expect_success () {
\r
190 test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
192 error "bug in the test script: not 2 or 3 parameters to test-expect-success"
\r
194 if ! test_skip "$@"
\r
197 - if [ "$?" = 0 -a "$eval_ret" = 0 ]
\r
199 + # test_run_ may update missing external prerequisites
\r
200 + test_check_missing_external_prereqs_ "$@" ||
\r
201 + if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
\r
210 test_expect_code () {
\r
211 test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
213 error "bug in the test script: not 3 or 4 parameters to test-expect-code"
\r
215 if ! test_skip "$@"
\r
218 - if [ "$?" = 0 -a "$eval_ret" = "$1" ]
\r
220 + # test_run_ may update missing external prerequisites,
\r
221 + test_check_missing_external_prereqs_ "$@" ||
\r
222 + if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
\r
231 # test_external runs external test scripts that provide continuous
\r
232 # test output about their progress, and succeeds/fails on
\r
233 # zero/non-zero exit code. It outputs the test output on stdout even
\r
234 # in non-verbose mode, and announces the external script with "* run
\r
235 # <n>: ..." before running it. When providing relative paths, keep in
\r
236 # mind that all scripts run in "trash directory".
\r
237 # Usage: test_external description command arguments...
\r
238 # Example: test_external 'Perl API' perl ../path/to/test.pl
\r
240 test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
242 error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
\r
243 @@ -848,40 +880,41 @@ test_emacs () {
\r
244 # user's TERM is given to dtach which assumes a minimally
\r
245 # VT100-compatible terminal -- and emacs inherits that
\r
246 TERM=$ORIGINAL_TERM dtach -n "$TMP_DIRECTORY/emacs-dtach-socket.$$" \
\r
247 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
\r
248 --no-window-system \
\r
249 --eval '(setq server-name \"$server_name\")' \
\r
250 --eval '(server-start)' \
\r
251 --eval '(orphan-watchdog $$)'" || return
\r
252 EMACS_SERVER="$server_name"
\r
253 # wait until the emacs server is up
\r
254 until test_emacs '()' 2>/dev/null; do
\r
259 emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
\r
262 test_reset_state_ () {
\r
263 test_subtest_known_broken_=
\r
264 + test_subtest_missing_external_prereqs_=
\r
268 find_notmuch_path ()
\r
272 while [ -n "$dir" ]; do
\r
274 if [ -x "$bin" ]; then
\r
278 dir="$(dirname "$dir")"
\r
279 if [ "$dir" = "/" ]; then
\r