]> git.notmuchmail.org Git - notmuch/blob - test/tagging
test/tagging: add test for error messages of tag --batch
[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: checking error messages'
50 notmuch dump --format=batch-tag > BACKUP
51 notmuch tag --batch <<EOF 2>OUTPUT
52 # the next line has a space
53  
54 # this line has no tag operations, but this is permitted in batch format.
55 a
56 +0
57 +a +b
58 # trailing whitespace
59 +a +b 
60 +c +d --
61 # this is a harmless comment, do not yell about it.
62
63 # the previous line was blank; also no yelling please
64 +%zz -- id:whatever
65 # the next non-comment line should report an an empty tag error for
66 # batch tagging, but not for restore
67 + +e -- id:foo
68 +- -- id:foo
69 EOF
70
71 cat <<EOF > EXPECTED
72 Warning: no query string [+0]
73 Warning: no query string [+a +b]
74 Warning: missing query string [+a +b ]
75 Warning: no query string after -- [+c +d --]
76 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
77 Warning: empty tag forbidden [+ +e -- id:foo]
78 Warning: tag starting with '-' forbidden [+- -- id:foo]
79 EOF
80
81 notmuch restore --format=batch-tag < BACKUP
82 test_expect_equal_file EXPECTED OUTPUT
83
84 test_expect_code 1 "Empty tag names" 'notmuch tag + One'
85
86 test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'
87
88 test_done