2 # Copyright (c) 2005 Junio C Hamano
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see http://www.gnu.org/licenses/ .
17 if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
18 echo "Error: The notmuch test suite requires a bash version >= 4.0"
19 echo "due to use of associative arrays within the test suite."
20 echo "Please try again with a newer bash (or help us fix the"
21 echo "test suite to be more portable). Thanks."
25 # if --tee was passed, write the output not only to the terminal, but
26 # additionally to the file test-results/$BASENAME.out, too.
27 case "$GIT_TEST_TEE_STARTED, $* " in
29 # do not redirect again
31 *' --tee '*|*' --va'*)
33 BASE=test-results/$(basename "$0" .sh)
34 (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
35 echo $? > $BASE.exit) | tee $BASE.out
36 test "$(cat $BASE.exit)" = 0
41 # Keep the original TERM for say_color and test_emacs
44 # dtach(1) provides more capable terminal environment to anything
45 # that requires more than dumb terminal...
46 [ x"${TERM:-dumb}" = xdumb ] && DTACH_TERM=vt100 || DTACH_TERM=$TERM
48 # For repeatability, reset the environment to known value.
54 export LANG LC_ALL PAGER TERM TZ
55 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
56 if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \
57 ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then
58 echo "error: must specify both or neither of TEST_EMACS and TEST_EMACSCLIENT" >&2
61 TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
62 TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
64 # Protect ourselves from common misconfiguration to export
65 # CDPATH into the environment
72 # A regexp to match 5 and 40 hexdigits
73 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
74 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
76 _x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
77 _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
79 # Each test should start with something like this, after copyright notices:
81 # test_description='Description of this test...
82 # This test checks if command xyzzy does the right thing...
85 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
86 TERM=$ORIGINAL_TERM &&
89 tput bold >/dev/null 2>&1 &&
90 tput setaf 1 >/dev/null 2>&1 &&
91 tput sgr0 >/dev/null 2>&1
98 -d|--d|--de|--deb|--debu|--debug)
100 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
101 immediate=t; shift ;;
102 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
103 GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
104 -h|--h|--he|--hel|--help)
106 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
108 -q|--q|--qu|--qui|--quie|--quiet)
111 with_dashes=t; shift ;;
117 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
118 valgrind=t; verbose=t; shift ;;
120 shift ;; # was handled already
122 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
125 echo "error: unknown test option '$1'" >&2; exit 1 ;;
129 if test -n "$debug"; then
131 printf " %-4s" "[$((test_count - 1))]"
139 if test -n "$color"; then
145 error) tput bold; tput setaf 1;; # bold red
146 skip) tput bold; tput setaf 2;; # bold green
147 pass) tput setaf 2;; # green
148 info) tput setaf 3;; # brown
149 *) test -n "$quiet" && return;;
160 test -z "$1" && test -n "$quiet" && return
169 say_color error "error: $*\n"
178 test "${test_description}" != "" ||
179 error "Test script did not set test_description."
181 if test "$help" = "t"
183 echo "Tests ${test_description}"
187 echo $(basename "$0"): "Testing ${test_description}"
199 rm -rf "$TEST_TMPDIR"
200 if test -n "$GIT_EXIT_OK"
204 echo >&5 "FATAL: Unexpected exit with code $code"
210 # Note: TEST_TMPDIR *NOT* exported!
211 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
214 test_decode_color () {
215 sed -e 's/.\[1m/<WHITE>/g' \
216 -e 's/.\[31m/<RED>/g' \
217 -e 's/.\[32m/<GREEN>/g' \
218 -e 's/.\[33m/<YELLOW>/g' \
219 -e 's/.\[34m/<BLUE>/g' \
220 -e 's/.\[35m/<MAGENTA>/g' \
221 -e 's/.\[36m/<CYAN>/g' \
222 -e 's/.\[m/<RESET>/g'
234 sed -e 's/$/Q/' | tr Q '\015'
238 tr '\015' Q | sed -e 's/Q$//'
241 # Generate a new message in the mail directory, with a unique message
242 # ID and subject. The message is not added to the index.
244 # After this function returns, the filename of the generated message
245 # is available as $gen_msg_filename and the message ID is available as
248 # This function supports named parameters with the bash syntax for
249 # assigning a value to an associative array ([name]=value). The
250 # supported parameters are:
252 # [dir]=directory/of/choice
254 # Generate the message in directory 'directory/of/choice' within
255 # the mail store. The directory will be created if necessary.
259 # Store the message in file 'name'. The default is to store it
260 # in 'msg-<count>', where <count> is three-digit number of the
265 # Text to use as the body of the email message
267 # '[from]="Some User <user@example.com>"'
268 # '[to]="Some User <user@example.com>"'
269 # '[subject]="Subject of email message"'
270 # '[date]="RFC 822 Date"'
272 # Values for email headers. If not provided, default values will
273 # be generated instead.
275 # '[cc]="Some User <user@example.com>"'
276 # [reply-to]=some-address
277 # [in-reply-to]=<message-id>
278 # [references]=<message-id>
279 # [content-type]=content-type-specification
280 # '[header]=full header line, including keyword'
282 # Additional values for email headers. If these are not provided
283 # then the relevant headers will simply not appear in the
288 # Controls the message-id of the created message.
294 # This is our (bash-specific) magic for doing named parameters
295 local -A template="($@)"
296 local additional_headers
298 gen_msg_cnt=$((gen_msg_cnt + 1))
299 if [ -z "${template[filename]}" ]; then
300 gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"
302 gen_msg_name=${template[filename]}
305 if [ -z "${template[id]}" ]; then
306 gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"
308 gen_msg_id="${template[id]}"
311 if [ -z "${template[dir]}" ]; then
312 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
314 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
315 mkdir -p "$(dirname "$gen_msg_filename")"
318 if [ -z "${template[body]}" ]; then
319 template[body]="This is just a test message (#${gen_msg_cnt})"
322 if [ -z "${template[from]}" ]; then
323 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
326 if [ -z "${template[to]}" ]; then
327 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
330 if [ -z "${template[subject]}" ]; then
331 if [ -n "$test_subtest_name" ]; then
332 template[subject]="$test_subtest_name"
334 template[subject]="Test message #${gen_msg_cnt}"
338 if [ -z "${template[date]}" ]; then
339 template[date]="Fri, 05 Jan 2001 15:43:57 +0000"
342 additional_headers=""
343 if [ ! -z "${template[header]}" ]; then
344 additional_headers="${template[header]}
345 ${additional_headers}"
348 if [ ! -z "${template[reply-to]}" ]; then
349 additional_headers="Reply-To: ${template[reply-to]}
350 ${additional_headers}"
353 if [ ! -z "${template[in-reply-to]}" ]; then
354 additional_headers="In-Reply-To: ${template[in-reply-to]}
355 ${additional_headers}"
358 if [ ! -z "${template[cc]}" ]; then
359 additional_headers="Cc: ${template[cc]}
360 ${additional_headers}"
363 if [ ! -z "${template[bcc]}" ]; then
364 additional_headers="Bcc: ${template[bcc]}
365 ${additional_headers}"
368 if [ ! -z "${template[references]}" ]; then
369 additional_headers="References: ${template[references]}
370 ${additional_headers}"
373 if [ ! -z "${template[content-type]}" ]; then
374 additional_headers="Content-Type: ${template[content-type]}
375 ${additional_headers}"
378 if [ ! -z "${template[content-transfer-encoding]}" ]; then
379 additional_headers="Content-Transfer-Encoding: ${template[content-transfer-encoding]}
380 ${additional_headers}"
383 # Note that in the way we're setting it above and using it below,
384 # `additional_headers' will also serve as the header / body separator
385 # (empty line in between).
387 cat <<EOF >"$gen_msg_filename"
388 From: ${template[from]}
390 Message-Id: <${gen_msg_id}>
391 Subject: ${template[subject]}
392 Date: ${template[date]}
393 ${additional_headers}
398 # Generate a new message and add it to the database.
400 # All of the arguments and return values supported by generate_message
401 # are also supported here, so see that function for details.
404 generate_message "$@" &&
405 notmuch new > /dev/null
408 # Deliver a message with emacs and add it to the database
410 # Uses emacs to generate and deliver a message to the mail store.
411 # Accepts arbitrary extra emacs/elisp functions to modify the message
412 # before sending, which is useful to doing things like attaching files
413 # to the message and encrypting/signing.
414 emacs_deliver_message ()
419 # before we can send a message, we have to prepare the FCC maildir
420 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
421 # eval'ing smtp-dummy --background will set smtp_dummy_pid
423 eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
424 test -n "$smtp_dummy_pid" || return 1
427 "(let ((message-send-mail-function 'message-smtpmail-send-it)
428 (smtpmail-smtp-server \"localhost\")
429 (smtpmail-smtp-service \"25025\"))
433 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
434 (message-goto-subject)
435 (insert \"${subject}\")
439 (message-send-and-exit))"
441 # In case message was sent properly, client waits for confirmation
442 # before exiting and resuming control here; therefore making sure
443 # that server exits by sending (KILL) signal to it is safe.
444 kill -9 $smtp_dummy_pid
445 notmuch new >/dev/null
448 # Generate a corpus of email and add it to the database.
450 # This corpus is fixed, (it happens to be 50 messages from early in
451 # the history of the notmuch mailing list), which allows for reliably
452 # testing commands that need to operate on a not-totally-trivial
453 # number of messages.
457 if [ -d $TEST_DIRECTORY/corpus.mail ]; then
458 cp -a $TEST_DIRECTORY/corpus.mail ${MAIL_DIR}
460 cp -a $TEST_DIRECTORY/corpus ${MAIL_DIR}
461 notmuch new >/dev/null
462 cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpus.mail
466 test_begin_subtest ()
468 if [ -n "$inside_subtest" ]; then
469 exec 1>&6 2>&7 # Restore stdout and stderr
470 error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
472 test_subtest_name="$1"
474 # Remember stdout and stderr file descriptors and redirect test
475 # output to the previously prepared file descriptors 3 and 4 (see
477 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
478 exec 6>&1 7>&2 >&3 2>&4
482 # Pass test if two arguments match
484 # Note: Unlike all other test_expect_* functions, this function does
485 # not accept a test name. Instead, the caller should call
486 # test_begin_subtest before calling this function in order to set the
490 exec 1>&6 2>&7 # Restore stdout and stderr
492 test "$#" = 3 && { prereq=$1; shift; } || prereq=
494 error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
498 if ! test_skip "$test_subtest_name"
500 if [ "$output" = "$expected" ]; then
501 test_ok_ "$test_subtest_name"
503 testname=$this_test.$test_count
504 echo "$expected" > $testname.expected
505 echo "$output" > $testname.output
506 test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"
511 # Like test_expect_equal, but takes two filenames.
512 test_expect_equal_file ()
514 exec 1>&6 2>&7 # Restore stdout and stderr
516 test "$#" = 3 && { prereq=$1; shift; } || prereq=
518 error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
521 basename1=`basename "$file1"`
523 basename2=`basename "$file2"`
524 if ! test_skip "$test_subtest_name"
526 if diff -q "$file1" "$file2" >/dev/null ; then
527 test_ok_ "$test_subtest_name"
529 testname=$this_test.$test_count
530 cp "$file1" "$testname.$basename1"
531 cp "$file2" "$testname.$basename2"
532 test_failure_ "$test_subtest_name" "$(diff -u "$testname.$basename1" "$testname.$basename2")"
537 # Like test_expect_equal, but arguments are JSON expressions to be
538 # canonicalized before diff'ing. If an argument cannot be parsed, it
539 # is used unchanged so that there's something to diff against.
540 test_expect_equal_json () {
541 # The test suite forces LC_ALL=C, but this causes Python 3 to
542 # decode stdin as ASCII. We need to read JSON in UTF-8, so
543 # override Python's stdio encoding defaults.
544 output=$(echo "$1" | PYTHONIOENCODING=utf-8 python -mjson.tool \
546 expected=$(echo "$2" | PYTHONIOENCODING=utf-8 python -mjson.tool \
549 test_expect_equal "$output" "$expected" "$@"
552 test_emacs_expect_t () {
553 test "$#" = 2 && { prereq=$1; shift; } || prereq=
555 error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
558 if ! test_skip "$test_subtest_name"
560 test_emacs "(notmuch-test-run $1)" >/dev/null
562 # Restore state after the test.
563 exec 1>&6 2>&7 # Restore stdout and stderr
566 # Report success/failure.
570 test_ok_ "$test_subtest_name"
572 test_failure_ "$test_subtest_name" "${result}"
575 # Restore state after the (non) test.
576 exec 1>&6 2>&7 # Restore stdout and stderr
583 notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
586 notmuch_search_sanitize ()
588 perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
591 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
592 notmuch_show_sanitize ()
594 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
596 notmuch_show_sanitize_all ()
599 -e 's| filename:.*| filename:XXXXX|' \
600 -e 's| id:[^ ]* | id:XXXXX |'
603 notmuch_json_show_sanitize ()
606 -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
607 -e 's|"filename": "/[^"]*",|"filename": "YYYYY",|g'
610 # End of notmuch helper functions
612 # Use test_set_prereq to tell that a particular prerequisite is available.
613 # The prerequisite can later be checked for in two ways:
615 # - Explicitly using test_have_prereq.
617 # - Implicitly by specifying the prerequisite tag in the calls to
618 # test_expect_{success,failure,code}.
620 # The single parameter is the prerequisite tag (a simple word, in all
621 # capital letters by convention).
624 satisfied="$satisfied$1 "
628 test_have_prereq () {
637 declare -A test_missing_external_prereq_
638 declare -A test_subtest_missing_external_prereq_
640 # declare prerequisite for the given external binary
641 test_declare_external_prereq () {
643 test "$#" = 2 && name=$2 || name="$binary(1)"
645 if ! hash $binary 2>/dev/null; then
646 test_missing_external_prereq_["${binary}"]=t
649 test_subtest_missing_external_prereq_[\"${name}\"]=t
655 # Explicitly require external prerequisite. Useful when binary is
656 # called indirectly (e.g. from emacs).
657 # Returns success if dependency is available, failure otherwise.
658 test_require_external_prereq () {
660 if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then
661 # dependency is missing, call the replacement function to note it
668 # You are not expected to call test_ok_ and test_failure_ directly, use
669 # the text_expect_* functions instead.
672 if test "$test_subtest_known_broken_" = "t"; then
673 test_known_broken_ok_ "$@"
676 test_success=$(($test_success + 1))
677 say_color pass "%-6s" "PASS"
682 if test "$test_subtest_known_broken_" = "t"; then
683 test_known_broken_failure_ "$@"
686 test_failure=$(($test_failure + 1))
687 test_failure_message_ "FAIL" "$@"
688 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
692 test_failure_message_ () {
693 say_color error "%-6s" "$1"
696 echo "$@" | sed -e 's/^/ /'
697 if test "$verbose" != "t"; then cat test.output; fi
700 test_known_broken_ok_ () {
702 test_fixed=$(($test_fixed+1))
703 say_color pass "%-6s" "FIXED"
707 test_known_broken_failure_ () {
709 test_broken=$(($test_broken+1))
710 test_failure_message_ "BROKEN" "$@"
715 test "$debug" = "" || eval "$1"
720 if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
723 eval >&3 2>&4 "$test_cleanup"
728 test_count=$(($test_count+1))
730 for skp in $NOTMUCH_SKIP_TESTS
732 case $this_test.$test_count in
737 if test -z "$to_skip" && test -n "$prereq" &&
738 ! test_have_prereq "$prereq"
744 test_report_skip_ "$@"
747 test_check_missing_external_prereqs_ "$@"
752 test_check_missing_external_prereqs_ () {
753 if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then
754 say_color skip >&1 "missing prerequisites: "
755 echo ${!test_subtest_missing_external_prereq_[@]} >&1
756 test_report_skip_ "$@"
762 test_report_skip_ () {
764 say_color skip >&3 "skipping test:"
766 say_color skip "%-6s" "SKIP"
770 test_subtest_known_broken () {
771 test_subtest_known_broken_=t
774 test_expect_success () {
775 test "$#" = 3 && { prereq=$1; shift; } || prereq=
777 error "bug in the test script: not 2 or 3 parameters to test-expect-success"
783 # test_run_ may update missing external prerequisites
784 test_check_missing_external_prereqs_ "$@" ||
785 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
794 test_expect_code () {
795 test "$#" = 4 && { prereq=$1; shift; } || prereq=
797 error "bug in the test script: not 3 or 4 parameters to test-expect-code"
803 # test_run_ may update missing external prerequisites,
804 test_check_missing_external_prereqs_ "$@" ||
805 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
814 # test_external runs external test scripts that provide continuous
815 # test output about their progress, and succeeds/fails on
816 # zero/non-zero exit code. It outputs the test output on stdout even
817 # in non-verbose mode, and announces the external script with "* run
818 # <n>: ..." before running it. When providing relative paths, keep in
819 # mind that all scripts run in "trash directory".
820 # Usage: test_external description command arguments...
821 # Example: test_external 'Perl API' perl ../path/to/test.pl
823 test "$#" = 4 && { prereq=$1; shift; } || prereq=
825 error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
829 if ! test_skip "$descr" "$@"
831 # Announce the script to reduce confusion about the
832 # test output that follows.
833 say_color "" " run $test_count: $descr ($*)"
834 # Run command; redirect its stderr to &4 as in
835 # test_run_, but keep its stdout on our stdout even in
842 test_failure_ "$descr" "$@"
847 # Like test_external, but in addition tests that the command generated
848 # no output on stderr.
849 test_external_without_stderr () {
850 # The temporary file has no (and must have no) security
852 tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
853 stderr="$tmp/git-external-stderr.$$.tmp"
854 test_external "$@" 4> "$stderr"
855 [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
856 descr="no stderr: $1"
858 if [ ! -s "$stderr" ]; then
862 if [ "$verbose" = t ]; then
863 output=`echo; echo Stderr is:; cat "$stderr"`
867 # rm first in case test_failure exits.
869 test_failure_ "$descr" "$@" "$output"
873 # This is not among top-level (test_expect_success)
874 # but is a prefix that can be used in the test script, like:
876 # test_expect_success 'complain and die' '
878 # do something else &&
879 # test_must_fail git checkout ../outerspace
882 # Writing this as "! git checkout ../outerspace" is wrong, because
883 # the failure could be due to a segv. We want a controlled failure.
887 test $? -gt 0 -a $? -le 129 -o $? -gt 192
890 # test_cmp is a helper function to compare actual and expected output.
891 # You can use it like:
893 # test_expect_success 'foo works' '
894 # echo expected >expected &&
896 # test_cmp expected actual
899 # This could be written as either "cmp" or "diff -u", but:
900 # - cmp's output is not nearly as easy to read as diff -u
901 # - not all diff versions understand "-u"
907 # This function can be used to schedule some commands to be run
908 # unconditionally at the end of the test to restore sanity:
910 # test_expect_success 'test core.capslock' '
911 # git config core.capslock true &&
912 # test_when_finished "git config --unset core.capslock" &&
916 # That would be roughly equivalent to
918 # test_expect_success 'test core.capslock' '
919 # git config core.capslock true &&
921 # git config --unset core.capslock
924 # except that the greeting and config --unset must both succeed for
927 test_when_finished () {
929 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
934 test_results_dir="$TEST_DIRECTORY/test-results"
935 mkdir -p "$test_results_dir"
936 test_results_path="$test_results_dir/${0%.sh}"
938 echo "total $test_count" >> $test_results_path
939 echo "success $test_success" >> $test_results_path
940 echo "fixed $test_fixed" >> $test_results_path
941 echo "broken $test_broken" >> $test_results_path
942 echo "failed $test_failure" >> $test_results_path
943 echo "" >> $test_results_path
947 [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
949 if [ "$test_failure" = "0" ]; then
950 if [ "$test_broken" = "0" ]; then
959 emacs_generate_script () {
960 # Construct a little test script here for the benefit of the user,
961 # (who can easily run "run_emacs" to get the same emacs environment
962 # for investigating any failures).
963 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
966 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
968 # Here's what we are using here:
970 # --no-init-file Don't load users ~/.emacs
972 # --no-site-file Don't load the site-wide startup stuff
974 # --directory Ensure that the local elisp sources are found
976 # --load Force loading of notmuch.el and test-lib.el
978 exec ${TEST_EMACS} --no-init-file --no-site-file \
979 --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
980 --directory "$TEST_DIRECTORY" --load test-lib.el \
983 chmod a+x "$TMP_DIRECTORY/run_emacs"
987 # test dependencies beforehand to avoid the waiting loop below
988 missing_dependencies=
989 test_require_external_prereq dtach || missing_dependencies=1
990 test_require_external_prereq emacs || missing_dependencies=1
991 test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
992 test -z "$missing_dependencies" || return
994 if [ -z "$EMACS_SERVER" ]; then
995 emacs_tests="$(basename $0).el"
996 if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
997 load_emacs_tests="--eval '(load \"$emacs_tests\")'"
1001 server_name="notmuch-test-suite-$$"
1002 # start a detached session with an emacs server
1003 # user's TERM (or 'vt100' in case user's TERM is unset, empty
1004 # or 'dumb') is given to dtach which assumes a minimally
1005 # VT100-compatible terminal -- and emacs inherits that
1006 TERM=$DTACH_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
1007 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
1008 --no-window-system \
1010 --eval '(setq server-name \"$server_name\")' \
1011 --eval '(server-start)' \
1012 --eval '(orphan-watchdog $$)'" || return
1013 EMACS_SERVER="$server_name"
1014 # wait until the emacs server is up
1015 until test_emacs '()' >/dev/null 2>/dev/null; do
1020 # Clear test-output output file. Most Emacs tests end with a
1021 # call to (test-output). If the test code fails with an
1022 # exception before this call, the output file won't get
1023 # updated. Since we don't want to compare against an output
1024 # file from another test, so start out with an empty file.
1028 ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(progn $@)"
1032 export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
1033 export PYTHONPATH=$TEST_DIRECTORY/../bindings/python
1035 # Some distros (e.g. Arch Linux) ship Python 2.* as /usr/bin/python2,
1036 # most others as /usr/bin/python. So first try python2, and fallback to
1037 # python if python2 doesn't exist.
1039 [[ ${test_missing_external_prereq_[python2]} == t ]] && cmd=python
1041 (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \
1045 # Creates a script that counts how much time it is executed and calls
1046 # notmuch. $notmuch_counter_command is set to the path to the
1047 # generated script. Use notmuch_counter_value() function to get the
1048 # current counter value.
1049 notmuch_counter_reset () {
1050 notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
1051 if [ ! -x "$notmuch_counter_command" ]; then
1052 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
1053 cat >"$notmuch_counter_command" <<EOF || return
1056 read count < "$notmuch_counter_state_path"
1057 echo \$((count + 1)) > "$notmuch_counter_state_path"
1061 chmod +x "$notmuch_counter_command" || return
1064 echo 0 > "$notmuch_counter_state_path"
1067 # Returns the current notmuch counter value.
1068 notmuch_counter_value () {
1069 if [ -r "$notmuch_counter_state_path" ]; then
1070 read count < "$notmuch_counter_state_path"
1077 test_reset_state_ () {
1078 test -z "$test_init_done_" && test_init_
1080 test_subtest_known_broken_=
1081 test_subtest_missing_external_prereq_=()
1084 # called once before the first subtest
1088 # skip all tests if there were external prerequisites missing during init
1089 test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
1093 . ./test-lib-common.sh
1095 emacs_generate_script
1098 # Use -P to resolve symlinks in our working directory so that the cwd
1099 # in subprocesses like git equals our $PWD (for pathname comparisons).
1100 cd -P "$test" || error "Cannot setup test environment"
1102 if test "$verbose" = "t"
1106 exec 4>test.output 3>&4
1110 for skp in $NOTMUCH_SKIP_TESTS
1113 for skp in $NOTMUCH_SKIP_TESTS
1115 case "$this_test" in
1122 say_color skip >&3 "skipping test $this_test altogether"
1123 say_color skip "skip all tests in $this_test"
1128 # Provide an implementation of the 'yes' utility
1143 # Fix some commands on Windows
1146 # Windows has its own (incompatible) sort and find
1156 # git sees Windows-style pwd
1160 # no POSIX permissions
1161 # backslashes in pathspec are converted to '/'
1162 # exec does not inherit the PID
1165 test_set_prereq POSIXPERM
1166 test_set_prereq BSLASHPSPEC
1167 test_set_prereq EXECKEEPSPID
1171 test -z "$NO_PERL" && test_set_prereq PERL
1172 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1174 # test whether the filesystem supports symbolic links
1175 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
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 gdb
1183 test_declare_external_prereq gpg
1184 test_declare_external_prereq python
1185 test_declare_external_prereq python2