2 test_description='"notmuch tag"'
5 add_message '[subject]=One'
6 add_message '[subject]=Two'
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)"
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)"
22 test_expect_code 1 "No tag operations" 'notmuch tag One'
23 test_expect_code 1 "No query" 'notmuch tag +tag2'
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)"
33 test_begin_subtest "Special characters in tags"
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)"
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)"
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
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)"
62 # generate a common input file for the next several tests.
65 +%40 -tag5 +tag6 -- One
66 +tag1 -tag1 -tag4 +tag4 -- Two
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)
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
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
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
95 # the previous line is empty
97 notmuch dump | sort > OUTPUT
98 test_expect_equal_file EXPECTED OUTPUT
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
105 # this line has no tag operations, but this is permitted in batch format.
109 # trailing whitespace
112 # this is a harmless comment, do not yell about it.
114 # the previous line was blank; also no yelling please
116 # the next non-comment line should report an an empty tag error for
117 # batch tagging, but not for restore
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]
132 notmuch restore --format=batch-tag < BACKUP
133 test_expect_equal_file EXPECTED OUTPUT
135 test_expect_code 1 "Empty tag names" 'notmuch tag + One'
137 test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'