Merge tag 'debian/0.17-4'
[notmuch] / test / T450-emacs-show.sh
1 #!/usr/bin/env bash
2
3 test_description="emacs notmuch-show view"
4 . ./test-lib.sh
5
6 EXPECTED=$TEST_DIRECTORY/emacs-show.expected-output
7
8 add_email_corpus
9
10 test_begin_subtest "Hiding Original Message region at beginning of a message"
11 message_id='OriginalMessageHiding.1@notmuchmail.org'
12 add_message \
13     [id]="$message_id" \
14     '[subject]="Hiding Original Message region at beginning of a message"' \
15     '[body]="-----Original Message-----
16 Text here."'
17
18 cat <<EOF >EXPECTED
19 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
20 Subject: Hiding Original Message region at beginning of a message
21 To: Notmuch Test Suite <test_suite@notmuchmail.org>
22 Date: GENERATED_DATE
23
24 [ 2-line hidden original message. Click/Enter to show. ]
25 EOF
26
27 test_emacs "(notmuch-show \"id:$message_id\")
28             (test-visible-output \"OUTPUT.raw\")"
29 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
30 test_expect_equal_file OUTPUT EXPECTED
31
32 test_begin_subtest "Bare subject #1"
33 output=$(test_emacs '(notmuch-show-strip-re "Re: subject")')
34 test_expect_equal "$output" '"subject"'
35
36 test_begin_subtest "Bare subject #2"
37 output=$(test_emacs '(notmuch-show-strip-re "re:Re: re:  Re:  re:subject")')
38 test_expect_equal "$output" '"subject"'
39
40 test_begin_subtest "Bare subject #3"
41 output=$(test_emacs '(notmuch-show-strip-re "the cure: fix the regexp")')
42 test_expect_equal "$output" '"the cure: fix the regexp"'
43
44 test_begin_subtest "don't process cryptographic MIME parts"
45 test_emacs '(let ((notmuch-crypto-process-mime nil))
46         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
47         (test-visible-output))'
48 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-process-crypto-mime-parts-off
49
50 test_begin_subtest "process cryptographic MIME parts"
51 test_emacs '(let ((notmuch-crypto-process-mime t))
52         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
53         (test-visible-output))'
54 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-process-crypto-mime-parts-on
55
56 test_begin_subtest "process cryptographic MIME parts (w/ notmuch-show-toggle-process-crypto)"
57 test_emacs '(let ((notmuch-crypto-process-mime nil))
58         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
59         (notmuch-show-toggle-process-crypto)
60         (test-visible-output))'
61 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-process-crypto-mime-parts-on
62
63 test_begin_subtest "notmuch-show: don't elide non-matching messages"
64 test_emacs '(let ((notmuch-show-only-matching-messages nil))
65         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
66         (notmuch-test-wait)
67         (notmuch-search-show-thread)
68         (notmuch-test-wait)
69         (test-visible-output))'
70 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-elide-non-matching-messages-off
71
72 test_begin_subtest "notmuch-show: elide non-matching messages"
73 test_emacs '(let ((notmuch-show-only-matching-messages t))
74         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
75         (notmuch-test-wait)
76         (notmuch-search-show-thread)
77         (notmuch-test-wait)
78         (test-visible-output))'
79 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-elide-non-matching-messages-on
80
81 test_begin_subtest "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
82 test_emacs '(let ((notmuch-show-only-matching-messages nil))
83         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
84         (notmuch-test-wait)
85         (notmuch-search-show-thread)
86         (notmuch-test-wait)
87         (notmuch-show-toggle-elide-non-matching)
88         (test-visible-output))'
89 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-elide-non-matching-messages-on
90
91 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
92 test_emacs '(let ((notmuch-show-only-matching-messages nil))
93         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
94         (notmuch-test-wait)
95         (notmuch-search-show-thread t)
96         (notmuch-test-wait)
97         (test-visible-output))'
98 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-elide-non-matching-messages-on
99
100 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
101 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
102         (notmuch-test-wait)
103         (notmuch-search-show-thread)
104         (notmuch-test-wait)
105         (notmuch-show-toggle-thread-indentation)
106         (test-visible-output)'
107 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-indent-thread-content-off
108
109 test_begin_subtest "id buttonization"
110 add_message '[body]="
111 id:abc
112 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
113 id:foo@bar.?baz? id:foo@bar!.baz!
114 (id:foo@bar.baz) [id:foo@bar.baz]
115 id:foo@bar.baz...
116 id:2+2=5
117 id:=_-:/.[]@$%+
118 id:abc)def
119 id:ab\"c def
120 id:\"abc\"def
121 id:\"ab\"\"c\"def
122 id:\"ab c\"def
123 id:\"abc\".def
124 id:\"abc
125 \"
126 id:)
127 id:
128 cid:xxx
129 mid:abc mid:abc/def
130 mid:abc%20def
131 mid:abc. mid:abc, mid:abc;"'
132 test_emacs '(notmuch-show "id:'$gen_msg_id'")
133         (notmuch-test-mark-links)
134         (test-visible-output "OUTPUT.raw")'
135 cat <<EOF >EXPECTED
136 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
137 Subject: id buttonization
138 To: Notmuch Test Suite <test_suite@notmuchmail.org>
139 Date: GENERATED_DATE
140
141 <<id:abc>>
142 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
143 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
144 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
145 <<id:foo@bar.baz>>...
146 <<id:2+2=5>>
147 <<id:=_-:/.[]@$%+>>
148 <<id:abc>>)def
149 <<id:ab"c>> def
150 <<id:"abc">>def
151 <<id:"ab""c">>def
152 <<id:"ab c">>def
153 <<id:"abc">>.def
154 id:"abc
155 "
156 id:)
157 id:
158 cid:xxx
159 <<mid:abc>> <<mid:abc/def>>
160 <<mid:abc%20def>>
161 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
162 EOF
163 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
164 test_expect_equal_file OUTPUT EXPECTED
165
166
167 test_begin_subtest "Show handles subprocess errors"
168 cat > notmuch_fail <<EOF
169 #!/bin/sh
170 echo This is output
171 echo This is an error >&2
172 exit 1
173 EOF
174 chmod a+x notmuch_fail
175 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
176                (with-current-buffer \"*Messages*\" (erase-buffer))
177                (condition-case err
178                    (notmuch-show \"*\")
179                  (error (message \"%s\" (second err))))
180                (notmuch-test-wait)
181                (with-current-buffer \"*Messages*\"
182                   (test-output \"MESSAGES\"))
183                (with-current-buffer \"*Notmuch errors*\"
184                   (test-output \"ERROR\"))
185                (test-output))"
186 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
187 === OUTPUT ===
188 === MESSAGES ===
189 This is an error (see *Notmuch errors* for more details)
190 === ERROR ===
191 [XXX]
192 This is an error
193 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=1 --exclude\\=false \\' \\* \\'
194 exit status: 1
195 stderr:
196 This is an error
197 stdout:
198 This is output"
199
200
201 test_done