]> git.notmuchmail.org Git - notmuch/blob - test/tagging
test/tagging: add basic tests for batch tagging functionality
[notmuch] / test / tagging
1 #!/usr/bin/env bash
2 test_description='"notmuch tag"'
3 . ./test-lib.sh
4
5 add_message '[subject]=One'
6 add_message '[subject]=Two'
7
8 test_begin_subtest "Adding tags"
9 notmuch tag +tag1 +tag2 +tag3 \*
10 output=$(notmuch search \* | notmuch_search_sanitize)
11 test_expect_equal "$output" "\
12 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 tag2 tag3 unread)
13 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 tag3 unread)"
14
15 test_begin_subtest "Removing tags"
16 notmuch tag -tag1 -tag2 \*
17 output=$(notmuch search \* | notmuch_search_sanitize)
18 test_expect_equal "$output" "\
19 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag3 unread)
20 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag3 unread)"
21
22 test_expect_code 1 "No tag operations" 'notmuch tag One'
23 test_expect_code 1 "No query" 'notmuch tag +tag2'
24
25 test_begin_subtest "Redundant tagging"
26 notmuch tag +tag1 -tag3 One
27 notmuch tag +tag1 -tag3 \*
28 output=$(notmuch search \* | notmuch_search_sanitize)
29 test_expect_equal "$output" "\
30 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
31 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
32
33 test_begin_subtest "Special characters in tags"
34 notmuch tag +':" ' \*
35 notmuch tag -':" ' Two
36 output=$(notmuch search \* | notmuch_search_sanitize)
37 test_expect_equal "$output" "\
38 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
39 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
40
41 test_begin_subtest "Tagging order"
42 notmuch tag +tag4 -tag4 One
43 notmuch tag -tag4 +tag4 Two
44 output=$(notmuch search \* | notmuch_search_sanitize)
45 test_expect_equal "$output" "\
46 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
47 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"
48
49 test_begin_subtest "--batch"
50 notmuch tag --batch <<EOF
51 # %20 is a space in tag
52 -:"%20 -tag1 +tag5 +tag6 -- One
53 +tag1 -tag1 -tag4 +tag4 -- Two
54 -tag6 One
55 +tag5 Two
56 EOF
57 output=$(notmuch search \* | notmuch_search_sanitize)
58 test_expect_equal "$output" "\
59 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag5 unread)
60 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag5 unread)"
61
62 # generate a common input file for the next several tests.
63 cat > batch.in  <<EOF
64 # %40 is an @ in tag
65 +%40 -tag5 +tag6 -- One
66 +tag1 -tag1 -tag4 +tag4 -- Two
67 -tag5 +tag6 Two
68 EOF
69
70 cat > batch.expected <<EOF
71 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (@ inbox tag6 unread)
72 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag6 unread)
73 EOF
74
75 test_begin_subtest "--input"
76 notmuch dump --format=batch-tag > backup.tags
77 notmuch tag --input=batch.in
78 notmuch search \* | notmuch_search_sanitize > OUTPUT
79 notmuch restore --format=batch-tag < backup.tags
80 test_expect_equal_file batch.expected OUTPUT
81
82 test_begin_subtest "--batch --input"
83 notmuch dump --format=batch-tag > backup.tags
84 notmuch tag --batch --input=batch.in
85 notmuch search \* | notmuch_search_sanitize > OUTPUT
86 notmuch restore --format=batch-tag < backup.tags
87 test_expect_equal_file batch.expected OUTPUT
88
89 test_begin_subtest "--batch, blank lines and comments"
90 notmuch dump | sort > EXPECTED
91 notmuch tag --batch <<EOF
92 # this line is a comment; the next has only white space
93          
94
95 # the previous line is empty
96 EOF
97 notmuch dump | sort > OUTPUT
98 test_expect_equal_file EXPECTED OUTPUT
99
100 test_begin_subtest '--batch: checking error messages'
101 notmuch dump --format=batch-tag > BACKUP
102 notmuch tag --batch <<EOF 2>OUTPUT
103 # the next line has a space
104  
105 # this line has no tag operations, but this is permitted in batch format.
106 a
107 +0
108 +a +b
109 # trailing whitespace
110 +a +b 
111 +c +d --
112 # this is a harmless comment, do not yell about it.
113
114 # the previous line was blank; also no yelling please
115 +%zz -- id:whatever
116 # the next non-comment line should report an an empty tag error for
117 # batch tagging, but not for restore
118 + +e -- id:foo
119 +- -- id:foo
120 EOF
121
122 cat <<EOF > EXPECTED
123 Warning: no query string [+0]
124 Warning: no query string [+a +b]
125 Warning: missing query string [+a +b ]
126 Warning: no query string after -- [+c +d --]
127 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
128 Warning: empty tag forbidden [+ +e -- id:foo]
129 Warning: tag starting with '-' forbidden [+- -- id:foo]
130 EOF
131
132 notmuch restore --format=batch-tag < BACKUP
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_expect_code 1 "Empty tag names" 'notmuch tag + One'
136
137 test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'
138
139 test_done