3 # Copyright (c) 2005 Junio C Hamano
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 http://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 # if --tee was passed, write the output not only to the terminal, but
27 # additionally to the file test-results/$BASENAME.out, too.
28 case "$GIT_TEST_TEE_STARTED, $* " in
30 # do not redirect again
32 *' --tee '*|*' --va'*)
34 BASE=test-results/$(basename "$0" .sh)
35 (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
36 echo $? > $BASE.exit) | tee $BASE.out
37 test "$(cat $BASE.exit)" = 0
42 # Keep the original TERM for say_color and test_emacs
45 # For repeatability, reset the environment to known value.
51 export LANG LC_ALL PAGER TERM TZ
52 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
54 # Protect ourselves from common misconfiguration to export
55 # CDPATH into the environment
62 # A regexp to match 5 and 40 hexdigits
63 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
64 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
66 _x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
67 _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
69 # Each test should start with something like this, after copyright notices:
71 # test_description='Description of this test...
72 # This test checks if command xyzzy does the right thing...
75 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
76 TERM=$ORIGINAL_TERM &&
79 tput bold >/dev/null 2>&1 &&
80 tput setaf 1 >/dev/null 2>&1 &&
81 tput sgr0 >/dev/null 2>&1
88 -d|--d|--de|--deb|--debu|--debug)
90 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
92 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
93 GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
94 -h|--h|--he|--hel|--help)
96 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
98 -q|--q|--qu|--qui|--quie|--quiet)
101 with_dashes=t; shift ;;
107 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
108 valgrind=t; verbose=t; shift ;;
110 shift ;; # was handled already
112 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
115 echo "error: unknown test option '$1'" >&2; exit 1 ;;
119 if test -n "$color"; then
125 error) tput bold; tput setaf 1;; # bold red
126 skip) tput bold; tput setaf 2;; # bold green
127 pass) tput setaf 2;; # green
128 info) tput setaf 3;; # brown
129 *) test -n "$quiet" && return;;
139 test -z "$1" && test -n "$quiet" && return
147 say_color error "error: $*\n"
156 test "${test_description}" != "" ||
157 error "Test script did not set test_description."
159 if test "$help" = "t"
161 echo "Tests ${test_description}"
165 echo $(basename "$0"): "Testing ${test_description}"
177 rm -rf "$TEST_TMPDIR"
178 if test -n "$GIT_EXIT_OK"
182 echo >&5 "FATAL: Unexpected exit with code $code"
188 # Note: TEST_TMPDIR *NOT* exported!
189 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
192 test_decode_color () {
193 sed -e 's/.\[1m/<WHITE>/g' \
194 -e 's/.\[31m/<RED>/g' \
195 -e 's/.\[32m/<GREEN>/g' \
196 -e 's/.\[33m/<YELLOW>/g' \
197 -e 's/.\[34m/<BLUE>/g' \
198 -e 's/.\[35m/<MAGENTA>/g' \
199 -e 's/.\[36m/<CYAN>/g' \
200 -e 's/.\[m/<RESET>/g'
212 sed -e 's/$/Q/' | tr Q '\015'
216 tr '\015' Q | sed -e 's/Q$//'
219 # Generate a new message in the mail directory, with a unique message
220 # ID and subject. The message is not added to the index.
222 # After this function returns, the filename of the generated message
223 # is available as $gen_msg_filename and the message ID is available as
226 # This function supports named parameters with the bash syntax for
227 # assigning a value to an associative array ([name]=value). The
228 # supported parameters are:
230 # [dir]=directory/of/choice
232 # Generate the message in directory 'directory/of/choice' within
233 # the mail store. The directory will be created if necessary.
237 # Store the message in file 'name'. The default is to store it
238 # in 'msg-<count>', where <count> is three-digit number of the
243 # Text to use as the body of the email message
245 # '[from]="Some User <user@example.com>"'
246 # '[to]="Some User <user@example.com>"'
247 # '[subject]="Subject of email message"'
248 # '[date]="RFC 822 Date"'
250 # Values for email headers. If not provided, default values will
251 # be generated instead.
253 # '[cc]="Some User <user@example.com>"'
254 # [reply-to]=some-address
255 # [in-reply-to]=<message-id>
256 # [references]=<message-id>
257 # [content-type]=content-type-specification
258 # '[header]=full header line, including keyword'
260 # Additional values for email headers. If these are not provided
261 # then the relevant headers will simply not appear in the
266 # Controls the message-id of the created message.
272 # This is our (bash-specific) magic for doing named parameters
273 local -A template="($@)"
274 local additional_headers
276 gen_msg_cnt=$((gen_msg_cnt + 1))
277 if [ -z "${template[filename]}" ]; then
278 gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"
280 gen_msg_name=${template[filename]}
283 if [ -z "${template[id]}" ]; then
284 gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"
286 gen_msg_id="${template[id]}"
289 if [ -z "${template[dir]}" ]; then
290 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
292 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
293 mkdir -p "$(dirname "$gen_msg_filename")"
296 if [ -z "${template[body]}" ]; then
297 template[body]="This is just a test message (#${gen_msg_cnt})"
300 if [ -z "${template[from]}" ]; then
301 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
304 if [ -z "${template[to]}" ]; then
305 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
308 if [ -z "${template[subject]}" ]; then
309 template[subject]="Test message #${gen_msg_cnt}"
312 if [ -z "${template[date]}" ]; then
313 template[date]="Tue, 05 Jan 2001 15:43:57 -0000"
316 additional_headers=""
317 if [ ! -z "${template[header]}" ]; then
318 additional_headers="${template[header]}
319 ${additional_headers}"
322 if [ ! -z "${template[reply-to]}" ]; then
323 additional_headers="Reply-To: ${template[reply-to]}
324 ${additional_headers}"
327 if [ ! -z "${template[in-reply-to]}" ]; then
328 additional_headers="In-Reply-To: ${template[in-reply-to]}
329 ${additional_headers}"
332 if [ ! -z "${template[cc]}" ]; then
333 additional_headers="Cc: ${template[cc]}
334 ${additional_headers}"
337 if [ ! -z "${template[references]}" ]; then
338 additional_headers="References: ${template[references]}
339 ${additional_headers}"
342 if [ ! -z "${template[content-type]}" ]; then
343 additional_headers="Content-Type: ${template[content-type]}
344 ${additional_headers}"
347 # Note that in the way we're setting it above and using it below,
348 # `additional_headers' will also serve as the header / body separator
349 # (empty line in between).
351 cat <<EOF >"$gen_msg_filename"
352 From: ${template[from]}
354 Message-Id: <${gen_msg_id}>
355 Subject: ${template[subject]}
356 Date: ${template[date]}
357 ${additional_headers}
362 # Generate a new message and add it to the database.
364 # All of the arguments and return values supported by generate_message
365 # are also supported here, so see that function for details.
368 generate_message "$@" &&
369 notmuch new > /dev/null
372 # Deliver a message with emacs and add it to the database
374 # Uses emacs to generate and deliver a message to the mail store.
375 # Accepts arbitrary extra emacs/elisp functions to modify the message
376 # before sending, which is useful to doing things like attaching files
377 # to the message and encrypting/signing.
378 emacs_deliver_message ()
383 # before we can send a message, we have to prepare the FCC maildir
384 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
385 $TEST_DIRECTORY/smtp-dummy sent_message &
388 "(let ((message-send-mail-function 'message-smtpmail-send-it)
389 (smtpmail-smtp-server \"localhost\")
390 (smtpmail-smtp-service \"25025\"))
394 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
395 (message-goto-subject)
396 (insert \"${subject}\")
400 (message-send-and-exit))"
401 # opportunistically quit smtp-dummy in case above fails.
402 { echo QUIT > /dev/tcp/localhost/25025; } 2>/dev/null
403 wait ${smtp_dummy_pid}
404 notmuch new >/dev/null
407 # Generate a corpus of email and add it to the database.
409 # This corpus is fixed, (it happens to be 50 messages from early in
410 # the history of the notmuch mailing list), which allows for reliably
411 # testing commands that need to operate on a not-totally-trivial
412 # number of messages.
416 if [ -d $TEST_DIRECTORY/corpus.mail ]; then
417 cp -a $TEST_DIRECTORY/corpus.mail ${MAIL_DIR}
419 cp -a $TEST_DIRECTORY/corpus ${MAIL_DIR}
420 notmuch new >/dev/null
421 cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpus.mail
425 test_begin_subtest ()
427 if [ -n "$inside_subtest" ]; then
428 exec 1>&6 2>&7 # Restore stdout and stderr
429 error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
431 test_subtest_name="$1"
433 # Remember stdout and stderr file descriptors and redirect test
434 # output to the previously prepared file descriptors 3 and 4 (see
436 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
437 exec 6>&1 7>&2 >&3 2>&4
441 # Pass test if two arguments match
443 # Note: Unlike all other test_expect_* functions, this function does
444 # not accept a test name. Instead, the caller should call
445 # test_begin_subtest before calling this function in order to set the
449 exec 1>&6 2>&7 # Restore stdout and stderr
451 test "$#" = 3 && { prereq=$1; shift; } || prereq=
453 error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
457 if ! test_skip "$test_subtest_name"
459 if [ "$output" = "$expected" ]; then
460 test_ok_ "$test_subtest_name"
462 testname=$this_test.$test_count
463 echo "$expected" > $testname.expected
464 echo "$output" > $testname.output
465 test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"
470 # Like test_expect_equal, but takes two filenames.
471 test_expect_equal_file ()
473 exec 1>&6 2>&7 # Restore stdout and stderr
475 test "$#" = 3 && { prereq=$1; shift; } || prereq=
477 error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
481 if ! test_skip "$test_subtest_name"
483 if diff -q "$expected" "$output" >/dev/null ; then
484 test_ok_ "$test_subtest_name"
486 testname=$this_test.$test_count
487 cp "$output" $testname.output
488 cp "$expected" $testname.expected
489 test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"
496 notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
499 notmuch_search_sanitize ()
501 sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
504 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
505 notmuch_show_sanitize ()
507 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
509 notmuch_show_sanitize_all ()
512 -e 's| filename:.*| filename:XXXXX|' \
513 -e 's| id:[^ ]* | id:XXXXX |'
516 notmuch_json_show_sanitize ()
518 sed -e 's|, |,\n |g' | \
520 -e 's|"id": "[^"]*",|"id": "XXXXX",|' \
521 -e 's|"filename": "[^"]*",|"filename": "YYYYY",|'
524 # End of notmuch helper functions
526 # Use test_set_prereq to tell that a particular prerequisite is available.
527 # The prerequisite can later be checked for in two ways:
529 # - Explicitly using test_have_prereq.
531 # - Implicitly by specifying the prerequisite tag in the calls to
532 # test_expect_{success,failure,code}.
534 # The single parameter is the prerequisite tag (a simple word, in all
535 # capital letters by convention).
538 satisfied="$satisfied$1 "
542 test_have_prereq () {
551 # declare prerequisite for the given external binary
552 test_declare_external_prereq () {
554 test "$#" = 2 && name=$2 || name="$binary(1)"
556 hash $binary 2>/dev/null || eval "
557 test_missing_external_prereq_${binary}_=t
559 echo -n \"\$test_subtest_missing_external_prereqs_ \" | grep -qe \" $name \" ||
560 test_subtest_missing_external_prereqs_=\"\$test_subtest_missing_external_prereqs_ $name\"
565 # Explicitly require external prerequisite. Useful when binary is
566 # called indirectly (e.g. from emacs).
567 # Returns success if dependency is available, failure otherwise.
568 test_require_external_prereq () {
570 if [ "$(eval echo -n \$test_missing_external_prereq_${binary}_)" = t ]; then
571 # dependency is missing, call the replacement function to note it
578 # You are not expected to call test_ok_ and test_failure_ directly, use
579 # the text_expect_* functions instead.
582 if test "$test_subtest_known_broken_" = "t"; then
583 test_known_broken_ok_ "$@"
586 test_success=$(($test_success + 1))
587 say_color pass "%-6s" "PASS"
592 if test "$test_subtest_known_broken_" = "t"; then
593 test_known_broken_failure_ "$@"
596 test_failure=$(($test_failure + 1))
597 test_failure_message_ "FAIL" "$@"
598 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
602 test_failure_message_ () {
603 say_color error "%-6s" "$1"
606 echo "$@" | sed -e 's/^/ /'
607 if test "$verbose" != "t"; then cat test.output; fi
610 test_known_broken_ok_ () {
612 test_fixed=$(($test_fixed+1))
613 say_color pass "%-6s" "FIXED"
617 test_known_broken_failure_ () {
619 test_broken=$(($test_broken+1))
620 test_failure_message_ "BROKEN" "$@"
625 test "$debug" = "" || eval "$1"
630 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
633 eval >&3 2>&4 "$test_cleanup"
638 test_count=$(($test_count+1))
640 for skp in $NOTMUCH_SKIP_TESTS
642 case $this_test.$test_count in
647 if test -z "$to_skip" && test -n "$prereq" &&
648 ! test_have_prereq "$prereq"
654 test_report_skip_ "$@"
657 test_check_missing_external_prereqs_ "$@"
662 test_check_missing_external_prereqs_ () {
663 if test -n "$test_subtest_missing_external_prereqs_"; then
664 say_color skip >&3 "missing prerequisites:"
665 echo "$test_subtest_missing_external_prereqs_" >&3
666 test_report_skip_ "$@"
672 test_report_skip_ () {
674 say_color skip >&3 "skipping test:"
676 say_color skip "%-6s" "SKIP"
680 test_subtest_known_broken () {
681 test_subtest_known_broken_=t
684 test_expect_success () {
685 test "$#" = 3 && { prereq=$1; shift; } || prereq=
687 error "bug in the test script: not 2 or 3 parameters to test-expect-success"
693 # test_run_ may update missing external prerequisites
694 test_check_missing_external_prereqs_ "$@" ||
695 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
704 test_expect_code () {
705 test "$#" = 4 && { prereq=$1; shift; } || prereq=
707 error "bug in the test script: not 3 or 4 parameters to test-expect-code"
713 # test_run_ may update missing external prerequisites,
714 test_check_missing_external_prereqs_ "$@" ||
715 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
724 # test_external runs external test scripts that provide continuous
725 # test output about their progress, and succeeds/fails on
726 # zero/non-zero exit code. It outputs the test output on stdout even
727 # in non-verbose mode, and announces the external script with "* run
728 # <n>: ..." before running it. When providing relative paths, keep in
729 # mind that all scripts run in "trash directory".
730 # Usage: test_external description command arguments...
731 # Example: test_external 'Perl API' perl ../path/to/test.pl
733 test "$#" = 4 && { prereq=$1; shift; } || prereq=
735 error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
739 if ! test_skip "$descr" "$@"
741 # Announce the script to reduce confusion about the
742 # test output that follows.
743 say_color "" " run $test_count: $descr ($*)"
744 # Run command; redirect its stderr to &4 as in
745 # test_run_, but keep its stdout on our stdout even in
752 test_failure_ "$descr" "$@"
757 # Like test_external, but in addition tests that the command generated
758 # no output on stderr.
759 test_external_without_stderr () {
760 # The temporary file has no (and must have no) security
762 tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
763 stderr="$tmp/git-external-stderr.$$.tmp"
764 test_external "$@" 4> "$stderr"
765 [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
766 descr="no stderr: $1"
768 if [ ! -s "$stderr" ]; then
772 if [ "$verbose" = t ]; then
773 output=`echo; echo Stderr is:; cat "$stderr"`
777 # rm first in case test_failure exits.
779 test_failure_ "$descr" "$@" "$output"
783 # This is not among top-level (test_expect_success)
784 # but is a prefix that can be used in the test script, like:
786 # test_expect_success 'complain and die' '
788 # do something else &&
789 # test_must_fail git checkout ../outerspace
792 # Writing this as "! git checkout ../outerspace" is wrong, because
793 # the failure could be due to a segv. We want a controlled failure.
797 test $? -gt 0 -a $? -le 129 -o $? -gt 192
800 # test_cmp is a helper function to compare actual and expected output.
801 # You can use it like:
803 # test_expect_success 'foo works' '
804 # echo expected >expected &&
806 # test_cmp expected actual
809 # This could be written as either "cmp" or "diff -u", but:
810 # - cmp's output is not nearly as easy to read as diff -u
811 # - not all diff versions understand "-u"
817 # This function can be used to schedule some commands to be run
818 # unconditionally at the end of the test to restore sanity:
820 # test_expect_success 'test core.capslock' '
821 # git config core.capslock true &&
822 # test_when_finished "git config --unset core.capslock" &&
826 # That would be roughly equivalent to
828 # test_expect_success 'test core.capslock' '
829 # git config core.capslock true &&
831 # git config --unset core.capslock
834 # except that the greeting and config --unset must both succeed for
837 test_when_finished () {
839 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
844 test_results_dir="$TEST_DIRECTORY/test-results"
845 mkdir -p "$test_results_dir"
846 test_results_path="$test_results_dir/${0%.sh}-$$"
848 echo "total $test_count" >> $test_results_path
849 echo "success $test_success" >> $test_results_path
850 echo "fixed $test_fixed" >> $test_results_path
851 echo "broken $test_broken" >> $test_results_path
852 echo "failed $test_failure" >> $test_results_path
853 echo "" >> $test_results_path
857 [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
859 if [ "$test_failure" = "0" ]; then
860 if [ "$test_broken" = "0" ]; then
869 emacs_generate_script () {
870 # Construct a little test script here for the benefit of the user,
871 # (who can easily run "run_emacs" to get the same emacs environment
872 # for investigating any failures).
873 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
876 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
878 # Here's what we are using here:
880 # --no-init-file Don't load users ~/.emacs
882 # --no-site-file Don't load the site-wide startup stuff
884 # --directory Ensure that the local elisp sources are found
886 # --load Force loading of notmuch.el and test-lib.el
888 exec emacs --no-init-file --no-site-file \
889 --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
890 --directory "$TEST_DIRECTORY" --load test-lib.el \
893 chmod a+x "$TMP_DIRECTORY/run_emacs"
897 # test dependencies beforehand to avoid the waiting loop below
898 test_require_external_prereq emacs || return
899 test_require_external_prereq emacsclient || return
901 if [ -z "$EMACS_SERVER" ]; then
902 server_name="notmuch-test-suite-$$"
903 # start a detached session with an emacs server
904 # user's TERM is given to dtach which assumes a minimally
905 # VT100-compatible terminal -- and emacs inherits that
906 TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
907 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
909 --eval '(setq server-name \"$server_name\")' \
910 --eval '(server-start)' \
911 --eval '(orphan-watchdog $$)'" || return
912 EMACS_SERVER="$server_name"
913 # wait until the emacs server is up
914 until test_emacs '()' 2>/dev/null; do
919 emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
923 export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
924 export PYTHONPATH=$TEST_DIRECTORY/../bindings/python
926 # Some distros (e.g. Arch Linux) ship Python 2.* as /usr/bin/python2,
927 # most others as /usr/bin/python. So first try python2, and fallback to
928 # python if python2 doesn't exist.
930 [[ "$test_missing_external_prereq_python2_" = t ]] && cmd=python
932 (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \
936 # Creates a script that counts how much time it is executed and calls
937 # notmuch. $notmuch_counter_command is set to the path to the
938 # generated script. Use notmuch_counter_value() function to get the
939 # current counter value.
940 notmuch_counter_reset () {
941 notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
942 if [ ! -x "$notmuch_counter_command" ]; then
943 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
944 cat >"$notmuch_counter_command" <<EOF || return
947 read count < "$notmuch_counter_state_path"
948 echo \$((count + 1)) > "$notmuch_counter_state_path"
952 chmod +x "$notmuch_counter_command" || return
955 echo 0 > "$notmuch_counter_state_path"
958 # Returns the current notmuch counter value.
959 notmuch_counter_value () {
960 if [ -r "$notmuch_counter_state_path" ]; then
961 read count < "$notmuch_counter_state_path"
968 test_reset_state_ () {
969 test -z "$test_init_done_" && test_init_
971 test_subtest_known_broken_=
972 test_subtest_missing_external_prereqs_=
975 # called once before the first subtest
979 # skip all tests if there were external prerequisites missing during init
980 test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
988 while [ -n "$dir" ]; do
990 if [ -x "$bin" ]; then
994 dir="$(dirname "$dir")"
995 if [ "$dir" = "/" ]; then
1001 # Test the binaries we have just built. The tests are kept in
1002 # test/ subdirectory and are run in 'trash directory' subdirectory.
1003 TEST_DIRECTORY=$(pwd)
1004 if test -n "$valgrind"
1008 test "$1" = "$(readlink "$2")" || {
1016 while test -d "$2".lock
1018 say "Waiting for lock on $2."
1025 make_valgrind_symlink () {
1026 # handle only executables
1027 test -x "$1" || return
1029 base=$(basename "$1")
1030 symlink_target=$TEST_DIRECTORY/../$base
1031 # do not override scripts
1032 if test -x "$symlink_target" &&
1033 test ! -d "$symlink_target" &&
1034 test "#!" != "$(head -c 2 < "$symlink_target")"
1036 symlink_target=$TEST_DIRECTORY/valgrind.sh
1040 symlink_target=$TEST_DIRECTORY/unprocessed-script
1042 # create the link, or replace it if it is out of date
1043 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
1046 # override notmuch executable in TEST_DIRECTORY/..
1047 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
1048 mkdir -p "$GIT_VALGRIND"/bin
1049 make_valgrind_symlink $TEST_DIRECTORY/../notmuch
1054 ls "$path"/notmuch 2> /dev/null |
1057 make_valgrind_symlink "$file"
1061 PATH=$GIT_VALGRIND/bin:$PATH
1062 GIT_EXEC_PATH=$GIT_VALGRIND/bin
1065 notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`
1066 test -n "$notmuch_path" && PATH="$notmuch_path:$PATH"
1071 test="tmp.$(basename "$0" .sh)"
1072 test -n "$root" && test="$root/$test"
1074 /*) TMP_DIRECTORY="$test" ;;
1075 *) TMP_DIRECTORY="$TEST_DIRECTORY/$test" ;;
1077 test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY
1080 echo >&5 "FATAL: Cannot prepare test area"
1084 # A temporary home directory is needed by at least:
1085 # - emacs/"Sending a message via (fake) SMTP"
1086 # - emacs/"Reply within emacs"
1087 # - crypto/emacs_deliver_message
1088 export HOME="${TMP_DIRECTORY}/home"
1091 MAIL_DIR="${TMP_DIRECTORY}/mail"
1092 export GNUPGHOME="${TMP_DIRECTORY}/gnupg"
1093 export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
1096 mkdir -p "${MAIL_DIR}"
1098 cat <<EOF >"${NOTMUCH_CONFIG}"
1103 name=Notmuch Test Suite
1104 primary_email=test_suite@notmuchmail.org
1105 other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
1108 emacs_generate_script
1111 # Use -P to resolve symlinks in our working directory so that the cwd
1112 # in subprocesses like git equals our $PWD (for pathname comparisons).
1113 cd -P "$test" || error "Cannot setup test environment"
1115 if test "$verbose" = "t"
1119 exec 4>test.output 3>&4
1123 for skp in $NOTMUCH_SKIP_TESTS
1126 for skp in $NOTMUCH_SKIP_TESTS
1128 case "$this_test" in
1135 say_color skip >&3 "skipping test $this_test altogether"
1136 say_color skip "skip all tests in $this_test"
1141 # Provide an implementation of the 'yes' utility
1156 # Fix some commands on Windows
1159 # Windows has its own (incompatible) sort and find
1169 # git sees Windows-style pwd
1173 # no POSIX permissions
1174 # backslashes in pathspec are converted to '/'
1175 # exec does not inherit the PID
1178 test_set_prereq POSIXPERM
1179 test_set_prereq BSLASHPSPEC
1180 test_set_prereq EXECKEEPSPID
1184 test -z "$NO_PERL" && test_set_prereq PERL
1185 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1187 # test whether the filesystem supports symbolic links
1188 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
1191 # declare prerequisites for external binaries used in tests
1192 test_declare_external_prereq dtach
1193 test_declare_external_prereq emacs
1194 test_declare_external_prereq emacsclient
1195 test_declare_external_prereq gdb
1196 test_declare_external_prereq gpg
1197 test_declare_external_prereq python
1198 test_declare_external_prereq python2