Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 81D6342116B for ; Thu, 17 Nov 2011 05:06:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bclLZuBFbWd1 for ; Thu, 17 Nov 2011 05:06:53 -0800 (PST) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id ED207429E45 for ; Thu, 17 Nov 2011 05:06:42 -0800 (PST) Received: by mail-bw0-f53.google.com with SMTP id q10so2108356bka.26 for ; Thu, 17 Nov 2011 05:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=Xc9GWZb50rFCh1hnIh+nJFHBEPhEm6prvoMXrTP8FsQ=; b=u1K+lQwo2jHhkoDFjWRsCG/of6aKmcy8uKO3b8Q2D+vIpBrlEkSmUPqmQNtLereB5k 7Le6y+w6NmJr+dRpzUQ8tjisW25wdvEPzixFbf5ZJwZy1pdq0KMugJsGHcnigtz8ELWM e2EfypM0/DcPDdHOpl2SSw6PzAEVtChpHlmH0= Received: by 10.204.145.130 with SMTP id d2mr33880939bkv.78.1321535202642; Thu, 17 Nov 2011 05:06:42 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id r12sm41225872bkw.5.2011.11.17.05.06.41 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Nov 2011 05:06:42 -0800 (PST) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH v2 08/10] test: add function to explicitly check for external dependencies Date: Thu, 17 Nov 2011 17:06:01 +0400 Message-Id: <1321535163-4895-9-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.7.2 In-Reply-To: <1321535163-4895-1-git-send-email-dmitry.kurochkin@gmail.com> References: <1321535163-4895-1-git-send-email-dmitry.kurochkin@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Nov 2011 13:06:56 -0000 Useful when binary is called indirectly (e.g. from emacs). --- test/test-lib.sh | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/test/test-lib.sh b/test/test-lib.sh index cf1b4f0..5a99216 100755 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -533,46 +533,60 @@ test_set_prereq () { satisfied="$satisfied$1 " } satisfied=" " test_have_prereq () { case $satisfied in *" $1 "*) : yes, have it ;; *) ! : nope ;; esac } # declare prerequisite for the given external binary test_declare_external_prereq () { binary="$1" test "$#" = 2 && name=$2 || name="$binary(1)" hash $binary 2>/dev/null || eval " $binary () { + test_missing_external_prereq_${binary}_=t echo -n \"\$test_subtest_missing_external_prereqs_\" | grep -e \" $name \" || test_subtest_missing_external_prereqs_=\"$test_subtest_missing_external_prereqs_ $name\" false }" } +# Explicitly require external prerequisite. Useful when binary is +# called indirectly (e.g. from emacs). +# Returns success if dependency is available, failure otherwise. +test_require_external_prereq () { + binary="$1" + if [ "$(eval echo -n \$test_missing_external_prereq_${binary}_)" = t ]; then + # dependency is missing, call the replacement function to note it + eval "$binary" + else + true + fi +} + # You are not expected to call test_ok_ and test_failure_ directly, use # the text_expect_* functions instead. test_ok_ () { if test "$test_subtest_known_broken_" = "t"; then test_known_broken_ok_ "$@" return fi test_success=$(($test_success + 1)) say_color pass "%-6s" "PASS" echo " $@" } test_failure_ () { if test "$test_subtest_known_broken_" = "t"; then test_known_broken_failure_ "$@" return fi test_failure=$(($test_failure + 1)) test_failure_message_ "FAIL" "$@" -- 1.7.7.2