X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=test%2Ftest-lib.sh;h=e1a597f716946b34695b5dc045b27c03c7bf6b92;hb=cd9ec20a49b731276ed5f0838b4f0782c281e239;hp=29baa0c17d966f0012438aa7d60738778f819a7b;hpb=6a7b61b1d50bf25ebce61fa58af1c195951b387c;p=notmuch diff --git a/test/test-lib.sh b/test/test-lib.sh index 29baa0c1..e1a597f7 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -104,11 +104,25 @@ unset CDPATH unset GREP_OPTIONS +# For lib/open.cc:_load_key_file +unset XDG_CONFIG_HOME + # For emacsclient unset ALTERNATE_EDITOR -add_gnupg_home () -{ +# for reproducibility +unset EMAIL +unset NAME + +test_require_emacs () { + 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 () { [ -e "${GNUPGHOME}/gpg.conf" ] && return _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; } at_exit_function _gnupg_exit @@ -128,8 +142,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; } @@ -261,8 +274,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}" @@ -342,8 +354,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" @@ -389,8 +400,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 @@ -428,8 +438,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} @@ -438,8 +447,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]}" @@ -459,8 +467,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 @@ -486,8 +493,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 @@ -585,6 +591,9 @@ test_emacs_expect_t () { 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 ] @@ -600,19 +609,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) @@ -621,41 +627,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' \ @@ -665,8 +664,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 @@ -678,29 +676,44 @@ 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_config_sanitize () -{ +notmuch_passwd_sanitize () { + ${NOTMUCH_PYTHON} -c' +import os, sys, pwd, socket + +pw = pwd.getpwuid(os.getuid()) +user = pw.pw_name +name = pw.pw_gecos.partition(",")[0] +fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3] + +for l in sys.stdin: + if user: + l = l.replace(user, "USERNAME") + if fqdn: + l = l.replace(fqdn, "FQDN").replace(".(none)","") + if name: + l = l.replace(name, "USER_FULL_NAME") + sys.stdout.write(l) +' +} + +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 }' } @@ -891,7 +904,7 @@ test_expect_success () { test_run_ "$1" run_ret="$?" # test_run_ may update missing external prerequisites - test_check_missing_external_prereqs_ "$@" || + test_check_missing_external_prereqs_ "$test_subtest_name" || if [ "$run_ret" = 0 -a "$eval_ret" = 0 ] then test_ok_ @@ -915,7 +928,7 @@ test_expect_code () { test_run_ "$2" run_ret="$?" # test_run_ may update missing external prerequisites, - test_check_missing_external_prereqs_ "$@" || + test_check_missing_external_prereqs_ "$test_subtest_name" || if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ] then test_ok_ @@ -955,7 +968,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 "$@" } @@ -1037,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" @@ -1080,17 +1089,13 @@ 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}" \ $NOTMUCH_PYTHON -B - > OUTPUT } -test_ruby() { - MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT -} - test_C () { local exec_file test_file exec_file="test${test_count}" @@ -1117,7 +1122,7 @@ notmuch_with_shim () { base_name="$1" shift shim_file="${base_name}.so" - LD_PRELOAD=./${shim_file}${LD_PRELOAD:+:$LD_PRELOAD} notmuch-shared "$@" + LD_PRELOAD=${LD_PRELOAD:+:$LD_PRELOAD}:./${shim_file} notmuch-shared "$@" } # Creates a script that counts how much time it is executed and calls @@ -1271,3 +1276,4 @@ test_declare_external_prereq openssl test_declare_external_prereq gpgsm test_declare_external_prereq ${NOTMUCH_PYTHON} test_declare_external_prereq xapian-metadata +test_declare_external_prereq xapian-delve