]> git.notmuchmail.org Git - notmuch/blobdiff - test/test-lib.sh
show: Convert do_show to use sprinter
[notmuch] / test / test-lib.sh
index 0174e93f7e7591edfaae1206eb125de41a72676b..791d2dc668e05dde0a0c4e5828db1dea8988e2b6 100644 (file)
@@ -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).
@@ -503,6 +512,16 @@ test_expect_equal_file ()
     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 ||
@@ -556,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
@@ -702,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