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