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
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
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
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
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
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
73 test/test-lib.sh | 49 +++++++++++++++++++++++++++++++++++++++++--------
\r
74 1 files changed, 41 insertions(+), 8 deletions(-)
\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
84 # The single parameter is the prerequisite tag (a simple word, in all
\r
85 # capital letters by convention).
\r
87 test_set_prereq () {
\r
88 satisfied="$satisfied$1 "
\r
92 test_have_prereq () {
\r
101 +# declare prerequisite for the given external binary
\r
102 +test_declare_external_prereq () {
\r
104 + test "$#" = 2 && name=$2 || name="$binary(1)"
\r
106 + hash $binary 2>/dev/null || eval "
\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
114 # You are not expected to call test_ok_ and test_failure_ directly, use
\r
115 # the text_expect_* functions instead.
\r
118 if test "$test_subtest_known_broken_" = "t"; then
\r
119 test_known_broken_ok_ "$@"
\r
122 test_success=$(($test_success + 1))
\r
123 say_color pass "%-6s" "PASS"
\r
128 if test "$test_subtest_known_broken_" = "t"; then
\r
129 test_known_broken_failure_ "$@"
\r
132 test_failure=$(($test_failure + 1))
\r
133 test_failure_message_ "FAIL" "$@"
\r
134 @@ -602,82 +615,101 @@ test_run_ () {
\r
139 test_count=$(($test_count+1))
\r
141 for skp in $NOTMUCH_SKIP_TESTS
\r
143 case $this_test.$test_count in
\r
148 if test -z "$to_skip" && test -n "$prereq" &&
\r
149 ! test_have_prereq "$prereq"
\r
155 - test_reset_state_
\r
156 - say_color skip >&3 "skipping test: $@"
\r
157 - say_color skip "%-6s" "SKIP"
\r
160 + test_report_skip_ "$@"
\r
164 + test_check_missing_external_prereqs_ "$@"
\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
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
186 test_subtest_known_broken () {
\r
187 test_subtest_known_broken_=t
\r
190 test_expect_success () {
\r
191 test "$#" = 3 && { prereq=$1; shift; } || prereq=
\r
193 error "bug in the test script: not 2 or 3 parameters to test-expect-success"
\r
195 if ! test_skip "$@"
\r
198 - if [ "$?" = 0 -a "$eval_ret" = 0 ]
\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
211 test_expect_code () {
\r
212 test "$#" = 4 && { prereq=$1; shift; } || prereq=
\r
214 error "bug in the test script: not 3 or 4 parameters to test-expect-code"
\r
216 if ! test_skip "$@"
\r
219 - if [ "$?" = 0 -a "$eval_ret" = "$1" ]
\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
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
241 test "$#" = 4 && { prereq=$1; shift; } || prereq=
\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
260 emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
\r
263 test_reset_state_ () {
\r
264 test_subtest_known_broken_=
\r
265 + test_subtest_missing_external_prereqs_=
\r
269 find_notmuch_path ()
\r
273 while [ -n "$dir" ]; do
\r
275 if [ -x "$bin" ]; then
\r
279 dir="$(dirname "$dir")"
\r
280 if [ "$dir" = "/" ]; then
\r