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.
30 this_test=${this_test%.sh}
31 this_test_bare=${this_test#T[0-9][0-9][0-9]-}
33 # if --tee was passed, write the output not only to the terminal, but
34 # additionally to the file test-results/$BASENAME.out, too.
35 case "$GIT_TEST_TEE_STARTED, $* " in
37 # do not redirect again
39 *' --tee '*|*' --va'*)
41 BASE=test-results/$this_test
42 (GIT_TEST_TEE_STARTED=done "$BASH" "$0" "$@" 2>&1;
43 echo $? > $BASE.exit) | tee $BASE.out
44 test "$(cat $BASE.exit)" = 0
49 # Save STDOUT to fd 6 and STDERR to fd 7.
51 # Make xtrace debugging (when used) use redirected STDERR, with verbose lead:
53 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
55 # Keep the original TERM for say_color and test_emacs
58 # Set SMART_TERM to vt100 for known dumb/unknown terminal.
59 # Otherwise use whatever TERM is currently used so that
60 # users' actual TERM environments are being used in tests.
68 # For repeatability, reset the environment to known value.
74 export LANG LC_ALL PAGER TERM TZ
75 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
76 if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \
77 ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then
78 echo "error: must specify both or neither of TEST_EMACS and TEST_EMACSCLIENT" >&2
81 TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
82 TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
83 TEST_GDB=${TEST_GDB:-gdb}
84 TEST_CC=${TEST_CC:-cc}
85 TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"}
87 # Protect ourselves from common misconfiguration to export
88 # CDPATH into the environment
94 unset ALTERNATE_EDITOR
96 # Each test should start with something like this, after copyright notices:
98 # test_description='Description of this test...
99 # This test checks if command xyzzy does the right thing...
101 # . ./test-lib.sh || exit 1
103 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
104 TERM=$ORIGINAL_TERM &&
107 tput bold >/dev/null 2>&1 &&
108 tput setaf 1 >/dev/null 2>&1 &&
109 tput sgr0 >/dev/null 2>&1
113 while test "$#" -ne 0
119 immediate=t; shift ;;
127 with_dashes=t; shift ;;
134 valgrind=t; verbose=t; shift ;;
136 shift ;; # was handled already
138 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
141 echo "error: unknown test option '$1'" >&2; exit 1 ;;
145 if test -n "$debug"; then
147 printf " %-4s" "[$((test_count - 1))]"
155 if test -n "$color"; then
161 error) tput bold; tput setaf 1;; # bold red
162 skip) tput bold; tput setaf 2;; # bold green
163 pass) tput setaf 2;; # green
164 info) tput setaf 3;; # brown
165 *) test -n "$quiet" && return;;
176 test -z "$1" && test -n "$quiet" && return
185 say_color error "error: $*\n"
194 test "${test_description}" != "" ||
195 error "Test script did not set test_description."
197 if test "$help" = "t"
199 echo "Tests ${test_description}"
203 test_description_printed=
204 print_test_description ()
206 test -z "$test_description_printed" || return 0
208 echo $this_test: "Testing ${test_description}"
209 test_description_printed=1
211 if [ -z "$NOTMUCH_TEST_QUIET" ]
213 print_test_description
222 declare -a _exit_functions=()
224 at_exit_function () {
225 _exit_functions=($1 ${_exit_functions[@]/$1})
228 rm_exit_function () {
229 _exit_functions=(${_exit_functions[@]/$1})
236 for _fn in ${_exit_functions[@]}; do $_fn; done
237 rm -rf "$TEST_TMPDIR"
242 if test -n "$GIT_EXIT_OK"
247 say_color error '%-6s' FATAL
248 echo " $test_subtest_name"
250 echo "Unexpected exit while executing $0. Exit code $code."
257 echo >&6 "FATAL: $0: interrupted by signal" $((code - 128))
264 say_color error '%-6s' FATAL
267 echo "Unexpected exit while executing $0."
272 # Note: TEST_TMPDIR *NOT* exported!
273 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
274 # Put GNUPGHOME in TMPDIR to avoid problems with long paths.
275 export GNUPGHOME="${TEST_TMPDIR}/gnupg"
276 trap 'trap_exit' EXIT
277 trap 'trap_signal' HUP INT TERM
279 # Deliver a message with emacs and add it to the database
281 # Uses emacs to generate and deliver a message to the mail store.
282 # Accepts arbitrary extra emacs/elisp functions to modify the message
283 # before sending, which is useful to doing things like attaching files
284 # to the message and encrypting/signing.
285 emacs_deliver_message ()
290 # before we can send a message, we have to prepare the FCC maildir
291 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
292 # eval'ing smtp-dummy --background will set smtp_dummy_pid
294 eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
295 test -n "$smtp_dummy_pid" || return 1
298 "(let ((message-send-mail-function 'message-smtpmail-send-it)
299 (mail-host-address \"example.com\")
300 (smtpmail-smtp-server \"localhost\")
301 (smtpmail-smtp-service \"25025\"))
304 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
305 (message-goto-subject)
306 (insert \"${subject}\")
310 (notmuch-mua-send-and-exit))"
312 # In case message was sent properly, client waits for confirmation
313 # before exiting and resuming control here; therefore making sure
314 # that server exits by sending (KILL) signal to it is safe.
315 kill -9 $smtp_dummy_pid
316 notmuch new >/dev/null
319 # Pretend to deliver a message with emacs. Really save it to a file
320 # and add it to the database
322 # Uses emacs to generate and deliver a message to the mail store.
323 # Accepts arbitrary extra emacs/elisp functions to modify the message
324 # before sending, which is useful to doing things like attaching files
325 # to the message and encrypting/signing.
331 # before we can send a message, we have to prepare the FCC maildir
332 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
335 "(let ((message-send-mail-function (lambda () t))
336 (mail-host-address \"example.com\"))
339 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
340 (message-goto-subject)
341 (insert \"${subject}\")
345 (notmuch-mua-send-and-exit))" || return 1
346 notmuch new >/dev/null
349 # Add an existing, fixed corpus of email to the database.
351 # $1 is the corpus dir under corpora to add, using "default" if unset.
353 # The default corpus is based on about 50 messages from early in the
354 # history of the notmuch mailing list, which allows for reliably
355 # testing commands that need to operate on a not-totally-trivial
356 # number of messages.
362 if [ -d $TEST_DIRECTORY/corpora.mail/$corpus ]; then
363 cp -a $TEST_DIRECTORY/corpora.mail/$corpus ${MAIL_DIR}
365 cp -a $TEST_DIRECTORY/corpora/$corpus ${MAIL_DIR}
366 notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
367 mkdir -p $TEST_DIRECTORY/corpora.mail
368 cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpora.mail/$corpus
372 test_begin_subtest ()
374 if [ -n "$inside_subtest" ]; then
375 exec 1>&6 2>&7 # Restore stdout and stderr
376 error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
378 test_subtest_name="$1"
380 # Redirect test output to the previously prepared file descriptors
381 # 3 and 4 (see below)
382 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
387 # Pass test if two arguments match
389 # Note: Unlike all other test_expect_* functions, this function does
390 # not accept a test name. Instead, the caller should call
391 # test_begin_subtest before calling this function in order to set the
395 exec 1>&6 2>&7 # Restore stdout and stderr
396 if [ -z "$inside_subtest" ]; then
397 error "bug in the test script: test_expect_equal without test_begin_subtest"
401 error "bug in the test script: not 2 parameters to test_expect_equal"
405 if ! test_skip "$test_subtest_name"
407 if [ "$output" = "$expected" ]; then
410 testname=$this_test.$test_count
411 echo "$expected" > $testname.expected
412 echo "$output" > $testname.output
413 test_failure_ "$(diff -u $testname.expected $testname.output)"
418 # Like test_expect_equal, but takes two filenames.
419 test_expect_equal_file ()
421 exec 1>&6 2>&7 # Restore stdout and stderr
422 if [ -z "$inside_subtest" ]; then
423 error "bug in the test script: test_expect_equal_file without test_begin_subtest"
427 error "bug in the test script: not 2 parameters to test_expect_equal_file"
431 if ! test_skip "$test_subtest_name"
433 if diff -q "$file1" "$file2" >/dev/null ; then
436 testname=$this_test.$test_count
437 basename1=`basename "$file1"`
438 basename2=`basename "$file2"`
439 cp "$file1" "$testname.$basename1"
440 cp "$file2" "$testname.$basename2"
441 test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"
446 # Like test_expect_equal, but arguments are JSON expressions to be
447 # canonicalized before diff'ing. If an argument cannot be parsed, it
448 # is used unchanged so that there's something to diff against.
449 test_expect_equal_json () {
450 # The test suite forces LC_ALL=C, but this causes Python 3 to
451 # decode stdin as ASCII. We need to read JSON in UTF-8, so
452 # override Python's stdio encoding defaults.
453 local script='import json, sys; json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)'
454 output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \
456 expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \
459 test_expect_equal "$output" "$expected" "$@"
462 # Sort the top-level list of JSON data from stdin.
464 PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \
465 "import sys, json; json.dump(sorted(json.load(sys.stdin)),sys.stdout)"
468 test_emacs_expect_t () {
470 error "bug in the test script: not 1 parameter to test_emacs_expect_t"
471 if [ -z "$inside_subtest" ]; then
472 error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
476 if ! test_skip "$test_subtest_name"
478 test_emacs "(notmuch-test-run $1)" >/dev/null
480 # Restore state after the test.
481 exec 1>&6 2>&7 # Restore stdout and stderr
484 # Report success/failure.
490 test_failure_ "${result}"
493 # Restore state after the (non) test.
494 exec 1>&6 2>&7 # Restore stdout and stderr
501 notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
506 # this relies on the default format being batch-tag, otherwise some tests will break
507 notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
510 notmuch_drop_mail_headers ()
514 msg = email.message_from_file(sys.stdin)
515 for hdr in sys.argv[1:]: del msg[hdr]
516 print(msg.as_string(False))
520 notmuch_search_sanitize ()
522 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
525 notmuch_search_files_sanitize ()
530 notmuch_dir_sanitize ()
532 sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
535 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
536 notmuch_show_sanitize ()
538 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
540 notmuch_show_sanitize_all ()
543 -e 's| filename:.*| filename:XXXXX|' \
544 -e 's| id:[^ ]* | id:XXXXX |' | \
545 notmuch_date_sanitize
548 notmuch_json_show_sanitize ()
551 -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
552 -e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
553 -e 's|"filename": "signature.asc",||g' \
554 -e 's|"filename": \["/[^"]*"\],|"filename": \["YYYYY"\],|g' \
555 -e 's|"timestamp": 97.......|"timestamp": 42|g' \
556 -e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
559 notmuch_emacs_error_sanitize ()
567 -e 's/^\[.*\]$/[XXX]/' \
568 -e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
571 notmuch_date_sanitize ()
574 -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
577 notmuch_uuid_sanitize ()
579 sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
582 notmuch_built_with_sanitize ()
584 sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
587 notmuch_config_sanitize ()
589 notmuch_dir_sanitize | notmuch_built_with_sanitize
592 # End of notmuch helper functions
594 # Use test_set_prereq to tell that a particular prerequisite is available.
596 # The prerequisite can later be checked for by using test_have_prereq.
598 # The single parameter is the prerequisite tag (a simple word, in all
599 # capital letters by convention).
602 satisfied="$satisfied$1 "
606 test_have_prereq () {
615 declare -A test_missing_external_prereq_
616 declare -A test_subtest_missing_external_prereq_
618 # declare prerequisite for the given external binary
619 test_declare_external_prereq () {
621 test "$#" = 2 && name=$2 || name="$binary(1)"
623 if ! hash $binary 2>/dev/null; then
624 test_missing_external_prereq_["${binary}"]=t
627 test_subtest_missing_external_prereq_[\"${name}\"]=t
633 # Explicitly require external prerequisite. Useful when binary is
634 # called indirectly (e.g. from emacs).
635 # Returns success if dependency is available, failure otherwise.
636 test_require_external_prereq () {
638 if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then
639 # dependency is missing, call the replacement function to note it
646 # You are not expected to call test_ok_ and test_failure_ directly, use
647 # the text_expect_* functions instead.
650 if test "$test_subtest_known_broken_" = "t"; then
651 test_known_broken_ok_
654 test_success=$(($test_success + 1))
655 if test -n "$NOTMUCH_TEST_QUIET"; then
658 say_color pass "%-6s" "PASS"
659 echo " $test_subtest_name"
663 print_test_description
664 if test "$test_subtest_known_broken_" = "t"; then
665 test_known_broken_failure_ "$@"
668 test_failure=$(($test_failure + 1))
669 test_failure_message_ "FAIL" "$test_subtest_name" "$@"
670 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
674 test_failure_message_ () {
675 say_color error "%-6s" "$1"
678 if [ "$#" != "0" ]; then
679 echo "$@" | sed -e 's/^/ /'
681 if test "$verbose" != "t"; then cat test.output; fi
684 test_known_broken_ok_ () {
686 test_fixed=$(($test_fixed+1))
687 say_color pass "%-6s" "FIXED"
688 echo " $test_subtest_name"
691 test_known_broken_failure_ () {
693 test_broken=$(($test_broken+1))
694 if [ -z "$NOTMUCH_TEST_QUIET" ]; then
695 test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
697 test_failure_message_ "BROKEN" "$test_subtest_name"
703 test "$debug" = "" || eval "$1"
708 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
711 eval >&3 2>&4 "$test_cleanup"
716 test_count=$(($test_count+1))
718 for skp in $NOTMUCH_SKIP_TESTS
720 case $this_test.$test_count in
725 case $this_test_bare.$test_count in
733 test_report_skip_ "$@"
736 test_check_missing_external_prereqs_ "$@"
741 test_check_missing_external_prereqs_ () {
742 if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then
743 say_color skip >&1 "missing prerequisites: "
744 echo ${!test_subtest_missing_external_prereq_[@]} >&1
745 test_report_skip_ "$@"
751 test_report_skip_ () {
753 say_color skip >&3 "skipping test:"
755 say_color skip "%-6s" "SKIP"
759 test_subtest_known_broken () {
760 test_subtest_known_broken_=t
763 test_expect_success () {
764 exec 1>&6 2>&7 # Restore stdout and stderr
765 if [ -z "$inside_subtest" ]; then
766 error "bug in the test script: test_expect_success without test_begin_subtest"
770 error "bug in the test script: not 1 parameters to test_expect_success"
772 if ! test_skip "$test_subtest_name"
776 # test_run_ may update missing external prerequisites
777 test_check_missing_external_prereqs_ "$@" ||
778 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
787 test_expect_code () {
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_code without test_begin_subtest"
794 error "bug in the test script: not 2 parameters to test_expect_code"
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" = "$1" ]
806 test_failure_ "exit code $eval_ret, expected $1" "$2"
811 # This is not among top-level (test_expect_success)
812 # but is a prefix that can be used in the test script, like:
814 # test_expect_success 'complain and die' '
816 # do something else &&
817 # test_must_fail git checkout ../outerspace
820 # Writing this as "! git checkout ../outerspace" is wrong, because
821 # the failure could be due to a segv. We want a controlled failure.
825 test $? -gt 0 -a $? -le 129 -o $? -gt 192
828 # test_cmp is a helper function to compare actual and expected output.
829 # You can use it like:
831 # test_expect_success 'foo works' '
832 # echo expected >expected &&
834 # test_cmp expected actual
837 # This could be written as either "cmp" or "diff -u", but:
838 # - cmp's output is not nearly as easy to read as diff -u
839 # - not all diff versions understand "-u"
845 # This function can be used to schedule some commands to be run
846 # unconditionally at the end of the test to restore sanity:
848 # test_expect_success 'test core.capslock' '
849 # git config core.capslock true &&
850 # test_when_finished "git config --unset core.capslock" &&
854 # That would be roughly equivalent to
856 # test_expect_success 'test core.capslock' '
857 # git config core.capslock true &&
859 # git config --unset core.capslock
862 # except that the greeting and config --unset must both succeed for
865 test_when_finished () {
867 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
872 test_results_dir="$TEST_DIRECTORY/test-results"
873 mkdir -p "$test_results_dir"
874 test_results_path="$test_results_dir/$this_test"
876 echo "total $test_count" >> $test_results_path
877 echo "success $test_success" >> $test_results_path
878 echo "fixed $test_fixed" >> $test_results_path
879 echo "broken $test_broken" >> $test_results_path
880 echo "failed $test_failure" >> $test_results_path
881 echo "" >> $test_results_path
883 [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
885 if [ "$test_failure" = "0" ]; then
886 if [ "$test_broken" = "0" ]; then
895 emacs_generate_script () {
896 # Construct a little test script here for the benefit of the user,
897 # (who can easily run "run_emacs" to get the same emacs environment
898 # for investigating any failures).
899 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
902 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
904 # Here's what we are using here:
906 # --quick Use minimal customization. This implies --no-init-file,
907 # --no-site-file and (emacs 24) --no-site-lisp
909 # --directory Ensure that the local elisp sources are found
911 # --load Force loading of notmuch.el and test-lib.el
913 exec ${TEST_EMACS} --quick \
914 --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
915 --directory "$TEST_DIRECTORY" --load test-lib.el \
918 chmod a+x "$TMP_DIRECTORY/run_emacs"
922 # test dependencies beforehand to avoid the waiting loop below
923 missing_dependencies=
924 test_require_external_prereq dtach || missing_dependencies=1
925 test_require_external_prereq emacs || missing_dependencies=1
926 test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
927 test -z "$missing_dependencies" || return
929 if [ -z "$EMACS_SERVER" ]; then
930 emacs_tests="${this_test_bare}.el"
931 if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
932 load_emacs_tests="--eval '(load \"$emacs_tests\")'"
936 server_name="notmuch-test-suite-$$"
937 # start a detached session with an emacs server
938 # user's TERM (or 'vt100' in case user's TERM is known dumb
939 # or unknown) is given to dtach which assumes a minimally
940 # VT100-compatible terminal -- and emacs inherits that
941 TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
942 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
945 --eval '(setq server-name \"$server_name\")' \
946 --eval '(server-start)' \
947 --eval '(orphan-watchdog $$)'" || return
948 EMACS_SERVER="$server_name"
949 # wait until the emacs server is up
950 until test_emacs '()' >/dev/null 2>/dev/null; do
955 # Clear test-output output file. Most Emacs tests end with a
956 # call to (test-output). If the test code fails with an
957 # exception before this call, the output file won't get
958 # updated. Since we don't want to compare against an output
959 # file from another test, so start out with an empty file.
963 ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $@)"
967 # Note: if there is need to print debug information from python program,
968 # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
969 PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
970 $NOTMUCH_PYTHON -B - > OUTPUT
974 MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
978 exec_file="test${test_count}"
979 test_file="${exec_file}.c"
981 ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${NOTMUCH_SRCDIR}/lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
982 echo "== stdout ==" > OUTPUT.stdout
983 echo "== stderr ==" > OUTPUT.stderr
984 ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
985 notmuch_dir_sanitize OUTPUT.stdout OUTPUT.stderr > OUTPUT
989 # Creates a script that counts how much time it is executed and calls
990 # notmuch. $notmuch_counter_command is set to the path to the
991 # generated script. Use notmuch_counter_value() function to get the
992 # current counter value.
993 notmuch_counter_reset () {
994 notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
995 if [ ! -x "$notmuch_counter_command" ]; then
996 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
997 cat >"$notmuch_counter_command" <<EOF || return
1000 read count < "$notmuch_counter_state_path"
1001 echo \$((count + 1)) > "$notmuch_counter_state_path"
1005 chmod +x "$notmuch_counter_command" || return
1008 echo 0 > "$notmuch_counter_state_path"
1011 # Returns the current notmuch counter value.
1012 notmuch_counter_value () {
1013 if [ -r "$notmuch_counter_state_path" ]; then
1014 read count < "$notmuch_counter_state_path"
1021 test_reset_state_ () {
1022 test -z "$test_init_done_" && test_init_
1024 test_subtest_known_broken_=
1025 test_subtest_missing_external_prereq_=()
1028 # called once before the first subtest
1032 # skip all tests if there were external prerequisites missing during init
1033 test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
1037 . ./test-lib-common.sh || exit 1
1039 if [ "${NOTMUCH_GMIME_MAJOR}" = 3 ]; then
1040 test_subtest_broken_gmime_3 () {
1041 test_subtest_known_broken
1043 test_subtest_broken_gmime_2 () {
1047 test_subtest_broken_gmime_3 () {
1050 test_subtest_broken_gmime_2 () {
1051 test_subtest_known_broken
1055 emacs_generate_script
1058 # Use -P to resolve symlinks in our working directory so that the cwd
1059 # in subprocesses like git equals our $PWD (for pathname comparisons).
1060 cd -P "$test" || error "Cannot set up test environment"
1062 if test "$verbose" = "t"
1066 exec 4>test.output 3>&4
1069 for skp in $NOTMUCH_SKIP_TESTS
1072 for skp in $NOTMUCH_SKIP_TESTS
1074 case "$this_test" in
1079 case "$this_test_bare" in
1087 say_color skip >&3 "skipping test $this_test altogether"
1088 say_color skip "skip all tests in $this_test"
1093 # Provide an implementation of the 'yes' utility
1108 # Fix some commands on Windows
1111 # Windows has its own (incompatible) sort and find
1121 # git sees Windows-style pwd
1125 # no POSIX permissions
1126 # backslashes in pathspec are converted to '/'
1127 # exec does not inherit the PID
1130 test_set_prereq POSIXPERM
1131 test_set_prereq BSLASHPSPEC
1132 test_set_prereq EXECKEEPSPID
1136 test -z "$NO_PERL" && test_set_prereq PERL
1137 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1139 # test whether the filesystem supports symbolic links
1140 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
1143 # convert variable from configure to more convenient form
1144 case "$NOTMUCH_DEFAULT_XAPIAN_BACKEND" in
1152 error "Unknown Xapian backend $NOTMUCH_DEFAULT_XAPIAN_BACKEND"
1154 # declare prerequisites for external binaries used in tests
1155 test_declare_external_prereq dtach
1156 test_declare_external_prereq emacs
1157 test_declare_external_prereq ${TEST_EMACSCLIENT}
1158 test_declare_external_prereq ${TEST_GDB}
1159 test_declare_external_prereq gpg
1160 test_declare_external_prereq openssl
1161 test_declare_external_prereq gpgsm
1162 test_declare_external_prereq ${NOTMUCH_PYTHON}