]> git.notmuchmail.org Git - notmuch/blob - test/T315-emacs-tagging.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T315-emacs-tagging.sh
1 #!/usr/bin/env bash
2
3 test_description="emacs interface"
4 . $(dirname "$0")/test-lib.sh || exit 1
5 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
6
7 EXPECTED=$NOTMUCH_SRCDIR/test/emacs.expected-output
8
9 test_require_emacs
10 add_email_corpus
11
12 test_begin_subtest "Add tag from search view"
13 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
14 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
15             (notmuch-test-wait)
16             (execute-kbd-macro \"+tag-from-search-view\")"
17 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
18 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-search-view unread)"
19
20 test_begin_subtest "Remove tag from search view"
21 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
22             (notmuch-test-wait)
23             (execute-kbd-macro \"-tag-from-search-view\")"
24 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
25 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
26
27 test_begin_subtest "Add tag (large query)"
28 # We use a long query to force us into batch mode and use a funny tag
29 # that requires escaping for batch tagging.
30 test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (mapconcat #'identity (make-list notmuch-tag-argument-limit \"x\") \"-\")) (list \"+tag-from-%-large-query\"))"
31 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
32 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-%-large-query unread)"
33 notmuch tag -tag-from-%-large-query $os_x_darwin_thread
34
35 test_begin_subtest "notmuch-show: add single tag to single message"
36 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
37             (execute-kbd-macro \"+tag-from-show-view\")"
38 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
39 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-show-view unread)"
40
41 test_begin_subtest "notmuch-show: remove single tag from single message"
42 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
43             (execute-kbd-macro \"-tag-from-show-view\")"
44 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
45 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
46
47 test_begin_subtest "notmuch-show: add multiple tags to single message"
48 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
49             (execute-kbd-macro \"+tag1-from-show-view +tag2-from-show-view\")"
50 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
51 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag1-from-show-view tag2-from-show-view unread)"
52
53 test_begin_subtest "notmuch-show: remove multiple tags from single message"
54 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
55             (execute-kbd-macro \"-tag1-from-show-view -tag2-from-show-view\")"
56 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
57 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
58
59 test_begin_subtest "notmuch-show: before-tag-hook is run, variables are defined"
60 output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil)
61                   (notmuch-before-tag-hook (function notmuch-test-tag-hook)))
62                (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com")
63                (execute-kbd-macro "+activate-hook\n")
64                (execute-kbd-macro "-activate-hook\n")
65                notmuch-test-tag-hook-output)')
66 test_expect_equal "$output" \
67 '(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook")
68  ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))'
69
70 test_begin_subtest "notmuch-show: after-tag-hook is run, variables are defined"
71 output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil)
72                   (notmuch-after-tag-hook (function notmuch-test-tag-hook)))
73                (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com")
74                (execute-kbd-macro "+activate-hook\n")
75                (execute-kbd-macro "-activate-hook\n")
76                notmuch-test-tag-hook-output)')
77 test_expect_equal "$output" \
78 '(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook")
79  ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))'
80
81
82 test_begin_subtest "Search thread tag operations are race-free"
83 add_message '[subject]="Search race test"'
84 gen_msg_id_1=$gen_msg_id
85 generate_message '[in-reply-to]="<'$gen_msg_id_1'>"' \
86             '[references]="<'$gen_msg_id_1'>"' \
87             '[subject]="Search race test two"'
88 test_emacs '(notmuch-search "subject:\"search race test\"")
89             (notmuch-test-wait)
90             (notmuch-poll)
91             (execute-kbd-macro "+search-thread-race-tag")'
92 output=$(notmuch search --output=messages 'tag:search-thread-race-tag')
93 test_expect_equal "$output" "id:$gen_msg_id_1"
94
95 test_begin_subtest "Search global tag operations are race-free"
96 generate_message '[in-reply-to]="<'$gen_msg_id_1'>"' \
97             '[references]="<'$gen_msg_id_1'>"' \
98             '[subject]="Re: Search race test"'
99 test_emacs '(notmuch-search "subject:\"search race test\" -subject:two")
100             (notmuch-test-wait)
101             (notmuch-poll)
102             (execute-kbd-macro "*+search-global-race-tag")'
103 output=$(notmuch search --output=messages 'tag:search-global-race-tag')
104 test_expect_equal "$output" "id:$gen_msg_id_1"
105
106 test_begin_subtest "undo with empty history is an error"
107 test_emacs "(let ((notmuch-tag-history nil))
108   (test-log-error
109    (notmuch-tag-undo)))
110   "
111 cat <<EOF > EXPECTED
112 (error no further notmuch undo information)
113 EOF
114 test_expect_equal_file EXPECTED MESSAGES
115
116 for mode in search show tree unthreaded; do
117     test_begin_subtest "undo tagging in $mode mode"
118     test_emacs "(let ((notmuch-tag-history nil))
119       (notmuch-$mode \"$os_x_darwin_thread\")
120       (notmuch-test-wait)
121       (execute-kbd-macro \"+tag-to-be-undone-$mode\")
122       (notmuch-tag-undo)
123       (notmuch-test-wait))"
124     count=$(notmuch count "tag:tag-to-be-undone-$mode")
125     test_expect_equal "$count" "0"
126
127     test_begin_subtest "undo tagging in $mode mode (multiple operations)"
128     test_emacs "(let ((notmuch-tag-history nil))
129       (notmuch-$mode \"$os_x_darwin_thread\")
130       (notmuch-test-wait)
131       (execute-kbd-macro \"+one-$mode\")
132       (execute-kbd-macro \"+two-$mode\")
133       (notmuch-tag-undo)
134       (notmuch-test-wait)
135       (execute-kbd-macro \"+three-$mode\"))"
136     output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
137     notmuch tag "-one-$mode" "-three-$mode" $os_x_darwin_thread
138     test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox one-$mode three-$mode unread)"
139
140     test_begin_subtest "undo tagging in $mode mode (multiple undo)"
141     test_emacs "(let ((notmuch-tag-history nil))
142       (notmuch-$mode \"$os_x_darwin_thread\")
143       (notmuch-test-wait)
144       (execute-kbd-macro \"+one-$mode\")
145       (execute-kbd-macro \"+two-$mode\")
146       (notmuch-tag-undo)
147       (notmuch-test-wait)
148       (notmuch-tag-undo)
149       (notmuch-test-wait)
150       (execute-kbd-macro \"+three-$mode\"))"
151     output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
152     notmuch tag "-one-$mode" "-three-$mode" $os_x_darwin_thread
153     test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox three-$mode unread)"
154
155     test_begin_subtest "undo tagging in $mode mode (via binding)"
156     test_emacs "(let ((notmuch-tag-history nil))
157       (notmuch-$mode \"$os_x_darwin_thread\")
158       (notmuch-test-wait)
159       (execute-kbd-macro \"+tag-to-be-undone-$mode\")
160       (execute-kbd-macro (kbd \"C-x u\"))
161       (notmuch-test-wait))"
162     count=$(notmuch count "tag:tag-to-be-undone-$mode")
163     test_expect_equal "$count" "0"
164 done
165
166 test_done