]> git.notmuchmail.org Git - notmuch/blob - test/t0003-json.sh
test: Fix test suite to integrate with our non-recursive Makefile system.
[notmuch] / test / t0003-json.sh
1 #!/bin/bash
2 test_description="--format=json output"
3 . ./test-lib.sh
4
5 test_expect_success "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 pass_if_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 '
11 test_expect_success "Search message: json" '
12 add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\"" &&
13 output=$($NOTMUCH search --format=json "json-search-message" | notmuch_search_sanitize) &&
14 pass_if_equal "$output" "[{\"thread\": \"XXX\",
15 \"timestamp\": 946728000,
16 \"matched\": 1,
17 \"total\": 1,
18 \"authors\": \"Notmuch Test Suite\",
19 \"subject\": \"json-search-subject\",
20 \"tags\": [\"inbox\", \"unread\"]}]"
21
22 '
23 test_expect_success "Search by subject (utf-8):" '
24 add_message [subject]=utf8-sübjéct "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
25 output=$($NOTMUCH search subject:utf8-sübjéct | notmuch_search_sanitize) &&
26 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
27
28 '
29 test_expect_success "Show message: json, utf-8" '
30 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\"" &&
31 output=$($NOTMUCH show --format=json "jsön-show-méssage") &&
32 pass_if_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\"}]}, []]]]"
33
34 '
35 test_expect_success "Search message: json, utf-8" '
36 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\"" &&
37 output=$($NOTMUCH search --format=json "jsön-search-méssage" | notmuch_search_sanitize) &&
38 pass_if_equal "$output" "[{\"thread\": \"XXX\",
39 \"timestamp\": 946728000,
40 \"matched\": 1,
41 \"total\": 1,
42 \"authors\": \"Notmuch Test Suite\",
43 \"subject\": \"json-search-utf8-body-sübjéct\",
44 \"tags\": [\"inbox\", \"unread\"]}]"
45 '
46 test_done