]> diplodocus.org Git - nmh/blob - test/post/test-sendfiles
Fix one of the POP tests to work on wide terminals.
[nmh] / test / post / test-sendfiles
1 #!/bin/sh
2 ######################################################
3 #
4 # Test sendfiles
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 actual=$MH_TEST_DIR/$$.actual
21 localmbox=`$MH_LIB_DIR/ap -format "%(localmbox)" 0`
22 #### Use this script itself for the test file.
23 testfiledir="$srcdir/test/post"
24 testfile=`basename $0`
25
26 (cd "$MH_TEST_DIR" && mkdir -p tmp)
27
28 #### Copy fakesendmail and the testfile because we cd to the
29 #### test directory, because tar doesn't like absolute paths.
30 cp "$srcdir/test/fakesendmail" "$testfiledir/$testfile" "$MH_TEST_DIR"
31
32 #### Use sendmail/pipe below to override default mts.
33 mts_fakesendmail="$MHMTSCONF-fakesendmail"
34 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "$MHMTSCONF" > "$mts_fakesendmail"
35 printf 'sendmail: %s/fakesendmail\n' "$MH_TEST_DIR" >>"$mts_fakesendmail"
36 MHMTSCONF="$mts_fakesendmail"
37
38 # $1: uncompress command
39 # $2: argument style:
40 # new: -to recipient -subject subject
41 # old: recipient subject
42 # remaining arguments: sendfiles switches
43 test_sendfiles ()
44 {
45 uncompress="$1"; shift
46 argstyle="$1"; shift
47
48 if [ "$argstyle" = 'new' ]; then
49 (cd "$MH_TEST_DIR" &&
50 sendfiles "$@" -to recipient@example.com -subject "sendfiles test" \
51 "$testfile" >/dev/null 2>&1)
52 elif [ "$argstyle" = 'old' ]; then
53 (cd "$MH_TEST_DIR" &&
54 sendfiles "$@" recipient@example.com "sendfiles test" \
55 "$testfile" >/dev/null 2>&1)
56 fi
57
58 # fakesendmail drops the message and any cc's into this mbox.
59 mbox="$MH_TEST_DIR"/Mail/fakesendmail.mbox
60 inc -silent -file "$mbox"
61 rm -f "$mbox" "$mbox.map"
62
63 mhlist -verbose last | sed -e 's/ *$//' -e 's/\(octet-stream\).*$/\1/' \
64 >"$actual"
65 (cd $MH_TEST_DIR/tmp &&
66 contents=`mhstore -noauto last 2>&1 | \
67 sed -e 's/storing message.*as file //'` &&
68 $uncompress "$contents" | tar xpf - && rm -f "$contents")
69
70 rmm last
71 check "$testfiledir/$testfile" "$MH_TEST_DIR/tmp/$testfile" \
72 'keep first'
73
74 [ -f "$expected" ] && check "$expected" "$actual" || rm -f "$actual"
75 }
76
77
78 # check -help
79 cat >"$expected" <<EOF
80 Usage: sendfiles [switches] -to recipient -subject subject file1 [file2 ...]
81 or
82 sendfiles [switches] recipient subject file1 [file2 ...]
83 switches are:
84 -compress [bzip2 | compress | gzip | lzma | none]
85 -from <sender>
86 -[delay] <delay> (expressed in seconds)
87 -version
88 -help
89 Can use PERSON environment variable instead of -from switch.
90 EOF
91
92 sendfiles -help >"$actual" 2>&1
93 check "$expected" "$actual"
94
95 # check -version
96 case `sendfiles -v` in
97 sendfiles\ --*) ;;
98 * ) printf '%s: sendfiles -v generated unexpected output\n' "$0" >&2
99 failed=`expr ${failed:-0} + 1`;;
100 esac
101
102 # check unknown switch
103 run_test 'sendfiles -nonexistent' "Usage: sendfiles [switches] -to recipient \
104 -subject subject file1 [file2 ...]
105 or
106 sendfiles [switches] recipient subject file1 [file2 ...]
107 switches are:
108 -compress [bzip2 | compress | gzip | lzma | none]
109 -from <sender>
110 -[delay] <delay> (expressed in seconds)
111 -version
112 -help
113 Can use PERSON environment variable instead of -from switch."
114
115 # check unknown compression method
116 run_test 'sendfiles -compress unknown to subject file' \
117 'sendfiles: unknown compression method "unknown"'"
118 Usage: sendfiles [switches] -to recipient \
119 -subject subject file1 [file2 ...]
120 or
121 sendfiles [switches] recipient subject file1 [file2 ...]
122 switches are:
123 -compress [bzip2 | compress | gzip | lzma | none]
124 -from <sender>
125 -[delay] <delay> (expressed in seconds)
126 -version
127 -help
128 Can use PERSON environment variable instead of -from switch."
129
130 # Check basic operation, using specified compression method.
131 # Don't check the mhlist output, by not creating an $expected file,
132 # because it will vary with compression method and compressed file
133 # size.
134 [ "`findprog bzip2`" ] && test_sendfiles 'bzip2 -cd' new -compress bzip2
135 [ "`findprog compress`" ] && test_sendfiles 'uncompress -c' new \
136 -compress compress
137 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -compress gzip
138 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -gzip
139 [ "`findprog lzma`" ] && test_sendfiles 'lzma -cd' new -compress lzma
140
141 # check with no compression
142 cat >"$expected" <<EOF
143 msg part type/subtype size description
144 11 application/octet-stream
145 type="tar"
146 (extract with cat | tar xvpf -)
147 EOF
148
149 test_sendfiles cat new -compress none
150
151 # check with no compression, -none
152 cat >"$expected" <<EOF
153 msg part type/subtype size description
154 11 application/octet-stream
155 type="tar"
156 (extract with cat | tar xvpf -)
157 EOF
158
159 test_sendfiles cat new -none
160
161 # check old argument style (without -to and -subject)
162 cat >"$expected" <<EOF
163 msg part type/subtype size description
164 11 application/octet-stream
165 type="tar"
166 (extract with cat | tar xvpf -)
167 EOF
168
169 test_sendfiles cat old -compress none
170
171 # check -from
172 cat >"$expected" <<EOF
173 msg part type/subtype size description
174 11 application/octet-stream
175 type="tar"
176 (extract with cat | tar xvpf -)
177 EOF
178
179 test_sendfiles cat new -compress none -from 'Sender <sender@example.com>'
180
181 # check PERSON environment variable
182 cat >"$expected" <<EOF
183 msg part type/subtype size description
184 11 application/octet-stream
185 type="tar"
186 (extract with cat | tar xvpf -)
187 EOF
188
189 PERSON='Sender <sender@example.com>' test_sendfiles cat new -compress none
190
191 # check -delay, though for a small file it doesn't do anything
192 cat >"$expected" <<EOF
193 msg part type/subtype size description
194 11 application/octet-stream
195 type="tar"
196 (extract with cat | tar xvpf -)
197 EOF
198
199 test_sendfiles cat new -compress none -delay 5
200
201 # check old style -delay, though for a small file it doesn't do anything
202 cat >"$expected" <<EOF
203 msg part type/subtype size description
204 11 application/octet-stream
205 type="tar"
206 (extract with cat | tar xvpf -)
207 EOF
208
209 test_sendfiles cat new -compress none -5
210
211 rm -fr "$MH_TEST_DIR/fakesendmail" "$MH_TEST_DIR/$testfile" "$MH_TEST_DIR/tmp"
212
213
214 exit ${failed:-0}