From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
Subject: [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization
Date: Sat, 22 May 2021 18:20:08 +0300 [thread overview]
Message-ID: <20210522152008.27059-1-tomi.ollila@iki.fi> (raw)
After test_emacs() has started emacs, it re-defines
itself as just calling the started emacs.
First call to test_emacs() will execute to the end of it;
next calls will just execute the 2 lines, first clearing OUTPUT,
second and last executing TEST_EMACSCLIENT...
This simplifies away one if constructs and reduces xtrace
output when doing test debugging with set -x.
---
This has been laying around like 6 years, every now thinking whether
to post or not. Now needed to rebase so finally polished to a
sendable format. re-defining functions just may be too much
to understand (or not)...
test/test-lib-emacs.sh | 79 +++++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 36 deletions(-)
diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
index dde32177..b2b490be 100644
--- a/test/test-lib-emacs.sh
+++ b/test/test-lib-emacs.sh
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2010-2020 Notmuch Developers
+# Copyright (c) 2010-2021 Notmuch Developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -166,44 +166,51 @@ EOF
}
test_emacs () {
- # test dependencies beforehand to avoid the waiting loop below
+ # Note: This test_emacs() is re-defined after emacs started below.
test_require_emacs || return
- if [ -z "$EMACS_SERVER" ]; then
- emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
- if [ -f "$emacs_tests" ]; then
- load_emacs_tests="--eval '(load \"$emacs_tests\")'"
- else
- load_emacs_tests=
- fi
- server_name="notmuch-test-suite-$$"
- # start a detached session with an emacs server
- # user's TERM (or 'vt100' in case user's TERM is known dumb
- # or unknown) is given to dtach which assumes a minimally
- # VT100-compatible terminal -- and emacs inherits that
- TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
- sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
- --no-window-system \
- $load_emacs_tests \
- --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 '()' >/dev/null 2>/dev/null; do
- sleep 1
- done
- fi
+ local emacs_tests load_emacs_tests server_name
- # Clear test-output output file. Most Emacs tests end with a
- # call to (test-output). If the test code fails with an
- # exception before this call, the output file won't get
- # updated. Since we don't want to compare against an output
- # file from another test, so start out with an empty file.
- rm -f OUTPUT
- touch OUTPUT
-
- ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $*)"
+ emacs_tests=$NOTMUCH_SRCDIR/test/${this_test_bare}.el
+ if [ -f "$emacs_tests" ]; then
+ load_emacs_tests="--eval '(load \"$emacs_tests\")'"
+ else
+ load_emacs_tests=
+ fi
+ server_name=notmuch-test-suite-$$
+ # start a detached session with an emacs server
+ # user's TERM (or 'vt100' in case user's TERM is known dumb
+ # or unknown) is given to dtach which assumes a minimally
+ # VT100-compatible terminal -- and emacs inherits that
+ TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
+ sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
+ --no-window-system \
+ $load_emacs_tests \
+ --eval '(setq server-name \"$server_name\")' \
+ --eval '(server-start)' \
+ --eval '(orphan-watchdog $$)'" || return
+
+ EMACS_SERVER=$server_name
+
+ # re-define test_emacs() -- further calls will use this one
+ test_emacs () {
+ # Clear test-output output file. Most Emacs tests end with a
+ # call to (test-output). If the test code fails with an
+ # exception before this call, the output file won't get
+ # updated. Since we don't want to compare against an output
+ # file from another test, so start out with an empty file.
+ : > OUTPUT
+ ${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" \
+ --eval "(notmuch-test-progn $*)"
+ }
+
+ # wait until the emacs server is up (now calling "new" test_emacs())
+ until test_emacs '()' >/dev/null 2>/dev/null; do
+ sleep 1
+ done
+
+ # and finally, call new test_emacs() with given args
+ test_emacs "$@"
}
emacs_generate_script
--
2.25.1
next reply other threads:[~2021-05-22 15:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-22 15:20 Tomi Ollila [this message]
2021-06-26 12:31 ` [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization David Bremner
2021-06-26 14:10 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210522152008.27059-1-tomi.ollila@iki.fi \
--to=tomi.ollila@iki.fi \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).