* [PATCH v2 1/6] test: trivial style cleanups
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 2/6] test: more style fixes Felipe Contreras
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 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 +-
| 10 +++++-----
test/export-dirs.sh | 2 +-
test/test-lib.sh | 6 +++---
5 files changed, 11 insertions(+), 11 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\"" \
--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 d46bb4c3..3147b782 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -710,7 +710,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
@@ -992,7 +992,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 "$@"
}
@@ -1117,7 +1117,7 @@ test_emacs () {
${TEST_EMACSCLIENT} --socket-name="$EMACS_SERVER" --eval "(notmuch-test-progn $*)"
}
-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}" \
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/6] test: more style fixes
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 1/6] test: trivial style cleanups Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-16 12:08 ` David Bremner
2021-05-15 20:47 ` [PATCH v2 3/6] test: emacs: simplify missing dependencies check Felipe Contreras
` (4 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 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.sh | 78 ++++++++++++----------------------
6 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.sh b/test/test-lib.sh
index 3147b782..c1395c87 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -120,8 +120,7 @@ test_require_emacs () {
test_require_external_prereq dtach
}
-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
@@ -141,8 +140,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; }
@@ -274,8 +272,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}"
@@ -355,8 +352,7 @@ trap 'trap_signal' HUP INT TERM
# 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"
@@ -402,8 +398,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
@@ -441,8 +436,7 @@ emacs_fcc_message ()
# 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}
@@ -451,8 +445,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]}"
@@ -472,8 +465,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
@@ -499,8 +491,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
@@ -616,19 +607,16 @@ test_emacs_expect_t () {
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)
@@ -637,41 +625,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' \
@@ -681,8 +662,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
@@ -694,24 +674,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
@@ -731,13 +707,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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/6] test: more style fixes
2021-05-15 20:47 ` [PATCH v2 2/6] test: more style fixes Felipe Contreras
@ 2021-05-16 12:08 ` David Bremner
2021-05-16 18:16 ` Felipe Contreras
0 siblings, 1 reply; 11+ messages in thread
From: David Bremner @ 2021-05-16 12:08 UTC (permalink / raw)
To: Felipe Contreras, notmuch
Felipe Contreras <felipe.contreras@gmail.com> writes:
> In order to fit the git coding style.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
I personally prefer this style, but I have to point out that the C and
C++ code in the code base (including the Ruby bindings) use the
"brace-on-the-next-line" style. Should we strive for consistency with
the C code, or is there some overriding concern here? Tomi mentioned
compactness; is that more important for shell scripts? Whatever we
decide, I guess it should be documented in test/README. For the record,
I don't think restyling the rest of the codebase to match is a good
option.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/6] test: more style fixes
2021-05-16 12:08 ` David Bremner
@ 2021-05-16 18:16 ` Felipe Contreras
2021-05-17 11:16 ` David Bremner
0 siblings, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2021-05-16 18:16 UTC (permalink / raw)
To: David Bremner; +Cc: notmuch@notmuchmail.org
On Sun, May 16, 2021 at 7:08 AM David Bremner <david@tethera.net> wrote:
>
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
> > In order to fit the git coding style.
> >
> > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
>
> I personally prefer this style, but I have to point out that the C and
> C++ code in the code base (including the Ruby bindings) use the
> "brace-on-the-next-line" style. Should we strive for consistency with
> the C code, or is there some overriding concern here?
I consistently code in C, Ruby, shell, Python, and Javascript. Each
one has different idioms, and in each one people tend to have
different styles. For example in C people tend to use tabs of 8
spaces, in Python 4, and in Ruby 2.
I personally have different styles depending on the language, and I
don't know any project that tries to be consistent among languages.
The testing framework for example seems to come from the git project,
which has a C style of:
void function(void)
{
}
But a shell style of:
function () {
}
I may have been spoiled by them, but I like both styles. Additionally
the testing framework was split into the sharness project [1], which
obviously has the same shell style. BTW, at some point you might want
to use sharness, instead of maintaining your own testing framework.
So my vote is no: we should not strive with consistency with the C
code. The original git shell style is fine, and if we adopt it, we can
refer to it in test/README instead of defining our own.
Cheers.
[1] https://github.com/chriscool/sharness
--
Felipe Contreras
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/6] test: more style fixes
2021-05-16 18:16 ` Felipe Contreras
@ 2021-05-17 11:16 ` David Bremner
0 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2021-05-17 11:16 UTC (permalink / raw)
To: Felipe Contreras; +Cc: notmuch@notmuchmail.org
Felipe Contreras <felipe.contreras@gmail.com> writes:
> The testing framework for example seems to come from the git project,
> which has a C style of:
>
> void function(void)
> {
> }
>
> But a shell style of:
>
> function () {
> }
I looked at the existing code, and it does seem to mostly use the latter
style. So I guess this change is less disruptive than flipping
everything the other way.
> I may have been spoiled by them, but I like both styles. Additionally
> the testing framework was split into the sharness project [1], which
> obviously has the same shell style. BTW, at some point you might want
> to use sharness, instead of maintaining your own testing framework.
That would depend how much work is involved in porting 17k+ lines of tests.
> So my vote is no: we should not strive with consistency with the C
> code. The original git shell style is fine, and if we adopt it, we can
> refer to it in test/README instead of defining our own.
Here again I'd want to see how much change to the test suite is
necessary to conform. I noticed a few things (like the location of
"then") where we don't currently follow the git shell style very closely.
d
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/6] test: emacs: simplify missing dependencies check
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 1/6] test: trivial style cleanups Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 2/6] test: more style fixes Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 4/6] test: emacs: check for configured emacs Felipe Contreras
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 UTC (permalink / raw)
To: notmuch; +Cc: Daniel Kahn Gillmor
No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
test/test-lib.sh | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/test/test-lib.sh b/test/test-lib.sh
index c1395c87..e1a597f7 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -115,9 +115,11 @@ unset EMAIL
unset NAME
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
}
add_gnupg_home () {
@@ -1048,11 +1050,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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 4/6] test: emacs: check for configured emacs
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
` (2 preceding siblings ...)
2021-05-15 20:47 ` [PATCH v2 3/6] test: emacs: simplify missing dependencies check Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 5/6] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 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.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test-lib.sh b/test/test-lib.sh
index e1a597f7..5c56bc22 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -116,7 +116,7 @@ unset NAME
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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 5/6] test: emacs: fix a couple of shellcheck complaints
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
` (3 preceding siblings ...)
2021-05-15 20:47 ` [PATCH v2 4/6] test: emacs: check for configured emacs Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-15 20:47 ` [PATCH v2 6/6] test: split emacs functionality to its own file Felipe Contreras
2021-05-17 11:17 ` [PATCH v2 0/6] test: several cleanups David Bremner
6 siblings, 0 replies; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 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.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 5c56bc22..756e5baf 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -116,8 +116,8 @@ unset NAME
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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 6/6] test: split emacs functionality to its own file
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
` (4 preceding siblings ...)
2021-05-15 20:47 ` [PATCH v2 5/6] test: emacs: fix a couple of shellcheck complaints Felipe Contreras
@ 2021-05-15 20:47 ` Felipe Contreras
2021-05-17 11:17 ` [PATCH v2 0/6] test: several cleanups David Bremner
6 siblings, 0 replies; 11+ messages in thread
From: Felipe Contreras @ 2021-05-15 20:47 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 +
| 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 | 209 +++++++++++++++++++++++++
test/test-lib.sh | 195 -----------------------
21 files changed, 241 insertions(+), 195 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 851ef64e..1ece6e00 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
##################################################
--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..dde32177
--- /dev/null
+++ b/test/test-lib-emacs.sh
@@ -0,0 +1,209 @@
+#
+# 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 () {
+ local ret=0
+ 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
+}
+
+# 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
+ test_require_emacs || return
+
+ if [ -z "$EMACS_SERVER" ]; then
+ emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
+ if [ -f "$emacs_tests" ]; then
+ load_emacs_tests="--eval '(load \"$emacs_tests\")'"
+ else
+ load_emacs_tests=
+ fi
+ server_name="notmuch-test-suite-$$"
+ # start a detached session with an emacs server
+ # user's TERM (or 'vt100' in case user's TERM is known dumb
+ # or unknown) is given to dtach which assumes a minimally
+ # VT100-compatible terminal -- and emacs inherits that
+ TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
+ sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
+ --no-window-system \
+ $load_emacs_tests \
+ --eval '(setq server-name \"$server_name\")' \
+ --eval '(server-start)' \
+ --eval '(orphan-watchdog $$)'" || return
+ EMACS_SERVER="$server_name"
+ # wait until the emacs server is up
+ until test_emacs '()' >/dev/null 2>/dev/null; do
+ sleep 1
+ done
+ fi
+
+ # 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 756e5baf..89eb744d 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -114,14 +114,6 @@ unset ALTERNATE_EDITOR
unset EMAIL
unset NAME
-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 dtach || ret=1
- return $ret
-}
-
add_gnupg_home () {
[ -e "${GNUPGHOME}/gpg.conf" ] && return
_gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
@@ -348,88 +340,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.
@@ -574,41 +484,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'
}
@@ -1022,73 +897,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
- test_require_emacs || return
-
- if [ -z "$EMACS_SERVER" ]; then
- emacs_tests="$NOTMUCH_SRCDIR/test/${this_test_bare}.el"
- if [ -f "$emacs_tests" ]; then
- load_emacs_tests="--eval '(load \"$emacs_tests\")'"
- else
- load_emacs_tests=
- fi
- server_name="notmuch-test-suite-$$"
- # start a detached session with an emacs server
- # user's TERM (or 'vt100' in case user's TERM is known dumb
- # or unknown) is given to dtach which assumes a minimally
- # VT100-compatible terminal -- and emacs inherits that
- TERM=$SMART_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
- sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
- --no-window-system \
- $load_emacs_tests \
- --eval '(setq server-name \"$server_name\")' \
- --eval '(server-start)' \
- --eval '(orphan-watchdog $$)'" || return
- EMACS_SERVER="$server_name"
- # wait until the emacs server is up
- until test_emacs '()' >/dev/null 2>/dev/null; do
- sleep 1
- done
- fi
-
- # 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')
@@ -1178,9 +986,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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/6] test: several cleanups
2021-05-15 20:47 [PATCH v2 0/6] test: several cleanups Felipe Contreras
` (5 preceding siblings ...)
2021-05-15 20:47 ` [PATCH v2 6/6] test: split emacs functionality to its own file Felipe Contreras
@ 2021-05-17 11:17 ` David Bremner
6 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2021-05-17 11:17 UTC (permalink / raw)
To: Felipe Contreras, notmuch; +Cc: Daniel Kahn Gillmor
Felipe Contreras <felipe.contreras@gmail.com> writes:
> Many cleanups from the last time I sent this series were not picked, I've rebased and reordered the
> patches so they have a better chance of being picked up.
>
> I only dropped the patch about USER_FULL_NAME, maybe there's a better way to do it, and this way the
> entire patch series is about cleanups.
applied to master
^ permalink raw reply [flat|nested] 11+ messages in thread