03f2f130f41b501756cd6ba8781f6866c3ffa7f8
[mmh] / test / prompter / test-prompter
1 #!/bin/sh
2 ######################################################
3 #
4 # Test prompter
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
25 # check -help
26 cat >$expected <<EOF
27 Usage: prompter [switches] file
28   switches are:
29   -erase chr
30   -kill chr
31   -[no]prepend
32   -[no]rapid
33   -[no]doteof
34   -version
35   -help
36 EOF
37
38 prompter -help >$actual 2>&1
39 check $expected $actual
40
41 # check -version
42 case `prompter -v` in
43   prompter\ --*) ;;
44   *           ) printf "$0: prompter -v generated unexpected output\n" >&2
45                 failed=`expr ${failed:-0} + 1`;;
46 esac
47
48 # check unknown switch
49 run_test 'prompter -nonexistent' 'prompter: -nonexistent unknown'
50
51
52 # check with no switches
53 run_test 'prompter' 'prompter: usage: prompter [switches] file'
54
55 # check with file
56 cat >$expected <<EOF
57 Resent-From: sender@example.com
58 Resent-To: recipient@example.com
59 Resent-cc: cc@example.com
60 Resent-fcc: +outbox
61 --------
62 message body
63 EOF
64
65 cat >$MH_TEST_DIR/prompter-file <<EOF
66 Resent-From: sender@example.com
67 Resent-To:
68 Resent-cc:
69 Resent-fcc:
70 EOF
71
72 printf 'recipient@example.com\ncc@example.com\n+outbox\nmessage body\n' | \
73   prompter $MH_TEST_DIR/prompter-file > /dev/null
74
75 check "$expected" "$MH_TEST_DIR/prompter-file" 'keep first'
76
77 # check -doteof
78 cat >$MH_TEST_DIR/prompter-file <<EOF
79 Resent-From: sender@example.com
80 Resent-To:
81 Resent-cc:
82 Resent-fcc:
83 EOF
84
85 printf 'recipient@example.com\ncc@example.com\n+outbox\nmessage body\n.\n' | \
86   prompter -doteof $MH_TEST_DIR/prompter-file > /dev/null
87
88 check "$expected" "$MH_TEST_DIR/prompter-file" 'keep first'
89
90 # check -nodoteof
91 cat >$MH_TEST_DIR/prompter-file <<EOF
92 Resent-From: sender@example.com
93 Resent-To:
94 Resent-cc:
95 Resent-fcc:
96 EOF
97
98 printf 'recipient@example.com\ncc@example.com\n+outbox\nmessage body\n' | \
99   prompter -doteof -nodoteof $MH_TEST_DIR/prompter-file > /dev/null
100
101 check "$expected" "$MH_TEST_DIR/prompter-file" 'keep first'
102
103 # check -noprepend
104 cat >$MH_TEST_DIR/prompter-file <<EOF
105 Resent-From: sender@example.com
106 Resent-To:
107 Resent-cc:
108 Resent-fcc:
109 --------
110 message body
111 EOF
112
113 printf 'appendage\n' >> "$expected"
114
115 printf 'recipient@example.com\ncc@example.com\n+outbox\nappendage\n' | \
116   prompter -noprepend $MH_TEST_DIR/prompter-file > /dev/null
117
118 check "$expected" "$MH_TEST_DIR/prompter-file"
119
120 # check -prepend
121 cat >$MH_TEST_DIR/prompter-file <<EOF
122 Resent-From: sender@example.com
123 Resent-To:
124 Resent-cc:
125 Resent-fcc:
126 --------
127 message body
128 EOF
129
130 cat >$expected <<EOF
131 Resent-From: sender@example.com
132 Resent-To: recipient@example.com
133 Resent-cc: cc@example.com
134 Resent-fcc: +outbox
135 --------
136 prependage
137 message body
138 EOF
139
140 printf 'recipient@example.com\ncc@example.com\n+outbox\nprependage\n' | \
141   prompter -noprepend -prepend $MH_TEST_DIR/prompter-file > /dev/null
142
143 check "$MH_TEST_DIR/prompter-file" "$expected" 'keep first'
144
145 # check -rapid
146 cat >$expected <<EOF
147 Resent-From: sender@example.com
148 Resent-To: recipient@example.com
149 Resent-cc: cc@example.com
150 Resent-fcc: +outbox
151
152 --------Enter initial text
153
154 --------
155 EOF
156
157 prompter -rapid $MH_TEST_DIR/prompter-file > "$actual" < /dev/null
158
159 check "$expected" "$actual"
160
161 # check -norapid
162 cat >$expected <<EOF
163 Resent-From: sender@example.com
164 Resent-To: recipient@example.com
165 Resent-cc: cc@example.com
166 Resent-fcc: +outbox
167
168 --------Enter initial text
169
170 prependage
171 message body
172 --------
173 EOF
174
175 prompter -rapid -norapid $MH_TEST_DIR/prompter-file > "$actual" < /dev/null
176
177 check "$expected" "$actual"
178
179 # check -erase and -kill.  We can't test their effects because they
180 # only affect the terminal and this test execution might not be
181 # connected to one.  So we can just check that the respective options
182 # were set.
183 cat >$expected <<EOF
184 erase ^U, kill ^?, intr ^@
185 Resent-From: sender@example.com
186 Resent-To: recipient@example.com
187 Resent-cc: cc@example.com
188 Resent-fcc: +outbox
189
190 --------Enter initial text
191
192 prependage
193 message body
194 --------
195 EOF
196
197 printf 'woot woot\n' | \
198   prompter -erase '\15' -kill '\7f' $MH_TEST_DIR/prompter-file > "$actual"
199
200 check "$expected" "$actual"
201
202 # check -body.  It's undocumented but the default, so make sure that
203 # it reverses the effect of -nobody.
204 cat >$expected <<EOF
205 Resent-From: sender@example.com
206 Resent-To: recipient@example.com
207 Resent-cc: cc@example.com
208 Resent-fcc: +outbox
209
210 --------Enter initial text
211
212 woot woot
213 prependage
214 message body
215 --------
216 EOF
217
218 prompter -nobody -body $MH_TEST_DIR/prompter-file > "$actual" < /dev/null
219
220 check "$expected" "$actual"
221
222 # check -nobody.  It's undocumented but looks like it removes the body.
223 cat >$expected <<EOF
224 Resent-From: sender@example.com
225 Resent-To: recipient@example.com
226 Resent-cc: cc@example.com
227 Resent-fcc: +outbox
228 EOF
229
230 prompter -nobody $MH_TEST_DIR/prompter-file > /dev/null
231
232 check "$expected" "$MH_TEST_DIR/prompter-file"
233
234
235 exit ${failed:-0}