Added Message-Id to messages in test suite.
[mmh] / test / anno / test-anno
1 #!/bin/sh
2 ######################################################
3 #
4 # Test anno
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 expected_err=$MH_TEST_DIR/$$.expected_err
21 actual=$MH_TEST_DIR/$$.actual
22 actual_err=$MH_TEST_DIR/$$.actual_err
23
24 # check -help
25 cat >"$expected" <<EOF
26 Usage: anno [+folder] [msgs] [switches]
27   switches are:
28   -component field
29   -[no]inplace
30   -[no]date
31   -text body
32   -version
33   -help
34   -(dr)aft
35   -(l)ist
36   -(de)lete
37   -(nu)mber
38   -(a)ppend
39   -([no]p)reserve
40 EOF
41
42 anno -help >"$actual" 2>&1
43 check "$expected" "$actual"
44
45 # check -version
46 case `anno -v` in
47   anno\ --*) ;;
48   *        ) printf '%s: anno -v generated unexpected output\n' "$0" >&2
49              failed=`expr ${failed:-0} + 1`;;
50 esac
51
52 # check unknown switch
53 run_test "anno -nonexistent" 'anno: -nonexistent unknown'
54
55 cat "${MH_TEST_DIR}/Mail/inbox/1" >"${MH_TEST_DIR}/Mail/inbox/11"
56
57 # check with no switches
58 printf 'Nmh-test:\n' >"$expected"
59 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
60 folder -fast 1 >/dev/null
61
62 printf 'Nmh-test' | anno >/dev/null
63 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
64 check "$expected" "$actual" 'keep first'
65 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
66
67 # check -component
68 anno -component Nmh-test
69 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
70 check "$expected" "$actual" 'keep first'
71 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
72
73 # check +folder
74 anno -component Nmh-test +inbox
75 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
76 check "$expected" "$actual" 'keep first'
77 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
78
79 # check msg
80 folder -fast 2 >/dev/null
81 anno 1 -component Nmh-test
82 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
83 check "$expected" "$actual" 'keep first'
84 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
85
86 check_for_hard_links
87 if [ $hard_links_supported -eq 1 ]; then
88   # check -noinplace
89   # Hard link the message and verify that the new one doesn't get annotated.
90   cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
91   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
92   anno 8 -component Nmh-test -noinplace
93   mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
94   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
95     'keep first'
96
97   # check -inplace
98   # Hard link the message and verify that the new one does get annotated.
99   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
100   anno 8 -component Nmh-test -noinplace -inplace
101   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
102 fi
103
104 # check -nodate.  Without -text, it doesn't change the message.
105 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "$expected-nodate"
106 anno 1 -component Nmh-test -nodate
107 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
108 check "$expected-nodate" "$actual"
109 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
110
111 # check -date
112 anno 1 -component Nmh-test -nodate -date
113 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
114 check "$expected" "$actual" 'keep first'
115 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
116
117 # check -draft.
118 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/draft"
119 anno -draft -component Nmh-test
120 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/draft" >"$actual"
121 check "$expected" "$actual"
122 rm "${MH_TEST_DIR}/Mail/draft"
123
124 # check -append
125 sed -e '5a\
126 Nmh-test:' "${MH_TEST_DIR}/Mail/inbox/1" >"$expected"
127 anno 1 -component Nmh-test -append
128 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
129 check "$expected" "$actual"
130 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
131
132 # check -list
133 printf 'Nmh-test: test of anno -list\n' >"$expected"
134 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
135 anno 1 -component Nmh-test -nodate -text 'test of anno -list'
136 run_test 'anno 1 -component Nmh-test -list' 'test of anno -list'
137 # check -text
138 check "$expected" "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
139 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
140
141 # check -list -number
142 printf 'Nmh-test: test of anno -list -number\n' >"$expected"
143 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
144 anno 1 -component Nmh-test -nodate -text 'test of anno -list -number'
145 run_test 'anno 1 -component Nmh-test -list -number' \
146          '1     test of anno -list -number'
147 check "$expected" "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
148 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
149
150 # check -delete
151 cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
152 anno 1 -component Nmh-test
153 anno 1 -component Nmh-test -delete
154 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
155 check "$expected" "$actual"
156 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
157
158 # check -delete -number
159 printf 'Nmh-test: 1\nNmh-test: 3\n' >"$expected"
160 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
161 anno 1 -component Nmh-test -nodate -text 3
162 anno 1 -component Nmh-test -nodate -text 2
163 anno 1 -component Nmh-test -nodate -text 1
164 anno 1 -component Nmh-test -delete -number 2
165 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
166 check "$expected" "$actual"
167 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
168
169 # check -delete -all
170 cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
171 anno 1 -component Nmh-test -nodate -text 3
172 anno 1 -component Nmh-test -nodate -text 2
173 anno 1 -component Nmh-test -nodate -text 1
174 anno 1 -component Nmh-test -delete -number all
175 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
176 check "$expected" "$actual"
177 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
178
179 # check -preserve
180 touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/1"
181 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
182 anno 1 -component Nmh-test -preserve
183 anno 1 -component Nmh-test -preserve -delete
184 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
185 check "$actual-ls1" "$actual-ls2"
186 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
187
188 # check -nopreserve
189 touch -t '2012100100.00' "${MH_TEST_DIR}/Mail/inbox/1"
190 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
191 anno 1 -component Nmh-test -preserve -nopreserve
192 anno 1 -component Nmh-test -preserve -nopreserve -delete
193 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
194 set +e
195 diff "$actual-ls1" "$actual-ls2" >/dev/null
196 run_test 'printf 1' "$?"
197 set -e
198 rm "$actual-ls1" "$actual-ls2"
199
200
201 exit ${failed:-0}