X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=test%2Ftest-lib.sh;h=9f0d7e02a3d940454edf1e5b71888e6a4e6815ed;hp=c505e76432669db0f0bdba8f5898de1a0d423a2e;hb=e1bd4f23634a88a49256c74e0780dd1dcdb852cd;hpb=1092c747ef99b757b7e31f8a0b8f12f0d5e556d3 diff --git a/test/test-lib.sh b/test/test-lib.sh index c505e764..9f0d7e02 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -26,6 +26,13 @@ fi # Make sure echo builtin does not expand backslash-escape sequences by default. shopt -u xpg_echo +# It appears that people try to run tests without building... +if ! test -x ../notmuch +then + echo >&2 'You do not seem to have built notmuch yet.' + exit 1 +fi + this_test=${0##*/} this_test=${this_test%.sh} this_test_bare=${this_test#T[0-9][0-9][0-9]-} @@ -93,6 +100,23 @@ unset GREP_OPTIONS # For emacsclient unset ALTERNATE_EDITOR +add_gnupg_home () +{ + local output + [ -d ${GNUPGHOME} ] && return + _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; } + at_exit_function _gnupg_exit + mkdir -m 0700 "$GNUPGHOME" + gpg --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1 + test_debug "cat $GNUPGHOME/import.log" + if (gpg --quick-random --version >/dev/null 2>&1) ; then + echo quick-random >> "$GNUPGHOME"/gpg.conf + elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then + echo debug-quick-random >> "$GNUPGHOME"/gpg.conf + fi + echo no-emit-version >> "$GNUPGHOME"/gpg.conf +} + # Each test should start with something like this, after copyright notices: # # test_description='Description of this test... @@ -450,9 +474,10 @@ test_expect_equal_json () { # The test suite forces LC_ALL=C, but this causes Python 3 to # decode stdin as ASCII. We need to read JSON in UTF-8, so # override Python's stdio encoding defaults. - output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \ + local script='import json, sys; json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)' + output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \ || echo "$1") - expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \ + expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "$script" \ || echo "$2") shift 2 test_expect_equal "$output" "$expected" "$@" @@ -506,6 +531,16 @@ NOTMUCH_DUMP_TAGS () notmuch dump --include=tags "${@}" | sed '/^#/d' | sort } +notmuch_drop_mail_headers () +{ + $NOTMUCH_PYTHON -c ' +import email, sys +msg = email.message_from_file(sys.stdin) +for hdr in sys.argv[1:]: del msg[hdr] +print(msg.as_string(False)) +' "$@" +} + notmuch_search_sanitize () { perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'