]> git.notmuchmail.org Git - notmuch/blob - test/T520-show.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T520-show.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch show"'
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 test_query_syntax () {
7     test_begin_subtest "sexpr query: $1"
8     sexp=$(notmuch show --format=json --query=sexp "$1")
9     infix=$(notmuch show --format=json "$2")
10     test_expect_equal_json "$sexp" "$infix"
11 }
12
13 add_email_corpus
14
15 test_begin_subtest "exit code for show invalid query"
16 notmuch show foo..
17 exit_code=$?
18 test_expect_equal 1 $exit_code
19
20 test_begin_subtest "notmuch show --sort=newest-first"
21 notmuch show --entire-thread=true '*' > EXPECTED
22 notmuch show --entire-thread=true --sort=newest-first '*' > OUTPUT
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest "notmuch show --sort=oldest-first"
26 notmuch show --entire-thread=true '*' | grep ^depth:0 > EXPECTED
27 notmuch show --entire-thread=true --sort=oldest-first '*' | grep ^depth:0 > OLDEST
28 perl -e 'print reverse<>' OLDEST > OUTPUT
29 test_expect_equal_file EXPECTED OUTPUT
30
31 test_begin_subtest "notmuch show --sort for single thread"
32 QUERY="id:yun1vjwegii.fsf@aiko.keithp.com"
33 notmuch show --entire-thread=true --sort=newest-first $QUERY > EXPECTED
34 notmuch show --entire-thread=true --sort=oldest-first $QUERY > OUTPUT
35 test_expect_equal_file EXPECTED OUTPUT
36
37
38 if [ "${NOTMUCH_HAVE_SFSEXP-0}" = "1" ]; then
39
40     test_query_syntax '(and "wonderful" "wizard")' 'wonderful and wizard'
41     test_query_syntax '(or "php" "wizard")' 'php or wizard'
42     test_query_syntax 'wizard' 'wizard'
43     test_query_syntax 'Wizard' 'Wizard'
44     test_query_syntax '(attachment notmuch-help.patch)' 'attachment:notmuch-help.patch'
45
46 fi
47
48 add_email_corpus duplicate
49
50 ID1=debian/2.6.1.dfsg-4-1-g87ea161@87ea161e851dfb1ea324af00e4ecfccc18875e15
51
52 test_begin_subtest "format json, --duplicate=2, duplicate key"
53 output=$(notmuch show --format=json --duplicate=2 id:${ID1})
54 test_json_nodes <<<"$output" "dup:['duplicate']=2"
55
56 test_begin_subtest "format json, subject, --duplicate=1"
57 output=$(notmuch show --format=json --duplicate=1 id:${ID1})
58 file=$(notmuch search --output=files id:${ID1} | head -n 1)
59 subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
60 test_json_nodes <<<"$output" "subject:['headers']['Subject']=\"$subject\""
61
62 test_begin_subtest "format json, subject, --duplicate=2"
63 output=$(notmuch show --format=json --duplicate=2 id:${ID1})
64 file=$(notmuch search --output=files id:${ID1} | tail -n 1)
65 subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
66 test_json_nodes <<<"$output" "subject:['headers']['Subject']=\"$subject\""
67
68 ID2=87r2geywh9.fsf@tethera.net
69 for dup in {1..2}; do
70     test_begin_subtest "format json, body, --duplicate=${dup}"
71     output=$(notmuch show --format=json --duplicate=${dup} id:${ID2} | \
72              $NOTMUCH_PYTHON -B "$NOTMUCH_SRCDIR"/test/json_check_nodes.py "body:['body'][0]['content']" | \
73              grep '^# body')
74     test_expect_equal "$output" "# body ${dup}"
75 done
76
77 ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
78 for dup in {1..5}; do
79     test_begin_subtest "format json, --duplicate=${dup}, 'duplicate' key"
80     output=$(notmuch show --format=json --duplicate=${dup} id:${ID3})
81     test_json_nodes <<<"$output" "dup:['duplicate']=${dup}"
82 done
83
84 test_done