]> git.notmuchmail.org Git - notmuch/blob - test/T600-named-queries.sh
doc: fix man page build for Sphinx 4.x
[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 to DB before initialization"
8 test_expect_code 1 "notmuch config set --database query.test \"$QUERYSTR\""
9
10 add_email_corpus
11
12 test_begin_subtest "adding named query (database)"
13 test_expect_success "notmuch config set --database 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 EOF
36 test_expect_equal_file QUERIES.BEFORE OUTPUT
37
38 test_begin_subtest 'dumping large queries'
39 # This value is just large enough to trigger a limitation of gzprintf
40 # to 8191 bytes in total (by default).
41 repeat=1329
42 notmuch config set --database query.big "$(seq -s' ' $repeat)"
43 notmuch dump --include=config > OUTPUT
44 notmuch config set --database query.big
45 printf "#notmuch-dump batch-tag:3 config\n#@ query.big " > EXPECTED
46 seq -s'%20' $repeat >> EXPECTED
47 cat <<EOF >> EXPECTED
48 #@ query.test date%3a2009-11-18..2009-11-18%20and%20tag%3aunread
49 EOF
50 test_expect_equal_file EXPECTED OUTPUT
51
52 test_begin_subtest "delete named queries"
53 notmuch dump > BEFORE
54 notmuch config set --database query.test
55 notmuch dump | grep '^#@' > OUTPUT
56 cat<<EOF > EXPECTED
57 EOF
58 test_expect_equal_file EXPECTED OUTPUT
59
60 test_begin_subtest "restore named queries"
61 notmuch restore < BEFORE
62 notmuch dump | grep '^#@' > OUTPUT
63 test_expect_equal_file QUERIES.BEFORE OUTPUT
64
65 test_begin_subtest "search named query"
66 notmuch search query:test > OUTPUT
67 notmuch search $QUERYSTR > EXPECTED
68 test_expect_equal_file EXPECTED OUTPUT
69
70 test_begin_subtest "search named query with other terms"
71 notmuch search query:test and subject:Maildir > OUTPUT
72 notmuch search $QUERYSTR and subject:Maildir > EXPECTED
73 test_expect_equal_file EXPECTED OUTPUT
74
75 test_begin_subtest "search nested named query"
76 notmuch search query:test2 > OUTPUT
77 notmuch search $QUERYSTR2 > EXPECTED
78 test_expect_equal_file EXPECTED OUTPUT
79
80 test_done