]> git.notmuchmail.org Git - notmuch/blob - test/test-lib.sh
ba1580cd1f3e803130a373c09a766fc82dbf1e7e
[notmuch] / test / test-lib.sh
1 #
2 # Copyright (c) 2005 Junio C Hamano
3 # Copyright (c) 2010 Notmuch Developers
4 #
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.
9 #
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.
14 #
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/ .
17
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."
23     exit 1
24 fi
25
26 # Make sure echo builtin does not expand backslash-escape sequences by default.
27 shopt -u xpg_echo
28
29 this_test=${0##*/}
30 this_test=${this_test%.sh}
31 this_test_bare=${this_test#T[0-9][0-9][0-9]-}
32
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
36 done,*)
37         # do not redirect again
38         ;;
39 *' --tee '*|*' --va'*)
40         mkdir -p test-results
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
45         exit
46         ;;
47 esac
48
49 # Save STDOUT to fd 6 and STDERR to fd 7.
50 exec 6>&1 7>&2
51 # Make xtrace debugging (when used) use redirected STDERR, with verbose lead:
52 BASH_XTRACEFD=7
53 export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
54
55 # Keep the original TERM for say_color and test_emacs
56 ORIGINAL_TERM=$TERM
57
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.
61 case ${TERM-} in
62         '' | dumb | unknown )
63                 SMART_TERM=vt100 ;;
64         *)
65                 SMART_TERM=$TERM ;;
66 esac
67
68 # For repeatability, reset the environment to known value.
69 LANG=C
70 LC_ALL=C
71 PAGER=cat
72 TZ=UTC
73 TERM=dumb
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
79     exit 1
80 fi
81 TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
82 TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
83 TEST_CC=${TEST_CC:-cc}
84 TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"}
85
86 # Protect ourselves from common misconfiguration to export
87 # CDPATH into the environment
88 unset CDPATH
89
90 unset GREP_OPTIONS
91
92 # For emacsclient
93 unset ALTERNATE_EDITOR
94
95 # Convenience
96 #
97 # A regexp to match 5 and 40 hexdigits
98 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
99 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
100
101 _x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
102 _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
103
104 # Each test should start with something like this, after copyright notices:
105 #
106 # test_description='Description of this test...
107 # This test checks if command xyzzy does the right thing...
108 # '
109 # . ./test-lib.sh || exit 1
110
111 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
112                 TERM=$ORIGINAL_TERM &&
113                 export TERM &&
114                 [ -t 1 ] &&
115                 tput bold >/dev/null 2>&1 &&
116                 tput setaf 1 >/dev/null 2>&1 &&
117                 tput sgr0 >/dev/null 2>&1
118         ) &&
119         color=t
120
121 while test "$#" -ne 0
122 do
123         case "$1" in
124         -d|--d|--de|--deb|--debu|--debug)
125                 debug=t; shift ;;
126         -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
127                 immediate=t; shift ;;
128         -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
129                 GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
130         -h|--h|--he|--hel|--help)
131                 help=t; shift ;;
132         -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
133                 verbose=t; shift ;;
134         -q|--q|--qu|--qui|--quie|--quiet)
135                 quiet=t; shift ;;
136         --with-dashes)
137                 with_dashes=t; shift ;;
138         --no-color)
139                 color=; shift ;;
140         --no-python)
141                 # noop now...
142                 shift ;;
143         --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
144                 valgrind=t; verbose=t; shift ;;
145         --tee)
146                 shift ;; # was handled already
147         --root=*)
148                 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
149                 shift ;;
150         *)
151                 echo "error: unknown test option '$1'" >&2; exit 1 ;;
152         esac
153 done
154
155 if test -n "$debug"; then
156     print_subtest () {
157         printf " %-4s" "[$((test_count - 1))]"
158     }
159 else
160     print_subtest () {
161         true
162     }
163 fi
164
165 if test -n "$color"; then
166         say_color () {
167                 (
168                 TERM=$ORIGINAL_TERM
169                 export TERM
170                 case "$1" in
171                         error) tput bold; tput setaf 1;; # bold red
172                         skip)  tput bold; tput setaf 2;; # bold green
173                         pass)  tput setaf 2;;            # green
174                         info)  tput setaf 3;;            # brown
175                         *) test -n "$quiet" && return;;
176                 esac
177                 shift
178                 printf " "
179                 printf "$@"
180                 tput sgr0
181                 print_subtest
182                 )
183         }
184 else
185         say_color() {
186                 test -z "$1" && test -n "$quiet" && return
187                 shift
188                 printf " "
189                 printf "$@"
190                 print_subtest
191         }
192 fi
193
194 error () {
195         say_color error "error: $*\n"
196         GIT_EXIT_OK=t
197         exit 1
198 }
199
200 say () {
201         say_color info "$*"
202 }
203
204 test "${test_description}" != "" ||
205 error "Test script did not set test_description."
206
207 if test "$help" = "t"
208 then
209         echo "Tests ${test_description}"
210         exit 0
211 fi
212
213 test_description_printed=
214 print_test_description ()
215 {
216         test -z "$test_description_printed" || return 0
217         echo
218         echo $this_test: "Testing ${test_description}"
219         test_description_printed=1
220 }
221 if [ -z "$NOTMUCH_TEST_QUIET" ]
222 then
223         print_test_description
224 fi
225
226 test_failure=0
227 test_count=0
228 test_fixed=0
229 test_broken=0
230 test_success=0
231
232
233 _shutdown_gpg_agent () {
234     if [ ${NOTMUCH_HAVE_GPGCONF_SOCKETDIR} = 1 ]; then
235         gpgconf --kill gpg-agent
236         gpgconf --remove-socketdir
237     fi
238 }
239
240 _exit_common () {
241         code=$?
242         trap - EXIT
243         set +ex
244         _shutdown_gpg_agent
245         rm -rf "$TEST_TMPDIR"
246 }
247
248 trap_exit () {
249         _exit_common
250         if test -n "$GIT_EXIT_OK"
251         then
252                 exit $code
253         else
254                 exec >&6
255                 say_color error '%-6s' FATAL
256                 echo " $test_subtest_name"
257                 echo
258                 echo "Unexpected exit while executing $0. Exit code $code."
259                 exit 1
260         fi
261 }
262
263 trap_signal () {
264         _exit_common
265         echo >&6 "FATAL: $0: interrupted by signal" $((code - 128))
266         exit $code
267 }
268
269 die () {
270         _exit_common
271         exec >&6
272         say_color error '%-6s' FATAL
273         echo " $*"
274         echo
275         echo "Unexpected exit while executing $0."
276         exit 1
277 }
278
279 GIT_EXIT_OK=
280 # Note: TEST_TMPDIR *NOT* exported!
281 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
282 trap 'trap_exit' EXIT
283 trap 'trap_signal' HUP INT TERM
284
285 test_decode_color () {
286         sed     -e 's/.\[1m/<WHITE>/g' \
287                 -e 's/.\[31m/<RED>/g' \
288                 -e 's/.\[32m/<GREEN>/g' \
289                 -e 's/.\[33m/<YELLOW>/g' \
290                 -e 's/.\[34m/<BLUE>/g' \
291                 -e 's/.\[35m/<MAGENTA>/g' \
292                 -e 's/.\[36m/<CYAN>/g' \
293                 -e 's/.\[m/<RESET>/g'
294 }
295
296 q_to_nul () {
297         perl -pe 'y/Q/\000/'
298 }
299
300 q_to_cr () {
301         tr Q '\015'
302 }
303
304 append_cr () {
305         sed -e 's/$/Q/' | tr Q '\015'
306 }
307
308 remove_cr () {
309         tr '\015' Q | sed -e 's/Q$//'
310 }
311
312 # Generate a new message in the mail directory, with a unique message
313 # ID and subject. The message is not added to the index.
314 #
315 # After this function returns, the filename of the generated message
316 # is available as $gen_msg_filename and the message ID is available as
317 # $gen_msg_id .
318 #
319 # This function supports named parameters with the bash syntax for
320 # assigning a value to an associative array ([name]=value). The
321 # supported parameters are:
322 #
323 #  [dir]=directory/of/choice
324 #
325 #       Generate the message in directory 'directory/of/choice' within
326 #       the mail store. The directory will be created if necessary.
327 #
328 #  [filename]=name
329 #
330 #       Store the message in file 'name'. The default is to store it
331 #       in 'msg-<count>', where <count> is three-digit number of the
332 #       message.
333 #
334 #  [body]=text
335 #
336 #       Text to use as the body of the email message
337 #
338 #  '[from]="Some User <user@example.com>"'
339 #  '[to]="Some User <user@example.com>"'
340 #  '[subject]="Subject of email message"'
341 #  '[date]="RFC 822 Date"'
342 #
343 #       Values for email headers. If not provided, default values will
344 #       be generated instead.
345 #
346 #  '[cc]="Some User <user@example.com>"'
347 #  [reply-to]=some-address
348 #  [in-reply-to]=<message-id>
349 #  [references]=<message-id>
350 #  [content-type]=content-type-specification
351 #  '[header]=full header line, including keyword'
352 #
353 #       Additional values for email headers. If these are not provided
354 #       then the relevant headers will simply not appear in the
355 #       message.
356 #
357 #  '[id]=message-id'
358 #
359 #       Controls the message-id of the created message.
360 gen_msg_cnt=0
361 gen_msg_filename=""
362 gen_msg_id=""
363 generate_message ()
364 {
365     # This is our (bash-specific) magic for doing named parameters
366     local -A template="($@)"
367     local additional_headers
368
369     gen_msg_cnt=$((gen_msg_cnt + 1))
370     if [ -z "${template[filename]}" ]; then
371         gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"
372     else
373         gen_msg_name=${template[filename]}
374     fi
375
376     if [ -z "${template[id]}" ]; then
377         gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"
378     else
379         gen_msg_id="${template[id]}"
380     fi
381
382     if [ -z "${template[dir]}" ]; then
383         gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
384     else
385         gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
386         mkdir -p "$(dirname "$gen_msg_filename")"
387     fi
388
389     if [ -z "${template[body]}" ]; then
390         template[body]="This is just a test message (#${gen_msg_cnt})"
391     fi
392
393     if [ -z "${template[from]}" ]; then
394         template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
395     fi
396
397     if [ -z "${template[to]}" ]; then
398         template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
399     fi
400
401     if [ -z "${template[subject]}" ]; then
402         if [ -n "$test_subtest_name" ]; then
403             template[subject]="$test_subtest_name"
404         else
405             template[subject]="Test message #${gen_msg_cnt}"
406         fi
407     elif [ "${template[subject]}" = "@FORCE_EMPTY" ]; then
408         template[subject]=""
409     fi
410
411     if [ -z "${template[date]}" ]; then
412         # we use decreasing timestamps here for historical reasons;
413         # the existing test suite when we converted to unique timestamps just
414         # happened to have signicantly fewer failures with that choice.
415         local date_secs=$((978709437 - gen_msg_cnt))
416         # printf %(..)T is bash 4.2+ feature. use perl fallback if needed...
417         TZ=UTC printf -v template[date] "%(%a, %d %b %Y %T %z)T" $date_secs 2>/dev/null ||
418             template[date]=`perl -le 'use POSIX "strftime";
419                                 @time = gmtime '"$date_secs"';
420                                 print strftime "%a, %d %b %Y %T +0000", @time'`
421     fi
422
423     additional_headers=""
424     if [ ! -z "${template[header]}" ]; then
425         additional_headers="${template[header]}
426 ${additional_headers}"
427     fi
428
429     if [ ! -z "${template[reply-to]}" ]; then
430         additional_headers="Reply-To: ${template[reply-to]}
431 ${additional_headers}"
432     fi
433
434     if [ ! -z "${template[in-reply-to]}" ]; then
435         additional_headers="In-Reply-To: ${template[in-reply-to]}
436 ${additional_headers}"
437     fi
438
439     if [ ! -z "${template[cc]}" ]; then
440         additional_headers="Cc: ${template[cc]}
441 ${additional_headers}"
442     fi
443
444     if [ ! -z "${template[bcc]}" ]; then
445         additional_headers="Bcc: ${template[bcc]}
446 ${additional_headers}"
447     fi
448
449     if [ ! -z "${template[references]}" ]; then
450         additional_headers="References: ${template[references]}
451 ${additional_headers}"
452     fi
453
454     if [ ! -z "${template[content-type]}" ]; then
455         additional_headers="Content-Type: ${template[content-type]}
456 ${additional_headers}"
457     fi
458
459     if [ ! -z "${template[content-transfer-encoding]}" ]; then
460         additional_headers="Content-Transfer-Encoding: ${template[content-transfer-encoding]}
461 ${additional_headers}"
462     fi
463
464     # Note that in the way we're setting it above and using it below,
465     # `additional_headers' will also serve as the header / body separator
466     # (empty line in between).
467
468     cat <<EOF >"$gen_msg_filename"
469 From: ${template[from]}
470 To: ${template[to]}
471 Message-Id: <${gen_msg_id}>
472 Subject: ${template[subject]}
473 Date: ${template[date]}
474 ${additional_headers}
475 ${template[body]}
476 EOF
477 }
478
479 # Generate a new message and add it to the database.
480 #
481 # All of the arguments and return values supported by generate_message
482 # are also supported here, so see that function for details.
483 add_message ()
484 {
485     generate_message "$@" &&
486     notmuch new > /dev/null
487 }
488
489 # Deliver a message with emacs and add it to the database
490 #
491 # Uses emacs to generate and deliver a message to the mail store.
492 # Accepts arbitrary extra emacs/elisp functions to modify the message
493 # before sending, which is useful to doing things like attaching files
494 # to the message and encrypting/signing.
495 emacs_deliver_message ()
496 {
497     local subject="$1"
498     local body="$2"
499     shift 2
500     # before we can send a message, we have to prepare the FCC maildir
501     mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
502     # eval'ing smtp-dummy --background will set smtp_dummy_pid
503     smtp_dummy_pid=
504     eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
505     test -n "$smtp_dummy_pid" || return 1
506
507     test_emacs \
508         "(let ((message-send-mail-function 'message-smtpmail-send-it)
509                (mail-host-address \"example.com\")
510                (smtpmail-smtp-server \"localhost\")
511                (smtpmail-smtp-service \"25025\"))
512            (notmuch-mua-mail)
513            (message-goto-to)
514            (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
515            (message-goto-subject)
516            (insert \"${subject}\")
517            (message-goto-body)
518            (insert \"${body}\")
519            $@
520            (notmuch-mua-send-and-exit))"
521
522     # In case message was sent properly, client waits for confirmation
523     # before exiting and resuming control here; therefore making sure
524     # that server exits by sending (KILL) signal to it is safe.
525     kill -9 $smtp_dummy_pid
526     notmuch new >/dev/null
527 }
528
529 # Pretend to deliver a message with emacs. Really save it to a file
530 # and add it to the database
531 #
532 # Uses emacs to generate and deliver a message to the mail store.
533 # Accepts arbitrary extra emacs/elisp functions to modify the message
534 # before sending, which is useful to doing things like attaching files
535 # to the message and encrypting/signing.
536 emacs_fcc_message ()
537 {
538     local subject="$1"
539     local body="$2"
540     shift 2
541     # before we can send a message, we have to prepare the FCC maildir
542     mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
543
544     test_emacs \
545         "(let ((message-send-mail-function (lambda () t))
546                (mail-host-address \"example.com\"))
547            (notmuch-mua-mail)
548            (message-goto-to)
549            (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
550            (message-goto-subject)
551            (insert \"${subject}\")
552            (message-goto-body)
553            (insert \"${body}\")
554            $@
555            (notmuch-mua-send-and-exit))" || return 1
556     notmuch new >/dev/null
557 }
558
559 # Add an existing, fixed corpus of email to the database.
560 #
561 # $1 is the corpus dir under corpora to add, using "default" if unset.
562 #
563 # The default corpus is based on about 50 messages from early in the
564 # history of the notmuch mailing list, which allows for reliably
565 # testing commands that need to operate on a not-totally-trivial
566 # number of messages.
567 add_email_corpus ()
568 {
569     corpus=${1:-default}
570
571     rm -rf ${MAIL_DIR}
572     if [ -d $TEST_DIRECTORY/corpora.mail/$corpus ]; then
573         cp -a $TEST_DIRECTORY/corpora.mail/$corpus ${MAIL_DIR}
574     else
575         cp -a $TEST_DIRECTORY/corpora/$corpus ${MAIL_DIR}
576         notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
577         mkdir -p $TEST_DIRECTORY/corpora.mail
578         cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpora.mail/$corpus
579     fi
580 }
581
582 test_begin_subtest ()
583 {
584     if [ -n "$inside_subtest" ]; then
585         exec 1>&6 2>&7          # Restore stdout and stderr
586         error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
587     fi
588     test_subtest_name="$1"
589     test_reset_state_
590     # Redirect test output to the previously prepared file descriptors
591     # 3 and 4 (see below)
592     if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
593     exec >&3 2>&4
594     inside_subtest=t
595 }
596
597 # Pass test if two arguments match
598 #
599 # Note: Unlike all other test_expect_* functions, this function does
600 # not accept a test name. Instead, the caller should call
601 # test_begin_subtest before calling this function in order to set the
602 # name.
603 test_expect_equal ()
604 {
605         exec 1>&6 2>&7          # Restore stdout and stderr
606         inside_subtest=
607         test "$#" = 3 && { prereq=$1; shift; } || prereq=
608         test "$#" = 2 ||
609         error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
610
611         output="$1"
612         expected="$2"
613         if ! test_skip "$test_subtest_name"
614         then
615                 if [ "$output" = "$expected" ]; then
616                         test_ok_
617                 else
618                         testname=$this_test.$test_count
619                         echo "$expected" > $testname.expected
620                         echo "$output" > $testname.output
621                         test_failure_ "$(diff -u $testname.expected $testname.output)"
622                 fi
623     fi
624 }
625
626 # Like test_expect_equal, but takes two filenames.
627 test_expect_equal_file ()
628 {
629         exec 1>&6 2>&7          # Restore stdout and stderr
630         inside_subtest=
631         test "$#" = 3 && { prereq=$1; shift; } || prereq=
632         test "$#" = 2 ||
633         error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
634
635         file1="$1"
636         basename1=`basename "$file1"`
637         file2="$2"
638         basename2=`basename "$file2"`
639         if ! test_skip "$test_subtest_name"
640         then
641                 if diff -q "$file1" "$file2" >/dev/null ; then
642                         test_ok_
643                 else
644                         testname=$this_test.$test_count
645                         cp "$file1" "$testname.$basename1"
646                         cp "$file2" "$testname.$basename2"
647                         test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"
648                 fi
649     fi
650 }
651
652 # Like test_expect_equal, but arguments are JSON expressions to be
653 # canonicalized before diff'ing.  If an argument cannot be parsed, it
654 # is used unchanged so that there's something to diff against.
655 test_expect_equal_json () {
656     # The test suite forces LC_ALL=C, but this causes Python 3 to
657     # decode stdin as ASCII.  We need to read JSON in UTF-8, so
658     # override Python's stdio encoding defaults.
659     output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \
660         || echo "$1")
661     expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \
662         || echo "$2")
663     shift 2
664     test_expect_equal "$output" "$expected" "$@"
665 }
666
667 # Sort the top-level list of JSON data from stdin.
668 test_sort_json () {
669     PYTHONIOENCODING=utf-8 python -c \
670         "import sys, json; json.dump(sorted(json.load(sys.stdin)),sys.stdout)"
671 }
672
673 test_emacs_expect_t () {
674         test "$#" = 2 && { prereq=$1; shift; } || prereq=
675         test "$#" = 1 ||
676         error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
677
678         # Run the test.
679         if ! test_skip "$test_subtest_name"
680         then
681                 test_emacs "(notmuch-test-run $1)" >/dev/null
682
683                 # Restore state after the test.
684                 exec 1>&6 2>&7          # Restore stdout and stderr
685                 inside_subtest=
686
687                 # Report success/failure.
688                 result=$(cat OUTPUT)
689                 if [ "$result" = t ]
690                 then
691                         test_ok_
692                 else
693                         test_failure_ "${result}"
694                 fi
695         else
696                 # Restore state after the (non) test.
697                 exec 1>&6 2>&7          # Restore stdout and stderr
698                 inside_subtest=
699         fi
700 }
701
702 NOTMUCH_NEW ()
703 {
704     notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
705 }
706
707 NOTMUCH_DUMP_TAGS ()
708 {
709     # this relies on the default format being batch-tag, otherwise some tests will break
710     notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
711 }
712
713 notmuch_search_sanitize ()
714 {
715     perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
716 }
717
718 notmuch_search_files_sanitize ()
719 {
720     notmuch_dir_sanitize
721 }
722
723 notmuch_dir_sanitize ()
724 {
725     sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
726 }
727
728 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
729 notmuch_show_sanitize ()
730 {
731     sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
732 }
733 notmuch_show_sanitize_all ()
734 {
735     sed \
736         -e 's| filename:.*| filename:XXXXX|' \
737         -e 's| id:[^ ]* | id:XXXXX |' | \
738         notmuch_date_sanitize
739 }
740
741 notmuch_json_show_sanitize ()
742 {
743     sed \
744         -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
745         -e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
746         -e 's|"filename": "signature.asc",||g' \
747         -e 's|"filename": "/[^"]*",|"filename": "YYYYY",|g' \
748         -e 's|"timestamp": 97.......|"timestamp": 42|g' \
749         -e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
750 }
751
752 notmuch_emacs_error_sanitize ()
753 {
754     local command=$1
755     shift
756     for file in "$@"; do
757         echo "=== $file ==="
758         cat "$file"
759     done | sed  \
760         -e 's/^\[.*\]$/[XXX]/' \
761         -e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
762 }
763
764 notmuch_date_sanitize ()
765 {
766     sed \
767         -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
768 }
769
770 notmuch_uuid_sanitize ()
771 {
772     sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
773 }
774
775 notmuch_built_with_sanitize ()
776 {
777     sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
778 }
779
780 notmuch_config_sanitize ()
781 {
782     notmuch_dir_sanitize | notmuch_built_with_sanitize
783 }
784
785 # End of notmuch helper functions
786
787 # Use test_set_prereq to tell that a particular prerequisite is available.
788 # The prerequisite can later be checked for in two ways:
789 #
790 # - Explicitly using test_have_prereq.
791 #
792 # - Implicitly by specifying the prerequisite tag in the calls to
793 #   test_expect_{success,failure,code}.
794 #
795 # The single parameter is the prerequisite tag (a simple word, in all
796 # capital letters by convention).
797
798 test_set_prereq () {
799         satisfied="$satisfied$1 "
800 }
801 satisfied=" "
802
803 test_have_prereq () {
804         case $satisfied in
805         *" $1 "*)
806                 : yes, have it ;;
807         *)
808                 ! : nope ;;
809         esac
810 }
811
812 declare -A test_missing_external_prereq_
813 declare -A test_subtest_missing_external_prereq_
814
815 # declare prerequisite for the given external binary
816 test_declare_external_prereq () {
817         binary="$1"
818         test "$#" = 2 && name=$2 || name="$binary(1)"
819
820         if ! hash $binary 2>/dev/null; then
821                 test_missing_external_prereq_["${binary}"]=t
822                 eval "
823 $binary () {
824         test_subtest_missing_external_prereq_[\"${name}\"]=t
825         false
826 }"
827         fi
828 }
829
830 # Explicitly require external prerequisite.  Useful when binary is
831 # called indirectly (e.g. from emacs).
832 # Returns success if dependency is available, failure otherwise.
833 test_require_external_prereq () {
834         binary="$1"
835         if [[ ${test_missing_external_prereq_["${binary}"]} == t ]]; then
836                 # dependency is missing, call the replacement function to note it
837                 eval "$binary"
838         else
839                 true
840         fi
841 }
842
843 # You are not expected to call test_ok_ and test_failure_ directly, use
844 # the text_expect_* functions instead.
845
846 test_ok_ () {
847         if test "$test_subtest_known_broken_" = "t"; then
848                 test_known_broken_ok_
849                 return
850         fi
851         test_success=$(($test_success + 1))
852         if test -n "$NOTMUCH_TEST_QUIET"; then
853                 return 0
854         fi
855         say_color pass "%-6s" "PASS"
856         echo " $test_subtest_name"
857 }
858
859 test_failure_ () {
860         if test "$test_subtest_known_broken_" = "t"; then
861                 test_known_broken_failure_ "$@"
862                 return
863         fi
864         test_failure=$(($test_failure + 1))
865         print_test_description
866         test_failure_message_ "FAIL" "$test_subtest_name" "$@"
867         test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
868         return 1
869 }
870
871 test_failure_message_ () {
872         say_color error "%-6s" "$1"
873         echo " $2"
874         shift 2
875         echo "$@" | sed -e 's/^/        /'
876         if test "$verbose" != "t"; then cat test.output; fi
877 }
878
879 test_known_broken_ok_ () {
880         test_reset_state_
881         test_fixed=$(($test_fixed+1))
882         say_color pass "%-6s" "FIXED"
883         echo " $test_subtest_name"
884 }
885
886 test_known_broken_failure_ () {
887         test_reset_state_
888         test_broken=$(($test_broken+1))
889         test_failure_message_ "BROKEN" "$test_subtest_name" "$@"
890         return 1
891 }
892
893 test_debug () {
894         test "$debug" = "" || eval "$1"
895 }
896
897 test_run_ () {
898         test_cleanup=:
899         if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
900         eval >&3 2>&4 "$1"
901         eval_ret=$?
902         eval >&3 2>&4 "$test_cleanup"
903         return 0
904 }
905
906 test_skip () {
907         test_count=$(($test_count+1))
908         to_skip=
909         for skp in $NOTMUCH_SKIP_TESTS
910         do
911                 case $this_test.$test_count in
912                 $skp)
913                         to_skip=t
914                         break
915                 esac
916                 case $this_test_bare.$test_count in
917                 $skp)
918                         to_skip=t
919                         break
920                 esac
921         done
922         if test -z "$to_skip" && test -n "$prereq" &&
923            ! test_have_prereq "$prereq"
924         then
925                 to_skip=t
926         fi
927         case "$to_skip" in
928         t)
929                 test_report_skip_ "$@"
930                 ;;
931         *)
932                 test_check_missing_external_prereqs_ "$@"
933                 ;;
934         esac
935 }
936
937 test_check_missing_external_prereqs_ () {
938         if [[ ${#test_subtest_missing_external_prereq_[@]} != 0 ]]; then
939                 say_color skip >&1 "missing prerequisites: "
940                 echo ${!test_subtest_missing_external_prereq_[@]} >&1
941                 test_report_skip_ "$@"
942         else
943                 false
944         fi
945 }
946
947 test_report_skip_ () {
948         test_reset_state_
949         say_color skip >&3 "skipping test:"
950         echo " $@" >&3
951         say_color skip "%-6s" "SKIP"
952         echo " $1"
953 }
954
955 test_subtest_known_broken () {
956         test_subtest_known_broken_=t
957 }
958
959 test_expect_success () {
960         test "$#" = 3 && { prereq=$1; shift; } || prereq=
961         test "$#" = 2 ||
962         error "bug in the test script: not 2 or 3 parameters to test-expect-success"
963         test_subtest_name="$1"
964         test_reset_state_
965         if ! test_skip "$@"
966         then
967                 test_run_ "$2"
968                 run_ret="$?"
969                 # test_run_ may update missing external prerequisites
970                 test_check_missing_external_prereqs_ "$@" ||
971                 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
972                 then
973                         test_ok_
974                 else
975                         test_failure_ "$2"
976                 fi
977         fi
978 }
979
980 test_expect_code () {
981         test "$#" = 4 && { prereq=$1; shift; } || prereq=
982         test "$#" = 3 ||
983         error "bug in the test script: not 3 or 4 parameters to test-expect-code"
984         test_subtest_name="$2"
985         test_reset_state_
986         if ! test_skip "$@"
987         then
988                 test_run_ "$3"
989                 run_ret="$?"
990                 # test_run_ may update missing external prerequisites,
991                 test_check_missing_external_prereqs_ "$@" ||
992                 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
993                 then
994                         test_ok_
995                 else
996                         test_failure_ "exit code $eval_ret, expected $1" "$3"
997                 fi
998         fi
999 }
1000
1001 # test_external runs external test scripts that provide continuous
1002 # test output about their progress, and succeeds/fails on
1003 # zero/non-zero exit code.  It outputs the test output on stdout even
1004 # in non-verbose mode, and announces the external script with "* run
1005 # <n>: ..." before running it.  When providing relative paths, keep in
1006 # mind that all scripts run in "trash directory".
1007 # Usage: test_external description command arguments...
1008 # Example: test_external 'Perl API' perl ../path/to/test.pl
1009 test_external () {
1010         test "$#" = 4 && { prereq=$1; shift; } || prereq=
1011         test "$#" = 3 ||
1012         error >&6 "bug in the test script: not 3 or 4 parameters to test_external"
1013         test_subtest_name="$1"
1014         shift
1015         test_reset_state_
1016         if ! test_skip "$test_subtest_name" "$@"
1017         then
1018                 # Announce the script to reduce confusion about the
1019                 # test output that follows.
1020                 say_color "" " run $test_count: $descr ($*)"
1021                 # Run command; redirect its stderr to &4 as in
1022                 # test_run_, but keep its stdout on our stdout even in
1023                 # non-verbose mode.
1024                 "$@" 2>&4
1025                 if [ "$?" = 0 ]
1026                 then
1027                         test_ok_
1028                 else
1029                         test_failure_ "$@"
1030                 fi
1031         fi
1032 }
1033
1034 # Like test_external, but in addition tests that the command generated
1035 # no output on stderr.
1036 test_external_without_stderr () {
1037         # The temporary file has no (and must have no) security
1038         # implications.
1039         tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
1040         stderr="$tmp/git-external-stderr.$$.tmp"
1041         test_external "$@" 4> "$stderr"
1042         [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
1043         test_subtest_name="no stderr: $1"
1044         shift
1045         if [ ! -s "$stderr" ]; then
1046                 rm "$stderr"
1047                 test_ok_
1048         else
1049                 if [ "$verbose" = t ]; then
1050                         output=`echo; echo Stderr is:; cat "$stderr"`
1051                 else
1052                         output=
1053                 fi
1054                 # rm first in case test_failure exits.
1055                 rm "$stderr"
1056                 test_failure_ "$@" "$output"
1057         fi
1058 }
1059
1060 # This is not among top-level (test_expect_success)
1061 # but is a prefix that can be used in the test script, like:
1062 #
1063 #       test_expect_success 'complain and die' '
1064 #           do something &&
1065 #           do something else &&
1066 #           test_must_fail git checkout ../outerspace
1067 #       '
1068 #
1069 # Writing this as "! git checkout ../outerspace" is wrong, because
1070 # the failure could be due to a segv.  We want a controlled failure.
1071
1072 test_must_fail () {
1073         "$@"
1074         test $? -gt 0 -a $? -le 129 -o $? -gt 192
1075 }
1076
1077 # test_cmp is a helper function to compare actual and expected output.
1078 # You can use it like:
1079 #
1080 #       test_expect_success 'foo works' '
1081 #               echo expected >expected &&
1082 #               foo >actual &&
1083 #               test_cmp expected actual
1084 #       '
1085 #
1086 # This could be written as either "cmp" or "diff -u", but:
1087 # - cmp's output is not nearly as easy to read as diff -u
1088 # - not all diff versions understand "-u"
1089
1090 test_cmp() {
1091         $GIT_TEST_CMP "$@"
1092 }
1093
1094 # This function can be used to schedule some commands to be run
1095 # unconditionally at the end of the test to restore sanity:
1096 #
1097 #       test_expect_success 'test core.capslock' '
1098 #               git config core.capslock true &&
1099 #               test_when_finished "git config --unset core.capslock" &&
1100 #               hello world
1101 #       '
1102 #
1103 # That would be roughly equivalent to
1104 #
1105 #       test_expect_success 'test core.capslock' '
1106 #               git config core.capslock true &&
1107 #               hello world
1108 #               git config --unset core.capslock
1109 #       '
1110 #
1111 # except that the greeting and config --unset must both succeed for
1112 # the test to pass.
1113
1114 test_when_finished () {
1115         test_cleanup="{ $*
1116                 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
1117 }
1118
1119 test_done () {
1120         GIT_EXIT_OK=t
1121         test_results_dir="$TEST_DIRECTORY/test-results"
1122         mkdir -p "$test_results_dir"
1123         test_results_path="$test_results_dir/$this_test"
1124
1125         echo "total $test_count" >> $test_results_path
1126         echo "success $test_success" >> $test_results_path
1127         echo "fixed $test_fixed" >> $test_results_path
1128         echo "broken $test_broken" >> $test_results_path
1129         echo "failed $test_failure" >> $test_results_path
1130         echo "" >> $test_results_path
1131
1132         [ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
1133
1134         if [ "$test_failure" = "0" ]; then
1135             if [ "$test_broken" = "0" ]; then
1136                 rm -rf "$remove_tmp"
1137             fi
1138             exit 0
1139         else
1140             exit 1
1141         fi
1142 }
1143
1144 emacs_generate_script () {
1145         # Construct a little test script here for the benefit of the user,
1146         # (who can easily run "run_emacs" to get the same emacs environment
1147         # for investigating any failures).
1148         cat <<EOF >"$TMP_DIRECTORY/run_emacs"
1149 #!/bin/sh
1150 export PATH=$PATH
1151 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
1152
1153 # Here's what we are using here:
1154 #
1155 # --quick              Use minimal customization. This implies --no-init-file,
1156 #                      --no-site-file and (emacs 24) --no-site-lisp
1157 #
1158 # --directory           Ensure that the local elisp sources are found
1159 #
1160 # --load                Force loading of notmuch.el and test-lib.el
1161
1162 exec ${TEST_EMACS} --quick \
1163         --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \
1164         --directory "$TEST_DIRECTORY" --load test-lib.el \
1165         "\$@"
1166 EOF
1167         chmod a+x "$TMP_DIRECTORY/run_emacs"
1168 }
1169
1170 test_emacs () {
1171         # test dependencies beforehand to avoid the waiting loop below
1172         missing_dependencies=
1173         test_require_external_prereq dtach || missing_dependencies=1
1174         test_require_external_prereq emacs || missing_dependencies=1
1175         test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
1176         test -z "$missing_dependencies" || return
1177
1178         if [ -z "$EMACS_SERVER" ]; then
1179                 emacs_tests="${this_test_bare}.el"
1180                 if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
1181                         load_emacs_tests="--eval '(load \"$emacs_tests\")'"
1182                 else
1183                         load_emacs_tests=
1184                 fi
1185                 server_name="notmuch-test-suite-$$"
1186                 # start a detached session with an emacs server
1187                 # user's TERM (or 'vt100' in case user's TERM is known dumb
1188                 # or unknown) is given to dtach which assumes a minimally
1189                 # VT100-compatible terminal -- and emacs inherits that
1190                 TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
1191                         sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
1192                                 --no-window-system \
1193                                 $load_emacs_tests \
1194                                 --eval '(setq server-name \"$server_name\")' \
1195                                 --eval '(server-start)' \
1196                                 --eval '(orphan-watchdog $$)'" || return
1197                 EMACS_SERVER="$server_name"
1198                 # wait until the emacs server is up
1199                 until test_emacs '()' >/dev/null 2>/dev/null; do
1200                         sleep 1
1201                 done
1202         fi
1203
1204         # Clear test-output output file.  Most Emacs tests end with a
1205         # call to (test-output).  If the test code fails with an
1206         # exception before this call, the output file won't get
1207         # updated.  Since we don't want to compare against an output
1208         # file from another test, so start out with an empty file.
1209         rm -f OUTPUT
1210         touch OUTPUT
1211
1212         ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $@)"
1213 }
1214
1215 test_python() {
1216     # Note: if there is need to print debug information from python program,
1217     # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
1218     PYTHONPATH="$TEST_DIRECTORY/../bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
1219         $NOTMUCH_PYTHON -B - > OUTPUT
1220 }
1221
1222 test_ruby() {
1223     MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
1224 }
1225
1226 test_C () {
1227     exec_file="test${test_count}"
1228     test_file="${exec_file}.c"
1229     cat > ${test_file}
1230     ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
1231     echo "== stdout ==" > OUTPUT.stdout
1232     echo "== stderr ==" > OUTPUT.stderr
1233     ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
1234     notmuch_dir_sanitize OUTPUT.stdout OUTPUT.stderr > OUTPUT
1235 }
1236
1237
1238 # Creates a script that counts how much time it is executed and calls
1239 # notmuch.  $notmuch_counter_command is set to the path to the
1240 # generated script.  Use notmuch_counter_value() function to get the
1241 # current counter value.
1242 notmuch_counter_reset () {
1243         notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
1244         if [ ! -x "$notmuch_counter_command" ]; then
1245                 notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
1246                 cat >"$notmuch_counter_command" <<EOF || return
1247 #!/bin/sh
1248
1249 read count < "$notmuch_counter_state_path"
1250 echo \$((count + 1)) > "$notmuch_counter_state_path"
1251
1252 exec notmuch "\$@"
1253 EOF
1254                 chmod +x "$notmuch_counter_command" || return
1255         fi
1256
1257         echo 0 > "$notmuch_counter_state_path"
1258 }
1259
1260 # Returns the current notmuch counter value.
1261 notmuch_counter_value () {
1262         if [ -r "$notmuch_counter_state_path" ]; then
1263                 read count < "$notmuch_counter_state_path"
1264         else
1265                 count=0
1266         fi
1267         echo $count
1268 }
1269
1270 test_reset_state_ () {
1271         test -z "$test_init_done_" && test_init_
1272
1273         test_subtest_known_broken_=
1274         test_subtest_missing_external_prereq_=()
1275 }
1276
1277 # called once before the first subtest
1278 test_init_ () {
1279         test_init_done_=t
1280
1281         # skip all tests if there were external prerequisites missing during init
1282         test_check_missing_external_prereqs_ "all tests in $this_test" && test_done
1283 }
1284
1285
1286 . ./test-lib-common.sh || exit 1
1287
1288 # we need the setting of GNUPGHOME in test-lib-common.sh
1289 if [ ${NOTMUCH_HAVE_GPGCONF_SOCKETDIR} = 1 ]; then
1290     gpgconf --create-socketdir
1291 fi
1292
1293 emacs_generate_script
1294
1295
1296 # Use -P to resolve symlinks in our working directory so that the cwd
1297 # in subprocesses like git equals our $PWD (for pathname comparisons).
1298 cd -P "$test" || error "Cannot set up test environment"
1299
1300 if test "$verbose" = "t"
1301 then
1302         exec 4>&2 3>&1
1303 else
1304         exec 4>test.output 3>&4
1305 fi
1306
1307 for skp in $NOTMUCH_SKIP_TESTS
1308 do
1309         to_skip=
1310         for skp in $NOTMUCH_SKIP_TESTS
1311         do
1312                 case "$this_test" in
1313                 $skp)
1314                         to_skip=t
1315                         break
1316                 esac
1317                 case "$this_test_bare" in
1318                 $skp)
1319                         to_skip=t
1320                         break
1321                 esac
1322         done
1323         case "$to_skip" in
1324         t)
1325                 say_color skip >&3 "skipping test $this_test altogether"
1326                 say_color skip "skip all tests in $this_test"
1327                 test_done
1328         esac
1329 done
1330
1331 # Provide an implementation of the 'yes' utility
1332 yes () {
1333         if test $# = 0
1334         then
1335                 y=y
1336         else
1337                 y="$*"
1338         fi
1339
1340         while echo "$y"
1341         do
1342                 :
1343         done
1344 }
1345
1346 # Fix some commands on Windows
1347 case $(uname -s) in
1348 *MINGW*)
1349         # Windows has its own (incompatible) sort and find
1350         sort () {
1351                 /usr/bin/sort "$@"
1352         }
1353         find () {
1354                 /usr/bin/find "$@"
1355         }
1356         sum () {
1357                 md5sum "$@"
1358         }
1359         # git sees Windows-style pwd
1360         pwd () {
1361                 builtin pwd -W
1362         }
1363         # no POSIX permissions
1364         # backslashes in pathspec are converted to '/'
1365         # exec does not inherit the PID
1366         ;;
1367 *)
1368         test_set_prereq POSIXPERM
1369         test_set_prereq BSLASHPSPEC
1370         test_set_prereq EXECKEEPSPID
1371         ;;
1372 esac
1373
1374 test -z "$NO_PERL" && test_set_prereq PERL
1375 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1376
1377 # test whether the filesystem supports symbolic links
1378 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
1379 rm -f y
1380
1381 # convert variable from configure to more convenient form
1382 case "$NOTMUCH_DEFAULT_XAPIAN_BACKEND" in
1383     glass)
1384         db_ending=glass
1385     ;;
1386     chert)
1387         db_ending=DB
1388     ;;
1389     *)
1390         error "Unknown Xapian backend $NOTMUCH_DEFAULT_XAPIAN_BACKEND"
1391 esac
1392 # declare prerequisites for external binaries used in tests
1393 test_declare_external_prereq dtach
1394 test_declare_external_prereq emacs
1395 test_declare_external_prereq ${TEST_EMACSCLIENT}
1396 test_declare_external_prereq gdb
1397 test_declare_external_prereq gpg
1398 test_declare_external_prereq openssl
1399 test_declare_external_prereq gpgsm
1400 test_declare_external_prereq ${NOTMUCH_PYTHON}