Rework in the test framework; updated and new tests
[mmh] / test / tests / anno / test-anno
1 #!/bin/sh
2 ######################################################
3 #
4 # Test anno
5 #
6 ######################################################
7
8 . "$MH_TEST_COMMON"
9
10
11 # check -help
12 runandcheck "anno -help" <<!
13 Usage: anno [+folder] [msgs] [switches]
14   switches are:
15   -component field
16   -[no]date
17   -text body
18   -Version
19   -help
20   -list
21   -delete
22   -number
23   -append
24   -[no]preserve
25 !
26
27
28 # check -Version
29 case `anno -V` in
30   anno\ --*) ;;
31   *        ) printf '%s: anno -V generated unexpected output\n' "$0" >&2
32              failed=`expr "${failed:-0}" + 1`;;
33 esac
34
35
36 # check unknown switch
37 runandcheck "anno -nonexistent ||:" <<!
38 anno: -nonexistent unknown
39 !
40
41
42 cp "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
43
44 # check with no switches
45
46 runandcheck 'anno -comp Nmh-test 11' <<!
47 !
48 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
49 runandcheck "cat `mhpath l`" <<!
50 Nmh-test:
51 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
52 !
53 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
54
55
56 # check -component
57
58 runandcheck 'anno -component Nmh-test 11' <<!
59 !
60 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
61 runandcheck "cat `mhpath l`" <<!
62 Nmh-test:
63 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
64 !
65 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
66
67
68 # check +folder
69
70 runandcheck 'anno -component Nmh-test +inbox 11' <<!
71 !
72 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
73 runandcheck "cat `mhpath l`" <<!
74 Nmh-test:
75 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
76 !
77 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
78
79
80
81
82 # check msg
83
84 folder -fast 2 >/dev/null
85
86 runandcheck "anno 11 -component Nmh-test" <<!
87 !
88 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
89 runandcheck "cat `mhpath l`" <<!
90 Nmh-test:
91 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
92 !
93 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
94
95
96
97 # Hard link the message and verify that the new one does get annotated.
98
99 ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
100 runandcheck "anno 8 -component Nmh-test" <<!
101 !
102 runandcheck "diff -u $MH_TEST_DIR/Mail/inbox/8 $MH_TEST_DIR/Mail/inbox/8.link" <<!
103 !
104
105
106 # check -nodate.  Without -text, it doesn't change the message.
107
108 runandcheck "anno 11 -component Nmh-test -nodate" <<!
109 anno: -nodate without -text is a no-op.
110 !
111 runandcheck "diff -u `mhpath f` `mhpath 11`" <<!
112 !
113 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
114
115
116 # check -date
117
118 runandcheck "anno 11 -component Nmh-test -nodate -date" <<!
119 !
120 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
121 runandcheck "cat `mhpath l`" <<!
122 Nmh-test:
123 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
124 !
125 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
126
127
128
129 # check -append
130
131 runandcheck "anno 11 -component Nmh-test -append" <<!
132 !
133 sed -e 's/^Nmh-test:.*/Nmh-test:/' "`mhpath 11`" >"`mhpath b`"
134 runandcheck "cat `mhpath l`" <<!
135 `awk '/^$/{print "Nmh-test:"}1' "${MH_TEST_DIR}/Mail/inbox/1"`
136 !
137 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
138
139
140 # check -list
141
142 runandcheck "anno 11 -component Nmh-test -nodate -text 'test of anno -list'" <<!
143 !
144 runandcheck "cat `mhpath 11`" <<!
145 Nmh-test: test of anno -list
146 `cat "${MH_TEST_DIR}/Mail/inbox/1"`
147 !
148 runandcheck 'anno 11 -component Nmh-test -list' <<!
149 test of anno -list
150 !
151 # check -list -number
152 runandcheck 'anno 11 -component Nmh-test -list -number' <<!
153 1       test of anno -list
154 !
155 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
156
157
158 # check -delete
159
160 runandcheck "anno 11 -component Nmh-test" <<!
161 !
162 runandcheck "anno 11 -component Nmh-test -delete" <<!
163 !
164 runandcheck "cat `mhpath 11`" <<!
165 `cat "$MH_TEST_DIR/Mail/inbox/1"`
166 !
167 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
168
169
170 # check -delete -number
171 anno 11 -component Nmh-test -nodate -text 3
172 anno 11 -component Nmh-test -nodate -text 2
173 anno 11 -component Nmh-test -nodate -text 1
174 runandcheck "anno 11 -component Nmh-test -delete -number 2" <<!
175 !
176 runandcheck "cat `mhpath 11`" <<!
177 Nmh-test: 1
178 Nmh-test: 3
179 `cat "$MH_TEST_DIR/Mail/inbox/1"`
180 !
181 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
182
183
184 # check -delete -all
185 anno 11 -component Nmh-test -nodate -text 3
186 anno 11 -component Nmh-test -nodate -text 2
187 anno 11 -component Nmh-test -nodate -text 1
188 runandcheck "anno 11 -component Nmh-test -delete -number all" <<!
189 !
190 runandcheck "cat `mhpath 11`" <<!
191 `cat "$MH_TEST_DIR/Mail/inbox/1"`
192 !
193 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
194
195
196 # check -preserve
197
198 touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/11"
199 output="`ls -l \`mhpath 11\``"
200 runandcheck "anno 11 -component Nmh-test -preserve" <<!
201 !
202 runandcheck "anno 11 -component Nmh-test -preserve -delete" <<!
203 !
204 runandcheck "ls -l `mhpath 11`" <<!
205 $output
206 !
207 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
208
209
210 # check -nopreserve
211
212 touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/11"
213 out1="`ls -l \`mhpath 11\``"
214 runandcheck "anno 11 -component Nmh-test -preserve -nopreserve" <<!
215 !
216 out2="`ls -l \`mhpath 11\``"
217 runandcheck "test \"$out1\" = \"$out2\" || echo differs" <<!
218 differs
219 !
220
221 touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/11"
222 out1="`ls -l \`mhpath 11\``"
223 runandcheck "anno 11 -component Nmh-test -preserve -nopreserve -delete" <<!
224 !
225 out2="`ls -l \`mhpath 11\``"
226 runandcheck "test \"$out1\" = \"$out2\" || echo differs" <<!
227 differs
228 !
229 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/inbox/11"
230