From 857a8195d913d351cf4cc52013bf13fba3abbe9e Mon Sep 17 00:00:00 2001 From: anton Date: Wed, 28 Jun 2017 15:09:41 +0000 Subject: [PATCH] Add regression tests for mail. --- regress/usr.bin/Makefile | 6 ++-- regress/usr.bin/mail/Makefile | 15 +++++++++ regress/usr.bin/mail/send.sh | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 regress/usr.bin/mail/Makefile create mode 100644 regress/usr.bin/mail/send.sh diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile index b9bbbf41ba0..0a06d0af864 100644 --- a/regress/usr.bin/Makefile +++ b/regress/usr.bin/Makefile @@ -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 index 00000000000..c6232afc677 --- /dev/null +++ b/regress/usr.bin/mail/Makefile @@ -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 diff --git a/regress/usr.bin/mail/send.sh b/regress/usr.bin/mail/send.sh new file mode 100644 index 00000000000..bbbd2581dba --- /dev/null +++ b/regress/usr.bin/mail/send.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# +# Copyright (c) 2017 Anton Lindqvist +# +# 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" -- 2.20.1