]> git.notmuchmail.org Git - notmuch/blob - test/json
test: allow specifying tests to run with NOTMUCH_TESTS env var
[notmuch] / test / json
1 #!/bin/bash
2 test_description="--format=json output"
3 . ./test-lib.sh
4
5 test_begin_subtest "Show message: json"
6 add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-show-message\""
7 output=$(notmuch show --format=json "json-show-message")
8 test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
9
10 test_begin_subtest "Search message: json"
11 add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
12 output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
13 test_expect_equal "$output" "[{\"thread\": \"XXX\",
14 \"timestamp\": 946728000,
15 \"matched\": 1,
16 \"total\": 1,
17 \"authors\": \"Notmuch Test Suite\",
18 \"subject\": \"json-search-subject\",
19 \"tags\": [\"inbox\", \"unread\"]}]"
20
21 test_begin_subtest "Search by subject (utf-8):"
22 add_message [subject]=utf8-sübjéct "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\""
23 output=$(notmuch search subject:utf8-sübjéct | notmuch_search_sanitize)
24 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
25
26 test_begin_subtest "Show message: json, utf-8"
27 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\""
28 output=$(notmuch show --format=json "jsön-show-méssage")
29 test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"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 <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
30
31 test_begin_subtest "Search message: json, utf-8"
32 add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
33 output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
34 test_expect_equal "$output" "[{\"thread\": \"XXX\",
35 \"timestamp\": 946728000,
36 \"matched\": 1,
37 \"total\": 1,
38 \"authors\": \"Notmuch Test Suite\",
39 \"subject\": \"json-search-utf8-body-sübjéct\",
40 \"tags\": [\"inbox\", \"unread\"]}]"
41
42 test_begin_subtest "Search returning no messages"
43 output=$(notmuch search --format=json "this string had better not match any messages" | notmuch_search_sanitize)
44 test_expect_equal "$output" "[]"
45
46 test_done