]> git.notmuchmail.org Git - notmuch/blobdiff - test/test-lib.sh
test: make it possible to have multiple corpora
[notmuch] / test / test-lib.sh
index 4a8ef1f46b478b376728b3c15965fbddf9a4a9df..e2e26e6f274a1260ac570b09cd92f27ae90f1478 100644 (file)
@@ -541,21 +541,26 @@ emacs_fcc_message ()
     notmuch new >/dev/null
 }
 
-# Generate a corpus of email and add it to the database.
+# Add an existing, fixed corpus of email to the database.
 #
-# This corpus is fixed, (it happens to be 50 messages from early in
-# the history of the notmuch mailing list), which allows for reliably
+# $1 is the corpus dir under corpora to add, using "default" if unset.
+#
+# The default corpus is based on about 50 messages from early in the
+# 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 ()
 {
+    corpus=${1:-default}
+
     rm -rf ${MAIL_DIR}
-    if [ -d $TEST_DIRECTORY/corpus.mail ]; then
-       cp -a $TEST_DIRECTORY/corpus.mail ${MAIL_DIR}
+    if [ -d $TEST_DIRECTORY/corpora.mail/$corpus ]; then
+       cp -a $TEST_DIRECTORY/corpora.mail/$corpus ${MAIL_DIR}
     else
-       cp -a $TEST_DIRECTORY/corpus ${MAIL_DIR}
+       cp -a $TEST_DIRECTORY/corpora/$corpus ${MAIL_DIR}
        notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
-       cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpus.mail
+       mkdir -p $TEST_DIRECTORY/corpora.mail
+       cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpora.mail/$corpus
     fi
 }
 
@@ -1192,15 +1197,13 @@ test_emacs () {
 }
 
 test_python() {
-       export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
-       export PYTHONPATH=$TEST_DIRECTORY/../bindings/python
-
-       (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \
-               | $NOTMUCH_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="$TEST_DIRECTORY/../bindings/python${PYTHONPATH:+:$PYTHONPATH}" \
+       $NOTMUCH_PYTHON -B - > OUTPUT
 }
 
 test_ruby() {
-    export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
     MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
 }
 
@@ -1208,8 +1211,7 @@ test_C () {
     exec_file="test${test_count}"
     test_file="${exec_file}.c"
     cat > ${test_file}
-    export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib
-    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
+    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
     echo "== stdout ==" > OUTPUT.stdout
     echo "== stderr ==" > OUTPUT.stderr
     ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr