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