]> git.notmuchmail.org Git - notmuch/blobdiff - test/test-lib.sh
python: move Threads class into its own file
[notmuch] / test / test-lib.sh
index d1fbc054dde05b11c9b7646146e97f0adcd6c5a5..063a2b273049c18a9ba95cbede3348063a174d3b 100644 (file)
@@ -140,7 +140,7 @@ if test -n "$color"; then
                esac
                shift
                printf " "
-                printf "$@"
+               printf "$@"
                tput sgr0
                print_subtest
                )
@@ -150,7 +150,7 @@ else
                test -z "$1" && test -n "$quiet" && return
                shift
                printf " "
-                printf "$@"
+               printf "$@"
                print_subtest
        }
 fi
@@ -249,7 +249,7 @@ remove_cr () {
 #      Store the message in file 'name'. The default is to store it
 #      in 'msg-<count>', where <count> is three-digit number of the
 #      message.
-#      
+#
 #  [body]=text
 #
 #      Text to use as the body of the email message
@@ -503,6 +503,35 @@ test_expect_equal_file ()
     fi
 }
 
+test_emacs_expect_t () {
+       test "$#" = 2 && { prereq=$1; shift; } || prereq=
+       test "$#" = 1 ||
+       error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
+
+       # Run the test.
+       if ! test_skip "$test_subtest_name"
+       then
+               test_emacs "(notmuch-test-run $1)" >/dev/null
+
+               # Restore state after the test.
+               exec 1>&6 2>&7          # Restore stdout and stderr
+               inside_subtest=
+
+               # Report success/failure.
+               result=$(cat OUTPUT)
+               if [ "$result" = t ]
+               then
+                       test_ok_ "$test_subtest_name"
+               else
+                       test_failure_ "$test_subtest_name" "${result}"
+               fi
+       else
+               # Restore state after the (non) test.
+               exec 1>&6 2>&7          # Restore stdout and stderr
+               inside_subtest=
+       fi
+}
+
 NOTMUCH_NEW ()
 {
     notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
@@ -673,8 +702,8 @@ test_skip () {
 
 test_check_missing_external_prereqs_ () {
        if test -n "$test_subtest_missing_external_prereqs_"; then
-               say_color skip >&3 "missing prerequisites:"
-               echo "$test_subtest_missing_external_prereqs_" >&3
+               say_color skip >&1 "missing prerequisites:"
+               echo "$test_subtest_missing_external_prereqs_" >&1
                test_report_skip_ "$@"
        else
                false
@@ -869,7 +898,7 @@ test_done () {
        [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
 
        if [ "$test_failure" = "0" ]; then
-           if [ "$test_broken" = "0" ]; then       
+           if [ "$test_broken" = "0" ]; then
                rm -rf "$remove_tmp"
            fi
            exit 0
@@ -881,7 +910,7 @@ test_done () {
 emacs_generate_script () {
        # Construct a little test script here for the benefit of the user,
        # (who can easily run "run_emacs" to get the same emacs environment
-       # for investigating any failures).    
+       # for investigating any failures).
        cat <<EOF >"$TMP_DIRECTORY/run_emacs"
 #!/bin/sh
 export PATH=$PATH
@@ -914,6 +943,12 @@ test_emacs () {
        test -z "$missing_dependencies" || return
 
        if [ -z "$EMACS_SERVER" ]; then
+               emacs_tests="$(basename $0).el"
+               if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
+                       load_emacs_tests="--eval '(load \"$emacs_tests\")'"
+               else
+                       load_emacs_tests=
+               fi
                server_name="notmuch-test-suite-$$"
                # start a detached session with an emacs server
                # user's TERM is given to dtach which assumes a minimally
@@ -921,12 +956,13 @@ test_emacs () {
                TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
                        sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
                                --no-window-system \
+                               $load_emacs_tests \
                                --eval '(setq server-name \"$server_name\")' \
                                --eval '(server-start)' \
                                --eval '(orphan-watchdog $$)'" || return
                EMACS_SERVER="$server_name"
                # wait until the emacs server is up
-               until test_emacs '()' 2>/dev/null; do
+               until test_emacs '()' >/dev/null 2>/dev/null; do
                        sleep 1
                done
        fi