Add regression tests for mail.
authoranton <anton@openbsd.org>
Wed, 28 Jun 2017 15:09:41 +0000 (15:09 +0000)
committeranton <anton@openbsd.org>
Wed, 28 Jun 2017 15:09:41 +0000 (15:09 +0000)
regress/usr.bin/Makefile
regress/usr.bin/mail/Makefile [new file with mode: 0644]
regress/usr.bin/mail/send.sh [new file with mode: 0644]

index b9bbbf4..0a06d0a 100644 (file)
@@ -1,9 +1,9 @@
-#      $OpenBSD: Makefile,v 1.41 2017/06/08 17:33:21 bluhm Exp $
+#      $OpenBSD: Makefile,v 1.42 2017/06/28 15:09:41 anton Exp $
 
 SUBDIR+= basename bc calendar colrm column cut dc diff diff3 dirname doas
 SUBDIR+= file fmt fold grep gzip
-SUBDIR+= jot lastcomm m4 mandoc openssl rev sdiff sed signify sort tsort ul
-SUBDIR+= wc xargs
+SUBDIR+= jot lastcomm m4 mail mandoc openssl rev sdiff sed signify sort tsort
+SUBDIR+= ul wc xargs
 
 .if defined(REGRESS_FULL) || make(clean) || make(cleandir) || make(obj)
 SUBDIR+= cap_mkdb libtool make patch pkg-config rcs ssh
diff --git a/regress/usr.bin/mail/Makefile b/regress/usr.bin/mail/Makefile
new file mode 100644 (file)
index 0000000..c6232af
--- /dev/null
@@ -0,0 +1,15 @@
+REGRESS_TARGETS=       send
+
+PROG=          edit
+SRCS=          edit.c
+CFLAGS+=       -Wall
+LDADD+=                -lutil
+CLEANFILES+=   edit.c
+
+edit.c: ${.CURDIR}/../../bin/ksh/edit/edit.c
+       @cp ${.CURDIR}/../../bin/ksh/edit/edit.c .
+
+send: edit
+       @sh ${.CURDIR}/send.sh
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mail/send.sh b/regress/usr.bin/mail/send.sh
new file mode 100644 (file)
index 0000000..bbbd258
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright (c) 2017 Anton Lindqvist <anton@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+set -e
+
+testseq() {
+       stdin=$1
+       exp=$(echo "$2")
+       act=$(echo -n "$stdin" | ./edit mail -En unknown)
+       [ "$exp" = "$act" ] && return 0
+
+       echo input:
+       echo ">>>${stdin}<<<"
+       echo -n "$stdin" | hexdump -C
+       echo expected:
+       echo ">>>${exp}<<<"
+       echo -n "$exp" | hexdump -C
+       echo actual:
+       echo ">>>${act}<<<"
+       echo -n "$act" | hexdump -C
+
+       return 1
+}
+
+MALLOC_OPTIONS=S
+export MALLOC_OPTIONS
+
+# NL: New line.
+testseq "\n" "Subject: \r\n"
+
+# VERASE: Delete character.
+testseq "\0177" "Subject: "
+testseq "a\0177" "Subject: a\b \b"
+
+# VINTR: Kill letter.
+testseq "\0003\0003" \
+       "Subject: ^C\r\n(Interrupt -- one more to kill letter)\r\nSubject: "
+
+# VKILL: Kill line.
+testseq "\0025" "Subject: "
+testseq "ab\0025" "Subject: ab\b\b  \b\b"
+
+# VWERASE: Delete word.
+testseq "\0027" "Subject: "
+testseq "ab\0027" "Subject: ab\b\b  \b\b"
+testseq "ab cd\0027\0027" "Subject: ab cd\b\b  \b\b\b\b\b   \b\b\b"