Fixed printf's 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 -s '4a\Nmh-test:' "${MH_TEST_DIR}/Mail/inbox/1" >"$expected"
126 anno 1 -component Nmh-test -append
127 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
128 check "$expected" "$actual"
129 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
130
131 # check -list
132 printf 'Nmh-test: test of anno -list\n' >"$expected"
133 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
134 anno 1 -component Nmh-test -nodate -text 'test of anno -list'
135 run_test 'anno 1 -component Nmh-test -list' 'test of anno -list'
136 # check -text
137 check "$expected" "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
138 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
139
140 # check -list -number
141 printf 'Nmh-test: test of anno -list -number\n' >"$expected"
142 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
143 anno 1 -component Nmh-test -nodate -text 'test of anno -list -number'
144 run_test 'anno 1 -component Nmh-test -list -number' \
145          '1     test of anno -list -number'
146 check "$expected" "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
147 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
148
149 # check -delete
150 cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
151 anno 1 -component Nmh-test
152 anno 1 -component Nmh-test -delete
153 sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
154 check "$expected" "$actual"
155 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
156
157 # check -delete -number
158 printf 'Nmh-test: 1\nNmh-test: 3\n' >"$expected"
159 cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
160 anno 1 -component Nmh-test -nodate -text 3
161 anno 1 -component Nmh-test -nodate -text 2
162 anno 1 -component Nmh-test -nodate -text 1
163 anno 1 -component Nmh-test -delete -number 2
164 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
165 check "$expected" "$actual"
166 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
167
168 # check -delete -all
169 cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
170 anno 1 -component Nmh-test -nodate -text 3
171 anno 1 -component Nmh-test -nodate -text 2
172 anno 1 -component Nmh-test -nodate -text 1
173 anno 1 -component Nmh-test -delete -number all
174 cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
175 check "$expected" "$actual"
176 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
177
178 # check -preserve
179 touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/1"
180 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
181 anno 1 -component Nmh-test -preserve
182 anno 1 -component Nmh-test -preserve -delete
183 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
184 check "$actual-ls1" "$actual-ls2"
185 cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"
186
187 # check -nopreserve
188 touch -t '2012100100.00' "${MH_TEST_DIR}/Mail/inbox/1"
189 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
190 anno 1 -component Nmh-test -preserve -nopreserve
191 anno 1 -component Nmh-test -preserve -nopreserve -delete
192 ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
193 set +e
194 diff "$actual-ls1" "$actual-ls2" >/dev/null
195 run_test 'printf 1' "$?"
196 set -e
197 rm "$actual-ls1" "$actual-ls2"
198
199
200 exit ${failed:-0}