File: test-anno

package info (click to toggle)
nmh 1.6-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,204 kB
  • ctags: 3,851
  • sloc: ansic: 48,922; sh: 16,422; makefile: 559; perl: 509; lex: 402; awk: 74
file content (201 lines) | stat: -rwxr-xr-x 6,983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
######################################################
#
# Test anno
#
######################################################

set -e

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname $0`/../..
    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi

. "$MH_OBJ_DIR/test/common.sh"

setup_test

expected=$MH_TEST_DIR/$$.expected
expected_err=$MH_TEST_DIR/$$.expected_err
actual=$MH_TEST_DIR/$$.actual
actual_err=$MH_TEST_DIR/$$.actual_err

# check -help
cat >"$expected" <<EOF
Usage: anno [+folder] [msgs] [switches]
  switches are:
  -component field
  -[no]inplace
  -[no]date
  -text body
  -version
  -help
  -(dr)aft
  -(l)ist
  -(de)lete
  -(nu)mber
  -(a)ppend
  -([no]p)reserve
EOF

run_prog anno -help >"$actual" 2>&1
check "$expected" "$actual"

# check -version
case `anno -v` in
  anno\ --*) ;;
  *        ) printf '%s: anno -v generated unexpected output\n' "$0" >&2
             failed=`expr ${failed:-0} + 1`;;
esac

# check unknown switch
run_test "anno -nonexistent" 'anno: -nonexistent unknown'

cat "${MH_TEST_DIR}/Mail/inbox/1" >"${MH_TEST_DIR}/Mail/inbox/11"

# check with no switches
printf 'Nmh-test:\n' >"$expected"
cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
folder -fast 1 >/dev/null

printf 'Nmh-test' | run_prog anno >/dev/null
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual" 'keep first'
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -component
run_prog anno -component Nmh-test
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual" 'keep first'
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check +folder
run_prog anno -component Nmh-test +inbox
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual" 'keep first'
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check msg
folder -fast 2 >/dev/null
run_prog anno 1 -component Nmh-test
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual" 'keep first'
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

check_for_hard_links
if [ $hard_links_supported -eq 1 ]; then
  # check -noinplace
  # Hard link the message and verify that the new one doesn't get annotated.
  cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
  ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
  run_prog anno 8 -component Nmh-test -noinplace
  mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
  check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
    'keep first'

  # check -inplace
  # Hard link the message and verify that the new one does get annotated.
  ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
  run_prog anno 8 -component Nmh-test -noinplace -inplace
  check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
fi

# check -nodate.  Without -text, it doesn't change the message.
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "$expected-nodate"
run_prog anno 1 -component Nmh-test -nodate
cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
check "$expected-nodate" "$actual"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -date
run_prog anno 1 -component Nmh-test -nodate -date
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual" 'keep first'
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -draft.
cp -f "${MH_TEST_DIR}/Mail/inbox/1" "${MH_TEST_DIR}/Mail/draft"
run_prog anno -draft -component Nmh-test
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/draft" >"$actual"
check "$expected" "$actual"
rm "${MH_TEST_DIR}/Mail/draft"

# check -append
sed -e 's/\(Subject: Testing message 1\)/\1\
Nmh-test:/' <"${MH_TEST_DIR}/Mail/inbox/1" >"$expected"
run_prog anno 1 -component Nmh-test -append
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -list
printf 'Nmh-test: test of anno -list\n' >"$expected"
cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
run_prog anno 1 -component Nmh-test -nodate -text 'test of anno -list'
run_test 'anno 1 -component Nmh-test -list' 'test of anno -list'
# check -text
check "$expected" "${MH_TEST_DIR}/Mail/inbox/1"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -list -number
printf 'Nmh-test: test of anno -list -number\n' >"$expected"
cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
run_prog anno 1 -component Nmh-test -nodate -text 'test of anno -list -number'
run_test 'anno 1 -component Nmh-test -list -number' \
         '1	test of anno -list -number'
check "$expected" "${MH_TEST_DIR}/Mail/inbox/1"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -delete
cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
run_prog anno 1 -component Nmh-test
run_prog anno 1 -component Nmh-test -delete
sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual"
check "$expected" "$actual"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -delete -number
printf 'Nmh-test: 1\nNmh-test: 3\n' >"$expected"
cat "${MH_TEST_DIR}/Mail/inbox/1" >>"$expected"
run_prog anno 1 -component Nmh-test -nodate -text 3
run_prog anno 1 -component Nmh-test -nodate -text 2
run_prog anno 1 -component Nmh-test -nodate -text 1
run_prog anno 1 -component Nmh-test -delete -number 2
cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
check "$expected" "$actual"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -delete -all
cp "${MH_TEST_DIR}/Mail/inbox/1" "$expected"
run_prog anno 1 -component Nmh-test -nodate -text 3
run_prog anno 1 -component Nmh-test -nodate -text 2
run_prog anno 1 -component Nmh-test -nodate -text 1
run_prog anno 1 -component Nmh-test -delete -number all
cp -f "${MH_TEST_DIR}/Mail/inbox/1" "$actual"
check "$expected" "$actual"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -preserve
touch -t '201210010000.00' "${MH_TEST_DIR}/Mail/inbox/1"
ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
run_prog anno 1 -component Nmh-test -preserve
run_prog anno 1 -component Nmh-test -preserve -delete
ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
check "$actual-ls1" "$actual-ls2"
cp -f "${MH_TEST_DIR}/Mail/inbox/11" "${MH_TEST_DIR}/Mail/inbox/1"

# check -nopreserve
touch -t '2012100100.00' "${MH_TEST_DIR}/Mail/inbox/1"
ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls1"
run_prog anno 1 -component Nmh-test -preserve -nopreserve
run_prog anno 1 -component Nmh-test -preserve -nopreserve -delete
ls -l "${MH_TEST_DIR}/Mail/inbox/1" >"$actual-ls2"
set +e
diff "$actual-ls1" "$actual-ls2" >/dev/null
run_test 'printf 1' "$?"
set -e
rm "$actual-ls1" "$actual-ls2"


exit ${failed:-0}