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

Reply via email to