unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] test-lib-emacs: re-define test_emacs() after initialization
@ 2021-05-22 15:20 Tomi Ollila
  0 siblings, 0 replies; only message 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	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-22 15:20 UTC | newest]

Thread overview: (only message) (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

unofficial mirror of notmuch@notmuchmail.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/notmuch/0 notmuch/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 notmuch notmuch/ https://yhetil.org/notmuch \
		notmuch@notmuchmail.org
	public-inbox-index notmuch

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.notmuch.general
	nntp://news.gmane.io/gmane.mail.notmuch.general


code repositories for project(s) associated with this inbox:

	notmuch.git.git (no URL configured)

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git