In test-post-common.sh and test-mhmail, wait for fakesmtp to start
[mmh] / test / mhmail / test-mhmail
index 5a7117b..fa90586 100755 (executable)
@@ -18,8 +18,7 @@ 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 &
@@ -28,9 +27,9 @@ test_mhmail ()
     # 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
+    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
         if [ $3 = '|' ]; then
-          if printf "$4" | mhmail recipient@example.com $2 \
+          if printf '%s' "$4" | mhmail recipient@example.com $2 \
              -server 127.0.0.1 -port $localport; then
               status=0
               break
@@ -42,9 +41,13 @@ test_mhmail ()
               break
           fi
         fi
-        sleep 1
+        sleep 2
     done
-    [ $status -eq 0 ] || exit 1
+    if [ $status -ne 0 ]; then
+      printf '%s: mhmail failed, was fakesmtp given enough time to start?\n' \
+             "$0" >&2
+      exit 1
+    fi
 
     wait ${pid}
 
@@ -57,8 +60,7 @@ test_mhmail ()
 
     sed -e 's/^Date:.*/Date:/' \
         -e 's/^Resent-Date:.*/Resent-Date:/' \
-        -e 's/^Message-ID:.*/Message-ID:/' \
-        -e 's/^Content-ID:.*/Content-ID:/' "$actual" > "$actual".nodate
+        -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
     rm -f "$actual"
 
     check "$actual".nodate "$1"
@@ -99,8 +101,8 @@ 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 for missing argument to switches that require them
@@ -122,10 +124,10 @@ done
 # 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
 
@@ -288,7 +290,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" <<EOF
 EHLO nosuchhost.example.com
@@ -462,7 +464,8 @@ Date:
 QUIT
 EOF
 
-test_mhmail "$expected" '-from sender@localhost' '|' '\n'
+test_mhmail "$expected" '-from sender@localhost' '|' '
+'
 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
 
 
@@ -484,7 +487,10 @@ Date:
 QUIT
 EOF
 
-test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n'
+test_mhmail "$expected" '-from sender@localhost' '|' '
+
+
+'
 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
 
 
@@ -526,7 +532,10 @@ here's some text
 QUIT
 EOF
 
-test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
+test_mhmail "$expected" '-from sender@localhost' '|' "here's some text
+
+
+"
 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
 
 
@@ -795,7 +804,6 @@ To: recipient@example.com
 From: sender@example.com
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID:
 Date:
 Message-ID: