Fixed printf's in test suite.
[mmh] / test / rcv / test-rcvstore
1 #!/bin/sh
2 ######################################################
3 #
4 # Test rcvstore
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 # Use proper program, likely not the first one on PATH.
20 rcvstore="${MH_LIB_DIR}/rcvstore"
21
22 expected=$MH_TEST_DIR/$$.expected
23 expected_err=$MH_TEST_DIR/$$.expected_err
24 actual=$MH_TEST_DIR/$$.actual
25 actual_err=$MH_TEST_DIR/$$.actual_err
26
27
28 # check -help
29 cat >$expected <<EOF
30 Usage: rcvstore [+folder] [switches]
31   switches are:
32   -[no]create
33   -[no]unseen
34   -[no]public
35   -[no]zero
36   -sequence name
37   -version
38   -help
39 EOF
40
41 $rcvstore -help >$actual 2>&1
42 check $expected $actual
43
44 # check -version
45 case `$rcvstore -v` in
46   rcvstore\ --*) ;;
47   *            ) printf '%s: rcvstore -v generated unexpected output\n' "$0" >&2
48                  failed=`expr ${failed:-0} + 1`;;
49 esac
50
51 # check unknown switch
52 run_test "$rcvstore -nonexistent" 'rcvstore: -nonexistent unknown'
53
54 # check with no switches and zero-length input message
55 cat >$expected <<EOF
56 rcvstore: empty file
57 EOF
58
59 $rcvstore </dev/null >$actual 2>&1
60 check $expected $actual
61
62 # check with no switches
63 cat >$expected <<EOF
64 EOF
65 $rcvstore <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
66 check $expected $actual 'keep first'
67 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
68
69 # check + of existing folder
70 $rcvstore +inbox <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
71 check $expected $actual 'keep first'
72 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
73
74 # check + of new folder
75 $rcvstore +newfolder <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
76 check $expected $actual 'keep first'
77 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/newfolder/1" \
78   'keep first'
79 rmdir "${MH_TEST_DIR}/Mail/newfolder"
80
81 # check -nocreate
82 cat >$expected_err <<EOF
83 rcvstore: folder ${MH_TEST_DIR}/Mail/newfolder doesn't exist
84 EOF
85
86 set +e
87 $rcvstore +newfolder -nocreate <${MH_TEST_DIR}/Mail/inbox/1 >$actual \
88   2>$actual_err
89 set -e
90 check $expected $actual 'keep first'
91 check $expected_err $actual_err
92
93 # check -create
94 $rcvstore +newfolder -nocreate -create <${MH_TEST_DIR}/Mail/inbox/1 \
95   >$actual 2>&1
96 check $expected $actual 'keep first'
97 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/newfolder/1" \
98   'keep first'
99 rmdir "${MH_TEST_DIR}/Mail/newfolder"
100
101 # check addition to unseen sequence
102 printf 'Unseen-Sequence: unseen\n' >> $MH
103 $rcvstore <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
104 check $expected $actual 'keep first'
105 run_test 'mark -sequence unseen -list' 'unseen: 11'
106 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
107 #### Need to clear the unseen sequence.
108 touch "${MH_TEST_DIR}/Mail/inbox/11"
109 rmm 11
110
111 # check -nounseen
112 $rcvstore -nounseen <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
113 check $expected $actual 'keep first'
114 run_test 'mark -sequence unseen -list' 'unseen: '
115 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
116
117 # check -unseen
118 $rcvstore -nounseen -unseen <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
119 check $expected $actual 'keep first'
120 run_test 'mark -sequence unseen -list' 'unseen: 11'
121 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
122
123 # check -sequence
124 $rcvstore -sequence newseq <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
125 check $expected $actual 'keep first'
126 run_test 'mark -sequence newseq -list' 'newseq: 11'
127 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
128
129 # check that default is -nozero
130 mark -sequence newseq all
131 $rcvstore -sequence newseq <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
132 check $expected $actual 'keep first'
133 run_test 'mark -sequence newseq -list' 'newseq: 1-11'
134 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
135
136 # check -zero
137 mark -sequence newseq all
138 $rcvstore -sequence newseq -zero <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
139 check $expected $actual 'keep first'
140 run_test 'mark -sequence newseq -list' 'newseq: 11'
141 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
142
143 # check -nozero
144 mark -sequence newseq all
145 $rcvstore -seq newseq -zero -nozero <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
146 check $expected $actual 'keep first'
147 run_test 'mark -sequence newseq -list' 'newseq: 1-11'
148 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
149
150 # check that default is -public
151 $rcvstore -sequence pubseq <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
152 check $expected $actual 'keep first'
153 run_test 'mark -sequence pubseq -list' 'pubseq: 11'
154 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
155
156 # check -nopublic
157 $rcvstore -sequence privseq -nopublic <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
158 check $expected $actual 'keep first'
159 run_test 'mark -sequence privseq -nopublic -list' 'privseq (private): 11'
160 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
161
162 # check -public
163 $rcvstore -sequence pubseq -nopublic -public <${MH_TEST_DIR}/Mail/inbox/1 \
164   >$actual 2>&1
165 check $expected $actual 'keep first'
166 run_test 'mark -sequence pubseq -public -list' 'pubseq: 11'
167 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
168
169 #### Windows FAT filesystems don't support file permissions that
170 #### disallow read access, and chmod doesn't fail.  If a test above
171 #### has failed, report that failure.  Otherwise, report that we're
172 #### skipping the remainer of the test if chmod can't remove read
173 #### permission.
174 printf '\n' >${MH_TEST_DIR}/Mail/test-read-perms
175 chmod 600 ${MH_TEST_DIR}/Mail/test-read-perms
176 if [ "`find ${MH_TEST_DIR}/Mail/test-read-perms -perm 600`"x = ''x ]; then
177   if [ ${failed:-0} -eq 0 ]; then
178     echo "$Test $0 SKIP (cannot remove read permission on plain files)"
179     exit 77
180   else
181     exit $failed
182   fi
183 else
184   rm -f ${MH_TEST_DIR}/Mail/test-read-perms
185 fi
186
187 # check default Msg-Protect
188 msgprot=`mhparam msgprot`
189 $rcvstore <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
190 check $expected $actual 'keep first'
191 run_test "find ${MH_TEST_DIR}/Mail/inbox/11 -perm $msgprot" \
192   "${MH_TEST_DIR}/Mail/inbox/11"
193 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11" 'keep first'
194
195 # check Msg-Protect profile entry
196 msgprot=640
197 printf 'Msg-Protect: %s\n' "$msgprot" >>$MH
198 $rcvstore <${MH_TEST_DIR}/Mail/inbox/1 >$actual 2>&1
199 check $expected $actual
200 run_test "find ${MH_TEST_DIR}/Mail/inbox/11 -perm $msgprot" \
201   "${MH_TEST_DIR}/Mail/inbox/11"
202 check "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
203
204
205 exit ${failed:-0}