]> git.notmuchmail.org Git - notmuch/commitdiff
test: add function to explicitly check for external dependencies
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Sun, 27 Nov 2011 18:36:17 +0000 (22:36 +0400)
committerDavid Bremner <bremner@debian.org>
Sun, 27 Nov 2011 19:32:52 +0000 (11:32 -0800)
Useful when binary is called indirectly (e.g. from emacs).

test/test-lib.sh

index fe80e89314e201feea3199a2a7c7b443b3b7d2fc..2422e32d9ece07aae03871fb0c81ea7b2825608c 100644 (file)
@@ -555,12 +555,26 @@ test_declare_external_prereq () {
 
        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.