]> git.notmuchmail.org Git - notmuch/blob - test/T600-named-queries.sh
421a11d42b493c858d0cb92262594c28756209c3
[notmuch] / test / T600-named-queries.sh
1 #!/usr/bin/env bash
2 test_description='named queries'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 QUERYSTR="date:2009-11-18..2009-11-18 and tag:unread"
6
7 test_begin_subtest "error adding named query before initializing DB"
8 test_expect_code 1 "notmuch config set query.test \"$QUERYSTR\""
9
10 add_email_corpus
11
12 test_begin_subtest "adding named query"
13 test_expect_success "notmuch config set query.test \"$QUERYSTR\""
14
15 test_begin_subtest "adding nested named query"
16 QUERYSTR2="query:test and subject:Maildir"
17 test_expect_success "notmuch config set query.test2 \"$QUERYSTR2\""
18
19 test_begin_subtest "retrieve named query"
20 output=$(notmuch config get query.test)
21 test_expect_equal "$QUERYSTR" "$output"
22
23 test_begin_subtest "List all queries"
24 notmuch config list | grep ^query | notmuch_config_sanitize > OUTPUT
25 cat <<EOF > EXPECTED
26 query.test=date:2009-11-18..2009-11-18 and tag:unread
27 query.test2=query:test and subject:Maildir
28 EOF
29 test_expect_equal_file EXPECTED OUTPUT
30
31 test_begin_subtest "dump named queries"
32 notmuch dump | grep '^#@' > OUTPUT
33 cat<<EOF > QUERIES.BEFORE
34 #@ query.test date%3a2009-11-18..2009-11-18%20and%20tag%3aunread
35 #@ query.test2 query%3atest%20and%20subject%3aMaildir
36 EOF
37 test_expect_equal_file QUERIES.BEFORE OUTPUT
38
39 test_begin_subtest 'dumping large queries'
40 # This value is just large enough to trigger a limitation of gzprintf
41 # to 8191 bytes in total (by default).
42 repeat=1329
43 notmuch config set query.big "$(seq -s' ' $repeat)"
44 notmuch dump --include=config > OUTPUT
45 notmuch config set query.big ''
46 printf "#notmuch-dump batch-tag:3 config\n#@ query.big " > EXPECTED
47 seq -s'%20' $repeat >> EXPECTED
48 cat <<EOF >> EXPECTED
49 #@ query.test date%3a2009-11-18..2009-11-18%20and%20tag%3aunread
50 #@ query.test2 query%3atest%20and%20subject%3aMaildir
51 EOF
52 test_expect_equal_file EXPECTED OUTPUT
53
54 test_begin_subtest "delete named queries"
55 notmuch dump > BEFORE
56 notmuch config set query.test
57 notmuch dump | grep '^#@' > OUTPUT
58 cat<<EOF > EXPECTED
59 #@ query.test2 query%3atest%20and%20subject%3aMaildir
60 EOF
61 test_expect_equal_file EXPECTED OUTPUT
62
63 test_begin_subtest "restore named queries"
64 notmuch restore < BEFORE
65 notmuch dump | grep '^#@' > OUTPUT
66 test_expect_equal_file QUERIES.BEFORE OUTPUT
67
68 test_begin_subtest "search named query"
69 notmuch search query:test > OUTPUT
70 notmuch search $QUERYSTR > EXPECTED
71 if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -ne 1 ]; then
72     test_subtest_known_broken
73 fi
74 test_expect_equal_file EXPECTED OUTPUT
75
76 test_begin_subtest "search named query with other terms"
77 notmuch search query:test and subject:Maildir > OUTPUT
78 notmuch search $QUERYSTR and subject:Maildir > EXPECTED
79 if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -ne 1 ]; then
80     test_subtest_known_broken
81 fi
82 test_expect_equal_file EXPECTED OUTPUT
83
84 test_begin_subtest "search nested named query"
85 notmuch search query:test2 > OUTPUT
86 notmuch search $QUERYSTR2 > EXPECTED
87 test_expect_equal_file EXPECTED OUTPUT
88
89 test_done