--- /dev/null
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7274D429E2E\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:57:07 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id aa18-wP9EFfC for <notmuch@notmuchmail.org>;\r
+ Wed, 16 Nov 2011 17:57:04 -0800 (PST)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+ [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id BD6C3429E39\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:56:56 -0800 (PST)\r
+Received: by mail-bw0-f53.google.com with SMTP id q10so1456807bka.26\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Nov 2011 17:56:56 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=LGlH135A5PBHZD5TmjaxaIQwi1a4gGc2zhsQSt4gfHo=;\r
+ b=fLNqGh+6xhD0OIe9RWFoVuWp98yni4Tjpe2bJaQktM0WIvsy3eqv3HzKjFw2osqzyR\r
+ hjYvNAcnQvYghz+ldu5U6trNrYnCZITiVnSWYBPz4z9wTeFMksH43348zxYB9Cbpkkip\r
+ K6rZ1LGtaLM6VpeYPOx0MXBM692eSwbKCctBc=\r
+Received: by 10.205.130.1 with SMTP id hk1mr14119258bkc.68.1321495016273;\r
+ Wed, 16 Nov 2011 17:56:56 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+ by mx.google.com with ESMTPS id cc2sm37989464bkb.8.2011.11.16.17.56.55\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Wed, 16 Nov 2011 17:56:55 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/9] test: add support for external executable dependencies\r
+Date: Thu, 17 Nov 2011 05:56:21 +0400\r
+Message-Id: <1321494986-18998-5-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.7.2\r
+In-Reply-To: <1321494986-18998-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1321494986-18998-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 17 Nov 2011 01:57:07 -0000\r
+\r
+There is existing support for general prerequisites in the test suite.\r
+But it is not very convenient to use: every test case has to keep\r
+track for it's dependencies and they have to be explicitly listed.\r
+\r
+The patch aims to add better support for a particular type of external\r
+dependencies: external executables. The main idea is to replace\r
+missing external binaries with shell functions that have the same\r
+name. These functions always fail and keep track of missing\r
+dependencies for a subtest. The result reporting functions later can\r
+check that an external binaries are missing and correctly report SKIP\r
+result instead of FAIL. The primary benefit is that the test cases do\r
+not need to declare their dependencies or be changed in any way.\r
+---\r
+ test/test-lib.sh | 49 +++++++++++++++++++++++++++++++++++++++++--------\r
+ 1 files changed, 41 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index f21e45e..ab8c6fd 100755\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -526,40 +526,53 @@ notmuch_json_show_sanitize ()\r
+ # - Implicitly by specifying the prerequisite tag in the calls to\r
+ # test_expect_{success,failure,code}.\r
+ #\r
+ # The single parameter is the prerequisite tag (a simple word, in all\r
+ # capital letters by convention).\r
+ \r
+ test_set_prereq () {\r
+ satisfied="$satisfied$1 "\r
+ }\r
+ satisfied=" "\r
+ \r
+ test_have_prereq () {\r
+ case $satisfied in\r
+ *" $1 "*)\r
+ : yes, have it ;;\r
+ *)\r
+ ! : nope ;;\r
+ esac\r
+ }\r
+ \r
++# declare prerequisite for the given external binary\r
++test_declare_external_prereq () {\r
++ binary="$1"\r
++ test "$#" = 2 && name=$2 || name="$binary(1)"\r
++\r
++ hash $binary 2>/dev/null || eval "\r
++$1 () {\r
++ echo -n \"\$test_subtest_missing_external_prereqs_\" | grep -e \" $name \" ||\r
++ test_subtest_missing_external_prereqs_=\"$test_subtest_missing_external_prereqs_ $name\"\r
++ false\r
++}"\r
++}\r
++\r
+ # You are not expected to call test_ok_ and test_failure_ directly, use\r
+ # the text_expect_* functions instead.\r
+ \r
+ test_ok_ () {\r
+ if test "$test_subtest_known_broken_" = "t"; then\r
+ test_known_broken_ok_ "$@"\r
+ return\r
+ fi\r
+ test_success=$(($test_success + 1))\r
+ say_color pass "%-6s" "PASS"\r
+ echo " $@"\r
+ }\r
+ \r
+ test_failure_ () {\r
+ if test "$test_subtest_known_broken_" = "t"; then\r
+ test_known_broken_failure_ "$@"\r
+ return\r
+ fi\r
+ test_failure=$(($test_failure + 1))\r
+ test_failure_message_ "FAIL" "$@"\r
+@@ -602,82 +615,101 @@ test_run_ () {\r
+ return 0\r
+ }\r
+ \r
+ test_skip () {\r
+ test_count=$(($test_count+1))\r
+ to_skip=\r
+ for skp in $NOTMUCH_SKIP_TESTS\r
+ do\r
+ case $this_test.$test_count in\r
+ $skp)\r
+ to_skip=t\r
+ esac\r
+ done\r
+ if test -z "$to_skip" && test -n "$prereq" &&\r
+ ! test_have_prereq "$prereq"\r
+ then\r
+ to_skip=t\r
+ fi\r
+ case "$to_skip" in\r
+ t)\r
+- test_reset_state_\r
+- say_color skip >&3 "skipping test: $@"\r
+- say_color skip "%-6s" "SKIP"\r
+- echo " $1"\r
+- : true\r
++ test_report_skip_ "$@"\r
+ ;;\r
+ *)\r
+- false\r
++ test_check_missing_external_prereqs_ "$@"\r
+ ;;\r
+ esac\r
+ }\r
+ \r
++test_check_missing_external_prereqs_ () {\r
++ if test -n "$test_subtest_missing_external_prereqs_"; then\r
++ say_color skip >&3 "missing prerequisites:"\r
++ echo "$test_subtest_missing_external_prereqs_" >&3\r
++ test_report_skip_ "$@"\r
++ else\r
++ false\r
++ fi\r
++}\r
++\r
++test_report_skip_ () {\r
++ test_reset_state_\r
++ say_color skip >&3 "skipping test: $@"\r
++ say_color skip "%-6s" "SKIP"\r
++ echo " $1"\r
++}\r
++\r
+ test_subtest_known_broken () {\r
+ test_subtest_known_broken_=t\r
+ }\r
+ \r
+ test_expect_success () {\r
+ test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 2 ||\r
+ error "bug in the test script: not 2 or 3 parameters to test-expect-success"\r
+ test_reset_state_\r
+ if ! test_skip "$@"\r
+ then\r
+ test_run_ "$2"\r
+- if [ "$?" = 0 -a "$eval_ret" = 0 ]\r
++ run_ret="$?"\r
++ # test_run_ may update missing external prerequisites\r
++ test_check_missing_external_prereqs_ "$@" ||\r
++ if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]\r
+ then\r
+ test_ok_ "$1"\r
+ else\r
+ test_failure_ "$@"\r
+ fi\r
+ fi\r
+ }\r
+ \r
+ test_expect_code () {\r
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 3 ||\r
+ error "bug in the test script: not 3 or 4 parameters to test-expect-code"\r
+ test_reset_state_\r
+ if ! test_skip "$@"\r
+ then\r
+ test_run_ "$3"\r
+- if [ "$?" = 0 -a "$eval_ret" = "$1" ]\r
++ run_ret="$?"\r
++ # test_run_ may update missing external prerequisites,\r
++ test_check_missing_external_prereqs_ "$@" ||\r
++ if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]\r
+ then\r
+ test_ok_ "$2"\r
+ else\r
+ test_failure_ "$@"\r
+ fi\r
+ fi\r
+ }\r
+ \r
+ # test_external runs external test scripts that provide continuous\r
+ # test output about their progress, and succeeds/fails on\r
+ # zero/non-zero exit code. It outputs the test output on stdout even\r
+ # in non-verbose mode, and announces the external script with "* run\r
+ # <n>: ..." before running it. When providing relative paths, keep in\r
+ # mind that all scripts run in "trash directory".\r
+ # Usage: test_external description command arguments...\r
+ # Example: test_external 'Perl API' perl ../path/to/test.pl\r
+ test_external () {\r
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 3 ||\r
+ error >&5 "bug in the test script: not 3 or 4 parameters to test_external"\r
+@@ -848,40 +880,41 @@ test_emacs () {\r
+ # user's TERM is given to dtach which assumes a minimally\r
+ # VT100-compatible terminal -- and emacs inherits that\r
+ TERM=$ORIGINAL_TERM dtach -n "$TMP_DIRECTORY/emacs-dtach-socket.$$" \\r
+ sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \\r
+ --no-window-system \\r
+ --eval '(setq server-name \"$server_name\")' \\r
+ --eval '(server-start)' \\r
+ --eval '(orphan-watchdog $$)'" || return\r
+ EMACS_SERVER="$server_name"\r
+ # wait until the emacs server is up\r
+ until test_emacs '()' 2>/dev/null; do\r
+ sleep 1\r
+ done\r
+ fi\r
+ \r
+ emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
+ }\r
+ \r
+ test_reset_state_ () {\r
+ test_subtest_known_broken_=\r
++ test_subtest_missing_external_prereqs_=\r
+ }\r
+ \r
+ \r
+ find_notmuch_path ()\r
+ {\r
+ dir="$1"\r
+ \r
+ while [ -n "$dir" ]; do\r
+ bin="$dir/notmuch"\r
+ if [ -x "$bin" ]; then\r
+ echo "$dir"\r
+ return\r
+ fi\r
+ dir="$(dirname "$dir")"\r
+ if [ "$dir" = "/" ]; then\r
+ break\r
+ fi\r
+ done\r
+ }\r
+ \r
+-- \r
+1.7.7.2\r
+\r