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