This makes the tests more robust against changing output formats, by
allowing us to centralize fixes in the sanitization function. It is
not appropriate for all cases, in particular it is unneeded when using
test_json_nodes, and unhelpful when testing filenames.
---
 test/T070-insert.sh    |  6 +++---
 test/T160-json.sh      | 16 ++++++++--------
 test/T190-multipart.sh | 24 ++++++++++++------------
 test/T220-reply.sh     |  7 ++++---
 4 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index e1e3b151..7d5f842d 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -43,13 +43,13 @@ test_begin_subtest "Permissions on inserted message should 
be 0600"
 test_expect_equal "600" "$(stat -c %a "$cur_msg_filename")"
 
 test_begin_subtest "Insert message adds default tags"
-output=$(notmuch show --format=json "subject:insert-subject")
+output=$(notmuch show --format=json "subject:insert-subject" | 
notmuch_json_show_sanitize)
 expected='[[[{
- "id": "'"${gen_msg_id}"'",
+ "id": "XXXXX",
  "crypto": {},
  "match": true,
  "excluded": false,
- "filename": ["'"${cur_msg_filename}"'"],
+ "filename": ["YYYYY"],
  "timestamp": 946728000,
  "date_relative": "2000-01-01",
  "tags": ["inbox","unread"],
diff --git a/test/T160-json.sh b/test/T160-json.sh
index ec7b1461..e1252353 100755
--- a/test/T160-json.sh
+++ b/test/T160-json.sh
@@ -5,17 +5,17 @@ test_description="--format=json output"
 
 test_begin_subtest "Show message: json"
 add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 
12:00:00 -0000\"" "[bcc]=\"[email protected]\"" 
"[reply-to]=\"[email protected]\"" 
"[body]=\"json-show-message\""
-output=$(notmuch show --format=json "json-show-message")
-test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": 
{}, \"match\": true, \"excluded\": false, \"filename\": 
[\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": 
\"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": 
\"json-show-subject\", \"From\": \"Notmuch Test Suite 
<[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": 
\"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
+output=$(notmuch show --format=json "json-show-message" | 
notmuch_json_show_sanitize)
+test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\", \"crypto\": {}, 
\"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 
946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], 
\"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test 
Suite <[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": 
\"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
 
 # This should be the same output as above.
 test_begin_subtest "Show message: json --body=true"
-output=$(notmuch show --format=json --body=true "json-show-message")
-test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\",  \"crypto\": 
{}, \"match\": true, \"excluded\": false, \"filename\": 
[\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": 
\"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": 
\"json-show-subject\", \"From\": \"Notmuch Test Suite 
<[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": 
\"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
+output=$(notmuch show --format=json --body=true "json-show-message" | 
notmuch_json_show_sanitize)
+test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\",  \"crypto\": {}, 
\"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 
946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], 
\"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test 
Suite <[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": 
\"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
 
 test_begin_subtest "Show message: json --body=false"
-output=$(notmuch show --format=json --body=false "json-show-message")
-test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\",  \"crypto\": 
{}, \"match\": true, \"excluded\": false, \"filename\": 
[\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": 
\"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": 
\"json-show-subject\", \"From\": \"Notmuch Test Suite 
<[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}}, []]]]"
+output=$(notmuch show --format=json --body=false "json-show-message" | 
notmuch_json_show_sanitize)
+test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\",  \"crypto\": {}, 
\"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 
946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], 
\"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test 
Suite <[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Bcc\": \"[email protected]\", 
\"Reply-To\": \"[email protected]\", \"Date\": \"Sat, 01 Jan 
2000 12:00:00 +0000\"}}, []]]]"
 
 test_begin_subtest "Search message: json"
 add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 
12:00:00 -0000\"" "[body]=\"json-search-message\""
@@ -33,8 +33,8 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
 
 test_begin_subtest "Show message: json, utf-8"
 add_message "[subject]=\"json-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 
2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
-output=$(notmuch show --format=json "jsön-show-méssage")
-test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\",  \"crypto\": 
{}, \"match\": true, \"excluded\": false, \"filename\": 
[\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": 
\"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": 
\"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite 
<[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, 
\"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": 
\"jsön-show-méssage\n\"}]}, []]]]"
+output=$(notmuch show --format=json "jsön-show-méssage" | 
notmuch_json_show_sanitize)
+test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\",  \"crypto\": {}, 
\"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 
946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], 
\"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch 
Test Suite <[email protected]>\", \"To\": \"Notmuch Test Suite 
<[email protected]>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, 
\"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": 
\"jsön-show-méssage\n\"}]}, []]]]"
 
 test_begin_subtest "Show message: json, inline attachment filename"
 subject='json-show-inline-attachment-filename'
diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index d3b7f87c..cfe48ac5 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -376,18 +376,18 @@ test_begin_subtest "--format=text --part=8, no part, 
expect error"
 test_expect_success "notmuch show --format=text --part=8 
'id:[email protected]'"
 
 test_begin_subtest "--format=json --part=0, full message"
-notmuch show --format=json --part=0 'id:[email protected]' 
>OUTPUT
+notmuch show --format=json --part=0 'id:[email protected]' | 
notmuch_json_show_sanitize >OUTPUT
 cat <<EOF >EXPECTED
-{"id": "[email protected]", "crypto": {}, "match": true, 
"excluded": false, "filename": ["${MAIL_DIR}/multipart"], "timestamp": 
978709437, "date_relative": "2001-01-05", "tags": 
["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart 
message", "From": "Carl Worth <[email protected]>", "To": "[email protected]", 
"Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
+{"id": "XXXXX", "crypto": {}, "match": true, "excluded": false, "filename": 
["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05", "tags": 
["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart 
message", "From": "Carl Worth <[email protected]>", "To": "[email protected]", 
"Date": "GENERATED_DATE"}, "body": [
 {"id": 1, "content-type": "multipart/signed", "content": [
 {"id": 2, "content-type": "multipart/mixed", "content": [
-{"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", 
"content": [{"headers": {"Subject": "html message", "From": "Carl Worth 
<[email protected]>", "To": "[email protected]", "Date": "Fri, 05 Jan 2001 
15:42:57 +0000"}, "body": [
+{"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", 
"content": [{"headers": {"Subject": "html message", "From": "Carl Worth 
<[email protected]>", "To": "[email protected]", "Date": "GENERATED_DATE"}, 
"body": [
 {"id": 4, "content-type": "multipart/alternative", "content": [
-{"id": 5, "content-type": "text/html", "content-length": 71},
+{"id": 5, "content-type": "text/html", "content-length": "NONZERO"},
 {"id": 6, "content-type": "text/plain", "content": "This is an embedded 
message, with a multipart/alternative part.\n"}]}]}]}, 
 {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", 
"filename": "attachment", "content": "This is a text attachment.\n"},
 {"id": 8, "content-type": "text/plain", "content": "And this message is 
signed.\n\n-Carl\n"}]}, 
-{"id": 9, "content-type": "application/pgp-signature", "content-length": 
197}]}]}
+{"id": 9, "content-type": "application/pgp-signature", "content-length": 
"NONZERO"}]}]}
 EOF
 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
 
@@ -485,7 +485,7 @@ notmuch show --format=raw 
'id:[email protected]' >OUTPUT
 test_expect_equal_file "${MAIL_DIR}"/multipart  OUTPUT
 
 test_begin_subtest "--format=raw --part=0, full message"
-notmuch show --format=raw --part=0 'id:[email protected]' 
>OUTPUT
+notmuch show --format=raw --part=0 'id:[email protected]' | 
notmuch_json_show_sanitize >OUTPUT
 test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
 
 test_begin_subtest "--format=raw --part=1, message body"
@@ -727,10 +727,10 @@ notmuch new > /dev/null
 
 cat_expected_head () {
         cat <<EOF
-[[[{"id": "htmlmessage", "match":true, "excluded": false, 
"date_relative":"2000-01-01",
+[[[{"id": "XXXXX", "match":true, "excluded": false, 
"date_relative":"2000-01-01",
    "crypto": {},
    "timestamp": 946684800,
-   "filename": ["${MAIL_DIR}/include-html"],
+   "filename": ["YYYYY"],
    "tags": ["inbox", "unread"],
    "headers": { "Date": "Sat, 01 Jan 2000 00:00:00 +0000", "From": "A 
<[email protected]>",
                 "Subject": "html message", "To": "B <[email protected]>"},
@@ -742,8 +742,8 @@ EOF
 cat_expected_head > EXPECTED.nohtml
 cat <<EOF >> EXPECTED.nohtml
 "content": [
-  { "id": 2, "content-charset": "UTF-8", "content-length": 21, "content-type": 
"text/html"},
-  { "id": 3, "content-charset": "ISO-8859-1", "content-length": 20, 
"content-type": "text/html"},
+  { "id": 2, "content-charset": "UTF-8", "content-length": "NONZERO", 
"content-type": "text/html"},
+  { "id": 3, "content-charset": "ISO-8859-1", "content-length": "NONZERO", 
"content-type": "text/html"},
   { "id": 4, "content-type": "text/plain", "content": "0.5 equals \\u00bd\\n"}
 ]}]},[]]]]
 EOF
@@ -759,11 +759,11 @@ cat <<EOF >> EXPECTED.withhtml
 EOF
 
 test_begin_subtest "html parts excluded by default"
-notmuch show --format=json id:htmlmessage > OUTPUT
+notmuch show --format=json id:htmlmessage | notmuch_json_show_sanitize > OUTPUT
 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.nohtml)"
 
 test_begin_subtest "html parts included"
-notmuch show --format=json --include-html id:htmlmessage > OUTPUT
+notmuch show --format=json --include-html id:htmlmessage | 
notmuch_json_show_sanitize > OUTPUT
 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.withhtml)"
 
 test_begin_subtest "indexes mime-type #1"
diff --git a/test/T220-reply.sh b/test/T220-reply.sh
index 4e9984d2..50179efc 100755
--- a/test/T220-reply.sh
+++ b/test/T220-reply.sh
@@ -298,7 +298,8 @@ On Tue, 05 Jan 2010 15:43:56 -0000, ☃ <[email protected]> 
wrote:
 OK"
 
 test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)"
-output=$(echo '{"answer":' && notmuch reply --format=json id:${gen_msg_id} 
2>&1 && echo ', "success": "OK"}')
+output=$(echo '{"answer":' && notmuch reply --format=json id:${gen_msg_id} 
2>&1 | notmuch_json_show_sanitize \
+        && echo ', "success": "OK"}')
 test_expect_equal_json "$output" '
 {  "answer": {
     "original": {
@@ -312,14 +313,14 @@ test_expect_equal_json "$output" '
         "crypto": {},
         "date_relative": "2010-01-05",
         "excluded": false,
-        "filename": ["'${MAIL_DIR}'/msg-015"],
+        "filename": ["YYYYY"],
         "headers": {
             "Date": "Tue, 05 Jan 2010 15:43:56 +0000",
             "From": "\u2603 <[email protected]>",
             "Subject": "\u00e0\u00df\u00e7",
             "To": "Notmuch Test Suite <[email protected]>"
         },
-        "id": "'${gen_msg_id}'",
+        "id": "XXXXX",
         "match": false,
         "tags": [
             "inbox",
-- 
2.35.2

_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to