mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
notmuch-test: Use named-parameters for generate_message function
This makes the test suite bash-specific, but that's not much of an issue for me, (if somebody else would prefer some other language then they can rewrite the test suite and maintain it). The advantage here is that we'll now be able to easily generate custom messages for testing operations that depend on the message content, (such as "notmuch reply", etc.).
This commit is contained in:
parent
8d37b2f982
commit
0d67c52f4d
1 changed files with 26 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
find_notmuch_binary ()
|
find_notmuch_binary ()
|
||||||
|
@ -25,17 +25,29 @@ find_notmuch_binary ()
|
||||||
#
|
#
|
||||||
# The filename of the message generated is available as
|
# The filename of the message generated is available as
|
||||||
# $gen_msg_filename
|
# $gen_msg_filename
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
gen_msg_cnt=0
|
gen_msg_cnt=0
|
||||||
gen_msg_filename=""
|
gen_msg_filename=""
|
||||||
generate_message ()
|
generate_message ()
|
||||||
{
|
{
|
||||||
|
# This is our (bash-specific) magic for doing named parameters
|
||||||
|
local -A template="($@)"
|
||||||
|
|
||||||
gen_msg_cnt=$((gen_msg_cnt + 1))
|
gen_msg_cnt=$((gen_msg_cnt + 1))
|
||||||
gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
|
gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
|
||||||
|
|
||||||
if [ "$#" = "0" ]; then
|
if [ -z "${template[dir]}" ]; then
|
||||||
gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
|
gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
|
||||||
else
|
else
|
||||||
gen_msg_filename="${MAIL_DIR}/$1/$gen_msg_name"
|
gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
|
||||||
mkdir -p $(dirname $gen_msg_filename)
|
mkdir -p $(dirname $gen_msg_filename)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -114,7 +126,7 @@ printf " New directories...\t\t"
|
||||||
rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
|
rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
|
||||||
mkdir ${MAIL_DIR}/def
|
mkdir ${MAIL_DIR}/def
|
||||||
mkdir ${MAIL_DIR}/ghi
|
mkdir ${MAIL_DIR}/ghi
|
||||||
generate_message def
|
generate_message [dir]=def
|
||||||
|
|
||||||
execute_expecting new "Added 1 new message to the database."
|
execute_expecting new "Added 1 new message to the database."
|
||||||
|
|
||||||
|
@ -123,7 +135,7 @@ printf " Alternate inode order...\t"
|
||||||
rm -rf ${MAIL_DIR}/.notmuch
|
rm -rf ${MAIL_DIR}/.notmuch
|
||||||
mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
|
mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
|
||||||
rm ${MAIL_DIR}/def/*
|
rm ${MAIL_DIR}/def/*
|
||||||
generate_message abc
|
generate_message [dir]=abc
|
||||||
|
|
||||||
execute_expecting new "Added 1 new message to the database."
|
execute_expecting new "Added 1 new message to the database."
|
||||||
|
|
||||||
|
@ -157,9 +169,9 @@ execute_expecting new "No new mail. Removed 1 message."
|
||||||
printf " Renamed directory...\t\t"
|
printf " Renamed directory...\t\t"
|
||||||
|
|
||||||
do_sleep
|
do_sleep
|
||||||
generate_message dir
|
generate_message [dir]=dir
|
||||||
generate_message dir
|
generate_message [dir]=dir
|
||||||
generate_message dir
|
generate_message [dir]=dir
|
||||||
|
|
||||||
$NOTMUCH new > /dev/null
|
$NOTMUCH new > /dev/null
|
||||||
|
|
||||||
|
@ -178,9 +190,9 @@ execute_expecting new "No new mail. Removed 3 messages."
|
||||||
printf " New directory (at end of list)... "
|
printf " New directory (at end of list)... "
|
||||||
|
|
||||||
do_sleep
|
do_sleep
|
||||||
generate_message zzz
|
generate_message [dir]=zzz
|
||||||
generate_message zzz
|
generate_message [dir]=zzz
|
||||||
generate_message zzz
|
generate_message [dir]=zzz
|
||||||
|
|
||||||
execute_expecting new "Added 3 new messages to the database."
|
execute_expecting new "Added 3 new messages to the database."
|
||||||
|
|
||||||
|
@ -214,9 +226,9 @@ execute_expecting new "Added 1 new message to the database."
|
||||||
printf " New two-level directory...\t"
|
printf " New two-level directory...\t"
|
||||||
|
|
||||||
do_sleep
|
do_sleep
|
||||||
generate_message two/levels
|
generate_message [dir]=two/levels
|
||||||
generate_message two/levels
|
generate_message [dir]=two/levels
|
||||||
generate_message two/levels
|
generate_message [dir]=two/levels
|
||||||
|
|
||||||
execute_expecting new "Added 3 new messages to the database."
|
execute_expecting new "Added 3 new messages to the database."
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue