2 # Copyright (c) 2010-2020 Notmuch Developers
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see https://www.gnu.org/licenses/ .
17 test_require_emacs () {
19 test_require_external_prereq "$TEST_EMACS" || ret=1
20 test_require_external_prereq "$TEST_EMACSCLIENT" || ret=1
21 test_require_external_prereq dtach || ret=1
25 # Deliver a message with emacs and add it to the database
27 # Uses emacs to generate and deliver a message to the mail store.
28 # Accepts arbitrary extra emacs/elisp functions to modify the message
29 # before sending, which is useful to doing things like attaching files
30 # to the message and encrypting/signing.
31 emacs_deliver_message () {
32 local subject body smtp_dummy_pid smtp_dummy_port
36 # before we can send a message, we have to prepare the FCC maildir
37 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
38 # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port
39 smtp_dummy_pid= smtp_dummy_port=
40 eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
41 test -n "$smtp_dummy_pid" || return 1
42 test -n "$smtp_dummy_port" || return 1
45 "(let ((message-send-mail-function 'message-smtpmail-send-it)
46 (mail-host-address \"example.com\")
47 (smtpmail-smtp-server \"localhost\")
48 (smtpmail-smtp-service \"${smtp_dummy_port}\"))
51 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
52 (message-goto-subject)
53 (insert \"${subject}\")
57 (let ((mml-secure-smime-sign-with-sender t)
58 (mml-secure-openpgp-sign-with-sender t))
59 (notmuch-mua-send-and-exit)))"
60 # In case message was sent properly, client waits for confirmation
61 # before exiting and resuming control here; therefore making sure
62 # that server exits by sending (KILL) signal to it is safe.
63 kill -9 $smtp_dummy_pid
64 notmuch new >/dev/null
67 # Pretend to deliver a message with emacs. Really save it to a file
68 # and add it to the database
70 # Uses emacs to generate and deliver a message to the mail store.
71 # Accepts arbitrary extra emacs/elisp functions to modify the message
72 # before sending, which is useful to doing things like attaching files
73 # to the message and encrypting/signing.
75 # If any GNU-style long-arguments (like --quiet or --decrypt=true) are
76 # at the head of the argument list, they are sent directly to "notmuch
77 # new" after message delivery
78 emacs_fcc_message () {
79 local nmn_args subject body
81 while [[ "$1" =~ ^-- ]]; do
82 nmn_args="$nmn_args $1"
88 # before we can send a message, we have to prepare the FCC maildir
89 mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
92 "(let ((message-send-mail-function (lambda () t))
93 (mail-host-address \"example.com\"))
96 (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
97 (message-goto-subject)
98 (insert \"${subject}\")
102 (let ((mml-secure-smime-sign-with-sender t)
103 (mml-secure-openpgp-sign-with-sender t))
104 (notmuch-mua-send-and-exit)))" || return 1
105 notmuch new $nmn_args >/dev/null
108 test_emacs_expect_t () {
111 error "bug in the test script: not 1 parameter to test_emacs_expect_t"
112 if [ -z "$inside_subtest" ]; then
113 error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
117 if ! test_skip "$test_subtest_name"
119 test_emacs "(notmuch-test-run $1)" >/dev/null
121 # Restore state after the test.
122 exec 1>&6 2>&7 # Restore stdout and stderr
125 # test_emacs may update missing external prerequisites
126 test_check_missing_external_prereqs_ "$test_subtest_name" && return
128 # Report success/failure.
134 test_failure_ "${result}"
137 # Restore state after the (non) test.
138 exec 1>&6 2>&7 # Restore stdout and stderr
143 emacs_generate_script () {
144 # Construct a little test script here for the benefit of the user,
145 # (who can easily run "run_emacs" to get the same emacs environment
146 # for investigating any failures).
147 cat <<EOF >"$TMP_DIRECTORY/run_emacs"
150 export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
152 # Here's what we are using here:
154 # --quick Use minimal customization. This implies --no-init-file,
155 # --no-site-file and (emacs 24) --no-site-lisp
157 # --directory Ensure that the local elisp sources are found
159 # --load Force loading of notmuch.el and test-lib.el
161 exec ${TEST_EMACS} --quick \
162 --directory "$NOTMUCH_BUILDDIR/emacs" --load notmuch.el \
163 --directory "$NOTMUCH_SRCDIR/test" --load test-lib.el \
166 chmod a+x "$TMP_DIRECTORY/run_emacs"
170 # test dependencies beforehand to avoid the waiting loop below
171 test_require_emacs || return
173 if [ -z "$EMACS_SERVER" ]; then
174 emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
175 if [ -f "$emacs_tests" ]; then
176 load_emacs_tests="--eval '(load \"$emacs_tests\")'"
180 server_name="notmuch-test-suite-$$"
181 # start a detached session with an emacs server
182 # user's TERM (or 'vt100' in case user's TERM is known dumb
183 # or unknown) is given to dtach which assumes a minimally
184 # VT100-compatible terminal -- and emacs inherits that
185 TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
186 sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
189 --eval '(setq server-name \"$server_name\")' \
190 --eval '(server-start)' \
191 --eval '(orphan-watchdog $$)'" || return
192 EMACS_SERVER="$server_name"
193 # wait until the emacs server is up
194 until test_emacs '()' >/dev/null 2>/dev/null; do
199 # Clear test-output output file. Most Emacs tests end with a
200 # call to (test-output). If the test code fails with an
201 # exception before this call, the output file won't get
202 # updated. Since we don't want to compare against an output
203 # file from another test, so start out with an empty file.
207 ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $*)"
214 test_emacs "(test-time $*)" > emacs.out
218 emacs_generate_script