unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 00/13] test: several fixes and improvements
@ 2021-05-01 11:54 Felipe Contreras
  2021-05-01 11:54 ` [PATCH 01/13] test: fix passwd_sanitize() Felipe Contreras
                   ` (13 more replies)
  0 siblings, 14 replies; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

The current tests fail on my machine due to my configuration, mainly because I didn't have dtach
installed, but also other stuff.

The following patches fix all the issues I found, and also do plenty of cleanups.

Felipe Contreras (13):
  test: fix passwd_sanitize()
  test: unset NAME environment variable
  test: remove USER_FULL_NAME when not present
  test: use correct fqdn in passwd_sanitize()
  test: fix wrong SKIP messages
  test: add prereqs check in test_emacs_expect_t
  test: add external prereqs to many emacs tests
  test: split emacs functionality to its own file
  test: emacs: simplify missing dependencies check
  test: emacs: check for configured emacs
  test: emacs: fix a couple of shellcheck complaints
  test: trivial style cleanups
  test: more style fixes

 test/T000-basic.sh                     |   2 +-
 test/T070-insert.sh                    |   2 +-
 test/T140-excludes.sh                  |   3 +-
 test/T160-json.sh                      |   1 +
 test/T170-sexp.sh                      |   1 +
 test/T190-multipart.sh                 |   3 +-
 test/T310-emacs.sh                     |   2 +
 test/T320-emacs-large-search-buffer.sh |   3 +
 test/T330-emacs-subject-to-filename.sh |   3 +
 test/T350-crypto.sh                    |   2 +
 test/T355-smime.sh                     |   2 +
 test/T357-index-decryption.sh          |   2 +
 test/T358-emacs-protected-headers.sh   |   2 +
 test/T420-emacs-test-functions.sh      |   1 +
 test/T430-emacs-address-cleaning.sh    |   3 +
 test/T440-emacs-hello.sh               |   2 +
 test/T450-emacs-show.sh                |   2 +
 test/T455-emacs-charsets.sh            |   3 +
 test/T460-emacs-tree.sh                |   2 +
 test/T490-parse-time-string.sh         |   6 +-
 test/T510-thread-replies.sh            |   1 +
 test/T590-libconfig.sh                 |  10 +
 test/T590-thread-breakage.sh           |  10 +-
 test/T630-emacs-draft.sh               |   2 +
 test/T720-emacs-attachment-warnings.sh |   3 +
 test/T730-emacs-forwarding.sh          |   3 +
 test/export-dirs.sh                    |   3 +-
 test/test-lib-common.sh                |   6 +-
 test/test-lib-emacs.sh                 | 209 ++++++++++++++++++
 test/test-lib.sh                       | 282 ++++---------------------
 30 files changed, 310 insertions(+), 266 deletions(-)
 create mode 100644 test/test-lib-emacs.sh

-- 
2.31.0

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH 01/13] test: fix passwd_sanitize()
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:01   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 02/13] test: unset NAME environment variable Felipe Contreras
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

If any of the variables is empty the output is completely messed up,
because replace("", "FOO") puts "FOO" before every single character.

I don't have my full name configured, and this is what I get:

  USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME USER_FULL_NAMEsUSER_FULL_NAMEtUSER_FULL_NAMEdUSER_FULL_NAMEoUSER_FULL_NAMEuUSER_FULL_NAMEtUSER_FULL_NAME USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME

Let's check for empty strings before doing any replace.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 4c9f2a21..e13797a7 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -711,7 +711,12 @@ name = pw.pw_gecos.partition(",")[0]
 fqdn = socket.getfqdn()
 
 for l in sys.stdin:
-    l = l.replace(user, "USERNAME").replace(fqdn, "FQDN").replace(".(none)","").replace(name, "USER_FULL_NAME")
+    if user:
+        l = l.replace(user, "USERNAME")
+    if fqdn:
+        l = l.replace(fqdn, "FQDN").replace(".(none)","")
+    if name:
+        l = l.replace(name, "USER_FULL_NAME")
     sys.stdout.write(l)
 '
 }
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 02/13] test: unset NAME environment variable
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
  2021-05-01 11:54 ` [PATCH 01/13] test: fix passwd_sanitize() Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:01   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 03/13] test: remove USER_FULL_NAME when not present Felipe Contreras
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

Otherwise the output from the tests would be different.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index e13797a7..ae653363 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -112,6 +112,7 @@ unset ALTERNATE_EDITOR
 
 # for reproducibility
 unset EMAIL
+unset NAME
 
 add_gnupg_home ()
 {
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 03/13] test: remove USER_FULL_NAME when not present
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
  2021-05-01 11:54 ` [PATCH 01/13] test: fix passwd_sanitize() Felipe Contreras
  2021-05-01 11:54 ` [PATCH 02/13] test: unset NAME environment variable Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:13   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 04/13] test: use correct fqdn in passwd_sanitize() Felipe Contreras
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

If a full name is not configured, the output is empty.

This is possibly not portable, but it's a start.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T590-libconfig.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 51dd29c8..36d9af1b 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -5,6 +5,14 @@ test_description="library config API"
 
 add_email_corpus
 
+get_name () {
+    if hash getent 2>/dev/null; then
+        getent passwd "$USER" | cut -d ':' -f 5
+    else
+        echo "Foo Bar"
+    fi
+}
+
 cat <<EOF > c_head
 #include <string.h>
 #include <stdlib.h>
@@ -402,6 +410,7 @@ NULL
 USER_FULL_NAME
 == stderr ==
 EOF
+test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
 unset MAILDIR
 test_expect_equal_file EXPECTED OUTPUT.clean
 
@@ -744,6 +753,7 @@ NULL
 USER_FULL_NAME
 == stderr ==
 EOF
+test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
 test_expect_equal_file EXPECTED OUTPUT.clean
 
 backup_database
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 04/13] test: use correct fqdn in passwd_sanitize()
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (2 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 03/13] test: remove USER_FULL_NAME when not present Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:14   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 05/13] test: fix wrong SKIP messages Felipe Contreras
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

My fqdn is 'natae.localdomain', however, socket.getfqdn() returns
'localhost'.

To fetch the true fqdn we need socket.getaddrinfo().

For more information see: https://stackoverflow.com/a/11580042/10474

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index ae653363..21dda265 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -709,7 +709,7 @@ import os, sys, pwd, socket
 pw = pwd.getpwuid(os.getuid())
 user = pw.pw_name
 name = pw.pw_gecos.partition(",")[0]
-fqdn = socket.getfqdn()
+fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3]
 
 for l in sys.stdin:
     if user:
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 05/13] test: fix wrong SKIP messages
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (3 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 04/13] test: use correct fqdn in passwd_sanitize() Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:18   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 06/13] test: add prereqs check in test_emacs_expect_t Felipe Contreras
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

When the external prereqs are updated inside the body of the command
(e.g. test_emacs) the message in test_report_skip_ is wrong: it outputs
the body of the command instead of the subtest name.

We need to pass the same argument we pass to test_skip.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 21dda265..1067316d 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -919,7 +919,7 @@ test_expect_success () {
 		test_run_ "$1"
 		run_ret="$?"
 		# test_run_ may update missing external prerequisites
-		test_check_missing_external_prereqs_ "$@" ||
+		test_check_missing_external_prereqs_ "$test_subtest_name" ||
 		if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
 		then
 			test_ok_
@@ -943,7 +943,7 @@ test_expect_code () {
 		test_run_ "$2"
 		run_ret="$?"
 		# test_run_ may update missing external prerequisites,
-		test_check_missing_external_prereqs_ "$@" ||
+		test_check_missing_external_prereqs_ "$test_subtest_name" ||
 		if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
 		then
 			test_ok_
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 06/13] test: add prereqs check in test_emacs_expect_t
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (4 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 05/13] test: fix wrong SKIP messages Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:18   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 07/13] test: add external prereqs to many emacs tests Felipe Contreras
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

test_emacs may update the external prereqs, in which case we want to
skip the test rather than fail.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 1067316d..72ac2e89 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -592,6 +592,9 @@ test_emacs_expect_t () {
 		exec 1>&6 2>&7		# Restore stdout and stderr
 		inside_subtest=
 
+		# test_emacs may update missing external prerequisites
+		test_check_missing_external_prereqs_ "$test_subtest_name" && return
+
 		# Report success/failure.
 		result=$(cat OUTPUT)
 		if [ "$result" = t ]
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 07/13] test: add external prereqs to many emacs tests
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (5 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 06/13] test: add prereqs check in test_emacs_expect_t Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:19   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 08/13] test: split emacs functionality to its own file Felipe Contreras
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

The tests fail otherwise.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T310-emacs.sh            | 1 +
 test/T350-crypto.sh           | 1 +
 test/T355-smime.sh            | 1 +
 test/T357-index-decryption.sh | 1 +
 test/T450-emacs-show.sh       | 1 +
 test/T460-emacs-tree.sh       | 1 +
 test/T730-emacs-forwarding.sh | 2 ++
 test/test-lib.sh              | 6 ++++++
 8 files changed, 14 insertions(+)

diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index 78ac19a8..e64627c6 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -5,6 +5,7 @@ test_description="emacs interface"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
 
+test_require_emacs
 add_email_corpus
 
 # syntax errors in test-lib.el cause mysterious failures
diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index 0aada4df..ae1d6a98 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -9,6 +9,7 @@ test_description='PGP/MIME signature verification and decryption'
 
 ##################################################
 
+test_require_emacs
 add_gnupg_home
 
 test_begin_subtest "emacs delivery of signed message"
diff --git a/test/T355-smime.sh b/test/T355-smime.sh
index 8b2b52be..12ac2525 100755
--- a/test/T355-smime.sh
+++ b/test/T355-smime.sh
@@ -3,6 +3,7 @@
 test_description='S/MIME signature verification and decryption'
 . $(dirname "$0")/test-lib.sh || exit 1
 
+test_require_emacs
 test_require_external_prereq openssl
 test_require_external_prereq gpgsm
 
diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh
index 1ed5f28c..b81bdfe1 100755
--- a/test/T357-index-decryption.sh
+++ b/test/T357-index-decryption.sh
@@ -7,6 +7,7 @@ test_description='indexing decrypted mail'
 
 ##################################################
 
+test_require_emacs
 add_gnupg_home
 
 # create a test encrypted message
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index cca56ca3..bd76d378 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -5,6 +5,7 @@ test_description="emacs notmuch-show view"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
 
+test_require_emacs
 add_email_corpus
 
 test_begin_subtest "Hiding Original Message region at beginning of a message"
diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
index cb2c90b8..195485c1 100755
--- a/test/T460-emacs-tree.sh
+++ b/test/T460-emacs-tree.sh
@@ -5,6 +5,7 @@ test_description="emacs tree view interface"
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
 
+test_require_emacs
 add_email_corpus
 
 test_begin_subtest "Basic notmuch-tree view in emacs"
diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
index 45e61568..5d6ac9f0 100755
--- a/test/T730-emacs-forwarding.sh
+++ b/test/T730-emacs-forwarding.sh
@@ -3,6 +3,8 @@
 test_description="emacs forwarding"
 . $(dirname "$0")/test-lib.sh || exit 1
 
+test_require_emacs
+
 test_begin_subtest "Forward setting the correct references header"
 # Check that, when forwarding a message, the new message has
 # a References-header pointing to the original (forwarded) message.
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 72ac2e89..88e2a82f 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -114,6 +114,12 @@ unset ALTERNATE_EDITOR
 unset EMAIL
 unset NAME
 
+test_require_emacs () {
+    test_require_external_prereq emacs
+    test_require_external_prereq ${TEST_EMACSCLIENT}
+    test_require_external_prereq dtach
+}
+
 add_gnupg_home ()
 {
     [ -e "${GNUPGHOME}/gpg.conf" ] && return
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 08/13] test: split emacs functionality to its own file
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (6 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 07/13] test: add external prereqs to many emacs tests Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:28   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 09/13] test: emacs: simplify missing dependencies check Felipe Contreras
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

This way it's easier to identify the tests that do require emacs stuff.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T160-json.sh                      |   1 +
 test/T170-sexp.sh                      |   1 +
 test/T310-emacs.sh                     |   1 +
 test/T320-emacs-large-search-buffer.sh |   3 +
 test/T330-emacs-subject-to-filename.sh |   3 +
 test/T350-crypto.sh                    |   1 +
 test/T355-smime.sh                     |   1 +
 test/T357-index-decryption.sh          |   1 +
 test/T358-emacs-protected-headers.sh   |   2 +
 test/T420-emacs-test-functions.sh      |   1 +
 test/T430-emacs-address-cleaning.sh    |   3 +
 test/T440-emacs-hello.sh               |   2 +
 test/T450-emacs-show.sh                |   1 +
 test/T455-emacs-charsets.sh            |   3 +
 test/T460-emacs-tree.sh                |   1 +
 test/T510-thread-replies.sh            |   1 +
 test/T630-emacs-draft.sh               |   2 +
 test/T720-emacs-attachment-warnings.sh |   3 +
 test/T730-emacs-forwarding.sh          |   1 +
 test/test-lib-emacs.sh                 | 213 +++++++++++++++++++++++++
 test/test-lib.sh                       | 199 -----------------------
 21 files changed, 245 insertions(+), 199 deletions(-)
 create mode 100644 test/test-lib-emacs.sh

diff --git a/test/T160-json.sh b/test/T160-json.sh
index e8b75605..638afb4d 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 test_description="--format=json output"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_begin_subtest "Show message: json"
 add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""
diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
index 24be8351..af8c4b44 100755
--- a/test/T170-sexp.sh
+++ b/test/T170-sexp.sh
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 test_description="--format=sexp output"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_begin_subtest "Show message: sexp"
 add_message "[subject]=\"sexp-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"sexp-show-message\""
diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index e64627c6..c08df5fc 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -2,6 +2,7 @@
 
 test_description="emacs interface"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
 
diff --git a/test/T320-emacs-large-search-buffer.sh b/test/T320-emacs-large-search-buffer.sh
index f61e8a97..d2638c8b 100755
--- a/test/T320-emacs-large-search-buffer.sh
+++ b/test/T320-emacs-large-search-buffer.sh
@@ -1,11 +1,14 @@
 #!/usr/bin/env bash
 test_description="Emacs with large search results buffer"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 x=xxxxxxxxxx # 10
 x=$x$x$x$x$x$x$x$x$x$x # 100
 x=$x$x$x$x$x$x$x$x$x # 900
 
+test_require_emacs
+
 # We generate a long subject here (over 900 bytes) so that the emacs
 # search results get large quickly. With 30 such messages we should
 # cross several 4kB page boundaries and see the bug.
diff --git a/test/T330-emacs-subject-to-filename.sh b/test/T330-emacs-subject-to-filename.sh
index eaf7c980..6e09a048 100755
--- a/test/T330-emacs-subject-to-filename.sh
+++ b/test/T330-emacs-subject-to-filename.sh
@@ -2,6 +2,9 @@
 
 test_description="emacs: mail subject to filename"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
+
+test_require_emacs
 
 # emacs server can't be started in a child process with $(test_emacs ...)
 test_emacs '(ignore)' > /dev/null
diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
index ae1d6a98..4508c984 100755
--- a/test/T350-crypto.sh
+++ b/test/T350-crypto.sh
@@ -6,6 +6,7 @@
 
 test_description='PGP/MIME signature verification and decryption'
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 ##################################################
 
diff --git a/test/T355-smime.sh b/test/T355-smime.sh
index 12ac2525..69bdcfac 100755
--- a/test/T355-smime.sh
+++ b/test/T355-smime.sh
@@ -2,6 +2,7 @@
 
 test_description='S/MIME signature verification and decryption'
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_require_emacs
 test_require_external_prereq openssl
diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh
index b81bdfe1..f5644d7e 100755
--- a/test/T357-index-decryption.sh
+++ b/test/T357-index-decryption.sh
@@ -4,6 +4,7 @@
 
 test_description='indexing decrypted mail'
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 ##################################################
 
diff --git a/test/T358-emacs-protected-headers.sh b/test/T358-emacs-protected-headers.sh
index bca78531..b25d7ea7 100755
--- a/test/T358-emacs-protected-headers.sh
+++ b/test/T358-emacs-protected-headers.sh
@@ -2,8 +2,10 @@
 
 test_description="protected headers in emacs interface"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 # testing protected headers with emacs
+test_require_emacs
 add_gnupg_home
 add_email_corpus protected-headers
 
diff --git a/test/T420-emacs-test-functions.sh b/test/T420-emacs-test-functions.sh
index bfc10be3..22e4f01e 100755
--- a/test/T420-emacs-test-functions.sh
+++ b/test/T420-emacs-test-functions.sh
@@ -2,6 +2,7 @@
 
 test_description="emacs test function sanity"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_begin_subtest "emacs test function sanity"
 test_emacs_expect_t 't'
diff --git a/test/T430-emacs-address-cleaning.sh b/test/T430-emacs-address-cleaning.sh
index 02d3b411..640bff3f 100755
--- a/test/T430-emacs-address-cleaning.sh
+++ b/test/T430-emacs-address-cleaning.sh
@@ -2,6 +2,9 @@
 
 test_description="emacs address cleaning"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
+
+test_require_emacs
 
 test_begin_subtest "notmuch-test-address-clean part 1"
 test_emacs_expect_t '(notmuch-test-address-cleaning-1)'
diff --git a/test/T440-emacs-hello.sh b/test/T440-emacs-hello.sh
index d23c1fca..642aa3cc 100755
--- a/test/T440-emacs-hello.sh
+++ b/test/T440-emacs-hello.sh
@@ -2,9 +2,11 @@
 
 test_description="emacs notmuch-hello view"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
 
+test_require_emacs
 add_email_corpus
 
 test_begin_subtest "User-defined section with inbox tag"
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index bd76d378..e58124d4 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -2,6 +2,7 @@
 
 test_description="emacs notmuch-show view"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
 
diff --git a/test/T455-emacs-charsets.sh b/test/T455-emacs-charsets.sh
index cb1297ca..a0f4dc24 100755
--- a/test/T455-emacs-charsets.sh
+++ b/test/T455-emacs-charsets.sh
@@ -2,11 +2,14 @@
 
 test_description="emacs notmuch-show charset handling"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 
 UTF8_YEN=$'\xef\xbf\xa5'
 BIG5_YEN=$'\xa2\x44'
 
+test_require_emacs
+
 # Add four messages with unusual encoding requirements:
 #
 # 1) text/plain in quoted-printable big5
diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
index 195485c1..dfc69049 100755
--- a/test/T460-emacs-tree.sh
+++ b/test/T460-emacs-tree.sh
@@ -2,6 +2,7 @@
 
 test_description="emacs tree view interface"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
 
diff --git a/test/T510-thread-replies.sh b/test/T510-thread-replies.sh
index 2859d29f..cdb4be44 100755
--- a/test/T510-thread-replies.sh
+++ b/test/T510-thread-replies.sh
@@ -10,6 +10,7 @@ test_description='test of proper handling of in-reply-to and references headers'
 # non-RFC-compliant headers'
 
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_begin_subtest "Use References when In-Reply-To is broken"
 add_message '[id]="foo@one.com"' \
diff --git a/test/T630-emacs-draft.sh b/test/T630-emacs-draft.sh
index d7903ce7..8553f022 100755
--- a/test/T630-emacs-draft.sh
+++ b/test/T630-emacs-draft.sh
@@ -1,7 +1,9 @@
 #!/usr/bin/env bash
 test_description="Emacs Draft Handling"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
+test_require_emacs
 add_email_corpus
 
 notmuch config set search.exclude_tags deleted
diff --git a/test/T720-emacs-attachment-warnings.sh b/test/T720-emacs-attachment-warnings.sh
index c8d2bcc2..4e8c5d26 100755
--- a/test/T720-emacs-attachment-warnings.sh
+++ b/test/T720-emacs-attachment-warnings.sh
@@ -2,6 +2,9 @@
 
 test_description="emacs attachment warnings"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
+
+test_require_emacs
 
 test_begin_subtest "notmuch-test-attachment-warning part 1"
 test_emacs_expect_t '(notmuch-test-attachment-warning-1)'
diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
index 5d6ac9f0..378067ed 100755
--- a/test/T730-emacs-forwarding.sh
+++ b/test/T730-emacs-forwarding.sh
@@ -2,6 +2,7 @@
 
 test_description="emacs forwarding"
 . $(dirname "$0")/test-lib.sh || exit 1
+. $(dirname "$0")/test-lib-emacs.sh || exit 1
 
 test_require_emacs
 
diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
new file mode 100644
index 00000000..ecad501a
--- /dev/null
+++ b/test/test-lib-emacs.sh
@@ -0,0 +1,213 @@
+#
+# Copyright (c) 2010-2020 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
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see https://www.gnu.org/licenses/ .
+
+test_require_emacs () {
+    test_require_external_prereq emacs
+    test_require_external_prereq ${TEST_EMACSCLIENT}
+    test_require_external_prereq dtach
+}
+
+# Deliver a message with emacs and add it to the database
+#
+# Uses emacs to generate and deliver a message to the mail store.
+# Accepts arbitrary extra emacs/elisp functions to modify the message
+# before sending, which is useful to doing things like attaching files
+# to the message and encrypting/signing.
+emacs_deliver_message ()
+{
+    local subject body smtp_dummy_pid smtp_dummy_port
+    subject="$1"
+    body="$2"
+    shift 2
+    # before we can send a message, we have to prepare the FCC maildir
+    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
+    # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port
+    smtp_dummy_pid= smtp_dummy_port=
+    eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
+    test -n "$smtp_dummy_pid" || return 1
+    test -n "$smtp_dummy_port" || return 1
+
+    test_emacs \
+	"(let ((message-send-mail-function 'message-smtpmail-send-it)
+	       (mail-host-address \"example.com\")
+	       (smtpmail-smtp-server \"localhost\")
+	       (smtpmail-smtp-service \"${smtp_dummy_port}\"))
+	   (notmuch-mua-mail)
+	   (message-goto-to)
+	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
+	   (message-goto-subject)
+	   (insert \"${subject}\")
+	   (message-goto-body)
+	   (insert \"${body}\")
+	   $*
+	   (notmuch-mua-send-and-exit))"
+
+    # In case message was sent properly, client waits for confirmation
+    # before exiting and resuming control here; therefore making sure
+    # that server exits by sending (KILL) signal to it is safe.
+    kill -9 $smtp_dummy_pid
+    notmuch new >/dev/null
+}
+
+# Pretend to deliver a message with emacs. Really save it to a file
+# and add it to the database
+#
+# Uses emacs to generate and deliver a message to the mail store.
+# Accepts arbitrary extra emacs/elisp functions to modify the message
+# before sending, which is useful to doing things like attaching files
+# to the message and encrypting/signing.
+#
+# If any GNU-style long-arguments (like --quiet or --decrypt=true) are
+# at the head of the argument list, they are sent directly to "notmuch
+# new" after message delivery
+emacs_fcc_message ()
+{
+    local nmn_args subject body
+    nmn_args=''
+    while [[ "$1" =~ ^-- ]]; do
+	nmn_args="$nmn_args $1"
+	shift
+    done
+    subject="$1"
+    body="$2"
+    shift 2
+    # before we can send a message, we have to prepare the FCC maildir
+    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
+
+    test_emacs \
+	"(let ((message-send-mail-function (lambda () t))
+	       (mail-host-address \"example.com\"))
+	   (notmuch-mua-mail)
+	   (message-goto-to)
+	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
+	   (message-goto-subject)
+	   (insert \"${subject}\")
+	   (message-goto-body)
+	   (insert \"${body}\")
+	   $*
+	   (let ((mml-secure-smime-sign-with-sender t)
+		 (mml-secure-openpgp-sign-with-sender t))
+	     (notmuch-mua-send-and-exit)))" || return 1
+    notmuch new $nmn_args >/dev/null
+}
+
+test_emacs_expect_t () {
+	local result
+	test "$#" = 1 ||
+	error "bug in the test script: not 1 parameter to test_emacs_expect_t"
+	if [ -z "$inside_subtest" ]; then
+		error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
+	fi
+
+	# Run the test.
+	if ! test_skip "$test_subtest_name"
+	then
+		test_emacs "(notmuch-test-run $1)" >/dev/null
+
+		# Restore state after the test.
+		exec 1>&6 2>&7		# Restore stdout and stderr
+		inside_subtest=
+
+		# test_emacs may update missing external prerequisites
+		test_check_missing_external_prereqs_ "$test_subtest_name" && return
+
+		# Report success/failure.
+		result=$(cat OUTPUT)
+		if [ "$result" = t ]
+		then
+			test_ok_
+		else
+			test_failure_ "${result}"
+		fi
+	else
+		# Restore state after the (non) test.
+		exec 1>&6 2>&7		# Restore stdout and stderr
+		inside_subtest=
+	fi
+}
+
+emacs_generate_script () {
+	# Construct a little test script here for the benefit of the user,
+	# (who can easily run "run_emacs" to get the same emacs environment
+	# for investigating any failures).
+	cat <<EOF >"$TMP_DIRECTORY/run_emacs"
+#!/bin/sh
+export PATH=$PATH
+export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
+
+# Here's what we are using here:
+#
+# --quick		Use minimal customization. This implies --no-init-file,
+#			--no-site-file and (emacs 24) --no-site-lisp
+#
+# --directory		Ensure that the local elisp sources are found
+#
+# --load		Force loading of notmuch.el and test-lib.el
+
+exec ${TEST_EMACS} --quick \
+	--directory "$NOTMUCH_BUILDDIR/emacs" --load notmuch.el \
+	--directory "$NOTMUCH_SRCDIR/test" --load test-lib.el \
+	"\$@"
+EOF
+	chmod a+x "$TMP_DIRECTORY/run_emacs"
+}
+
+test_emacs () {
+	# test dependencies beforehand to avoid the waiting loop below
+	missing_dependencies=
+	test_require_external_prereq dtach || missing_dependencies=1
+	test_require_external_prereq emacs || missing_dependencies=1
+	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
+	test -z "$missing_dependencies" || 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
+
+	# 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_generate_script
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 88e2a82f..7fdc0007 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -114,12 +114,6 @@ unset ALTERNATE_EDITOR
 unset EMAIL
 unset NAME
 
-test_require_emacs () {
-    test_require_external_prereq emacs
-    test_require_external_prereq ${TEST_EMACSCLIENT}
-    test_require_external_prereq dtach
-}
-
 add_gnupg_home ()
 {
     [ -e "${GNUPGHOME}/gpg.conf" ] && return
@@ -349,90 +343,6 @@ export GNUPGHOME="${TEST_TMPDIR}/gnupg"
 trap 'trap_exit' EXIT
 trap 'trap_signal' HUP INT TERM
 
-# Deliver a message with emacs and add it to the database
-#
-# Uses emacs to generate and deliver a message to the mail store.
-# Accepts arbitrary extra emacs/elisp functions to modify the message
-# before sending, which is useful to doing things like attaching files
-# to the message and encrypting/signing.
-emacs_deliver_message ()
-{
-    local subject body smtp_dummy_pid smtp_dummy_port
-    subject="$1"
-    body="$2"
-    shift 2
-    # before we can send a message, we have to prepare the FCC maildir
-    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
-    # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port
-    smtp_dummy_pid= smtp_dummy_port=
-    eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
-    test -n "$smtp_dummy_pid" || return 1
-    test -n "$smtp_dummy_port" || return 1
-
-    test_emacs \
-	"(let ((message-send-mail-function 'message-smtpmail-send-it)
-	       (mail-host-address \"example.com\")
-	       (smtpmail-smtp-server \"localhost\")
-	       (smtpmail-smtp-service \"${smtp_dummy_port}\"))
-	   (notmuch-mua-mail)
-	   (message-goto-to)
-	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
-	   (message-goto-subject)
-	   (insert \"${subject}\")
-	   (message-goto-body)
-	   (insert \"${body}\")
-	   $*
-	   (notmuch-mua-send-and-exit))"
-
-    # In case message was sent properly, client waits for confirmation
-    # before exiting and resuming control here; therefore making sure
-    # that server exits by sending (KILL) signal to it is safe.
-    kill -9 $smtp_dummy_pid
-    notmuch new >/dev/null
-}
-
-# Pretend to deliver a message with emacs. Really save it to a file
-# and add it to the database
-#
-# Uses emacs to generate and deliver a message to the mail store.
-# Accepts arbitrary extra emacs/elisp functions to modify the message
-# before sending, which is useful to doing things like attaching files
-# to the message and encrypting/signing.
-#
-# If any GNU-style long-arguments (like --quiet or --decrypt=true) are
-# at the head of the argument list, they are sent directly to "notmuch
-# new" after message delivery
-emacs_fcc_message ()
-{
-    local nmn_args subject body
-    nmn_args=''
-    while [[ "$1" =~ ^-- ]]; do
-	nmn_args="$nmn_args $1"
-	shift
-    done
-    subject="$1"
-    body="$2"
-    shift 2
-    # before we can send a message, we have to prepare the FCC maildir
-    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
-
-    test_emacs \
-	"(let ((message-send-mail-function (lambda () t))
-	       (mail-host-address \"example.com\"))
-	   (notmuch-mua-mail)
-	   (message-goto-to)
-	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
-	   (message-goto-subject)
-	   (insert \"${subject}\")
-	   (message-goto-body)
-	   (insert \"${body}\")
-	   $*
-	   (let ((mml-secure-smime-sign-with-sender t)
-		 (mml-secure-openpgp-sign-with-sender t))
-	     (notmuch-mua-send-and-exit)))" || return 1
-    notmuch new $nmn_args >/dev/null
-}
-
 # Add an existing, fixed corpus of email to the database.
 #
 # $1 is the corpus dir under corpora to add, using "default" if unset.
@@ -581,41 +491,6 @@ test_json_nodes () {
 	fi
 }
 
-test_emacs_expect_t () {
-	local result
-	test "$#" = 1 ||
-	error "bug in the test script: not 1 parameter to test_emacs_expect_t"
-	if [ -z "$inside_subtest" ]; then
-		error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
-	fi
-
-	# Run the test.
-	if ! test_skip "$test_subtest_name"
-	then
-		test_emacs "(notmuch-test-run $1)" >/dev/null
-
-		# Restore state after the test.
-		exec 1>&6 2>&7		# Restore stdout and stderr
-		inside_subtest=
-
-		# test_emacs may update missing external prerequisites
-		test_check_missing_external_prereqs_ "$test_subtest_name" && return
-
-		# Report success/failure.
-		result=$(cat OUTPUT)
-		if [ "$result" = t ]
-		then
-			test_ok_
-		else
-			test_failure_ "${result}"
-		fi
-	else
-		# Restore state after the (non) test.
-		exec 1>&6 2>&7		# Restore stdout and stderr
-		inside_subtest=
-	fi
-}
-
 NOTMUCH_NEW ()
 {
     notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
@@ -1046,77 +921,6 @@ test_done () {
 	fi
 }
 
-emacs_generate_script () {
-	# Construct a little test script here for the benefit of the user,
-	# (who can easily run "run_emacs" to get the same emacs environment
-	# for investigating any failures).
-	cat <<EOF >"$TMP_DIRECTORY/run_emacs"
-#!/bin/sh
-export PATH=$PATH
-export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
-
-# Here's what we are using here:
-#
-# --quick		Use minimal customization. This implies --no-init-file,
-#			--no-site-file and (emacs 24) --no-site-lisp
-#
-# --directory		Ensure that the local elisp sources are found
-#
-# --load		Force loading of notmuch.el and test-lib.el
-
-exec ${TEST_EMACS} --quick \
-	--directory "$NOTMUCH_BUILDDIR/emacs" --load notmuch.el \
-	--directory "$NOTMUCH_SRCDIR/test" --load test-lib.el \
-	"\$@"
-EOF
-	chmod a+x "$TMP_DIRECTORY/run_emacs"
-}
-
-test_emacs () {
-	# test dependencies beforehand to avoid the waiting loop below
-	missing_dependencies=
-	test_require_external_prereq dtach || missing_dependencies=1
-	test_require_external_prereq emacs || missing_dependencies=1
-	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
-	test -z "$missing_dependencies" || 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
-
-	# 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 $*)"
-}
-
 test_python() {
     # Note: if there is need to print debug information from python program,
     # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
@@ -1210,9 +1014,6 @@ TEST_DIRECTORY=$NOTMUCH_BUILDDIR/test
 
 . "$NOTMUCH_SRCDIR/test/test-lib-common.sh" || exit 1
 
-emacs_generate_script
-
-
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TMP_DIRECTORY" || error "Cannot set up test environment"
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 09/13] test: emacs: simplify missing dependencies check
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (7 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 08/13] test: split emacs functionality to its own file Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:20   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 10/13] test: emacs: check for configured emacs Felipe Contreras
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib-emacs.sh | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
index ecad501a..83f5b10b 100644
--- a/test/test-lib-emacs.sh
+++ b/test/test-lib-emacs.sh
@@ -15,9 +15,11 @@
 # along with this program.  If not, see https://www.gnu.org/licenses/ .
 
 test_require_emacs () {
-    test_require_external_prereq emacs
-    test_require_external_prereq ${TEST_EMACSCLIENT}
-    test_require_external_prereq dtach
+    local ret=0
+    test_require_external_prereq emacs || ret=1
+    test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
+    test_require_external_prereq dtach || ret=1
+    return $ret
 }
 
 # Deliver a message with emacs and add it to the database
@@ -167,11 +169,7 @@ EOF
 
 test_emacs () {
 	# test dependencies beforehand to avoid the waiting loop below
-	missing_dependencies=
-	test_require_external_prereq dtach || missing_dependencies=1
-	test_require_external_prereq emacs || missing_dependencies=1
-	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
-	test -z "$missing_dependencies" || return
+	test_require_emacs || return
 
 	if [ -z "$EMACS_SERVER" ]; then
 		emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 10/13] test: emacs: check for configured emacs
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (8 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 09/13] test: emacs: simplify missing dependencies check Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:20   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

Commit d59d9c81 (test: Make the emacsclient binary user-configurable,
2012-11-27) modified the prereq check for the configured emacsclient,
but we probably want to do the same for emacs itself.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib-emacs.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
index 83f5b10b..3075fa59 100644
--- a/test/test-lib-emacs.sh
+++ b/test/test-lib-emacs.sh
@@ -16,7 +16,7 @@
 
 test_require_emacs () {
     local ret=0
-    test_require_external_prereq emacs || ret=1
+    test_require_external_prereq ${TEST_EMACS} || ret=1
     test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
     test_require_external_prereq dtach || ret=1
     return $ret
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (9 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 10/13] test: emacs: check for configured emacs Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:21   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 12/13] test: trivial style cleanups Felipe Contreras
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

In test-lib-emacs.sh line 20:
    test_require_external_prereq ${TEST_EMACS} || ret=1
                                 ^-----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    test_require_external_prereq "${TEST_EMACS}" || ret=1

In test-lib-emacs.sh line 21:
    test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
                                 ^-----------------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    test_require_external_prereq "${TEST_EMACSCLIENT}" || ret=1

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/test-lib-emacs.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
index 3075fa59..bf875a28 100644
--- a/test/test-lib-emacs.sh
+++ b/test/test-lib-emacs.sh
@@ -16,8 +16,8 @@
 
 test_require_emacs () {
     local ret=0
-    test_require_external_prereq ${TEST_EMACS} || ret=1
-    test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
+    test_require_external_prereq "$TEST_EMACS" || ret=1
+    test_require_external_prereq "$TEST_EMACSCLIENT" || ret=1
     test_require_external_prereq dtach || ret=1
     return $ret
 }
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 12/13] test: trivial style cleanups
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (10 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:28   ` Tomi Ollila
  2021-05-01 11:54 ` [PATCH 13/13] test: more style fixes Felipe Contreras
  2021-05-02  0:36 ` [PATCH 00/13] test: several fixes and improvements David Bremner
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T000-basic.sh           |  2 +-
 test/T070-insert.sh          |  2 +-
 test/T590-thread-breakage.sh | 10 +++++-----
 test/export-dirs.sh          |  2 +-
 test/test-lib.sh             |  8 ++++----
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/test/T000-basic.sh b/test/T000-basic.sh
index 7fbdcfa3..a2f4d93f 100755
--- a/test/T000-basic.sh
+++ b/test/T000-basic.sh
@@ -33,7 +33,7 @@ test_begin_subtest 'failure to clean up causes the test to fail'
 test_expect_code 2 'test_when_finished "(exit 2)"'
 
 EXPECTED=$NOTMUCH_SRCDIR/test/test.expected-output
-suppress_diff_date() {
+suppress_diff_date () {
     sed -e 's/\(.*\-\-\- test-verbose\.4\.\expected\).*/\1/' \
 	-e 's/\(.*\+\+\+ test-verbose\.4\.\output\).*/\1/'
 }
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index b37a9b67..208deb1c 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -15,7 +15,7 @@ notmuch new > /dev/null
 # They happen to be in the mail directory already but that is okay
 # since we do not call notmuch new hereafter.
 
-gen_insert_msg() {
+gen_insert_msg () {
     generate_message \
 	"[subject]=\"insert-subject\"" \
 	"[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
diff --git a/test/T590-thread-breakage.sh b/test/T590-thread-breakage.sh
index aeb82cf4..92a70e3e 100755
--- a/test/T590-thread-breakage.sh
+++ b/test/T590-thread-breakage.sh
@@ -21,7 +21,7 @@ test_description='thread breakage during reindexing'
 
 . $(dirname "$0")/test-lib.sh || exit 1
 
-message_a() {
+message_a () {
     mkdir -p ${MAIL_DIR}/cur
     cat > ${MAIL_DIR}/cur/a <<EOF
 Subject: First message
@@ -35,7 +35,7 @@ Apple
 EOF
 }
 
-message_b() {
+message_b () {
     mkdir -p ${MAIL_DIR}/cur
     cat > ${MAIL_DIR}/cur/b <<EOF
 Subject: Second message
@@ -52,19 +52,19 @@ EOF
 }
 
 
-test_content_count() {
+test_content_count () {
     test_begin_subtest "${3:-looking for $2 instance of '$1'}"
     count=$(notmuch count --output=threads "$1")
     test_expect_equal "$count" "$2"
 }
 
-test_thread_count() {
+test_thread_count () {
     test_begin_subtest "${2:-Expecting $1 thread(s)}"
     count=$(notmuch count --output=threads)
     test_expect_equal "$count" "$1"
 }
 
-test_ghost_count() {
+test_ghost_count () {
     test_begin_subtest "${2:-Expecting $1 ghosts(s)}"
     ghosts=$($NOTMUCH_BUILDDIR/test/ghost-report ${MAIL_DIR}/.notmuch/xapian)
     test_expect_equal "$ghosts" "$1"
diff --git a/test/export-dirs.sh b/test/export-dirs.sh
index 0578b1e5..844ee682 100644
--- a/test/export-dirs.sh
+++ b/test/export-dirs.sh
@@ -9,7 +9,7 @@ if [[ -z "${NOTMUCH_SRCDIR}" ]]; then
 	export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
 fi
 
-find_builddir()
+find_builddir ()
 {
 	local dir="$1"
 
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 7fdc0007..1b502456 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -585,7 +585,7 @@ notmuch_built_with_sanitize ()
     sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
 }
 
-notmuch_passwd_sanitize()
+notmuch_passwd_sanitize ()
 {
     ${NOTMUCH_PYTHON} -c'
 import os, sys, pwd, socket
@@ -867,7 +867,7 @@ test_must_fail () {
 # - cmp's output is not nearly as easy to read as diff -u
 # - not all diff versions understand "-u"
 
-test_cmp() {
+test_cmp () {
 	$GIT_TEST_CMP "$@"
 }
 
@@ -921,14 +921,14 @@ test_done () {
 	fi
 }
 
-test_python() {
+test_python () {
     # Note: if there is need to print debug information from python program,
     # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
     PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
 	$NOTMUCH_PYTHON -B - > OUTPUT
 }
 
-test_ruby() {
+test_ruby () {
     MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
 }
 
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 13/13] test: more style fixes
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (11 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 12/13] test: trivial style cleanups Felipe Contreras
@ 2021-05-01 11:54 ` Felipe Contreras
  2021-05-01 20:29   ` Tomi Ollila
  2021-05-02  0:36 ` [PATCH 00/13] test: several fixes and improvements David Bremner
  13 siblings, 1 reply; 29+ messages in thread
From: Felipe Contreras @ 2021-05-01 11:54 UTC (permalink / raw)
  To: notmuch; +Cc: Daniel Kahn Gillmor

In order to fit the git coding style.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 test/T140-excludes.sh          |  3 +-
 test/T190-multipart.sh         |  3 +-
 test/T490-parse-time-string.sh |  6 +--
 test/export-dirs.sh            |  3 +-
 test/test-lib-common.sh        |  6 +--
 test/test-lib-emacs.sh         |  6 +--
 test/test-lib.sh               | 72 ++++++++++++----------------------
 7 files changed, 33 insertions(+), 66 deletions(-)

diff --git a/test/T140-excludes.sh b/test/T140-excludes.sh
index acab5381..352b3eb8 100755
--- a/test/T140-excludes.sh
+++ b/test/T140-excludes.sh
@@ -5,8 +5,7 @@ test_description='"notmuch search, count and show" with excludes in several vari
 # Generates a thread consisting of a top level message and 'length'
 # replies. The subject of the top message 'subject: top message"
 # and the subject of the nth reply in the thread is "subject: reply n"
-generate_thread ()
-{
+generate_thread () {
     local subject="$1"
     local length="$2"
     generate_message '[subject]="'"${subject}: top message"'"' '[body]="'"body of top message"'"'
diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index 6f715ff9..3545a599 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -725,8 +725,7 @@ EOF
 
 notmuch new > /dev/null
 
-cat_expected_head ()
-{
+cat_expected_head () {
         cat <<EOF
 [[[{"id": "htmlmessage", "match":true, "excluded": false, "date_relative":"2000-01-01",
    "crypto": {},
diff --git a/test/T490-parse-time-string.sh b/test/T490-parse-time-string.sh
index d1c70cfa..f89755ed 100755
--- a/test/T490-parse-time-string.sh
+++ b/test/T490-parse-time-string.sh
@@ -4,13 +4,11 @@ test_description="date/time parser module"
 
 # Sanity/smoke tests for the date/time parser independent of notmuch
 
-_date ()
-{
+_date () {
     date -d "$*" +%s
 }
 
-_parse_time ()
-{
+_parse_time () {
     ${TEST_DIRECTORY}/parse-time --format=%s "$*"
 }
 
diff --git a/test/export-dirs.sh b/test/export-dirs.sh
index 844ee682..0a048e1f 100644
--- a/test/export-dirs.sh
+++ b/test/export-dirs.sh
@@ -9,8 +9,7 @@ if [[ -z "${NOTMUCH_SRCDIR}" ]]; then
 	export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
 fi
 
-find_builddir ()
-{
+find_builddir () {
 	local dir="$1"
 
 	while [[ -n "$dir" ]] && [[ "$dir" != "/" ]]; do
diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
index 2f7950ac..ebbf4cdf 100644
--- a/test/test-lib-common.sh
+++ b/test/test-lib-common.sh
@@ -105,8 +105,7 @@ fi
 gen_msg_cnt=0
 gen_msg_filename=""
 gen_msg_id=""
-generate_message ()
-{
+generate_message () {
     # This is our (bash-specific) magic for doing named parameters
     local -A template="($@)"
     local additional_headers
@@ -225,8 +224,7 @@ EOF
 #
 # All of the arguments and return values supported by generate_message
 # are also supported here, so see that function for details.
-add_message ()
-{
+add_message () {
     generate_message "$@" &&
     notmuch new > /dev/null
 }
diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
index bf875a28..dde32177 100644
--- a/test/test-lib-emacs.sh
+++ b/test/test-lib-emacs.sh
@@ -28,8 +28,7 @@ test_require_emacs () {
 # Accepts arbitrary extra emacs/elisp functions to modify the message
 # before sending, which is useful to doing things like attaching files
 # to the message and encrypting/signing.
-emacs_deliver_message ()
-{
+emacs_deliver_message () {
     local subject body smtp_dummy_pid smtp_dummy_port
     subject="$1"
     body="$2"
@@ -75,8 +74,7 @@ emacs_deliver_message ()
 # If any GNU-style long-arguments (like --quiet or --decrypt=true) are
 # at the head of the argument list, they are sent directly to "notmuch
 # new" after message delivery
-emacs_fcc_message ()
-{
+emacs_fcc_message () {
     local nmn_args subject body
     nmn_args=''
     while [[ "$1" =~ ^-- ]]; do
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 1b502456..1d0178f0 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -114,8 +114,7 @@ unset ALTERNATE_EDITOR
 unset EMAIL
 unset NAME
 
-add_gnupg_home ()
-{
+add_gnupg_home () {
     [ -e "${GNUPGHOME}/gpg.conf" ] && return
     _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
     at_exit_function _gnupg_exit
@@ -135,8 +134,7 @@ add_gnupg_home ()
     printf '%s:6:\n' "$FINGERPRINT" | gpg --quiet --batch --no-tty --import-ownertrust
 }
 
-add_gpgsm_home ()
-{
+add_gpgsm_home () {
     local fpr
     [ -e "$GNUPGHOME/gpgsm.conf" ] && return
     _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
@@ -268,8 +266,7 @@ then
 fi
 
 test_description_printed=
-print_test_description ()
-{
+print_test_description () {
 	test -z "$test_description_printed" || return 0
 	echo
 	echo $this_test: "Testing ${test_description}"
@@ -351,8 +348,7 @@ trap 'trap_signal' HUP INT TERM
 # history of the notmuch mailing list, which allows for reliably
 # testing commands that need to operate on a not-totally-trivial
 # number of messages.
-add_email_corpus ()
-{
+add_email_corpus () {
     local corpus
     corpus=${1:-default}
 
@@ -361,8 +357,7 @@ add_email_corpus ()
     notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
 }
 
-test_begin_subtest ()
-{
+test_begin_subtest () {
     if [ -n "$inside_subtest" ]; then
 	exec 1>&6 2>&7		# Restore stdout and stderr
 	error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
@@ -382,8 +377,7 @@ test_begin_subtest ()
 # not accept a test name. Instead, the caller should call
 # test_begin_subtest before calling this function in order to set the
 # name.
-test_expect_equal ()
-{
+test_expect_equal () {
 	local output expected testname
 	exec 1>&6 2>&7		# Restore stdout and stderr
 	if [ -z "$inside_subtest" ]; then
@@ -409,8 +403,7 @@ test_expect_equal ()
 }
 
 # Like test_expect_equal, but takes two filenames.
-test_expect_equal_file ()
-{
+test_expect_equal_file () {
 	local file1 file2 testname basename1 basename2
 	exec 1>&6 2>&7		# Restore stdout and stderr
 	if [ -z "$inside_subtest" ]; then
@@ -491,19 +484,16 @@ test_json_nodes () {
 	fi
 }
 
-NOTMUCH_NEW ()
-{
+NOTMUCH_NEW () {
     notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
 }
 
-NOTMUCH_DUMP_TAGS ()
-{
+NOTMUCH_DUMP_TAGS () {
     # this relies on the default format being batch-tag, otherwise some tests will break
     notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
 }
 
-notmuch_drop_mail_headers ()
-{
+notmuch_drop_mail_headers () {
     $NOTMUCH_PYTHON -c '
 import email, sys
 msg = email.message_from_file(sys.stdin)
@@ -512,41 +502,34 @@ print(msg.as_string(False))
 ' "$@"
 }
 
-notmuch_exception_sanitize ()
-{
+notmuch_exception_sanitize () {
     perl -pe 's/(A Xapian exception occurred at .*[.]cc?):([0-9]*)/\1:XXX/'
 }
 
-notmuch_search_sanitize ()
-{
+notmuch_search_sanitize () {
     perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
 }
 
-notmuch_search_files_sanitize ()
-{
+notmuch_search_files_sanitize () {
     notmuch_dir_sanitize
 }
 
-notmuch_dir_sanitize ()
-{
+notmuch_dir_sanitize () {
     sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
 }
 
 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
-notmuch_show_sanitize ()
-{
+notmuch_show_sanitize () {
     sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
 }
-notmuch_show_sanitize_all ()
-{
+notmuch_show_sanitize_all () {
     sed \
 	-e 's| filename:.*| filename:XXXXX|' \
 	-e 's| id:[^ ]* | id:XXXXX |' | \
 	notmuch_date_sanitize
 }
 
-notmuch_json_show_sanitize ()
-{
+notmuch_json_show_sanitize () {
     sed \
 	-e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
 	-e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
@@ -556,8 +539,7 @@ notmuch_json_show_sanitize ()
 	-e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
 }
 
-notmuch_emacs_error_sanitize ()
-{
+notmuch_emacs_error_sanitize () {
     local command
     command=$1
     shift
@@ -569,24 +551,20 @@ notmuch_emacs_error_sanitize ()
 	-e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
 }
 
-notmuch_date_sanitize ()
-{
+notmuch_date_sanitize () {
     sed \
 	-e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
 }
 
-notmuch_uuid_sanitize ()
-{
+notmuch_uuid_sanitize () {
     sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
 }
 
-notmuch_built_with_sanitize ()
-{
+notmuch_built_with_sanitize () {
     sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
 }
 
-notmuch_passwd_sanitize ()
-{
+notmuch_passwd_sanitize () {
     ${NOTMUCH_PYTHON} -c'
 import os, sys, pwd, socket
 
@@ -606,13 +584,11 @@ for l in sys.stdin:
 '
 }
 
-notmuch_config_sanitize ()
-{
+notmuch_config_sanitize () {
     notmuch_dir_sanitize | notmuch_built_with_sanitize
 }
 
-notmuch_show_part ()
-{
+notmuch_show_part () {
     awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: '"$1"'/{ f=1 }'
 }
 
-- 
2.31.0

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH 01/13] test: fix passwd_sanitize()
  2021-05-01 11:54 ` [PATCH 01/13] test: fix passwd_sanitize() Felipe Contreras
@ 2021-05-01 20:01   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:01 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

On Sat, May 01 2021, Felipe Contreras wrote:

> If any of the variables is empty the output is completely messed up,
> because replace("", "FOO") puts "FOO" before every single character.
>
> I don't have my full name configured, and this is what I get:
>
>   USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME USER_FULL_NAMEsUSER_FULL_NAMEtUSER_FULL_NAMEdUSER_FULL_NAMEoUSER_FULL_NAMEuUSER_FULL_NAMEtUSER_FULL_NAME USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME
>
> Let's check for empty strings before doing any replace.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib.sh | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 4c9f2a21..e13797a7 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -711,7 +711,12 @@ name = pw.pw_gecos.partition(",")[0]
>  fqdn = socket.getfqdn()
>  
>  for l in sys.stdin:
> -    l = l.replace(user, "USERNAME").replace(fqdn, "FQDN").replace(".(none)","").replace(name, "USER_FULL_NAME")
> +    if user:
> +        l = l.replace(user, "USERNAME")
> +    if fqdn:
> +        l = l.replace(fqdn, "FQDN").replace(".(none)","")
> +    if name:
> +        l = l.replace(name, "USER_FULL_NAME")

This looks like a good change.

This made me think of something. When I quickly deviced the initial code of
this I thinkoed that str.replace() replaces only the first match -- now
that I tested (in python3 repl) it replaces *all* matches...

In my home machines I usually have both "username" and "user_full_name"
(using the terms used in the sanitizer) as 'too'...

Currently all is lost in USER_FULL_NAME replacement -- all 'too's are
replaced with USERNAME and no USER_FULL_NAME replacements happen.
If we had l.replace(user, "USERNAME", 1) then only the first match were
replaced -- and if both matches are expected to happen in same line --
the "full name" replacement later in line, then this change would help
in such a cases. If these replacements are to be done in different lines
then the USERNAME replacement would always be done and nothing helps
there (except more specific replacement code)...

And, now as this chance of having empty username come into our
understanding, instead of empty, but some short (or why not longer) strings 
that just happen to be (sub)strings of the text it gets as input we get
unwanted replacements and test failures... :/

Tomi


>      sys.stdout.write(l)
>  '
>  }
> -- 
> 2.31.0

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 02/13] test: unset NAME environment variable
  2021-05-01 11:54 ` [PATCH 02/13] test: unset NAME environment variable Felipe Contreras
@ 2021-05-01 20:01   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:01 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> Otherwise the output from the tests would be different.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib.sh | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index e13797a7..ae653363 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -112,6 +112,7 @@ unset ALTERNATE_EDITOR
>  
>  # for reproducibility
>  unset EMAIL
> +unset NAME

LGTM. trivial

Tomi

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 03/13] test: remove USER_FULL_NAME when not present
  2021-05-01 11:54 ` [PATCH 03/13] test: remove USER_FULL_NAME when not present Felipe Contreras
@ 2021-05-01 20:13   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:13 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> If a full name is not configured, the output is empty.

> This is possibly not portable, but it's a start.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/T590-libconfig.sh | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
> index 51dd29c8..36d9af1b 100755
> --- a/test/T590-libconfig.sh
> +++ b/test/T590-libconfig.sh
> @@ -5,6 +5,14 @@ test_description="library config API"
>  
>  add_email_corpus
>  
> +get_name () {
> +    if hash getent 2>/dev/null; then
> +        getent passwd "$USER" | cut -d ':' -f 5
> +    else
> +        echo "Foo Bar"
> +    fi
> +}

I'd do

if test -n "$(getent passwd "$USER" | cut -d ':' -f 5)
then
        USER_FULL_NAME=USER_FULL_NAME
else
        USER_FULL_NAME=
fi

and then e.g.

cat <<"EOF" >EXPECTED
== stdout ==
MAIL_DIR
...
$USER_FULL_NAME
== stderr ==
EOF

if getent does not exist, then we'd get empty string
and $USER_FULL_NAME empty (as good as "Foo bar")


> +
>  cat <<EOF > c_head
>  #include <string.h>
>  #include <stdlib.h>
> @@ -402,6 +410,7 @@ NULL
>  USER_FULL_NAME
>  == stderr ==
>  EOF
> +test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
>  unset MAILDIR
>  test_expect_equal_file EXPECTED OUTPUT.clean
>  
> @@ -744,6 +753,7 @@ NULL
>  USER_FULL_NAME
>  == stderr ==
>  EOF
> +test "$(get_name)" = "" && sed -e "s/USER_FULL_NAME//" -i EXPECTED
>  test_expect_equal_file EXPECTED OUTPUT.clean
>  
>  backup_database
> -- 
> 2.31.0

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 04/13] test: use correct fqdn in passwd_sanitize()
  2021-05-01 11:54 ` [PATCH 04/13] test: use correct fqdn in passwd_sanitize() Felipe Contreras
@ 2021-05-01 20:14   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:14 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> My fqdn is 'natae.localdomain', however, socket.getfqdn() returns
> 'localhost'.
>
> To fetch the true fqdn we need socket.getaddrinfo().
>
> For more information see: https://stackoverflow.com/a/11580042/10474
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index ae653363..21dda265 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -709,7 +709,7 @@ import os, sys, pwd, socket
>  pw = pwd.getpwuid(os.getuid())
>  user = pw.pw_name
>  name = pw.pw_gecos.partition(",")[0]
> -fqdn = socket.getfqdn()
> +fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3]

I trust you this works better. 

LGTM.

Tomi

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 05/13] test: fix wrong SKIP messages
  2021-05-01 11:54 ` [PATCH 05/13] test: fix wrong SKIP messages Felipe Contreras
@ 2021-05-01 20:18   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:18 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> When the external prereqs are updated inside the body of the command
> (e.g. test_emacs) the message in test_report_skip_ is wrong: it outputs
> the body of the command instead of the subtest name.
>
> We need to pass the same argument we pass to test_skip.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 21dda265..1067316d 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -919,7 +919,7 @@ test_expect_success () {
>  		test_run_ "$1"
>  		run_ret="$?"
>  		# test_run_ may update missing external prerequisites
> -		test_check_missing_external_prereqs_ "$@" ||
> +		test_check_missing_external_prereqs_ "$test_subtest_name" ||
>  		if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]
>  		then
>  			test_ok_
> @@ -943,7 +943,7 @@ test_expect_code () {
>  		test_run_ "$2"
>  		run_ret="$?"
>  		# test_run_ may update missing external prerequisites,
> -		test_check_missing_external_prereqs_ "$@" ||
> +		test_check_missing_external_prereqs_ "$test_subtest_name" ||

Looks sensible to me. hard to verify ;/

Tomi

>  		if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]
>  		then
>  			test_ok_
> -- 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 06/13] test: add prereqs check in test_emacs_expect_t
  2021-05-01 11:54 ` [PATCH 06/13] test: add prereqs check in test_emacs_expect_t Felipe Contreras
@ 2021-05-01 20:18   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:18 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> test_emacs may update the external prereqs, in which case we want to
> skip the test rather than fail.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib.sh | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 1067316d..72ac2e89 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -592,6 +592,9 @@ test_emacs_expect_t () {
>  		exec 1>&6 2>&7		# Restore stdout and stderr
>  		inside_subtest=
>  
> +		# test_emacs may update missing external prerequisites
> +		test_check_missing_external_prereqs_ "$test_subtest_name" && return
> +

Ditto. LGTM.

Tomi

>  		# Report success/failure.
>  		result=$(cat OUTPUT)
>  		if [ "$result" = t ]
> -- 
> 2.31.0

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 07/13] test: add external prereqs to many emacs tests
  2021-05-01 11:54 ` [PATCH 07/13] test: add external prereqs to many emacs tests Felipe Contreras
@ 2021-05-01 20:19   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:19 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> The tests fail otherwise.

LGTM.

Tomi


>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/T310-emacs.sh            | 1 +
>  test/T350-crypto.sh           | 1 +
>  test/T355-smime.sh            | 1 +
>  test/T357-index-decryption.sh | 1 +
>  test/T450-emacs-show.sh       | 1 +
>  test/T460-emacs-tree.sh       | 1 +
>  test/T730-emacs-forwarding.sh | 2 ++
>  test/test-lib.sh              | 6 ++++++
>  8 files changed, 14 insertions(+)
>
> diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
> index 78ac19a8..e64627c6 100755
> --- a/test/T310-emacs.sh
> +++ b/test/T310-emacs.sh
> @@ -5,6 +5,7 @@ test_description="emacs interface"
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
>  
> +test_require_emacs
>  add_email_corpus
>  
>  # syntax errors in test-lib.el cause mysterious failures
> diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
> index 0aada4df..ae1d6a98 100755
> --- a/test/T350-crypto.sh
> +++ b/test/T350-crypto.sh
> @@ -9,6 +9,7 @@ test_description='PGP/MIME signature verification and decryption'
>  
>  ##################################################
>  
> +test_require_emacs
>  add_gnupg_home
>  
>  test_begin_subtest "emacs delivery of signed message"
> diff --git a/test/T355-smime.sh b/test/T355-smime.sh
> index 8b2b52be..12ac2525 100755
> --- a/test/T355-smime.sh
> +++ b/test/T355-smime.sh
> @@ -3,6 +3,7 @@
>  test_description='S/MIME signature verification and decryption'
>  . $(dirname "$0")/test-lib.sh || exit 1
>  
> +test_require_emacs
>  test_require_external_prereq openssl
>  test_require_external_prereq gpgsm
>  
> diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh
> index 1ed5f28c..b81bdfe1 100755
> --- a/test/T357-index-decryption.sh
> +++ b/test/T357-index-decryption.sh
> @@ -7,6 +7,7 @@ test_description='indexing decrypted mail'
>  
>  ##################################################
>  
> +test_require_emacs
>  add_gnupg_home
>  
>  # create a test encrypted message
> diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
> index cca56ca3..bd76d378 100755
> --- a/test/T450-emacs-show.sh
> +++ b/test/T450-emacs-show.sh
> @@ -5,6 +5,7 @@ test_description="emacs notmuch-show view"
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
>  
> +test_require_emacs
>  add_email_corpus
>  
>  test_begin_subtest "Hiding Original Message region at beginning of a message"
> diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
> index cb2c90b8..195485c1 100755
> --- a/test/T460-emacs-tree.sh
> +++ b/test/T460-emacs-tree.sh
> @@ -5,6 +5,7 @@ test_description="emacs tree view interface"
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
>  
> +test_require_emacs
>  add_email_corpus
>  
>  test_begin_subtest "Basic notmuch-tree view in emacs"
> diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
> index 45e61568..5d6ac9f0 100755
> --- a/test/T730-emacs-forwarding.sh
> +++ b/test/T730-emacs-forwarding.sh
> @@ -3,6 +3,8 @@
>  test_description="emacs forwarding"
>  . $(dirname "$0")/test-lib.sh || exit 1
>  
> +test_require_emacs
> +
>  test_begin_subtest "Forward setting the correct references header"
>  # Check that, when forwarding a message, the new message has
>  # a References-header pointing to the original (forwarded) message.
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 72ac2e89..88e2a82f 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -114,6 +114,12 @@ unset ALTERNATE_EDITOR
>  unset EMAIL
>  unset NAME
>  
> +test_require_emacs () {
> +    test_require_external_prereq emacs
> +    test_require_external_prereq ${TEST_EMACSCLIENT}
> +    test_require_external_prereq dtach
> +}
> +
>  add_gnupg_home ()
>  {
>      [ -e "${GNUPGHOME}/gpg.conf" ] && return
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 09/13] test: emacs: simplify missing dependencies check
  2021-05-01 11:54 ` [PATCH 09/13] test: emacs: simplify missing dependencies check Felipe Contreras
@ 2021-05-01 20:20   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:20 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> No functional changes.

LGTM.

Tomi


>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib-emacs.sh | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
> index ecad501a..83f5b10b 100644
> --- a/test/test-lib-emacs.sh
> +++ b/test/test-lib-emacs.sh
> @@ -15,9 +15,11 @@
>  # along with this program.  If not, see https://www.gnu.org/licenses/ .
>  
>  test_require_emacs () {
> -    test_require_external_prereq emacs
> -    test_require_external_prereq ${TEST_EMACSCLIENT}
> -    test_require_external_prereq dtach
> +    local ret=0
> +    test_require_external_prereq emacs || ret=1
> +    test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
> +    test_require_external_prereq dtach || ret=1
> +    return $ret
>  }
>  
>  # Deliver a message with emacs and add it to the database
> @@ -167,11 +169,7 @@ EOF
>  
>  test_emacs () {
>  	# test dependencies beforehand to avoid the waiting loop below
> -	missing_dependencies=
> -	test_require_external_prereq dtach || missing_dependencies=1
> -	test_require_external_prereq emacs || missing_dependencies=1
> -	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
> -	test -z "$missing_dependencies" || return
> +	test_require_emacs || return
>  
>  	if [ -z "$EMACS_SERVER" ]; then
>  		emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 10/13] test: emacs: check for configured emacs
  2021-05-01 11:54 ` [PATCH 10/13] test: emacs: check for configured emacs Felipe Contreras
@ 2021-05-01 20:20   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:20 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> Commit d59d9c81 (test: Make the emacsclient binary user-configurable,
> 2012-11-27) modified the prereq check for the configured emacsclient,
> but we probably want to do the same for emacs itself.

LGTM.

>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib-emacs.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
> index 83f5b10b..3075fa59 100644
> --- a/test/test-lib-emacs.sh
> +++ b/test/test-lib-emacs.sh
> @@ -16,7 +16,7 @@
>  
>  test_require_emacs () {
>      local ret=0
> -    test_require_external_prereq emacs || ret=1
> +    test_require_external_prereq ${TEST_EMACS} || ret=1
>      test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
>      test_require_external_prereq dtach || ret=1
>      return $ret
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints
  2021-05-01 11:54 ` [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
@ 2021-05-01 20:21   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:21 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

LGTM

> In test-lib-emacs.sh line 20:
>     test_require_external_prereq ${TEST_EMACS} || ret=1
>                                  ^-----------^ SC2086: Double quote to prevent globbing and word splitting.
>
> Did you mean:
>     test_require_external_prereq "${TEST_EMACS}" || ret=1
>
> In test-lib-emacs.sh line 21:
>     test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
>                                  ^-----------------^ SC2086: Double quote to prevent globbing and word splitting.
>
> Did you mean:
>     test_require_external_prereq "${TEST_EMACSCLIENT}" || ret=1
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/test-lib-emacs.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
> index 3075fa59..bf875a28 100644
> --- a/test/test-lib-emacs.sh
> +++ b/test/test-lib-emacs.sh
> @@ -16,8 +16,8 @@
>  
>  test_require_emacs () {
>      local ret=0
> -    test_require_external_prereq ${TEST_EMACS} || ret=1
> -    test_require_external_prereq ${TEST_EMACSCLIENT} || ret=1
> +    test_require_external_prereq "$TEST_EMACS" || ret=1
> +    test_require_external_prereq "$TEST_EMACSCLIENT" || ret=1
>      test_require_external_prereq dtach || ret=1
>      return $ret
>  }
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 08/13] test: split emacs functionality to its own file
  2021-05-01 11:54 ` [PATCH 08/13] test: split emacs functionality to its own file Felipe Contreras
@ 2021-05-01 20:28   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:28 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> This way it's easier to identify the tests that do require emacs stuff.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/T160-json.sh                      |   1 +
>  test/T170-sexp.sh                      |   1 +
>  test/T310-emacs.sh                     |   1 +
>  test/T320-emacs-large-search-buffer.sh |   3 +
>  test/T330-emacs-subject-to-filename.sh |   3 +
>  test/T350-crypto.sh                    |   1 +
>  test/T355-smime.sh                     |   1 +
>  test/T357-index-decryption.sh          |   1 +
>  test/T358-emacs-protected-headers.sh   |   2 +
>  test/T420-emacs-test-functions.sh      |   1 +
>  test/T430-emacs-address-cleaning.sh    |   3 +
>  test/T440-emacs-hello.sh               |   2 +
>  test/T450-emacs-show.sh                |   1 +
>  test/T455-emacs-charsets.sh            |   3 +
>  test/T460-emacs-tree.sh                |   1 +
>  test/T510-thread-replies.sh            |   1 +
>  test/T630-emacs-draft.sh               |   2 +
>  test/T720-emacs-attachment-warnings.sh |   3 +
>  test/T730-emacs-forwarding.sh          |   1 +
>  test/test-lib-emacs.sh                 | 213 +++++++++++++++++++++++++
>  test/test-lib.sh                       | 199 -----------------------
>  21 files changed, 245 insertions(+), 199 deletions(-)
>  create mode 100644 test/test-lib-emacs.sh
>
> diff --git a/test/T160-json.sh b/test/T160-json.sh
> index e8b75605..638afb4d 100755
> --- a/test/T160-json.sh
> +++ b/test/T160-json.sh
> @@ -1,6 +1,7 @@
>  #!/usr/bin/env bash
>  test_description="--format=json output"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_begin_subtest "Show message: json"
>  add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""
> diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh
> index 24be8351..af8c4b44 100755
> --- a/test/T170-sexp.sh
> +++ b/test/T170-sexp.sh
> @@ -1,6 +1,7 @@
>  #!/usr/bin/env bash
>  test_description="--format=sexp output"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_begin_subtest "Show message: sexp"
>  add_message "[subject]=\"sexp-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"sexp-show-message\""
> diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
> index e64627c6..c08df5fc 100755
> --- a/test/T310-emacs.sh
> +++ b/test/T310-emacs.sh
> @@ -2,6 +2,7 @@
>  
>  test_description="emacs interface"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
>  
> diff --git a/test/T320-emacs-large-search-buffer.sh b/test/T320-emacs-large-search-buffer.sh
> index f61e8a97..d2638c8b 100755
> --- a/test/T320-emacs-large-search-buffer.sh
> +++ b/test/T320-emacs-large-search-buffer.sh
> @@ -1,11 +1,14 @@
>  #!/usr/bin/env bash
>  test_description="Emacs with large search results buffer"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  x=xxxxxxxxxx # 10
>  x=$x$x$x$x$x$x$x$x$x$x # 100
>  x=$x$x$x$x$x$x$x$x$x # 900
>  
> +test_require_emacs

Could the following work in case of emacs tests:

  . $(dirname "$0")/test-lib.sh || exit 1
  test_require_emacs
  . $(dirname "$0")/test-lib-emacs.sh || exit 1

i.e. in case of emacs tests test_require_emacs would always be needed 
-- and it requirement not satisfied, exit even before sourcing
test-lib-emacs.sh

Tomi

>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  x=xxxxxxxxxx # 10
>  x=$x$x$x$x$x$x$x$x$x$x # 100
>  x=$x$x$x$x$x$x$x$x$x # 900
>  
> +test_require_emacs




> +
>  # We generate a long subject here (over 900 bytes) so that the emacs
>  # search results get large quickly. With 30 such messages we should
>  # cross several 4kB page boundaries and see the bug.
> diff --git a/test/T330-emacs-subject-to-filename.sh b/test/T330-emacs-subject-to-filename.sh
> index eaf7c980..6e09a048 100755
> --- a/test/T330-emacs-subject-to-filename.sh
> +++ b/test/T330-emacs-subject-to-filename.sh
> @@ -2,6 +2,9 @@
>  
>  test_description="emacs: mail subject to filename"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
> +
> +test_require_emacs
>  
>  # emacs server can't be started in a child process with $(test_emacs ...)
>  test_emacs '(ignore)' > /dev/null
> diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
> index ae1d6a98..4508c984 100755
> --- a/test/T350-crypto.sh
> +++ b/test/T350-crypto.sh
> @@ -6,6 +6,7 @@
>  
>  test_description='PGP/MIME signature verification and decryption'
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  ##################################################
>  
> diff --git a/test/T355-smime.sh b/test/T355-smime.sh
> index 12ac2525..69bdcfac 100755
> --- a/test/T355-smime.sh
> +++ b/test/T355-smime.sh
> @@ -2,6 +2,7 @@
>  
>  test_description='S/MIME signature verification and decryption'
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_require_emacs
>  test_require_external_prereq openssl
> diff --git a/test/T357-index-decryption.sh b/test/T357-index-decryption.sh
> index b81bdfe1..f5644d7e 100755
> --- a/test/T357-index-decryption.sh
> +++ b/test/T357-index-decryption.sh
> @@ -4,6 +4,7 @@
>  
>  test_description='indexing decrypted mail'
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  ##################################################
>  
> diff --git a/test/T358-emacs-protected-headers.sh b/test/T358-emacs-protected-headers.sh
> index bca78531..b25d7ea7 100755
> --- a/test/T358-emacs-protected-headers.sh
> +++ b/test/T358-emacs-protected-headers.sh
> @@ -2,8 +2,10 @@
>  
>  test_description="protected headers in emacs interface"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  # testing protected headers with emacs
> +test_require_emacs
>  add_gnupg_home
>  add_email_corpus protected-headers
>  
> diff --git a/test/T420-emacs-test-functions.sh b/test/T420-emacs-test-functions.sh
> index bfc10be3..22e4f01e 100755
> --- a/test/T420-emacs-test-functions.sh
> +++ b/test/T420-emacs-test-functions.sh
> @@ -2,6 +2,7 @@
>  
>  test_description="emacs test function sanity"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_begin_subtest "emacs test function sanity"
>  test_emacs_expect_t 't'
> diff --git a/test/T430-emacs-address-cleaning.sh b/test/T430-emacs-address-cleaning.sh
> index 02d3b411..640bff3f 100755
> --- a/test/T430-emacs-address-cleaning.sh
> +++ b/test/T430-emacs-address-cleaning.sh
> @@ -2,6 +2,9 @@
>  
>  test_description="emacs address cleaning"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
> +
> +test_require_emacs
>  
>  test_begin_subtest "notmuch-test-address-clean part 1"
>  test_emacs_expect_t '(notmuch-test-address-cleaning-1)'
> diff --git a/test/T440-emacs-hello.sh b/test/T440-emacs-hello.sh
> index d23c1fca..642aa3cc 100755
> --- a/test/T440-emacs-hello.sh
> +++ b/test/T440-emacs-hello.sh
> @@ -2,9 +2,11 @@
>  
>  test_description="emacs notmuch-hello view"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
>  
> +test_require_emacs
>  add_email_corpus
>  
>  test_begin_subtest "User-defined section with inbox tag"
> diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
> index bd76d378..e58124d4 100755
> --- a/test/T450-emacs-show.sh
> +++ b/test/T450-emacs-show.sh
> @@ -2,6 +2,7 @@
>  
>  test_description="emacs notmuch-show view"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
>  
> diff --git a/test/T455-emacs-charsets.sh b/test/T455-emacs-charsets.sh
> index cb1297ca..a0f4dc24 100755
> --- a/test/T455-emacs-charsets.sh
> +++ b/test/T455-emacs-charsets.sh
> @@ -2,11 +2,14 @@
>  
>  test_description="emacs notmuch-show charset handling"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  
>  UTF8_YEN=$'\xef\xbf\xa5'
>  BIG5_YEN=$'\xa2\x44'
>  
> +test_require_emacs
> +
>  # Add four messages with unusual encoding requirements:
>  #
>  # 1) text/plain in quoted-printable big5
> diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
> index 195485c1..dfc69049 100755
> --- a/test/T460-emacs-tree.sh
> +++ b/test/T460-emacs-tree.sh
> @@ -2,6 +2,7 @@
>  
>  test_description="emacs tree view interface"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
>  
> diff --git a/test/T510-thread-replies.sh b/test/T510-thread-replies.sh
> index 2859d29f..cdb4be44 100755
> --- a/test/T510-thread-replies.sh
> +++ b/test/T510-thread-replies.sh
> @@ -10,6 +10,7 @@ test_description='test of proper handling of in-reply-to and references headers'
>  # non-RFC-compliant headers'
>  
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_begin_subtest "Use References when In-Reply-To is broken"
>  add_message '[id]="foo@one.com"' \
> diff --git a/test/T630-emacs-draft.sh b/test/T630-emacs-draft.sh
> index d7903ce7..8553f022 100755
> --- a/test/T630-emacs-draft.sh
> +++ b/test/T630-emacs-draft.sh
> @@ -1,7 +1,9 @@
>  #!/usr/bin/env bash
>  test_description="Emacs Draft Handling"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
> +test_require_emacs
>  add_email_corpus
>  
>  notmuch config set search.exclude_tags deleted
> diff --git a/test/T720-emacs-attachment-warnings.sh b/test/T720-emacs-attachment-warnings.sh
> index c8d2bcc2..4e8c5d26 100755
> --- a/test/T720-emacs-attachment-warnings.sh
> +++ b/test/T720-emacs-attachment-warnings.sh
> @@ -2,6 +2,9 @@
>  
>  test_description="emacs attachment warnings"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
> +
> +test_require_emacs
>  
>  test_begin_subtest "notmuch-test-attachment-warning part 1"
>  test_emacs_expect_t '(notmuch-test-attachment-warning-1)'
> diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
> index 5d6ac9f0..378067ed 100755
> --- a/test/T730-emacs-forwarding.sh
> +++ b/test/T730-emacs-forwarding.sh
> @@ -2,6 +2,7 @@
>  
>  test_description="emacs forwarding"
>  . $(dirname "$0")/test-lib.sh || exit 1
> +. $(dirname "$0")/test-lib-emacs.sh || exit 1
>  
>  test_require_emacs
>  
> diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
> new file mode 100644
> index 00000000..ecad501a
> --- /dev/null
> +++ b/test/test-lib-emacs.sh
> @@ -0,0 +1,213 @@
> +#
> +# Copyright (c) 2010-2020 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
> +# the Free Software Foundation, either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see https://www.gnu.org/licenses/ .
> +
> +test_require_emacs () {
> +    test_require_external_prereq emacs
> +    test_require_external_prereq ${TEST_EMACSCLIENT}
> +    test_require_external_prereq dtach
> +}
> +
> +# Deliver a message with emacs and add it to the database
> +#
> +# Uses emacs to generate and deliver a message to the mail store.
> +# Accepts arbitrary extra emacs/elisp functions to modify the message
> +# before sending, which is useful to doing things like attaching files
> +# to the message and encrypting/signing.
> +emacs_deliver_message ()
> +{
> +    local subject body smtp_dummy_pid smtp_dummy_port
> +    subject="$1"
> +    body="$2"
> +    shift 2
> +    # before we can send a message, we have to prepare the FCC maildir
> +    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
> +    # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port
> +    smtp_dummy_pid= smtp_dummy_port=
> +    eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
> +    test -n "$smtp_dummy_pid" || return 1
> +    test -n "$smtp_dummy_port" || return 1
> +
> +    test_emacs \
> +	"(let ((message-send-mail-function 'message-smtpmail-send-it)
> +	       (mail-host-address \"example.com\")
> +	       (smtpmail-smtp-server \"localhost\")
> +	       (smtpmail-smtp-service \"${smtp_dummy_port}\"))
> +	   (notmuch-mua-mail)
> +	   (message-goto-to)
> +	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
> +	   (message-goto-subject)
> +	   (insert \"${subject}\")
> +	   (message-goto-body)
> +	   (insert \"${body}\")
> +	   $*
> +	   (notmuch-mua-send-and-exit))"
> +
> +    # In case message was sent properly, client waits for confirmation
> +    # before exiting and resuming control here; therefore making sure
> +    # that server exits by sending (KILL) signal to it is safe.
> +    kill -9 $smtp_dummy_pid
> +    notmuch new >/dev/null
> +}
> +
> +# Pretend to deliver a message with emacs. Really save it to a file
> +# and add it to the database
> +#
> +# Uses emacs to generate and deliver a message to the mail store.
> +# Accepts arbitrary extra emacs/elisp functions to modify the message
> +# before sending, which is useful to doing things like attaching files
> +# to the message and encrypting/signing.
> +#
> +# If any GNU-style long-arguments (like --quiet or --decrypt=true) are
> +# at the head of the argument list, they are sent directly to "notmuch
> +# new" after message delivery
> +emacs_fcc_message ()
> +{
> +    local nmn_args subject body
> +    nmn_args=''
> +    while [[ "$1" =~ ^-- ]]; do
> +	nmn_args="$nmn_args $1"
> +	shift
> +    done
> +    subject="$1"
> +    body="$2"
> +    shift 2
> +    # before we can send a message, we have to prepare the FCC maildir
> +    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
> +
> +    test_emacs \
> +	"(let ((message-send-mail-function (lambda () t))
> +	       (mail-host-address \"example.com\"))
> +	   (notmuch-mua-mail)
> +	   (message-goto-to)
> +	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
> +	   (message-goto-subject)
> +	   (insert \"${subject}\")
> +	   (message-goto-body)
> +	   (insert \"${body}\")
> +	   $*
> +	   (let ((mml-secure-smime-sign-with-sender t)
> +		 (mml-secure-openpgp-sign-with-sender t))
> +	     (notmuch-mua-send-and-exit)))" || return 1
> +    notmuch new $nmn_args >/dev/null
> +}
> +
> +test_emacs_expect_t () {
> +	local result
> +	test "$#" = 1 ||
> +	error "bug in the test script: not 1 parameter to test_emacs_expect_t"
> +	if [ -z "$inside_subtest" ]; then
> +		error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
> +	fi
> +
> +	# Run the test.
> +	if ! test_skip "$test_subtest_name"
> +	then
> +		test_emacs "(notmuch-test-run $1)" >/dev/null
> +
> +		# Restore state after the test.
> +		exec 1>&6 2>&7		# Restore stdout and stderr
> +		inside_subtest=
> +
> +		# test_emacs may update missing external prerequisites
> +		test_check_missing_external_prereqs_ "$test_subtest_name" && return
> +
> +		# Report success/failure.
> +		result=$(cat OUTPUT)
> +		if [ "$result" = t ]
> +		then
> +			test_ok_
> +		else
> +			test_failure_ "${result}"
> +		fi
> +	else
> +		# Restore state after the (non) test.
> +		exec 1>&6 2>&7		# Restore stdout and stderr
> +		inside_subtest=
> +	fi
> +}
> +
> +emacs_generate_script () {
> +	# Construct a little test script here for the benefit of the user,
> +	# (who can easily run "run_emacs" to get the same emacs environment
> +	# for investigating any failures).
> +	cat <<EOF >"$TMP_DIRECTORY/run_emacs"
> +#!/bin/sh
> +export PATH=$PATH
> +export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
> +
> +# Here's what we are using here:
> +#
> +# --quick		Use minimal customization. This implies --no-init-file,
> +#			--no-site-file and (emacs 24) --no-site-lisp
> +#
> +# --directory		Ensure that the local elisp sources are found
> +#
> +# --load		Force loading of notmuch.el and test-lib.el
> +
> +exec ${TEST_EMACS} --quick \
> +	--directory "$NOTMUCH_BUILDDIR/emacs" --load notmuch.el \
> +	--directory "$NOTMUCH_SRCDIR/test" --load test-lib.el \
> +	"\$@"
> +EOF
> +	chmod a+x "$TMP_DIRECTORY/run_emacs"
> +}
> +
> +test_emacs () {
> +	# test dependencies beforehand to avoid the waiting loop below
> +	missing_dependencies=
> +	test_require_external_prereq dtach || missing_dependencies=1
> +	test_require_external_prereq emacs || missing_dependencies=1
> +	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
> +	test -z "$missing_dependencies" || 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
> +
> +	# 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_generate_script
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 88e2a82f..7fdc0007 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -114,12 +114,6 @@ unset ALTERNATE_EDITOR
>  unset EMAIL
>  unset NAME
>  
> -test_require_emacs () {
> -    test_require_external_prereq emacs
> -    test_require_external_prereq ${TEST_EMACSCLIENT}
> -    test_require_external_prereq dtach
> -}
> -
>  add_gnupg_home ()
>  {
>      [ -e "${GNUPGHOME}/gpg.conf" ] && return
> @@ -349,90 +343,6 @@ export GNUPGHOME="${TEST_TMPDIR}/gnupg"
>  trap 'trap_exit' EXIT
>  trap 'trap_signal' HUP INT TERM
>  
> -# Deliver a message with emacs and add it to the database
> -#
> -# Uses emacs to generate and deliver a message to the mail store.
> -# Accepts arbitrary extra emacs/elisp functions to modify the message
> -# before sending, which is useful to doing things like attaching files
> -# to the message and encrypting/signing.
> -emacs_deliver_message ()
> -{
> -    local subject body smtp_dummy_pid smtp_dummy_port
> -    subject="$1"
> -    body="$2"
> -    shift 2
> -    # before we can send a message, we have to prepare the FCC maildir
> -    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
> -    # eval'ing smtp-dummy --background will set smtp_dummy_pid and -_port
> -    smtp_dummy_pid= smtp_dummy_port=
> -    eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
> -    test -n "$smtp_dummy_pid" || return 1
> -    test -n "$smtp_dummy_port" || return 1
> -
> -    test_emacs \
> -	"(let ((message-send-mail-function 'message-smtpmail-send-it)
> -	       (mail-host-address \"example.com\")
> -	       (smtpmail-smtp-server \"localhost\")
> -	       (smtpmail-smtp-service \"${smtp_dummy_port}\"))
> -	   (notmuch-mua-mail)
> -	   (message-goto-to)
> -	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
> -	   (message-goto-subject)
> -	   (insert \"${subject}\")
> -	   (message-goto-body)
> -	   (insert \"${body}\")
> -	   $*
> -	   (notmuch-mua-send-and-exit))"
> -
> -    # In case message was sent properly, client waits for confirmation
> -    # before exiting and resuming control here; therefore making sure
> -    # that server exits by sending (KILL) signal to it is safe.
> -    kill -9 $smtp_dummy_pid
> -    notmuch new >/dev/null
> -}
> -
> -# Pretend to deliver a message with emacs. Really save it to a file
> -# and add it to the database
> -#
> -# Uses emacs to generate and deliver a message to the mail store.
> -# Accepts arbitrary extra emacs/elisp functions to modify the message
> -# before sending, which is useful to doing things like attaching files
> -# to the message and encrypting/signing.
> -#
> -# If any GNU-style long-arguments (like --quiet or --decrypt=true) are
> -# at the head of the argument list, they are sent directly to "notmuch
> -# new" after message delivery
> -emacs_fcc_message ()
> -{
> -    local nmn_args subject body
> -    nmn_args=''
> -    while [[ "$1" =~ ^-- ]]; do
> -	nmn_args="$nmn_args $1"
> -	shift
> -    done
> -    subject="$1"
> -    body="$2"
> -    shift 2
> -    # before we can send a message, we have to prepare the FCC maildir
> -    mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
> -
> -    test_emacs \
> -	"(let ((message-send-mail-function (lambda () t))
> -	       (mail-host-address \"example.com\"))
> -	   (notmuch-mua-mail)
> -	   (message-goto-to)
> -	   (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
> -	   (message-goto-subject)
> -	   (insert \"${subject}\")
> -	   (message-goto-body)
> -	   (insert \"${body}\")
> -	   $*
> -	   (let ((mml-secure-smime-sign-with-sender t)
> -		 (mml-secure-openpgp-sign-with-sender t))
> -	     (notmuch-mua-send-and-exit)))" || return 1
> -    notmuch new $nmn_args >/dev/null
> -}
> -
>  # Add an existing, fixed corpus of email to the database.
>  #
>  # $1 is the corpus dir under corpora to add, using "default" if unset.
> @@ -581,41 +491,6 @@ test_json_nodes () {
>  	fi
>  }
>  
> -test_emacs_expect_t () {
> -	local result
> -	test "$#" = 1 ||
> -	error "bug in the test script: not 1 parameter to test_emacs_expect_t"
> -	if [ -z "$inside_subtest" ]; then
> -		error "bug in the test script: test_emacs_expect_t without test_begin_subtest"
> -	fi
> -
> -	# Run the test.
> -	if ! test_skip "$test_subtest_name"
> -	then
> -		test_emacs "(notmuch-test-run $1)" >/dev/null
> -
> -		# Restore state after the test.
> -		exec 1>&6 2>&7		# Restore stdout and stderr
> -		inside_subtest=
> -
> -		# test_emacs may update missing external prerequisites
> -		test_check_missing_external_prereqs_ "$test_subtest_name" && return
> -
> -		# Report success/failure.
> -		result=$(cat OUTPUT)
> -		if [ "$result" = t ]
> -		then
> -			test_ok_
> -		else
> -			test_failure_ "${result}"
> -		fi
> -	else
> -		# Restore state after the (non) test.
> -		exec 1>&6 2>&7		# Restore stdout and stderr
> -		inside_subtest=
> -	fi
> -}
> -
>  NOTMUCH_NEW ()
>  {
>      notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
> @@ -1046,77 +921,6 @@ test_done () {
>  	fi
>  }
>  
> -emacs_generate_script () {
> -	# Construct a little test script here for the benefit of the user,
> -	# (who can easily run "run_emacs" to get the same emacs environment
> -	# for investigating any failures).
> -	cat <<EOF >"$TMP_DIRECTORY/run_emacs"
> -#!/bin/sh
> -export PATH=$PATH
> -export NOTMUCH_CONFIG=$NOTMUCH_CONFIG
> -
> -# Here's what we are using here:
> -#
> -# --quick		Use minimal customization. This implies --no-init-file,
> -#			--no-site-file and (emacs 24) --no-site-lisp
> -#
> -# --directory		Ensure that the local elisp sources are found
> -#
> -# --load		Force loading of notmuch.el and test-lib.el
> -
> -exec ${TEST_EMACS} --quick \
> -	--directory "$NOTMUCH_BUILDDIR/emacs" --load notmuch.el \
> -	--directory "$NOTMUCH_SRCDIR/test" --load test-lib.el \
> -	"\$@"
> -EOF
> -	chmod a+x "$TMP_DIRECTORY/run_emacs"
> -}
> -
> -test_emacs () {
> -	# test dependencies beforehand to avoid the waiting loop below
> -	missing_dependencies=
> -	test_require_external_prereq dtach || missing_dependencies=1
> -	test_require_external_prereq emacs || missing_dependencies=1
> -	test_require_external_prereq ${TEST_EMACSCLIENT} || missing_dependencies=1
> -	test -z "$missing_dependencies" || 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
> -
> -	# 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 $*)"
> -}
> -
>  test_python() {
>      # Note: if there is need to print debug information from python program,
>      # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
> @@ -1210,9 +1014,6 @@ TEST_DIRECTORY=$NOTMUCH_BUILDDIR/test
>  
>  . "$NOTMUCH_SRCDIR/test/test-lib-common.sh" || exit 1
>  
> -emacs_generate_script
> -
> -
>  # Use -P to resolve symlinks in our working directory so that the cwd
>  # in subprocesses like git equals our $PWD (for pathname comparisons).
>  cd -P "$TMP_DIRECTORY" || error "Cannot set up test environment"
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 12/13] test: trivial style cleanups
  2021-05-01 11:54 ` [PATCH 12/13] test: trivial style cleanups Felipe Contreras
@ 2021-05-01 20:28   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:28 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>

LGTM

Tomi


> ---
>  test/T000-basic.sh           |  2 +-
>  test/T070-insert.sh          |  2 +-
>  test/T590-thread-breakage.sh | 10 +++++-----
>  test/export-dirs.sh          |  2 +-
>  test/test-lib.sh             |  8 ++++----
>  5 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/test/T000-basic.sh b/test/T000-basic.sh
> index 7fbdcfa3..a2f4d93f 100755
> --- a/test/T000-basic.sh
> +++ b/test/T000-basic.sh
> @@ -33,7 +33,7 @@ test_begin_subtest 'failure to clean up causes the test to fail'
>  test_expect_code 2 'test_when_finished "(exit 2)"'
>  
>  EXPECTED=$NOTMUCH_SRCDIR/test/test.expected-output
> -suppress_diff_date() {
> +suppress_diff_date () {
>      sed -e 's/\(.*\-\-\- test-verbose\.4\.\expected\).*/\1/' \
>  	-e 's/\(.*\+\+\+ test-verbose\.4\.\output\).*/\1/'
>  }
> diff --git a/test/T070-insert.sh b/test/T070-insert.sh
> index b37a9b67..208deb1c 100755
> --- a/test/T070-insert.sh
> +++ b/test/T070-insert.sh
> @@ -15,7 +15,7 @@ notmuch new > /dev/null
>  # They happen to be in the mail directory already but that is okay
>  # since we do not call notmuch new hereafter.
>  
> -gen_insert_msg() {
> +gen_insert_msg () {
>      generate_message \
>  	"[subject]=\"insert-subject\"" \
>  	"[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
> diff --git a/test/T590-thread-breakage.sh b/test/T590-thread-breakage.sh
> index aeb82cf4..92a70e3e 100755
> --- a/test/T590-thread-breakage.sh
> +++ b/test/T590-thread-breakage.sh
> @@ -21,7 +21,7 @@ test_description='thread breakage during reindexing'
>  
>  . $(dirname "$0")/test-lib.sh || exit 1
>  
> -message_a() {
> +message_a () {
>      mkdir -p ${MAIL_DIR}/cur
>      cat > ${MAIL_DIR}/cur/a <<EOF
>  Subject: First message
> @@ -35,7 +35,7 @@ Apple
>  EOF
>  }
>  
> -message_b() {
> +message_b () {
>      mkdir -p ${MAIL_DIR}/cur
>      cat > ${MAIL_DIR}/cur/b <<EOF
>  Subject: Second message
> @@ -52,19 +52,19 @@ EOF
>  }
>  
>  
> -test_content_count() {
> +test_content_count () {
>      test_begin_subtest "${3:-looking for $2 instance of '$1'}"
>      count=$(notmuch count --output=threads "$1")
>      test_expect_equal "$count" "$2"
>  }
>  
> -test_thread_count() {
> +test_thread_count () {
>      test_begin_subtest "${2:-Expecting $1 thread(s)}"
>      count=$(notmuch count --output=threads)
>      test_expect_equal "$count" "$1"
>  }
>  
> -test_ghost_count() {
> +test_ghost_count () {
>      test_begin_subtest "${2:-Expecting $1 ghosts(s)}"
>      ghosts=$($NOTMUCH_BUILDDIR/test/ghost-report ${MAIL_DIR}/.notmuch/xapian)
>      test_expect_equal "$ghosts" "$1"
> diff --git a/test/export-dirs.sh b/test/export-dirs.sh
> index 0578b1e5..844ee682 100644
> --- a/test/export-dirs.sh
> +++ b/test/export-dirs.sh
> @@ -9,7 +9,7 @@ if [[ -z "${NOTMUCH_SRCDIR}" ]]; then
>  	export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
>  fi
>  
> -find_builddir()
> +find_builddir ()
>  {
>  	local dir="$1"
>  
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 7fdc0007..1b502456 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -585,7 +585,7 @@ notmuch_built_with_sanitize ()
>      sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
>  }
>  
> -notmuch_passwd_sanitize()
> +notmuch_passwd_sanitize ()
>  {
>      ${NOTMUCH_PYTHON} -c'
>  import os, sys, pwd, socket
> @@ -867,7 +867,7 @@ test_must_fail () {
>  # - cmp's output is not nearly as easy to read as diff -u
>  # - not all diff versions understand "-u"
>  
> -test_cmp() {
> +test_cmp () {
>  	$GIT_TEST_CMP "$@"
>  }
>  
> @@ -921,14 +921,14 @@ test_done () {
>  	fi
>  }
>  
> -test_python() {
> +test_python () {
>      # Note: if there is need to print debug information from python program,
>      # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w')
>      PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
>  	$NOTMUCH_PYTHON -B - > OUTPUT
>  }
>  
> -test_ruby() {
> +test_ruby () {
>      MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
>  }
>  
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 13/13] test: more style fixes
  2021-05-01 11:54 ` [PATCH 13/13] test: more style fixes Felipe Contreras
@ 2021-05-01 20:29   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-01 20:29 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, Felipe Contreras wrote:

> In order to fit the git coding style.

I personally disagree, and (IIRC) we don't "enforce" git coding style
but it may add to consistency and drops line count ;/

Tomi

>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  test/T140-excludes.sh          |  3 +-
>  test/T190-multipart.sh         |  3 +-
>  test/T490-parse-time-string.sh |  6 +--
>  test/export-dirs.sh            |  3 +-
>  test/test-lib-common.sh        |  6 +--
>  test/test-lib-emacs.sh         |  6 +--
>  test/test-lib.sh               | 72 ++++++++++++----------------------
>  7 files changed, 33 insertions(+), 66 deletions(-)
>
> diff --git a/test/T140-excludes.sh b/test/T140-excludes.sh
> index acab5381..352b3eb8 100755
> --- a/test/T140-excludes.sh
> +++ b/test/T140-excludes.sh
> @@ -5,8 +5,7 @@ test_description='"notmuch search, count and show" with excludes in several vari
>  # Generates a thread consisting of a top level message and 'length'
>  # replies. The subject of the top message 'subject: top message"
>  # and the subject of the nth reply in the thread is "subject: reply n"
> -generate_thread ()
> -{
> +generate_thread () {
>      local subject="$1"
>      local length="$2"
>      generate_message '[subject]="'"${subject}: top message"'"' '[body]="'"body of top message"'"'
> diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
> index 6f715ff9..3545a599 100755
> --- a/test/T190-multipart.sh
> +++ b/test/T190-multipart.sh
> @@ -725,8 +725,7 @@ EOF
>  
>  notmuch new > /dev/null
>  
> -cat_expected_head ()
> -{
> +cat_expected_head () {
>          cat <<EOF
>  [[[{"id": "htmlmessage", "match":true, "excluded": false, "date_relative":"2000-01-01",
>     "crypto": {},
> diff --git a/test/T490-parse-time-string.sh b/test/T490-parse-time-string.sh
> index d1c70cfa..f89755ed 100755
> --- a/test/T490-parse-time-string.sh
> +++ b/test/T490-parse-time-string.sh
> @@ -4,13 +4,11 @@ test_description="date/time parser module"
>  
>  # Sanity/smoke tests for the date/time parser independent of notmuch
>  
> -_date ()
> -{
> +_date () {
>      date -d "$*" +%s
>  }
>  
> -_parse_time ()
> -{
> +_parse_time () {
>      ${TEST_DIRECTORY}/parse-time --format=%s "$*"
>  }
>  
> diff --git a/test/export-dirs.sh b/test/export-dirs.sh
> index 844ee682..0a048e1f 100644
> --- a/test/export-dirs.sh
> +++ b/test/export-dirs.sh
> @@ -9,8 +9,7 @@ if [[ -z "${NOTMUCH_SRCDIR}" ]]; then
>  	export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
>  fi
>  
> -find_builddir ()
> -{
> +find_builddir () {
>  	local dir="$1"
>  
>  	while [[ -n "$dir" ]] && [[ "$dir" != "/" ]]; do
> diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
> index 2f7950ac..ebbf4cdf 100644
> --- a/test/test-lib-common.sh
> +++ b/test/test-lib-common.sh
> @@ -105,8 +105,7 @@ fi
>  gen_msg_cnt=0
>  gen_msg_filename=""
>  gen_msg_id=""
> -generate_message ()
> -{
> +generate_message () {
>      # This is our (bash-specific) magic for doing named parameters
>      local -A template="($@)"
>      local additional_headers
> @@ -225,8 +224,7 @@ EOF
>  #
>  # All of the arguments and return values supported by generate_message
>  # are also supported here, so see that function for details.
> -add_message ()
> -{
> +add_message () {
>      generate_message "$@" &&
>      notmuch new > /dev/null
>  }
> diff --git a/test/test-lib-emacs.sh b/test/test-lib-emacs.sh
> index bf875a28..dde32177 100644
> --- a/test/test-lib-emacs.sh
> +++ b/test/test-lib-emacs.sh
> @@ -28,8 +28,7 @@ test_require_emacs () {
>  # Accepts arbitrary extra emacs/elisp functions to modify the message
>  # before sending, which is useful to doing things like attaching files
>  # to the message and encrypting/signing.
> -emacs_deliver_message ()
> -{
> +emacs_deliver_message () {
>      local subject body smtp_dummy_pid smtp_dummy_port
>      subject="$1"
>      body="$2"
> @@ -75,8 +74,7 @@ emacs_deliver_message ()
>  # If any GNU-style long-arguments (like --quiet or --decrypt=true) are
>  # at the head of the argument list, they are sent directly to "notmuch
>  # new" after message delivery
> -emacs_fcc_message ()
> -{
> +emacs_fcc_message () {
>      local nmn_args subject body
>      nmn_args=''
>      while [[ "$1" =~ ^-- ]]; do
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 1b502456..1d0178f0 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -114,8 +114,7 @@ unset ALTERNATE_EDITOR
>  unset EMAIL
>  unset NAME
>  
> -add_gnupg_home ()
> -{
> +add_gnupg_home () {
>      [ -e "${GNUPGHOME}/gpg.conf" ] && return
>      _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
>      at_exit_function _gnupg_exit
> @@ -135,8 +134,7 @@ add_gnupg_home ()
>      printf '%s:6:\n' "$FINGERPRINT" | gpg --quiet --batch --no-tty --import-ownertrust
>  }
>  
> -add_gpgsm_home ()
> -{
> +add_gpgsm_home () {
>      local fpr
>      [ -e "$GNUPGHOME/gpgsm.conf" ] && return
>      _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
> @@ -268,8 +266,7 @@ then
>  fi
>  
>  test_description_printed=
> -print_test_description ()
> -{
> +print_test_description () {
>  	test -z "$test_description_printed" || return 0
>  	echo
>  	echo $this_test: "Testing ${test_description}"
> @@ -351,8 +348,7 @@ trap 'trap_signal' HUP INT TERM
>  # history of the notmuch mailing list, which allows for reliably
>  # testing commands that need to operate on a not-totally-trivial
>  # number of messages.
> -add_email_corpus ()
> -{
> +add_email_corpus () {
>      local corpus
>      corpus=${1:-default}
>  
> @@ -361,8 +357,7 @@ add_email_corpus ()
>      notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
>  }
>  
> -test_begin_subtest ()
> -{
> +test_begin_subtest () {
>      if [ -n "$inside_subtest" ]; then
>  	exec 1>&6 2>&7		# Restore stdout and stderr
>  	error "bug in test script: Missing test_expect_equal in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
> @@ -382,8 +377,7 @@ test_begin_subtest ()
>  # not accept a test name. Instead, the caller should call
>  # test_begin_subtest before calling this function in order to set the
>  # name.
> -test_expect_equal ()
> -{
> +test_expect_equal () {
>  	local output expected testname
>  	exec 1>&6 2>&7		# Restore stdout and stderr
>  	if [ -z "$inside_subtest" ]; then
> @@ -409,8 +403,7 @@ test_expect_equal ()
>  }
>  
>  # Like test_expect_equal, but takes two filenames.
> -test_expect_equal_file ()
> -{
> +test_expect_equal_file () {
>  	local file1 file2 testname basename1 basename2
>  	exec 1>&6 2>&7		# Restore stdout and stderr
>  	if [ -z "$inside_subtest" ]; then
> @@ -491,19 +484,16 @@ test_json_nodes () {
>  	fi
>  }
>  
> -NOTMUCH_NEW ()
> -{
> +NOTMUCH_NEW () {
>      notmuch new "${@}" | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
>  }
>  
> -NOTMUCH_DUMP_TAGS ()
> -{
> +NOTMUCH_DUMP_TAGS () {
>      # this relies on the default format being batch-tag, otherwise some tests will break
>      notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
>  }
>  
> -notmuch_drop_mail_headers ()
> -{
> +notmuch_drop_mail_headers () {
>      $NOTMUCH_PYTHON -c '
>  import email, sys
>  msg = email.message_from_file(sys.stdin)
> @@ -512,41 +502,34 @@ print(msg.as_string(False))
>  ' "$@"
>  }
>  
> -notmuch_exception_sanitize ()
> -{
> +notmuch_exception_sanitize () {
>      perl -pe 's/(A Xapian exception occurred at .*[.]cc?):([0-9]*)/\1:XXX/'
>  }
>  
> -notmuch_search_sanitize ()
> -{
> +notmuch_search_sanitize () {
>      perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
>  }
>  
> -notmuch_search_files_sanitize ()
> -{
> +notmuch_search_files_sanitize () {
>      notmuch_dir_sanitize
>  }
>  
> -notmuch_dir_sanitize ()
> -{
> +notmuch_dir_sanitize () {
>      sed -e "s,$MAIL_DIR,MAIL_DIR," -e "s,${PWD},CWD,g" "$@"
>  }
>  
>  NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
> -notmuch_show_sanitize ()
> -{
> +notmuch_show_sanitize () {
>      sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
>  }
> -notmuch_show_sanitize_all ()
> -{
> +notmuch_show_sanitize_all () {
>      sed \
>  	-e 's| filename:.*| filename:XXXXX|' \
>  	-e 's| id:[^ ]* | id:XXXXX |' | \
>  	notmuch_date_sanitize
>  }
>  
> -notmuch_json_show_sanitize ()
> -{
> +notmuch_json_show_sanitize () {
>      sed \
>  	-e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
>  	-e 's|"Date": "Fri, 05 Jan 2001 [^"]*0000"|"Date": "GENERATED_DATE"|g' \
> @@ -556,8 +539,7 @@ notmuch_json_show_sanitize ()
>  	-e 's|"content-length": [1-9][0-9]*|"content-length": "NONZERO"|g'
>  }
>  
> -notmuch_emacs_error_sanitize ()
> -{
> +notmuch_emacs_error_sanitize () {
>      local command
>      command=$1
>      shift
> @@ -569,24 +551,20 @@ notmuch_emacs_error_sanitize ()
>  	-e "s|^\(command: \)\{0,1\}/.*/$command|\1YYY/$command|"
>  }
>  
> -notmuch_date_sanitize ()
> -{
> +notmuch_date_sanitize () {
>      sed \
>  	-e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
>  }
>  
> -notmuch_uuid_sanitize ()
> -{
> +notmuch_uuid_sanitize () {
>      sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
>  }
>  
> -notmuch_built_with_sanitize ()
> -{
> +notmuch_built_with_sanitize () {
>      sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
>  }
>  
> -notmuch_passwd_sanitize ()
> -{
> +notmuch_passwd_sanitize () {
>      ${NOTMUCH_PYTHON} -c'
>  import os, sys, pwd, socket
>  
> @@ -606,13 +584,11 @@ for l in sys.stdin:
>  '
>  }
>  
> -notmuch_config_sanitize ()
> -{
> +notmuch_config_sanitize () {
>      notmuch_dir_sanitize | notmuch_built_with_sanitize
>  }
>  
> -notmuch_show_part ()
> -{
> +notmuch_show_part () {
>      awk '/^\014part}/{ f=0 }; { if (f) { print $0 } } /^\014part{ ID: '"$1"'/{ f=1 }'
>  }
>  
> -- 
> 2.31.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 00/13] test: several fixes and improvements
  2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
                   ` (12 preceding siblings ...)
  2021-05-01 11:54 ` [PATCH 13/13] test: more style fixes Felipe Contreras
@ 2021-05-02  0:36 ` David Bremner
  2021-05-02  5:08   ` Tomi Ollila
  13 siblings, 1 reply; 29+ messages in thread
From: David Bremner @ 2021-05-02  0:36 UTC (permalink / raw)
  To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

Felipe Contreras <felipe.contreras@gmail.com> writes:

> The current tests fail on my machine due to my configuration, mainly because I didn't have dtach
> installed, but also other stuff.
>
> The following patches fix all the issues I found, and also do plenty of cleanups.

I have applied 1,2,4,5,6,7 to master.  10, 11, and 12 are also marked
ready to apply, but currently don't because of skipped patches.

d

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 00/13] test: several fixes and improvements
  2021-05-02  0:36 ` [PATCH 00/13] test: several fixes and improvements David Bremner
@ 2021-05-02  5:08   ` Tomi Ollila
  0 siblings, 0 replies; 29+ messages in thread
From: Tomi Ollila @ 2021-05-02  5:08 UTC (permalink / raw)
  To: David Bremner, Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor

On Sat, May 01 2021, David Bremner wrote:

> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> The current tests fail on my machine due to my configuration, mainly because I didn't have dtach
>> installed, but also other stuff.
>>
>> The following patches fix all the issues I found, and also do plenty of cleanups.
>
> I have applied 1,2,4,5,6,7 to master.  10, 11, and 12 are also marked
> ready to apply, but currently don't because of skipped patches.

Good progress !

Now in the morning, after good night's sleep, I think of the following:

The following changes could be done (in 2 or 3 (3 for consistency) places):

--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -375,18 +375,19 @@ test_begin_subtest "load default values"
 export MAILDIR=${MAIL_DIR}
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} '' %NULL%
 {
     notmuch_config_key_t key;
     for (key = NOTMUCH_CONFIG_FIRST;
         key < NOTMUCH_CONFIG_LAST;
         key = (notmuch_config_key_t)(key + 1)) {
         const char *val = notmuch_config_get (db, key);
         printf("%s\n", val ? val : "NULL" );
+        printf("%s = %s\n", key, val ? val : "NULL" );
     }
 }
 EOF
 
Then, update the EXPECTED strings.

Finally, move the notmuch_passwd_sanitize () from lib to 
T590-libconfig.sh (perhaps rename to more "specialized"
name) and change it to first match key before replacing
the value in the c program output (and replace to empty
strings, too!).

I am soon going somewhere, I'll look this in the evening
in (+0300 timezone) unless someone(tm) is faster there...

>
> d

Tomi

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2021-05-02  5:08 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-01 11:54 [PATCH 00/13] test: several fixes and improvements Felipe Contreras
2021-05-01 11:54 ` [PATCH 01/13] test: fix passwd_sanitize() Felipe Contreras
2021-05-01 20:01   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 02/13] test: unset NAME environment variable Felipe Contreras
2021-05-01 20:01   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 03/13] test: remove USER_FULL_NAME when not present Felipe Contreras
2021-05-01 20:13   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 04/13] test: use correct fqdn in passwd_sanitize() Felipe Contreras
2021-05-01 20:14   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 05/13] test: fix wrong SKIP messages Felipe Contreras
2021-05-01 20:18   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 06/13] test: add prereqs check in test_emacs_expect_t Felipe Contreras
2021-05-01 20:18   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 07/13] test: add external prereqs to many emacs tests Felipe Contreras
2021-05-01 20:19   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 08/13] test: split emacs functionality to its own file Felipe Contreras
2021-05-01 20:28   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 09/13] test: emacs: simplify missing dependencies check Felipe Contreras
2021-05-01 20:20   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 10/13] test: emacs: check for configured emacs Felipe Contreras
2021-05-01 20:20   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 11/13] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
2021-05-01 20:21   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 12/13] test: trivial style cleanups Felipe Contreras
2021-05-01 20:28   ` Tomi Ollila
2021-05-01 11:54 ` [PATCH 13/13] test: more style fixes Felipe Contreras
2021-05-01 20:29   ` Tomi Ollila
2021-05-02  0:36 ` [PATCH 00/13] test: several fixes and improvements David Bremner
2021-05-02  5:08   ` Tomi Ollila

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).