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