X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=test%2Ftest-lib.sh;h=f34b1fb86af15eb89b91c328e2558d0f0eb8207b;hp=82c686ca074030e86397693775512c764751b690;hb=d29ff5699de10394d7fdab41ce1c39e18c736332;hpb=2903b32f79dcf7789a2b015c48194cb40ac71462 diff --git a/test/test-lib.sh b/test/test-lib.sh index 82c686ca..f34b1fb8 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -318,7 +318,11 @@ generate_message () fi if [ -z "${template[subject]}" ]; then - template[subject]="Test message #${gen_msg_cnt}" + if [ -n "$test_subtest_name" ]; then + template[subject]="$test_subtest_name" + else + template[subject]="Test message #${gen_msg_cnt}" + fi fi if [ -z "${template[date]}" ]; then @@ -356,6 +360,11 @@ ${additional_headers}" ${additional_headers}" fi + if [ ! -z "${template[content-transfer-encoding]}" ]; then + additional_headers="Content-Transfer-Encoding: ${template[content-transfer-encoding]} +${additional_headers}" + fi + # Note that in the way we're setting it above and using it below, # `additional_headers' will also serve as the header / body separator # (empty line in between). @@ -488,21 +497,60 @@ test_expect_equal_file () test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_equal" - output="$1" - expected="$2" + file1="$1" + file2="$2" if ! test_skip "$test_subtest_name" then - if diff -q "$expected" "$output" >/dev/null ; then + if diff -q "$file1" "$file2" >/dev/null ; then test_ok_ "$test_subtest_name" else testname=$this_test.$test_count - cp "$output" $testname.output - cp "$expected" $testname.expected - test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)" + cp "$file1" "$testname.$file1" + cp "$file2" "$testname.$file2" + test_failure_ "$test_subtest_name" "$(diff -u "$testname.$file1" "$testname.$file2")" fi fi } +# Like test_expect_equal, but arguments are JSON expressions to be +# canonicalized before diff'ing. If an argument cannot be parsed, it +# is used unchanged so that there's something to diff against. +test_expect_equal_json () { + output=$(echo "$1" | python -mjson.tool || echo "$1") + expected=$(echo "$2" | python -mjson.tool || echo "$2") + shift 2 + test_expect_equal "$output" "$expected" "$@" +} + +test_emacs_expect_t () { + test "$#" = 2 && { prereq=$1; shift; } || prereq= + test "$#" = 1 || + error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t" + + # Run the test. + if ! test_skip "$test_subtest_name" + then + test_emacs "(notmuch-test-run $1)" >/dev/null + + # Restore state after the test. + exec 1>&6 2>&7 # Restore stdout and stderr + inside_subtest= + + # Report success/failure. + result=$(cat OUTPUT) + if [ "$result" = t ] + then + test_ok_ "$test_subtest_name" + else + test_failure_ "$test_subtest_name" "${result}" + fi + else + # Restore state after the (non) test. + exec 1>&6 2>&7 # Restore stdout and stderr + inside_subtest= + fi +} + NOTMUCH_NEW () { notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file' @@ -527,10 +575,9 @@ notmuch_show_sanitize_all () notmuch_json_show_sanitize () { - sed -e 's|, |,\n |g' | \ - sed \ - -e 's|"id": "[^"]*",|"id": "XXXXX",|' \ - -e 's|"filename": "[^"]*",|"filename": "YYYYY",|' + sed \ + -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \ + -e 's|"filename": "[^"]*",|"filename": "YYYYY",|g' } # End of notmuch helper functions @@ -673,8 +720,8 @@ test_skip () { test_check_missing_external_prereqs_ () { if test -n "$test_subtest_missing_external_prereqs_"; then - say_color skip >&3 "missing prerequisites:" - echo "$test_subtest_missing_external_prereqs_" >&3 + say_color skip >&1 "missing prerequisites:" + echo "$test_subtest_missing_external_prereqs_" >&1 test_report_skip_ "$@" else false @@ -914,6 +961,12 @@ test_emacs () { test -z "$missing_dependencies" || return if [ -z "$EMACS_SERVER" ]; then + emacs_tests="$(basename $0).el" + if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then + load_emacs_tests="--eval '(load \"$emacs_tests\")'" + else + load_emacs_tests= + fi server_name="notmuch-test-suite-$$" # start a detached session with an emacs server # user's TERM is given to dtach which assumes a minimally @@ -921,6 +974,7 @@ test_emacs () { TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \ sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \ --no-window-system \ + $load_emacs_tests \ --eval '(setq server-name \"$server_name\")' \ --eval '(server-start)' \ --eval '(orphan-watchdog $$)'" || return @@ -1016,6 +1070,7 @@ find_notmuch_path () # Test the binaries we have just built. The tests are kept in # test/ subdirectory and are run in 'trash directory' subdirectory. TEST_DIRECTORY=$(pwd) +notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"` if test -n "$valgrind" then make_symlink () { @@ -1076,11 +1131,15 @@ then PATH=$GIT_VALGRIND/bin:$PATH GIT_EXEC_PATH=$GIT_VALGRIND/bin export GIT_VALGRIND + test -n "$notmuch_path" && MANPATH="$notmuch_path/man:$MANPATH" else # normal case - notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"` - test -n "$notmuch_path" && PATH="$notmuch_path:$PATH" + if test -n "$notmuch_path" + then + PATH="$notmuch_path:$PATH" + MANPATH="$notmuch_path/man:$MANPATH" + fi fi -export PATH +export PATH MANPATH # Test repository test="tmp.$(basename "$0" .sh)"