X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=test%2Fmhmail%2Ftest-mhmail;h=37452073cf99b2a2a64dbe7a92ab3d47f918326a;hb=bdddaaec97b85b1e4a23272431076c538afa11c0;hp=422c647dc959b6669bc3db4caf61f2a46c39ed29;hpb=4c3830a96cdc7f17576d986d440a08ead54bee7a;p=mmh diff --git a/test/mhmail/test-mhmail b/test/mhmail/test-mhmail index 422c647..3745207 100755 --- a/test/mhmail/test-mhmail +++ b/test/mhmail/test-mhmail @@ -18,35 +18,18 @@ fi # $1 is expected output file, provided by caller # $2 is mhmail switches, except for -body # $3 of -b signifies use -body switch, | signifies provide body on stdin -# $4 contains message body. When using stdin, can contain printf(1) format -# specifiers. +# $4 contains the message body. test_mhmail () { - "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport & - pid="$!" - - # The server doesn't always come up fast enough, so sleep and - # retry a few times if it fails... - status=1 - for i in 0 1 2 3 4 5 6 7 8 9; do - if [ $3 = '|' ]; then - if printf "$4" | mhmail recipient@example.com $2 \ - -server 127.0.0.1 -port $localport; then - status=0 - break - fi - else - if mhmail recipient@example.com $2 -body "$4" \ - -server 127.0.0.1 -port $localport; then - status=0 - break - fi - fi - sleep 1 - done - [ $status -eq 0 ] || exit 1 - - wait ${pid} + pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport` + + if [ $3 = '|' ]; then + printf '%s' "$4" | mhmail recipient@example.com $2 \ + -server 127.0.0.1 -port $localport + else + mhmail recipient@example.com $2 -body "$4" \ + -server 127.0.0.1 -port $localport + fi # # It's hard to calculate the exact Date: header post is going to @@ -72,12 +55,13 @@ actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err # check -help # Verified behavior consistent with compiled sendmail. cat >$expected <$actual 2>&1 @@ -96,19 +81,33 @@ check $expected $actual # Verified same behavior as compiled mhmail. case `mhmail -v` in mhmail\ --*) ;; - * ) echo "$0: mhmail -v generated unexpected output" 1>&2 - failed=`expr ${failed:-0} + 1`;; + * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2 + failed=`expr ${failed:-0} + 1`;; esac - -# check with no arguments +# check for missing argument to switches that require them +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch" \ + "mhmail: missing argument to -$switch" +done +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch -nosend" \ + "mhmail: missing argument to -$switch" +done +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch -server 127.0.0.1" \ + "mhmail: missing argument to -$switch" +done + + +# check with no switches # That will just run inc, which we don't want to do anything, # so tell inc to just display its version. # Verified same behavior as compiled mhmail. -printf "inc: -version\n" >> $MH +printf 'inc: -version\n' >> $MH case `mhmail` in inc\ --*) ;; - * ) echo "$0: mhmail generated unexpected output" 1>&2 + * ) echo "$0: mhmail generated unexpected output" >&2 failed=`expr ${failed:-0} + 1`;; esac @@ -271,7 +270,7 @@ test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message # 2) use send(1) by added a send switch to the profile and # verifying that it gets used. # Not supported by compiled mhmail. -printf "send: -msgid\n" >> $MH +printf 'send: -msgid\n' >> $MH cat > "$expected" < "$expected" < "$expected" < "$expected" < "$expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com, recipient2@example.com +Cc: cc1@example.com +Subject: Test +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@localhost -cc cc1@example.com -subject Test \ + -to recipient2@example.com" \ + -b message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + # check with no newline on stdin # Shows different behavior than compiled mhmail, which was silent in this case. cat > "$expected" < "$expected" < "$expected" < "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@example.com +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" +Date: +Message-ID: + +------- =_aaaaaaaaaa0 +Content-Type: text/plain; charset="us-ascii" + +See how easy it is to add an attachment! + +------- =_aaaaaaaaaa0 +Content-Type: text/plain; name="attachment.txt"; charset="us-ascii" +Content-Description: attachment.txt +Content-Disposition: attachment; filename="attachment.txt" + +The future disappears into memory, With only a moment between, +Forever dwells in that moment, hope is what remains to be seen +Forever dwells in that moment, hope is what remains to be seen. + +------- =_aaaaaaaaaa0-- +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \ + -b 'See how easy it is to add an attachment!' + +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + exit ${failed:-0}