2 test_description='"notmuch count" for messages and threads'
3 . $(dirname "$0")/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 target=(${MAIL_DIR}/.notmuch/xapian/postlist.*)
99 dd if=/dev/zero of="$target" count=3
100 notmuch count '*' 2>OUTPUT 1>/dev/null
101 output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
102 test_expect_equal "${output}" "A Xapian exception occurred opening database"
105 cat <<EOF > count-files.gdb
106 set breakpoint pending on
107 set logging file count-files-gdb.log
111 shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.*
118 test_begin_subtest "error message from query_search_messages"
119 ${TEST_GDB} --batch-silent --return-child-result -x count-files.gdb \
120 --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
122 notmuch count: A Xapian exception occurred
123 A Xapian exception occurred performing query
126 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
127 test_expect_equal_file EXPECTED OUTPUT.clean
130 test_begin_subtest "count library function is non-destructive"
142 query_string = 'tag:inbox or tag:spam'
145 database = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
146 query = notmuch.Query(database, query_string)
148 print("1: {} messages".format(query.count_messages()))
149 print("2: {} messages".format(query.count_messages()))
150 print("Exclude '{}'".format(tag_string))
151 query.exclude_tag(tag_string)
152 print("3: {} messages".format(query.count_messages()))
153 print("4: {} messages".format(query.count_messages()))
155 test_expect_equal_file EXPECTED OUTPUT