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