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