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_search_sanitize ()
512 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
515 notmuch_search_files_sanitize ()
520 notmuch_dir_sanitize ()
522 sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
525 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
526 notmuch_show_sanitize ()
528 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
530 notmuch_show_sanitize_all ()
533 -e 's| filename:.*| filename:XXXXX|' \
534 -e 's| id:[^ ]* | id:XXXXX |' | \
535 notmuch_date_sanitize
538 notmuch_json_show_sanitize ()
541 -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
542 -e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
543 -e 's|"filename": "signature.asc",||g' \
544 -e 's|"filename": \["/[^"]*"\],|"filename": \["YYYYY"\],|g' \
545 -e 's|"timestamp": 97.......|"timestamp": 42|g' \
546 -e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
549 notmuch_emacs_error_sanitize ()
557 -e 's/^\[.*\]$/[XXX]/' \
558 -e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
561 notmuch_date_sanitize ()
564 -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
567 notmuch_uuid_sanitize ()
569 sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
572 notmuch_built_with_sanitize ()
574 sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
577 notmuch_config_sanitize ()
579 notmuch_dir_sanitize | notmuch_built_with_sanitize
582 # End of notmuch helper functions
584 # Use test_set_prereq to tell that a particular prerequisite is available.
586 # The prerequisite can later be checked for by using test_have_prereq.
588 # The single parameter is the prerequisite tag (a simple word, in all
589 # capital letters by convention).
592 satisfied="$satisfied$1 "
596 test_have_prereq () {
605 declare -A test_missing_external_prereq_
606 declare -A test_subtest_missing_external_prereq_
608 # declare prerequisite for the given external binary
609 test_declare_external_prereq () {
611 test "$#" = 2 && name=$2 || name="$binary(1)"
613 if ! hash $binary 2>/dev/null; then
614 test_missing_external_prereq_["${binary}"]=t
617 test_subtest_missing_external_prereq_[\"${name}\"]=t
623 # Explicitly require external prerequisite. Useful when binary is
624 # called indirectly (e.g. from emacs).
625 # Returns success if dependency is available, failure otherwise.
626 test_require_external_prereq () {
628 if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then
629 # dependency is missing, call the replacement function to note it
636 # You are not expected to call test_ok_ and test_failure_ directly, use
637 # the text_expect_* functions instead.
640 if test "$test_subtest_known_broken_" = "t"; then
641 test_known_broken_ok_
644 test_success=$(($test_success + 1))
645 if test -n "$NOTMUCH_TEST_QUIET"; then
648 say_color pass "%-6s" "PASS"
649 echo " $test_subtest_name"
653 print_test_description
654 if test "$test_subtest_known_broken_" = "t"; then
655 test_known_broken_failure_ "$@"
658 test_failure=$(($test_failure + 1))
659 test_failure_message_ "FAIL" "$test_subtest_name" "$@"
660 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
664 test_failure_message_ () {
665 say_color error "%-6s" "$1"
668 if [ "$#" != "0" ]; then
669 echo "$@" | sed -e 's/^/ /'
671 if test "$verbose" != "t"; then cat test.output; fi
674 test_known_broken_ok_ () {
676 test_fixed=$(($test_fixed+1))
677 say_color pass "%-6s" "FIXED"
678 echo " $test_subtest_name"
681 test_known_broken_failure_ () {
683 test_broken=$(($test_broken+1))
684 if [ -z "$NOTMUCH_TEST_QUIET" ]; then
685 test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
687 test_failure_message_ "BROKEN" "$test_subtest_name"
693 test "$debug" = "" || eval "$1"
698 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
701 eval >&3 2>&4 "$test_cleanup"
706 test_count=$(($test_count+1))
708 for skp in $NOTMUCH_SKIP_TESTS
710 case $this_test.$test_count in
715 case $this_test_bare.$test_count in
723 test_report_skip_ "$@"
726 test_check_missing_external_prereqs_ "$@"
731 test_check_missing_external_prereqs_ () {
732 if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then
733 say_color skip >&1 "missing prerequisites: "
734 echo ${!test_subtest_missing_external_prereq_[@]} >&1
735 test_report_skip_ "$@"
741 test_report_skip_ () {
743 say_color skip >&3 "skipping test:"
745 say_color skip "%-6s" "SKIP"
749 test_subtest_known_broken () {
750 test_subtest_known_broken_=t
753 test_expect_success () {
754 exec 1>&6 2>&7 # Restore stdout and stderr
755 if [ -z "$inside_subtest" ]; then
756 error "bug in the test script: test_expect_success without test_begin_subtest"
760 error "bug in the test script: not 1 parameters to test_expect_success"
762 if ! test_skip "$test_subtest_name"
766 # test_run_ may update missing external prerequisites
767 test_check_missing_external_prereqs_ "$@" ||
768 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
777 test_expect_code () {
778 exec 1>&6 2>&7 # Restore stdout and stderr
779 if [ -z "$inside_subtest" ]; then
780 error "bug in the test script: test_expect_code without test_begin_subtest"
784 error "bug in the test script: not 2 parameters to test_expect_code"
786 if ! test_skip "$test_subtest_name"
790 # test_run_ may update missing external prerequisites,
791 test_check_missing_external_prereqs_ "$@" ||
792 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
796 test_failure_ "exit code $eval_ret, expected $1" "$2"
801 # This is not among top-level (test_expect_success)
802 # but is a prefix that can be used in the test script, like:
804 # test_expect_success 'complain and die' '
806 # do something else &&
807 # test_must_fail git checkout ../outerspace
810 # Writing this as "! git checkout ../outerspace" is wrong, because
811 # the failure could be due to a segv. We want a controlled failure.
815 test $? -gt 0 -a $? -le 129 -o $? -gt 192
818 # test_cmp is a helper function to compare actual and expected output.
819 # You can use it like:
821 # test_expect_success 'foo works' '
822 # echo expected >expected &&
824 # test_cmp expected actual
827 # This could be written as either "cmp" or "diff -u", but:
828 # - cmp's output is not nearly as easy to read as diff -u
829 # - not all diff versions understand "-u"
835 # This function can be used to schedule some commands to be run
836 # unconditionally at the end of the test to restore sanity:
838 # test_expect_success 'test core.capslock' '
839 # git config core.capslock true &&
840 # test_when_finished "git config --unset core.capslock" &&
844 # That would be roughly equivalent to
846 # test_expect_success 'test core.capslock' '
847 # git config core.capslock true &&
849 # git config --unset core.capslock
852 # except that the greeting and config --unset must both succeed for
855 test_when_finished () {
857 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
862 test_results_dir="$TEST_DIRECTORY/test-results"
863 mkdir -p "$test_results_dir"
864 test_results_path="$test_results_dir/$this_test"
866 echo "total $test_count" >> $test_results_path
867 echo "success $test_success" >> $test_results_path
868 echo "fixed $test_fixed" >> $test_results_path
869 echo "broken $test_broken" >> $test_results_path
870 echo "failed $test_failure" >> $test_results_path
871 echo "" >> $test_results_path
873 [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
875 if [ "$test_failure" = "0" ]; then
876 if [ "$test_broken" = "0" ]; then
885 emacs_generate_script () {
886 # Construct a little test script here for the benefit of the user,
887 # (who can easily run "run_emacs" to get the same emacs environment
888 # for investigating any failures).
889 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
892 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
894 # Here's what we are using here:
896 # --quick Use minimal customization. This implies --no-init-file,
897 # --no-site-file and (emacs 24) --no-site-lisp
899 # --directory Ensure that the local elisp sources are found
901 # --load Force loading of notmuch.el and test-lib.el
903 exec ${TEST_EMACS} --quick \
904 --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
905 --directory "$TEST_DIRECTORY" --load test-lib.el \
908 chmod a+x "$TMP_DIRECTORY/run_emacs"
912 # test dependencies beforehand to avoid the waiting loop below
913 missing_dependencies=
914 test_require_external_prereq dtach || missing_dependencies=1
915 test_require_external_prereq emacs || missing_dependencies=1
916 test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
917 test -z "$missing_dependencies" || return
919 if [ -z "$EMACS_SERVER" ]; then
920 emacs_tests="${this_test_bare}.el"
921 if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
922 load_emacs_tests="--eval '(load \"$emacs_tests\")'"
926 server_name="notmuch-test-suite-$$"
927 # start a detached session with an emacs server
928 # user's TERM (or 'vt100' in case user's TERM is known dumb
929 # or unknown) is given to dtach which assumes a minimally
930 # VT100-compatible terminal -- and emacs inherits that
931 TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
932 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
935 --eval '(setq server-name \"$server_name\")' \
936 --eval '(server-start)' \
937 --eval '(orphan-watchdog $$)'" || return
938 EMACS_SERVER="$server_name"
939 # wait until the emacs server is up
940 until test_emacs '()' >/dev/null 2>/dev/null; do
945 # Clear test-output output file. Most Emacs tests end with a
946 # call to (test-output). If the test code fails with an
947 # exception before this call, the output file won't get
948 # updated. Since we don't want to compare against an output
949 # file from another test, so start out with an empty file.
953 ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $@)"
957 # Note: if there is need to print debug information from python program,
958 # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
959 PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
960 $NOTMUCH_PYTHON -B - > OUTPUT
964 MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
968 exec_file="test${test_count}"
969 test_file="${exec_file}.c"
971 ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${NOTMUCH_SRCDIR}/lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
972 echo "== stdout ==" > OUTPUT.stdout
973 echo "== stderr ==" > OUTPUT.stderr
974 ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
975 notmuch_dir_sanitize OUTPUT.stdout OUTPUT.stderr > OUTPUT
979 # Creates a script that counts how much time it is executed and calls
980 # notmuch. $notmuch_counter_command is set to the path to the
981 # generated script. Use notmuch_counter_value() function to get the
982 # current counter value.
983 notmuch_counter_reset () {
984 notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
985 if [ ! -x "$notmuch_counter_command" ]; then
986 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
987 cat >"$notmuch_counter_command" <<EOF || return
990 read count < "$notmuch_counter_state_path"
991 echo \$((count + 1)) > "$notmuch_counter_state_path"
995 chmod +x "$notmuch_counter_command" || return
998 echo 0 > "$notmuch_counter_state_path"
1001 # Returns the current notmuch counter value.
1002 notmuch_counter_value () {
1003 if [ -r "$notmuch_counter_state_path" ]; then
1004 read count < "$notmuch_counter_state_path"
1011 test_reset_state_ () {
1012 test -z "$test_init_done_" && test_init_
1014 test_subtest_known_broken_=
1015 test_subtest_missing_external_prereq_=()
1018 # called once before the first subtest
1022 # skip all tests if there were external prerequisites missing during init
1023 test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
1027 . ./test-lib-common.sh || exit 1
1029 if [ "${NOTMUCH_GMIME_MAJOR}" = 3 ]; then
1030 test_subtest_broken_gmime_3 () {
1031 test_subtest_known_broken
1033 test_subtest_broken_gmime_2 () {
1037 test_subtest_broken_gmime_3 () {
1040 test_subtest_broken_gmime_2 () {
1041 test_subtest_known_broken
1045 emacs_generate_script
1048 # Use -P to resolve symlinks in our working directory so that the cwd
1049 # in subprocesses like git equals our $PWD (for pathname comparisons).
1050 cd -P "$test" || error "Cannot set up test environment"
1052 if test "$verbose" = "t"
1056 exec 4>test.output 3>&4
1059 for skp in $NOTMUCH_SKIP_TESTS
1062 for skp in $NOTMUCH_SKIP_TESTS
1064 case "$this_test" in
1069 case "$this_test_bare" in
1077 say_color skip >&3 "skipping test $this_test altogether"
1078 say_color skip "skip all tests in $this_test"
1083 # Provide an implementation of the 'yes' utility
1098 # Fix some commands on Windows
1101 # Windows has its own (incompatible) sort and find
1111 # git sees Windows-style pwd
1115 # no POSIX permissions
1116 # backslashes in pathspec are converted to '/'
1117 # exec does not inherit the PID
1120 test_set_prereq POSIXPERM
1121 test_set_prereq BSLASHPSPEC
1122 test_set_prereq EXECKEEPSPID
1126 test -z "$NO_PERL" && test_set_prereq PERL
1127 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1129 # test whether the filesystem supports symbolic links
1130 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
1133 # convert variable from configure to more convenient form
1134 case "$NOTMUCH_DEFAULT_XAPIAN_BACKEND" in
1142 error "Unknown Xapian backend $NOTMUCH_DEFAULT_XAPIAN_BACKEND"
1144 # declare prerequisites for external binaries used in tests
1145 test_declare_external_prereq dtach
1146 test_declare_external_prereq emacs
1147 test_declare_external_prereq ${TEST_EMACSCLIENT}
1148 test_declare_external_prereq ${TEST_GDB}
1149 test_declare_external_prereq gpg
1150 test_declare_external_prereq openssl
1151 test_declare_external_prereq gpgsm
1152 test_declare_external_prereq ${NOTMUCH_PYTHON}