diff options
author | 2016-05-03 16:06:11 +0000 | |
---|---|---|
committer | 2016-05-03 16:06:11 +0000 | |
commit | 554a44c8523ca391ba8940cab970b81cc76ef8b0 (patch) | |
tree | 2831c9b85c4eefd511269799b0f2ec5da04af0e7 | |
parent | fix overriding of StreamLocalBindMask and StreamLocalBindUnlink in (diff) | |
download | wireguard-openbsd-554a44c8523ca391ba8940cab970b81cc76ef8b0.tar.xz wireguard-openbsd-554a44c8523ca391ba8940cab970b81cc76ef8b0.zip |
Regression tests for fold(1).
The lines containing SKIPUTF8 will be removed once the utility is fixed.
-rw-r--r-- | regress/usr.bin/Makefile | 4 | ||||
-rw-r--r-- | regress/usr.bin/fold/Makefile | 6 | ||||
-rw-r--r-- | regress/usr.bin/fold/fold.sh | 85 |
3 files changed, 93 insertions, 2 deletions
diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile index 8445b346bf7..f3410b5edf0 100644 --- a/regress/usr.bin/Makefile +++ b/regress/usr.bin/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.34 2016/04/10 15:00:03 schwarze Exp $ +# $OpenBSD: Makefile,v 1.35 2016/05/03 16:06:11 schwarze Exp $ # $NetBSD: Makefile,v 1.1 1997/12/30 23:27:11 cgd Exp $ -SUBDIR+= basename bc dc diff diff3 dirname doas file fmt grep gzip +SUBDIR+= basename bc dc diff diff3 dirname doas file fmt fold grep gzip SUBDIR+= m4 mandoc openssl rev sdiff sed signify sort tsort SUBDIR+= xargs diff --git a/regress/usr.bin/fold/Makefile b/regress/usr.bin/fold/Makefile new file mode 100644 index 00000000000..fde587ee75c --- /dev/null +++ b/regress/usr.bin/fold/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 2016/05/03 16:06:11 schwarze Exp $ + +regress: + @sh ${.CURDIR}/fold.sh + +.include <bsd.regress.mk> diff --git a/regress/usr.bin/fold/fold.sh b/regress/usr.bin/fold/fold.sh new file mode 100644 index 00000000000..393e8c7e6cc --- /dev/null +++ b/regress/usr.bin/fold/fold.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# +# Copyright (c) 2016 Ingo Schwarze <schwarze@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. + +test_fold() +{ + expect=`echo -n "$3" ; echo .` + if [ $SKIPUTF8 -eq 0 ]; then + result=`echo -n "$2" | fold $1 2>&1 ; echo .` + if [ "$result" != "$expect" ]; then + echo "fold $1 \"$2\":" + echo -n "$2" | hexdump -C + echo "expect: $expect" + echo -n "$expect" | hexdump -C + echo "result: $result" + echo -n "$result" | hexdump -C + exit 1 + fi + fi + [ -n "$4" ] && expect=`echo -n "$4" ; echo .` + result=`echo -n "$2" | fold -b $1 2>&1 ; echo .` + if [ "$result" != "$expect" ]; then + echo "fold -b $1 \"$2\":" + echo -n "$2" | hexdump -C + echo "expect: $expect" + echo -n "$expect" | hexdump -C + echo "result: $result" + echo -n "$result" | hexdump -C + exit 1 + fi +} + +export LC_ALL=C + +SKIPUTF8=0 + +test_fold "" "" "" +test_fold "" "\n" "\n" +test_fold "" "\n\n" "\n\n" +test_fold "-w 1" "\n\n" "\n\n" + +# backspace +test_fold "-w 2" "123" "12\n3" +test_fold "-w 2" "1\b234" "1\b23\n4" "1\b\n23\n4" +test_fold "-w 2" "\b1234" "\b12\n34" "\b1\n23\n4" +test_fold "-w 2" "12\r3" "12\r3" "12\n\r3" + +# tabulator +test_fold "-w 2" "1\t9" "1\n\t\n9" "1\t\n9" +test_fold "-w 8" "0\t123456789" "0\t\n12345678\n9" "0\t123456\n789" +test_fold "-w 9" "1\t9\b\b89012" "1\t9\b\b89\n012" "1\t9\b\b8901\n2" + +# split after last blank +test_fold "-sw 4" "1 23 45" "1 \n23 \n45" +test_fold "-sw 3" "1234 56" "123\n4 \n56" + +export LC_ALL=en_US.UTF-8 + +# invalid characters +test_fold "-w 3" "1\037734" "1\03773\n4" +test_fold "-w 3" "1\000734" "1\00073\n4" + +SKIPUTF8=1 + +# double width characters +test_fold "-w 4" "1\0343\0201\020145" "1\0343\0201\02014\n5" \ + "1\0343\0201\0201\n45" + +# zero width characters +test_fold "-w 3" "1a\0314\020034" "1a\0314\02003\n4" "1a\0314\n\020034" +test_fold "-w 2" "1a\0314\02003" "1a\0314\0200\n3" "1a\n\0314\0200\n3" + +exit 0 |