]> diplodocus.org Git - nmh/blob - test/pick/test-pick
new.c: Order two return statements to match comment.
[nmh] / test / pick / test-pick
1 #!/bin/sh
2 ######################################################
3 #
4 # Test pick
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 expected=$MH_TEST_DIR/$$.expected
20 actual=$MH_TEST_DIR/$$.actual
21
22 # Add an 11th message.
23 sed \
24 -e 's/10/11/g' \
25 -e 's/^To:\(.*\)/To:\1\
26 Cc: <another@example.com>/' \
27 -e 's/^\(Date:.*\)2006\( 00:00:\)00/\12008\200\
28 Delivery-Date: \12009\241/' \
29 $MH_TEST_DIR/Mail/inbox/10 >$MH_TEST_DIR/Mail/inbox/11
30
31 # Test message specification.
32 run_test 'pick first last' '1
33 11'
34
35 # Test -and.
36 run_test 'pick -subject message.3 -and -from Test3' '3'
37 run_test 'pick -subject message.3 -and -from Test4' \
38 'pick: no messages match specification
39 0'
40
41 # Test -or.
42 run_test 'pick -subject message.3 -or -from Test3' '3'
43 run_test 'pick -subject message.3 -or -from Test4' '3
44 4'
45
46 # Test -not.
47 run_test 'pick -not -subject message.8 last:5' '7
48 9
49 10
50 11'
51
52 # Test -reverse.
53 run_test 'pick -reverse -not -subject message.8 last:5' '11
54 10
55 9
56 7'
57
58 # Test -lbrace, -rbrace.
59 run_test 'pick -subject message.12 -and -subject message.3 -or -from Test4' '4'
60 run_test 'pick -subject message.12 -and -lbrace -subject message.3 -rbrace' \
61 'pick: no messages match specification
62 0'
63
64 # -and takes precedence over -or.
65 run_test 'pick -subject message.12 -or -subject message.3 -and -from Test3' '3'
66 run_test 'pick -subject message.12 -or -subject message.3 -and -from Test4' \
67 'pick: no messages match specification
68 0'
69
70 # -not takes precedence over -and.
71 run_test 'pick -not -subject message.12 -and -subject message.3' '3'
72 run_test 'pick -not -lbrace -subject NoMatch -and -subject message.3 -rbrace' \
73 '1
74 2
75 3
76 4
77 5
78 6
79 7
80 8
81 9
82 10
83 11'
84
85 # Test -debug.
86 run_prog pick -debug -not -lbrace -subject NoMatch -and -subject message.3 \
87 -rbrace >/dev/null 2>"$actual"
88 cat >"$expected" <<EOF
89 NOT
90 | AND
91 | | PATTERN(header) ^subject[ ]*:.*NoMatch
92 | | PATTERN(header) ^subject[ ]*:.*message.3
93 EOF
94 check "$expected" "$actual"
95
96 set +e
97
98 # Produce 0 if no messages match and standard output is not a tty.
99 # Note that there is an error message on stderr, but it's redirected
100 # to /dev/null here.
101 echo \
102 `run_prog pick -subject message.3 -and -from Test4 >"$actual" 2>/dev/null` \
103 >/dev/null
104 cat >"$expected" <<EOF
105 0
106 EOF
107 check "$expected" "$actual"
108
109 if test -t 1 && (printf '' >/dev/tty) 2>/dev/null; then
110 # Produce no standard output if no messages match and standard
111 # output is a tty. To test that even when run with stdout
112 # detached, write directly to /dev/tty. Can't capture the
113 # output so hopefully the user will notice it.
114 run_prog pick -subject message.3 -and -from Test4 >/dev/tty 2>/dev/null
115 fi
116
117 # Also, check that the exit status is 1.
118 run_prog pick -subject message.3 -and -from Test4 >/dev/null 2>&1
119 run_test "echo $?" '1'
120
121 set -e
122
123 # Test -cc.
124 run_test 'pick -cc another' '11'
125
126 # Test -date.
127 run_test 'pick -date 29.Sep.2008' '11'
128
129 # Test -from.
130 run_test 'pick -from test7' '7'
131
132 # Test -search.
133 run_test 'pick -search This.is.message.number.[456]' '4
134 5
135 6'
136
137 # Test -subject.
138 run_test 'pick -subject message.2' '2'
139
140 # Test -to.
141 run_test 'pick -to some -nolist' '11 hits'
142 run_test 'pick -to user@example.com -nolist' '11 hits'
143
144 # Test -after.
145 run_prog pick -after '28 Sep 2008 00:00:00' >"$actual" 2>&1
146 cat >"$expected" <<EOF
147 11
148 EOF
149 check "$expected" "$actual"
150
151 # Invert exit status so execution doesn't terminate due to -e.
152 set +e
153 run_prog pick -after '29 Sep 2008 00:00:00' >"$actual" 2>/dev/null
154 set -e
155 cat >"$expected" <<EOF
156 0
157 EOF
158 check "$expected" "$actual"
159
160 # Test -before. While -after doesn't include the specified date, -before does.
161 run_prog pick -before '29 Sep 2008 00:00:01' last:3 >"$actual" 2>&1
162 cat >"$expected" <<EOF
163 9
164 10
165 11
166 EOF
167 check "$expected" "$actual"
168 run_prog pick -before '28 Sep 2008 00:00:00:' last:3 >"$actual" 2>&1
169 cat >"$expected" <<EOF
170 9
171 10
172 EOF
173 check "$expected" "$actual"
174 set +e
175 run_prog pick -before '28 Sep 2006 00:00:00' last:3 >"$actual" 2>/dev/null
176 set -e
177 cat >"$expected" <<EOF
178 0
179 EOF
180 check "$expected" "$actual"
181
182 # Test -datefield.
183 set +e
184 run_prog pick -datefield date -after '29 Sep 2008 00:00:00' \
185 >"$actual" 2>/dev/null
186 set -e
187 cat >"$expected" <<EOF
188 0
189 EOF
190 check "$expected" "$actual"
191 run_prog pick -datefield delivery-date -after '29 Sep 2008 00:00:00' \
192 >"$actual" 2>&1
193 cat >"$expected" <<EOF
194 11
195 EOF
196 check "$expected" "$actual"
197
198 # Test sequence creation.
199 run_test 'pick 2 4 6 8 10 -sequence even' '5 hits'
200 run_test 'mark -s even -list' 'even: 2 4 6 8 10'
201
202 # Test private sequence creation.
203 # Set current message for following tests.
204 folder +inbox 1 > /dev/null
205 run_test 'pick -date 29.Sep.2008 -sequence privateseq -nopublic' '1 hit'
206 run_test 'mark -list' 'cur: 1
207 even: 2 4 6 8 10
208 privateseq (private): 11'
209
210 # Test add to private sequence.
211 run_test 'pick first -sequence privateseq -nozero -nopublic' '1 hit'
212 run_test 'mark -list' 'cur: 1
213 even: 2 4 6 8 10
214 privateseq (private): 1 11'
215
216 # Test sequence creation, with -list.
217 run_test 'pick 5 7 -sequence odd -list' '5
218 7'
219 run_test 'mark -s odd -list' 'odd: 5 7'
220
221 # Test sequence creation, with default of -zero.
222 run_test 'pick 1 3 -sequence odd' '2 hits'
223 run_test 'mark -s odd -list' 'odd: 1 3'
224
225 # Test sequence creation, with -nozero.
226 run_test 'pick 5 7 9 -sequence odd -nozero' '3 hits'
227 run_test 'mark -s odd -list' 'odd: 1 3 5 7 9'
228
229 # Test sequence creation, with explicit folder, -public, and -zero.
230 run_test 'pick +inbox 5 7 9 11 -public -sequence odd' '4 hits'
231 run_test 'mark -s odd -list' 'odd: 5 7 9 11'
232
233 # Test -nolist.
234 run_test 'pick all -nolist' '11 hits'
235
236 # Test unfolding of multi-line header fields: it should only
237 # remove embedded newlines.
238 cat >"$MH_TEST_DIR/Mail/inbox/12" <<EOF
239 From: Test12 <test12@example.com>
240 To: Some User <user@example.com>
241 Date: Fri, 29 Sep 2006 00:00:00
242 Message-Id: 12@test.nmh
243 Subject: multi-line
244 header field
245
246 This is message number 12
247 EOF
248
249 echo 12 >"$expected"
250
251 run_prog pick -subject 'multi-line header field' 12 >"$actual" 2>&1
252 check "$expected" "$actual"
253
254 # Test MIME-encoded header.
255 cat >"$MH_TEST_DIR/Mail/inbox/13" <<EOF
256 From: Test13 <test13@example.com>
257 To: Some User <user@example.com>
258 Date: Fri, 29 Sep 2006 00:00:00
259 Message-Id: 13@test.nmh
260 Subject: =?us-ascii?q?=66=6f=6f?=
261 =?utf-8?q?=62=61=72?=
262
263 This is message number 13, with MIME-encoded Subject "foobar".
264 EOF
265
266 echo 13 >"$expected"
267
268 set +e
269
270 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
271 # Don't use run_prog here because it loses the environment setting.
272 pick -subject foobar 13 >"$actual" 2>&1
273 set -e
274 check "$expected" "$actual"
275
276 # Test -nosequence.
277 run_test 'pick +inbox 5 7 9 11 -sequence test -nosequence' '5
278 7
279 9
280 11'
281 run_test 'mark -list -sequence test' 'test: '
282
283
284 exit $failed