]> git.notmuchmail.org Git - notmuch/blobdiff - test/test-lib.sh
test: check if emacs is available in the beginning of test_emacs
[notmuch] / test / test-lib.sh
index 0996a7426442cca7ab4c1913fa7612a88e6ce767..11e66465108bb952d09443adfe0f68dbf29654e8 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.
 
@@ -657,7 +671,8 @@ test_check_missing_external_prereqs_ () {
 
 test_report_skip_ () {
        test_reset_state_
-       say_color skip >&3 "skipping test: $@"
+       say_color skip >&3 "skipping test:"
+       echo " $@" >&3
        say_color skip "%-6s" "SKIP"
        echo " $1"
 }
@@ -879,6 +894,10 @@ EOF
 }
 
 test_emacs () {
+       # test dependencies beforehand to avoid the waiting loop below
+       test_require_external_prereq emacs || return
+       test_require_external_prereq emacsclient || return
+
        if [ -z "$EMACS_SERVER" ]; then
                server_name="notmuch-test-suite-$$"
                # start a detached session with an emacs server
@@ -901,10 +920,20 @@ test_emacs () {
 }
 
 test_reset_state_ () {
+       test -z "$test_init_done_" && test_init_
+
        test_subtest_known_broken_=
        test_subtest_missing_external_prereqs_=
 }
 
+# called once before the first subtest
+test_init_ () {
+       test_init_done_=t
+
+       # skip all tests if there were external prerequisites missing during init
+       test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
+}
+
 
 find_notmuch_path ()
 {
@@ -1112,3 +1141,10 @@ test -z "$NO_PYTHON" && test_set_prereq PYTHON
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
 rm -f y
+
+# declare prerequisites for external binaries used in tests
+test_declare_external_prereq dtach
+test_declare_external_prereq emacs
+test_declare_external_prereq emacsclient
+test_declare_external_prereq gdb
+test_declare_external_prereq gpg