2 test_description='"notmuch count" for messages and threads'
3 . ./test-lib.sh || exit 1
7 # Note: The 'wc -l' results below are wrapped in arithmetic evaluation
8 # $((...)) to strip whitespace. This is for portability, as 'wc -l'
9 # emits whitespace on some BSD variants.
11 test_begin_subtest "message count is the default for notmuch count"
13 "$((`notmuch search --output=messages '*' | wc -l`))" \
16 test_begin_subtest "message count with --output=messages"
18 "$((`notmuch search --output=messages '*' | wc -l`))" \
19 "`notmuch count --output=messages '*'`"
21 test_begin_subtest "thread count with --output=threads"
23 "$((`notmuch search --output=threads '*' | wc -l`))" \
24 "`notmuch count --output=threads '*'`"
26 test_begin_subtest "thread count is the default for notmuch search"
28 "$((`notmuch search '*' | wc -l`))" \
29 "`notmuch count --output=threads '*'`"
31 test_begin_subtest "files count"
33 "$((`notmuch search --output=files '*' | wc -l`))" \
34 "`notmuch count --output=files '*'`"
36 test_begin_subtest "files count for a duplicate message-id"
39 "`notmuch count --output=files id:20091117232137.GA7669@griffis1.net`"
41 test_begin_subtest "count with no matching messages"
44 "`notmuch count --output=messages from:cworth and not from:cworth`"
46 test_begin_subtest "count with no matching threads"
49 "`notmuch count --output=threads from:cworth and not from:cworth`"
51 test_begin_subtest "message count is the default for batch count"
52 notmuch count --batch >OUTPUT <<EOF
56 notmuch count --output=messages >EXPECTED
57 notmuch count --output=messages from:cworth >>EXPECTED
58 test_expect_equal_file EXPECTED OUTPUT
60 test_begin_subtest "batch message count"
61 notmuch count --batch --output=messages >OUTPUT <<EOF
66 notmuch count --output=messages from:cworth >EXPECTED
67 notmuch count --output=messages >>EXPECTED
68 notmuch count --output=messages tag:inbox >>EXPECTED
69 test_expect_equal_file EXPECTED OUTPUT
71 test_begin_subtest "batch thread count"
72 notmuch count --batch --output=threads >OUTPUT <<EOF
75 from:cworth and not from:cworth
78 notmuch count --output=threads >EXPECTED
79 notmuch count --output=threads from:cworth >>EXPECTED
80 notmuch count --output=threads from:cworth and not from:cworth >>EXPECTED
81 notmuch count --output=threads foo >>EXPECTED
82 test_expect_equal_file EXPECTED OUTPUT
84 test_begin_subtest "batch message count with input file"
90 notmuch count --input=INPUT --output=messages >OUTPUT
91 notmuch count --output=messages from:cworth >EXPECTED
92 notmuch count --output=messages >>EXPECTED
93 notmuch count --output=messages tag:inbox >>EXPECTED
94 test_expect_equal_file EXPECTED OUTPUT
97 test_begin_subtest "error message for database open"
98 dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3
99 notmuch count '*' 2>OUTPUT 1>/dev/null
100 output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
101 test_expect_equal "${output}" "A Xapian exception occurred opening database"
104 cat <<EOF > count-files.gdb
105 set breakpoint pending on
108 shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB
115 test_begin_subtest "error message from query_search_messages"
116 gdb --batch-silent --return-child-result -x count-files.gdb \
117 --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
119 notmuch count: A Xapian exception occurred
120 A Xapian exception occurred performing query
123 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
124 test_expect_equal_file EXPECTED OUTPUT.clean