+ chmod a+x "$TMP_DIRECTORY/run_emacs"
+}
+
+test_emacs () {
+ # test dependencies beforehand to avoid the waiting loop below
+ test_require_external_prereq emacs || return
+ test_require_external_prereq emacsclient || return
+
+ if [ -z "$EMACS_SERVER" ]; then
+ server_name="notmuch-test-suite-$$"
+ # start a detached session with an emacs server
+ # user's TERM is given to dtach which assumes a minimally
+ # VT100-compatible terminal -- and emacs inherits that
+ TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
+ sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
+ --no-window-system \
+ --eval '(setq server-name \"$server_name\")' \
+ --eval '(server-start)' \
+ --eval '(orphan-watchdog $$)'" || return
+ EMACS_SERVER="$server_name"
+ # wait until the emacs server is up
+ until test_emacs '()' 2>/dev/null; do
+ sleep 1
+ done
+ fi
+
+ emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
+}
+
+test_reset_state_ () {
+ test -z "$test_init_done_" && test_init_
+
+ test_subtest_known_broken_=
+ test_subtest_missing_external_prereqs_=
+}
+
+# called once before the first subtest
+test_init_ () {
+ test_init_done_=t
+
+ # skip all tests if there were external prerequisites missing during init
+ test_check_missing_external_prereqs_ "all tests in $this_test" && test_done