* [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization
@ 2021-05-22 15:20 Tomi Ollila
2021-06-26 12:31 ` David Bremner
2021-06-26 14:10 ` David Bremner
0 siblings, 2 replies; 3+ messages in thread
From: Tomi Ollila @ 2021-05-22 15:20 UTC (permalink / raw)
To: notmuch; +Cc: tomi.ollila
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization
2021-05-22 15:20 [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization Tomi Ollila
@ 2021-06-26 12:31 ` David Bremner
2021-06-26 14:10 ` David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2021-06-26 12:31 UTC (permalink / raw)
To: Tomi Ollila, notmuch; +Cc: tomi.ollila
Tomi Ollila <tomi.ollila@iki.fi> writes:
> 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.
Although I am slightly horrified to learn that bash functions can
redefine themselves, I guess I can live with this if it is useful. It's
not like checking an environment variable is such a pretty construct.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization
2021-05-22 15:20 [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization Tomi Ollila
2021-06-26 12:31 ` David Bremner
@ 2021-06-26 14:10 ` David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2021-06-26 14:10 UTC (permalink / raw)
To: Tomi Ollila, notmuch; +Cc: tomi.ollila
Tomi Ollila <tomi.ollila@iki.fi> writes:
> 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.
I was thinking about this, and wouldn't factoring out the first run
stuff into a separate function be almost as good for debugging with set
-x?
d
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-26 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-22 15:20 [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization Tomi Ollila
2021-06-26 12:31 ` David Bremner
2021-06-26 14:10 ` David Bremner
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).