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