summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2015-12-22 22:37:57 +0000
committerschwarze <schwarze@openbsd.org>2015-12-22 22:37:57 +0000
commit27f4a94870df59122fa67f96ea33e5e49a1ad824 (patch)
treec8d1faddbbd1f10e08b02e9330c0556c8f2a358b
parentMake xs_setprop a bit more useful by removing property nodes (diff)
downloadwireguard-openbsd-27f4a94870df59122fa67f96ea33e5e49a1ad824.tar.xz
wireguard-openbsd-27f4a94870df59122fa67f96ea33e5e49a1ad824.zip
Test suite for colrm(1) including tests for single byte characters,
tabs, backspaces, multibyte characters of width 1, 0, and 2, invalid bytes and non-printable characters. All tests are run both with the UTF-8 and the C locale. About half the tests are currently broken, and not only the multibyte tests, but also half of the tab and backspace tests. The program is expected to be fixed soon, and the suite will be hooked up after that.
-rw-r--r--regress/usr.bin/colrm/Makefile8
-rw-r--r--regress/usr.bin/colrm/colrm.sh100
2 files changed, 108 insertions, 0 deletions
diff --git a/regress/usr.bin/colrm/Makefile b/regress/usr.bin/colrm/Makefile
new file mode 100644
index 00000000000..91abc400e11
--- /dev/null
+++ b/regress/usr.bin/colrm/Makefile
@@ -0,0 +1,8 @@
+# $OpenBSD: Makefile,v 1.1 2015/12/22 22:37:57 schwarze Exp $
+
+REGRESS_TARGETS = colrm
+
+colrm:
+ sh ${.CURDIR}/colrm.sh
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/colrm/colrm.sh b/regress/usr.bin/colrm/colrm.sh
new file mode 100644
index 00000000000..f50e95b276e
--- /dev/null
+++ b/regress/usr.bin/colrm/colrm.sh
@@ -0,0 +1,100 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 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.
+
+unset LC_ALL
+
+test_colrm()
+{
+ args=$1
+ stdin=$2
+ expected=`echo -n "$3."`
+ export LC_CTYPE=en_US.UTF-8
+ result=`echo -n "$stdin" | colrm $args ; echo -n .`
+ if [ "$result" != "${expected}" ]; then
+ echo "echo -n \"$stdin\" | colrm $args"
+ echo "expected: \"$expected\""
+ echo "result: \"$result\""
+ exit 1;
+ fi
+
+ if [ -n "$4" ]; then
+ expected=`echo -n "$4."`
+ fi
+ export LC_CTYPE=C
+ result=`echo -n "$stdin" | colrm $args ; echo -n .`
+ if [ "$result" != "${expected}" ]; then
+ echo "[C] echo -n \"$stdin\" | colrm $args"
+ echo "expected: \"$expected\""
+ echo "result: \"$result\""
+ exit 1;
+ fi
+}
+
+# single byte characters
+test_colrm "" "abcd" "abcd"
+test_colrm "2" "abcd" "a"
+test_colrm "5" "abcd" "abcd"
+test_colrm "2 3" "abcd" "ad"
+test_colrm "5 6" "abcd" "abcd"
+
+# tab characters
+test_colrm "" "a\tb" "a\tb"
+test_colrm "10" "\tab" "\ta"
+test_colrm "9" "\tab" "\t"
+test_colrm "8" "\tab" " "
+test_colrm "3 7" "a\tb" "a b"
+test_colrm "7 9" "abcd\txe" "abcd e"
+test_colrm "3 6" "abcd\tef" "ab ef"
+
+# zero width
+test_colrm "2 2" "ax̀b" "ab" "àb"
+test_colrm "3 3" "ax̀bx̀c" "ax̀x̀c" \
+ "ax€bxÌ€c"
+
+# double width
+test_colrm "2 3" "aì¿¿b" "ab" "a¿b"
+test_colrm "2 2" "aì¿¿b" "a b" "a¿¿b"
+test_colrm "3 3" "aì¿¿b" "a b" "aì¿b"
+test_colrm "4 4" "aì¿¿bì¿¿c" "aì¿¿ì¿¿c" \
+ "aì¿bì¿¿c"
+
+# backspaces
+test_colrm "3 3" "ab_cd_e" "ab_d_e"
+test_colrm "2 2" "ab_c" "ac"
+test_colrm "2 2" "ax̀b" "ab" "àb"
+test_colrm "3 3" "ax̀bx̀c" "ax̀x̀c" \
+ "ax€bxÌ€c"
+test_colrm "2 3" "aì¿¿bcde" "ade" "a¿bcde"
+test_colrm "2 2" "aì¿¿bcde" "acde" "a¿¿bcde"
+test_colrm "3 3" "aì¿¿bcde" "abde" "aì¿bcde"
+test_colrm "4 4" "aì¿¿bì¿¿c" "aì¿¿ì¿¿c" \
+ "aì¿bì¿¿c"
+test_colrm "" "\bx" "\bx"
+test_colrm "1" "\bx" "\b"
+
+# invalid bytes and non-printable characters
+test_colrm "3 3" "aÿbÿc" "aÿÿc"
+test_colrm "2 2" "aÿb" "ab"
+test_colrm "3 3" "abc" "ac"
+test_colrm "2 2" "ab" "ab"
+test_colrm "3 3" "a͸b͸c" "a͸͸c" "aÍb͸c"
+test_colrm "2 2" "a͸b" "ab" "a¸b"
+
+# edge cases
+test_colrm "" "" ""
+test_colrm "2 2" "\n" "\n"
+
+exit 0