2 # Copyright (c) 2005 Junio C Hamano
3 # Copyright (c) 2010 Notmuch Developers
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/ .
18 if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
19 echo "Error: The notmuch test suite requires a bash version >= 4.0"
20 echo "due to use of associative arrays within the test suite."
21 echo "Please try again with a newer bash (or help us fix the"
22 echo "test suite to be more portable). Thanks."
26 # Make sure echo builtin does not expand backslash-escape sequences by default.
29 # It appears that people try to run tests without building...
30 if ! test -x ../notmuch
32 echo >&2 'You do not seem to have built notmuch yet.'
37 this_test=${this_test%.sh}
38 this_test_bare=${this_test#T[0-9][0-9][0-9]-}
40 # if --tee was passed, write the output not only to the terminal, but
41 # additionally to the file test-results/$BASENAME.out, too.
42 case "$GIT_TEST_TEE_STARTED, $* " in
44 # do not redirect again
46 *' --tee '*|*' --va'*)
48 BASE=test-results/$this_test
49 (GIT_TEST_TEE_STARTED=done "$BASH" "$0" "$@" 2>&1;
50 echo $? > $BASE.exit) | tee $BASE.out
51 test "$(cat $BASE.exit)" = 0
56 # Save STDOUT to fd 6 and STDERR to fd 7.
58 # Make xtrace debugging (when used) use redirected STDERR, with verbose lead:
60 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
62 # Keep the original TERM for say_color and test_emacs
65 # Set SMART_TERM to vt100 for known dumb/unknown terminal.
66 # Otherwise use whatever TERM is currently used so that
67 # users' actual TERM environments are being used in tests.
75 # For repeatability, reset the environment to known value.
81 export LANG LC_ALL PAGER TERM TZ
82 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
83 if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \
84 ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then
85 echo "error: must specify both or neither of TEST_EMACS and TEST_EMACSCLIENT" >&2
88 TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
89 TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
90 TEST_GDB=${TEST_GDB:-gdb}
91 TEST_CC=${TEST_CC:-cc}
92 TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"}
94 # Protect ourselves from common misconfiguration to export
95 # CDPATH into the environment
101 unset ALTERNATE_EDITOR
106 [ -d ${GNUPGHOME} ] && return
107 _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
108 at_exit_function _gnupg_exit
109 mkdir -m 0700 "$GNUPGHOME"
110 gpg --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1
111 test_debug "cat $GNUPGHOME/import.log"
112 if (gpg --quick-random --version >/dev/null 2>&1) ; then
113 echo quick-random >> "$GNUPGHOME"/gpg.conf
114 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
115 echo debug-quick-random >> "$GNUPGHOME"/gpg.conf
117 echo no-emit-version >> "$GNUPGHOME"/gpg.conf
120 # Each test should start with something like this, after copyright notices:
122 # test_description='Description of this test...
123 # This test checks if command xyzzy does the right thing...
125 # . ./test-lib.sh || exit 1
127 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
128 TERM=$ORIGINAL_TERM &&
131 tput bold >/dev/null 2>&1 &&
132 tput setaf 1 >/dev/null 2>&1 &&
133 tput sgr0 >/dev/null 2>&1
137 while test "$#" -ne 0
143 immediate=t; shift ;;
151 with_dashes=t; shift ;;
158 valgrind=t; verbose=t; shift ;;
160 shift ;; # was handled already
162 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
165 echo "error: unknown test option '$1'" >&2; exit 1 ;;
169 if test -n "$debug"; then
171 printf " %-4s" "[$((test_count - 1))]"
179 if test -n "$color"; then
185 error) tput bold; tput setaf 1;; # bold red
186 skip) tput bold; tput setaf 2;; # bold green
187 pass) tput setaf 2;; # green
188 info) tput setaf 3;; # brown
189 *) test -n "$quiet" && return;;
200 test -z "$1" && test -n "$quiet" && return
209 say_color error "error: $*\n"
218 test "${test_description}" != "" ||
219 error "Test script did not set test_description."
221 if test "$help" = "t"
223 echo "Tests ${test_description}"
227 test_description_printed=
228 print_test_description ()
230 test -z "$test_description_printed" || return 0
232 echo $this_test: "Testing ${test_description}"
233 test_description_printed=1
235 if [ -z "$NOTMUCH_TEST_QUIET" ]
237 print_test_description
246 declare -a _exit_functions=()
248 at_exit_function () {
249 _exit_functions=($1 ${_exit_functions[@]/$1})
252 rm_exit_function () {
253 _exit_functions=(${_exit_functions[@]/$1})
260 for _fn in ${_exit_functions[@]}; do $_fn; done
261 rm -rf "$TEST_TMPDIR"
266 if test -n "$GIT_EXIT_OK"
271 say_color error '%-6s' FATAL
272 echo " $test_subtest_name"
274 echo "Unexpected exit while executing $0. Exit code $code."
281 echo >&6 "FATAL: $0: interrupted by signal" $((code - 128))
288 say_color error '%-6s' FATAL
291 echo "Unexpected exit while executing $0."
296 # Note: TEST_TMPDIR *NOT* exported!
297 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
298 # Put GNUPGHOME in TMPDIR to avoid problems with long paths.
299 export GNUPGHOME="${TEST_TMPDIR}/gnupg"
300 trap 'trap_exit' EXIT
301 trap 'trap_signal' HUP INT TERM
303 # Deliver a message with emacs and add it to the database
305 # Uses emacs to generate and deliver a message to the mail store.
306 # Accepts arbitrary extra emacs/elisp functions to modify the message
307 # before sending, which is useful to doing things like attaching files
308 # to the message and encrypting/signing.
309 emacs_deliver_message ()
314 # before we can send a message, we have to prepare the FCC maildir
315 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
316 # eval'ing smtp-dummy --background will set smtp_dummy_pid
318 eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
319 test -n "$smtp_dummy_pid" || return 1
322 "(let ((message-send-mail-function 'message-smtpmail-send-it)
323 (mail-host-address \"example.com\")
324 (smtpmail-smtp-server \"localhost\")
325 (smtpmail-smtp-service \"25025\"))
328 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
329 (message-goto-subject)
330 (insert \"${subject}\")
334 (notmuch-mua-send-and-exit))"
336 # In case message was sent properly, client waits for confirmation
337 # before exiting and resuming control here; therefore making sure
338 # that server exits by sending (KILL) signal to it is safe.
339 kill -9 $smtp_dummy_pid
340 notmuch new >/dev/null
343 # Pretend to deliver a message with emacs. Really save it to a file
344 # and add it to the database
346 # Uses emacs to generate and deliver a message to the mail store.
347 # Accepts arbitrary extra emacs/elisp functions to modify the message
348 # before sending, which is useful to doing things like attaching files
349 # to the message and encrypting/signing.
355 # before we can send a message, we have to prepare the FCC maildir
356 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
359 "(let ((message-send-mail-function (lambda () t))
360 (mail-host-address \"example.com\"))
363 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
364 (message-goto-subject)
365 (insert \"${subject}\")
369 (notmuch-mua-send-and-exit))" || return 1
370 notmuch new >/dev/null
373 # Add an existing, fixed corpus of email to the database.
375 # $1 is the corpus dir under corpora to add, using "default" if unset.
377 # The default corpus is based on about 50 messages from early in the
378 # history of the notmuch mailing list, which allows for reliably
379 # testing commands that need to operate on a not-totally-trivial
380 # number of messages.
386 if [ -d $TEST_DIRECTORY/corpora.mail/$corpus ]; then
387 cp -a $TEST_DIRECTORY/corpora.mail/$corpus ${MAIL_DIR}
389 cp -a $TEST_DIRECTORY/corpora/$corpus ${MAIL_DIR}
390 notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
391 mkdir -p $TEST_DIRECTORY/corpora.mail
392 cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpora.mail/$corpus
396 test_begin_subtest ()
398 if [ -n "$inside_subtest" ]; then
399 exec 1>&6 2>&7 # Restore stdout and stderr
400 error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
402 test_subtest_name="$1"
404 # Redirect test output to the previously prepared file descriptors
405 # 3 and 4 (see below)
406 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
411 # Pass test if two arguments match
413 # Note: Unlike all other test_expect_* functions, this function does
414 # not accept a test name. Instead, the caller should call
415 # test_begin_subtest before calling this function in order to set the
419 exec 1>&6 2>&7 # Restore stdout and stderr
420 if [ -z "$inside_subtest" ]; then
421 error "bug in the test script: test_expect_equal without test_begin_subtest"
425 error "bug in the test script: not 2 parameters to test_expect_equal"
429 if ! test_skip "$test_subtest_name"
431 if [ "$output" = "$expected" ]; then
434 testname=$this_test.$test_count
435 echo "$expected" > $testname.expected
436 echo "$output" > $testname.output
437 test_failure_ "$(diff -u $testname.expected $testname.output)"
442 # Like test_expect_equal, but takes two filenames.
443 test_expect_equal_file ()
445 exec 1>&6 2>&7 # Restore stdout and stderr
446 if [ -z "$inside_subtest" ]; then
447 error "bug in the test script: test_expect_equal_file without test_begin_subtest"
451 error "bug in the test script: not 2 parameters to test_expect_equal_file"
455 if ! test_skip "$test_subtest_name"
457 if diff -q "$file1" "$file2" >/dev/null ; then
460 testname=$this_test.$test_count
461 basename1=`basename "$file1"`
462 basename2=`basename "$file2"`
463 cp "$file1" "$testname.$basename1"
464 cp "$file2" "$testname.$basename2"
465 test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"
470 # Like test_expect_equal, but arguments are JSON expressions to be
471 # canonicalized before diff'ing. If an argument cannot be parsed, it
472 # is used unchanged so that there's something to diff against.
473 test_expect_equal_json () {
474 # The test suite forces LC_ALL=C, but this causes Python 3 to
475 # decode stdin as ASCII. We need to read JSON in UTF-8, so
476 # override Python's stdio encoding defaults.
477 local script='import json, sys; json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)'
478 output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \
480 expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \
483 test_expect_equal "$output" "$expected" "$@"
486 # Sort the top-level list of JSON data from stdin.
488 PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \
489 "import sys, json; json.dump(sorted(json.load(sys.stdin)),sys.stdout)"
492 test_emacs_expect_t () {
494 error "bug in the test script: not 1 parameter to test_emacs_expect_t"
495 if [ -z "$inside_subtest" ]; then
496 error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
500 if ! test_skip "$test_subtest_name"
502 test_emacs "(notmuch-test-run $1)" >/dev/null
504 # Restore state after the test.
505 exec 1>&6 2>&7 # Restore stdout and stderr
508 # Report success/failure.
514 test_failure_ "${result}"
517 # Restore state after the (non) test.
518 exec 1>&6 2>&7 # Restore stdout and stderr
525 notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
530 # this relies on the default format being batch-tag, otherwise some tests will break
531 notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
534 notmuch_drop_mail_headers ()
538 msg = email.message_from_file(sys.stdin)
539 for hdr in sys.argv[1:]: del msg[hdr]
540 print(msg.as_string(False))
544 notmuch_search_sanitize ()
546 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
549 notmuch_search_files_sanitize ()
554 notmuch_dir_sanitize ()
556 sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
559 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
560 notmuch_show_sanitize ()
562 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
564 notmuch_show_sanitize_all ()
567 -e 's| filename:.*| filename:XXXXX|' \
568 -e 's| id:[^ ]* | id:XXXXX |' | \
569 notmuch_date_sanitize
572 notmuch_json_show_sanitize ()
575 -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
576 -e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
577 -e 's|"filename": "signature.asc",||g' \
578 -e 's|"filename": \["/[^"]*"\],|"filename": \["YYYYY"\],|g' \
579 -e 's|"timestamp": 97.......|"timestamp": 42|g' \
580 -e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
583 notmuch_emacs_error_sanitize ()
591 -e 's/^\[.*\]$/[XXX]/' \
592 -e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
595 notmuch_date_sanitize ()
598 -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
601 notmuch_uuid_sanitize ()
603 sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
606 notmuch_built_with_sanitize ()
608 sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
611 notmuch_config_sanitize ()
613 notmuch_dir_sanitize | notmuch_built_with_sanitize
616 # End of notmuch helper functions
618 # Use test_set_prereq to tell that a particular prerequisite is available.
620 # The prerequisite can later be checked for by using test_have_prereq.
622 # The single parameter is the prerequisite tag (a simple word, in all
623 # capital letters by convention).
626 satisfied="$satisfied$1 "
630 test_have_prereq () {
639 declare -A test_missing_external_prereq_
640 declare -A test_subtest_missing_external_prereq_
642 # declare prerequisite for the given external binary
643 test_declare_external_prereq () {
645 test "$#" = 2 && name=$2 || name="$binary(1)"
647 if ! hash $binary 2>/dev/null; then
648 test_missing_external_prereq_["${binary}"]=t
651 test_subtest_missing_external_prereq_[\"${name}\"]=t
657 # Explicitly require external prerequisite. Useful when binary is
658 # called indirectly (e.g. from emacs).
659 # Returns success if dependency is available, failure otherwise.
660 test_require_external_prereq () {
662 if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then
663 # dependency is missing, call the replacement function to note it
670 # You are not expected to call test_ok_ and test_failure_ directly, use
671 # the text_expect_* functions instead.
674 if test "$test_subtest_known_broken_" = "t"; then
675 test_known_broken_ok_
678 test_success=$(($test_success + 1))
679 if test -n "$NOTMUCH_TEST_QUIET"; then
682 say_color pass "%-6s" "PASS"
683 echo " $test_subtest_name"
687 print_test_description
688 if test "$test_subtest_known_broken_" = "t"; then
689 test_known_broken_failure_ "$@"
692 test_failure=$(($test_failure + 1))
693 test_failure_message_ "FAIL" "$test_subtest_name" "$@"
694 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
698 test_failure_message_ () {
699 say_color error "%-6s" "$1"
702 if [ "$#" != "0" ]; then
703 echo "$@" | sed -e 's/^/ /'
705 if test "$verbose" != "t"; then cat test.output; fi
708 test_known_broken_ok_ () {
710 test_fixed=$(($test_fixed+1))
711 say_color pass "%-6s" "FIXED"
712 echo " $test_subtest_name"
715 test_known_broken_failure_ () {
717 test_broken=$(($test_broken+1))
718 if [ -z "$NOTMUCH_TEST_QUIET" ]; then
719 test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
721 test_failure_message_ "BROKEN" "$test_subtest_name"
727 test "$debug" = "" || eval "$1"
732 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
735 eval >&3 2>&4 "$test_cleanup"
740 test_count=$(($test_count+1))
742 for skp in $NOTMUCH_SKIP_TESTS
744 case $this_test.$test_count in
749 case $this_test_bare.$test_count in
757 test_report_skip_ "$@"
760 test_check_missing_external_prereqs_ "$@"
765 test_check_missing_external_prereqs_ () {
766 if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then
767 say_color skip >&1 "missing prerequisites: "
768 echo ${!test_subtest_missing_external_prereq_[@]} >&1
769 test_report_skip_ "$@"
775 test_report_skip_ () {
777 say_color skip >&3 "skipping test:"
779 say_color skip "%-6s" "SKIP"
783 test_subtest_known_broken () {
784 test_subtest_known_broken_=t
787 test_expect_success () {
788 exec 1>&6 2>&7 # Restore stdout and stderr
789 if [ -z "$inside_subtest" ]; then
790 error "bug in the test script: test_expect_success without test_begin_subtest"
794 error "bug in the test script: not 1 parameters to test_expect_success"
796 if ! test_skip "$test_subtest_name"
800 # test_run_ may update missing external prerequisites
801 test_check_missing_external_prereqs_ "$@" ||
802 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
811 test_expect_code () {
812 exec 1>&6 2>&7 # Restore stdout and stderr
813 if [ -z "$inside_subtest" ]; then
814 error "bug in the test script: test_expect_code without test_begin_subtest"
818 error "bug in the test script: not 2 parameters to test_expect_code"
820 if ! test_skip "$test_subtest_name"
824 # test_run_ may update missing external prerequisites,
825 test_check_missing_external_prereqs_ "$@" ||
826 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
830 test_failure_ "exit code $eval_ret, expected $1" "$2"
835 # This is not among top-level (test_expect_success)
836 # but is a prefix that can be used in the test script, like:
838 # test_expect_success 'complain and die' '
840 # do something else &&
841 # test_must_fail git checkout ../outerspace
844 # Writing this as "! git checkout ../outerspace" is wrong, because
845 # the failure could be due to a segv. We want a controlled failure.
849 test $? -gt 0 -a $? -le 129 -o $? -gt 192
852 # test_cmp is a helper function to compare actual and expected output.
853 # You can use it like:
855 # test_expect_success 'foo works' '
856 # echo expected >expected &&
858 # test_cmp expected actual
861 # This could be written as either "cmp" or "diff -u", but:
862 # - cmp's output is not nearly as easy to read as diff -u
863 # - not all diff versions understand "-u"
869 # This function can be used to schedule some commands to be run
870 # unconditionally at the end of the test to restore sanity:
872 # test_expect_success 'test core.capslock' '
873 # git config core.capslock true &&
874 # test_when_finished "git config --unset core.capslock" &&
878 # That would be roughly equivalent to
880 # test_expect_success 'test core.capslock' '
881 # git config core.capslock true &&
883 # git config --unset core.capslock
886 # except that the greeting and config --unset must both succeed for
889 test_when_finished () {
891 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
896 test_results_dir="$TEST_DIRECTORY/test-results"
897 mkdir -p "$test_results_dir"
898 test_results_path="$test_results_dir/$this_test"
900 echo "total $test_count" >> $test_results_path
901 echo "success $test_success" >> $test_results_path
902 echo "fixed $test_fixed" >> $test_results_path
903 echo "broken $test_broken" >> $test_results_path
904 echo "failed $test_failure" >> $test_results_path
905 echo "" >> $test_results_path
907 [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
909 if [ "$test_failure" = "0" ]; then
910 if [ "$test_broken" = "0" ]; then
919 emacs_generate_script () {
920 # Construct a little test script here for the benefit of the user,
921 # (who can easily run "run_emacs" to get the same emacs environment
922 # for investigating any failures).
923 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
926 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
928 # Here's what we are using here:
930 # --quick Use minimal customization. This implies --no-init-file,
931 # --no-site-file and (emacs 24) --no-site-lisp
933 # --directory Ensure that the local elisp sources are found
935 # --load Force loading of notmuch.el and test-lib.el
937 exec ${TEST_EMACS} --quick \
938 --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
939 --directory "$TEST_DIRECTORY" --load test-lib.el \
942 chmod a+x "$TMP_DIRECTORY/run_emacs"
946 # test dependencies beforehand to avoid the waiting loop below
947 missing_dependencies=
948 test_require_external_prereq dtach || missing_dependencies=1
949 test_require_external_prereq emacs || missing_dependencies=1
950 test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
951 test -z "$missing_dependencies" || return
953 if [ -z "$EMACS_SERVER" ]; then
954 emacs_tests="${this_test_bare}.el"
955 if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
956 load_emacs_tests="--eval '(load \"$emacs_tests\")'"
960 server_name="notmuch-test-suite-$$"
961 # start a detached session with an emacs server
962 # user's TERM (or 'vt100' in case user's TERM is known dumb
963 # or unknown) is given to dtach which assumes a minimally
964 # VT100-compatible terminal -- and emacs inherits that
965 TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
966 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
969 --eval '(setq server-name \"$server_name\")' \
970 --eval '(server-start)' \
971 --eval '(orphan-watchdog $$)'" || return
972 EMACS_SERVER="$server_name"
973 # wait until the emacs server is up
974 until test_emacs '()' >/dev/null 2>/dev/null; do
979 # Clear test-output output file. Most Emacs tests end with a
980 # call to (test-output). If the test code fails with an
981 # exception before this call, the output file won't get
982 # updated. Since we don't want to compare against an output
983 # file from another test, so start out with an empty file.
987 ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $@)"
991 # Note: if there is need to print debug information from python program,
992 # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
993 PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
994 $NOTMUCH_PYTHON -B - > OUTPUT
998 MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
1002 exec_file="test${test_count}"
1003 test_file="${exec_file}.c"
1005 ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${NOTMUCH_SRCDIR}/lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
1006 echo "== stdout ==" > OUTPUT.stdout
1007 echo "== stderr ==" > OUTPUT.stderr
1008 ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
1009 notmuch_dir_sanitize OUTPUT.stdout OUTPUT.stderr > OUTPUT
1013 # Creates a script that counts how much time it is executed and calls
1014 # notmuch. $notmuch_counter_command is set to the path to the
1015 # generated script. Use notmuch_counter_value() function to get the
1016 # current counter value.
1017 notmuch_counter_reset () {
1018 notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
1019 if [ ! -x "$notmuch_counter_command" ]; then
1020 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
1021 cat >"$notmuch_counter_command" <<EOF || return
1024 read count < "$notmuch_counter_state_path"
1025 echo \$((count + 1)) > "$notmuch_counter_state_path"
1029 chmod +x "$notmuch_counter_command" || return
1032 echo 0 > "$notmuch_counter_state_path"
1035 # Returns the current notmuch counter value.
1036 notmuch_counter_value () {
1037 if [ -r "$notmuch_counter_state_path" ]; then
1038 read count < "$notmuch_counter_state_path"
1045 test_reset_state_ () {
1046 test -z "$test_init_done_" && test_init_
1048 test_subtest_known_broken_=
1049 test_subtest_missing_external_prereq_=()
1052 # called once before the first subtest
1056 # skip all tests if there were external prerequisites missing during init
1057 test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
1061 . ./test-lib-common.sh || exit 1
1063 if [ "${NOTMUCH_GMIME_MAJOR}" = 3 ]; then
1064 test_subtest_broken_gmime_3 () {
1065 test_subtest_known_broken
1067 test_subtest_broken_gmime_2 () {
1071 test_subtest_broken_gmime_3 () {
1074 test_subtest_broken_gmime_2 () {
1075 test_subtest_known_broken
1079 emacs_generate_script
1082 # Use -P to resolve symlinks in our working directory so that the cwd
1083 # in subprocesses like git equals our $PWD (for pathname comparisons).
1084 cd -P "$test" || error "Cannot set up test environment"
1086 if test "$verbose" = "t"
1090 exec 4>test.output 3>&4
1093 for skp in $NOTMUCH_SKIP_TESTS
1096 for skp in $NOTMUCH_SKIP_TESTS
1098 case "$this_test" in
1103 case "$this_test_bare" in
1111 say_color skip >&3 "skipping test $this_test altogether"
1112 say_color skip "skip all tests in $this_test"
1117 # Provide an implementation of the 'yes' utility
1132 # Fix some commands on Windows
1135 # Windows has its own (incompatible) sort and find
1145 # git sees Windows-style pwd
1149 # no POSIX permissions
1150 # backslashes in pathspec are converted to '/'
1151 # exec does not inherit the PID
1154 test_set_prereq POSIXPERM
1155 test_set_prereq BSLASHPSPEC
1156 test_set_prereq EXECKEEPSPID
1160 test -z "$NO_PERL" && test_set_prereq PERL
1161 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1163 # test whether the filesystem supports symbolic links
1164 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
1167 # convert variable from configure to more convenient form
1168 case "$NOTMUCH_DEFAULT_XAPIAN_BACKEND" in
1176 error "Unknown Xapian backend $NOTMUCH_DEFAULT_XAPIAN_BACKEND"
1178 # declare prerequisites for external binaries used in tests
1179 test_declare_external_prereq dtach
1180 test_declare_external_prereq emacs
1181 test_declare_external_prereq ${TEST_EMACSCLIENT}
1182 test_declare_external_prereq ${TEST_GDB}
1183 test_declare_external_prereq gpg
1184 test_declare_external_prereq openssl
1185 test_declare_external_prereq gpgsm
1186 test_declare_external_prereq ${NOTMUCH_PYTHON}