unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 29d5c919e3ea85a8ec768698de84c86cfc91b68f 6605 bytes (raw)
name: test/notmuch-test 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
 
#!/bin/bash
set -e

# Messages contain time/date values with time zone and notmuch
# displays them converted to the local time zone. We need to set fixed
# timezone here so that the output of the tests is always the same
# without regard to the time zone of where the test suite is run.
export TZ=UTC+8

TEST_COLLECTION_DIR="$(dirname $(readlink -f $0))/tests"

TEST_COLLECTIONS="notmuch-new
notmuch-search
json
thread-naming
notmuch-reply
uuencoded
notmuch-dump-restore
out-of-order-threading
author-reordering
from-guessing-multiple
from-guessing-single"

find_notmuch_binary ()
{
    dir=$1

    while [ -n "$dir" ]; do
	bin=$dir/notmuch
	if [ -x $bin ]; then
	    echo $bin
	    return
	fi
	dir=$(dirname $dir)
	if [ "$dir" = "/" ]; then
	    break
	fi
    done

    echo notmuch
}

increment_mtime_amount=0
increment_mtime ()
{
    dir=$1

    increment_mtime_amount=$((increment_mtime_amount + 1))
    touch -d "+${increment_mtime_amount} seconds" $dir
}

# Generate a new message in the mail directory, with a unique message
# ID and subject. The message is not added to the index.
#
# After this function returns, the filename of the generated message
# is available as $gen_msg_filename and the message ID is available as
# $gen_msg_id .
#
# This function supports named parameters with the bash syntax for
# assigning a value to an associative array ([name]=value). The
# supported parameters are:
#
#  [dir]=directory/of/choice
#
#	Generate the message in directory 'directory/of/choice' within
#	the mail store. The directory will be created if necessary.
#
#  [body]=text
#
#	Text to use as the body of the email message
#
#  '[from]="Some User <user@example.com>"'
#  '[to]="Some User <user@example.com>"'
#  '[subject]="Subject of email message"'
#  '[date]="RFC 822 Date"'
#
#	Values for email headers. If not provided, default values will
#	be generated instead.
#
#  '[cc]="Some User <user@example.com>"'
#  [reply-to]=some-address
#  [in-reply-to]=<message-id>
#  '[header]=full header line, including keyword'
#
#	Additional values for email headers. If these are not provided
#	then the relevant headers will simply not appear in the
#	message.
#
#  '[id]=<message-id>'
#
#	Controls the message-id of the created message.
gen_msg_cnt=0
gen_msg_filename=""
gen_msg_id=""
generate_message ()
{
    # This is our (bash-specific) magic for doing named parameters
    local -A template="($@)"
    local additional_headers

    if [ -z "${template[id]}" ]; then
	gen_msg_cnt=$((gen_msg_cnt + 1))
	gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
	gen_msg_id="${gen_msg_name}@notmuch-test-suite"
    else
	gen_msg_name="msg-${template[id]}"
	gen_msg_id="${template[id]}"
    fi

    if [ -z "${template[dir]}" ]; then
	gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
    else
	gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
	mkdir -p $(dirname $gen_msg_filename)
    fi

    if [ -z "${template[body]}" ]; then
	template[body]="This is just a test message (#${gen_msg_cnt})"
    fi

    if [ -z "${template[from]}" ]; then
	template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
    fi

    if [ -z "${template[to]}" ]; then
	template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
    fi

    if [ -z "${template[subject]}" ]; then
	template[subject]="Test message #${gen_msg_cnt}"
    fi

    if [ -z "${template[date]}" ]; then
	template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
    fi

    additional_headers=""
    if [ ! -z "${template[header]}" ]; then
	additional_headers="${template[header]}
${additional_headers}"
    fi

    if [ ! -z "${template[reply-to]}" ]; then
	additional_headers="Reply-To: ${template[reply-to]}
${additional_headers}"
    fi

    if [ ! -z "${template[in-reply-to]}" ]; then
	additional_headers="In-Reply-To: ${template[in-reply-to]}
${additional_headers}"
    fi

    if [ ! -z "${template[cc]}" ]; then
	additional_headers="Cc: ${template[cc]}
${additional_headers}"
    fi


cat <<EOF >$gen_msg_filename
From: ${template[from]}
To: ${template[to]}
Message-Id: <${gen_msg_id}>
Subject: ${template[subject]}
Date: ${template[date]}
${additional_headers}
${template[body]}
EOF

    # Ensure that the mtime of the containing directory is updated
    increment_mtime $(dirname ${gen_msg_filename})
}

# Generate a new message and add it to the index.
#
# All of the arguments and return values supported by generate_message
# are also supported here, so see that function for details.
add_message ()
{
    generate_message "$@"

    $NOTMUCH new > /dev/null
}

tests=0
test_failures=0

pass_if_equal ()
{
    output=$1
    expected=$2

    tests=$((tests + 1))

    if [ "$output" = "$expected" ]; then
	echo "	PASS"
    else
	echo "	FAIL"
	testname=test-$(printf "%03d" $tests)
	echo "$expected" > $testname.expected
	echo "$output" > $testname.output
	diff -u $testname.expected $testname.output || true
	test_failures=$((test_failures + 1))
    fi
}

TEST_DIR=$(pwd)/test.$$
MAIL_DIR=${TEST_DIR}/mail
export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
NOTMUCH=$(find_notmuch_binary $(pwd))

NOTMUCH_NEW ()
{
    $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
}

notmuch_search_sanitize ()
{
    sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
}

NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
notmuch_show_sanitize ()
{
    sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
}

initialize_notmuch_test ()
{
    rm -rf ${TEST_DIR}
    mkdir ${TEST_DIR}
    cd ${TEST_DIR}

    mkdir ${MAIL_DIR}

    cat <<EOF > ${NOTMUCH_CONFIG}
[database]
path=${MAIL_DIR}

[user]
name=Notmuch Test Suite
primary_email=test_suite@notmuchmail.org
other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
EOF
}

run_collection_setup_and_tests ()
{
    for testfile in $(find ${TEST_COLLECTION_DIR}/$1 \
	-name "*.test" -o -name "*.setup" |
	sort -n);
    do
	source $testfile
    done
}

run_test_suite ()
{
    initialize_notmuch_test;

    if [ "$#" = "0" -o "$1" = "all" ]; then
	for dir in $(echo ${TEST_COLLECTIONS}); do
	    run_collection_setup_and_tests "$(basename ${dir})";
	done;
    elif [ ! -d "${TEST_COLLECTION_DIR}/$1" ]; then
	echo "${TEST_COLLECTION_DIR}/$1 is not a directory"
	exit
    else
	run_collection_setup_and_tests "$1";
    fi
}

run_test_suite $1

echo ""
echo "Notmuch test suite complete."

if [ "$test_failures" = "0" ]; then
    echo "All $tests tests passed."
    rm -rf ${TEST_DIR}
else
    echo "$test_failures/$tests tests failed. The failures can be investigated in:"
    echo "${TEST_DIR}"
fi

echo ""

exit $test_failures

debug log:

solving 29d5c91 ...
found 29d5c91 in https://yhetil.org/notmuch/87fx2cdagi.fsf@jhu.edu/
found a861df1 in https://yhetil.org/notmuch.git/
preparing index
index prepared:
100755 a861df16cdcdc8968c2b7d5a41bbec48b9df97e3	test/notmuch-test

applying [1/1] https://yhetil.org/notmuch/87fx2cdagi.fsf@jhu.edu/
diff --git a/test/notmuch-test b/test/notmuch-test
index a861df1..29d5c91 100755

Checking patch test/notmuch-test...
Applied patch test/notmuch-test cleanly.

index at:
100755 29d5c919e3ea85a8ec768698de84c86cfc91b68f	test/notmuch-test

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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