summaryrefslogtreecommitdiff
path: root/regress/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-12-06 18:42:13 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-12-06 18:42:13 +0000
commit2bdb4f17410ba3207fec6fb306718418e7bde767 (patch)
tree39276b5ff9fa347326e265af2ffcad06c784ba21 /regress/usr.bin
parentbfc9361963796259733fa920fbcc8347525ec170 (diff)
test suite for fmt(1) written from scratch
Diffstat (limited to 'regress/usr.bin')
-rw-r--r--regress/usr.bin/Makefile4
-rw-r--r--regress/usr.bin/fmt/Makefile6
-rw-r--r--regress/usr.bin/fmt/fmt.sh105
3 files changed, 113 insertions, 2 deletions
diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile
index d37cb72e429..4b7337b33ea 100644
--- a/regress/usr.bin/Makefile
+++ b/regress/usr.bin/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.32 2015/07/26 17:29:41 zhuk Exp $
+# $OpenBSD: Makefile,v 1.33 2015/12/06 18:42:12 schwarze Exp $
# $NetBSD: Makefile,v 1.1 1997/12/30 23:27:11 cgd Exp $
-SUBDIR+= basename bc dc diff diff3 dirname doas file grep gzip
+SUBDIR+= basename bc dc diff diff3 dirname doas file fmt grep gzip
SUBDIR+= m4 mandoc openssl sdiff sed signify sort tsort
SUBDIR+= xargs
diff --git a/regress/usr.bin/fmt/Makefile b/regress/usr.bin/fmt/Makefile
new file mode 100644
index 00000000000..f6d63d4381e
--- /dev/null
+++ b/regress/usr.bin/fmt/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2015/12/06 18:42:12 schwarze Exp $
+
+regress:
+ @sh ${.CURDIR}/fmt.sh
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/fmt/fmt.sh b/regress/usr.bin/fmt/fmt.sh
new file mode 100644
index 00000000000..0d33f5aeec4
--- /dev/null
+++ b/regress/usr.bin/fmt/fmt.sh
@@ -0,0 +1,105 @@
+#!/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.
+
+test_fmt()
+{
+ expected=`echo -n "$3" ; echo .`
+ result=`echo -n "$2" | fmt $1 2>&1 ; echo .`
+ if [ "$result" != "$expected" ]; then
+ echo "fmt $1 \"$2\": expected \"$expected\", got \"$result\""
+ exit 1
+ fi
+}
+
+# paragraph handling: function process_stream()
+test_fmt "" "a\nb\n" "a b\n"
+test_fmt "" "a\n\nb\n" "a\n\nb\n"
+test_fmt "" "a\n.b\n" "a\n.b\n"
+test_fmt "-n" "a\n.b\n" "a .b\n"
+test_fmt "" "a\nb\n c\n d\n" "a b\n c d\n"
+test_fmt "" " a\n b\nc\nd\n" " a b\nc d\n"
+test_fmt "" " a\nb\nc\n" " a\nb c\n"
+test_fmt "" " a\n\tb\n c\n\td\n e\n" " a\n b c d\n e\n"
+test_fmt "-l 8" " a\n\tb\n c\n\td\n e\n" " a\n\tb c d\n e\n"
+
+# The -p option seems to be broken.
+# Apparently, it allows the *second* line of a paragraph
+# to have a different indentation, not the first as documented.
+# The following tests demonstrate the current behaviour:
+test_fmt "-p" " a\nb\nc\n" " a b\nc\n"
+test_fmt "-p" "a\n b\nc\n" "a b c\n"
+test_fmt "-p" "a\nb\n c\nd\ne\n" "a b\n c d\ne\n"
+
+# mail header handling: function process_stream()
+test_fmt "-m 6 6" "X: a\n b\n" "X: a b\n"
+test_fmt "-m 6 6" "X: a\n b\n" "X: a b\n"
+test_fmt "-m 3 6" "a\nX: b\n" "a X:\nb\n"
+
+# The -m option seems to be broken.
+# The following tests demonstrate the current behaviour:
+# If a mail header is too long, it gets wrapped, but the
+# indentation is missing from the continuation line:
+test_fmt "-m 3 6" "X: a b\n" "X: a\nb\n"
+test_fmt "-m 6 6" "X: a\n b c\n" "X: a b\nc\n"
+test_fmt "-m 6 6" "X: a\n b c\n" "X: a b\nc\n"
+test_fmt "-m 3 6" "a\n\nX: b c\n" "a\n\nX: b\nc\n"
+test_fmt "-m 3 6" "a\n\nX: b\n c\n" "a\n\nX: b\nc\n"
+
+# in-line whitespace handling: function output_word()
+test_fmt "" "a b\n" "a b\n"
+test_fmt "-s" "a b\n" "a b\n"
+test_fmt "" "a.\nb\n" "a. b\n"
+test_fmt "" "a. b\n" "a. b\n"
+test_fmt "-s" "a. b\n" "a. b\n"
+
+# line breaking: function output_word()
+test_fmt "2 4" "a\nb\nc\n" "a b\nc\n"
+test_fmt "2 4" "longish\na\nb\n" "longish\na b\n"
+test_fmt "2 4" "a\nlongish\nb\nc\n" "a\nlongish\nb c\n"
+test_fmt "2 4" "aa\nb\nc\nd\n" "aa\nb c\nd\n"
+
+# centering: function center_stream()
+test_fmt "-c 4" "a\n b\n\tc\n" " a\n b\n c\n"
+test_fmt "-c 4" "aa\n bb\n\tcc\n" " aa\n bb\n cc\n"
+test_fmt "-c 4" "aaa\n bbb\n\tccc\n" " aaa\n bbb\n ccc\n"
+test_fmt "-c 4" "aaaa\n bbbb\n\tcccc\n" "aaaa\nbbbb\ncccc\n"
+
+# control characters in the input stream: function get_line()
+test_fmt "" "a\ab\n" "ab\n"
+test_fmt "" "a\bb\n" "b\n"
+test_fmt "" "a\tb\n" "a b\n"
+test_fmt "" ".a\ab\n" ".a\ab\n"
+test_fmt "" ".a\bb\n" ".a\bb\n"
+test_fmt "" ".a\tb\n" ".a\tb\n"
+test_fmt "" " .a\ab\n" " .ab\n"
+test_fmt "" " .a\bb\n" " .b\n"
+test_fmt "" " .a\tb\n" " .a b\n"
+test_fmt "-n" ".a\ab\n" ".ab\n"
+test_fmt "-n" ".a\bb\n" ".b\n"
+test_fmt "-n" ".a\tb\n" ".a b\n"
+
+# input corner cases: function get_line()
+test_fmt "" "" ""
+test_fmt "" " " ""
+test_fmt "" "\t" ""
+test_fmt "" "a" "a\n"
+test_fmt "" "a " "a\n"
+test_fmt "" "a\t" "a\n"
+test_fmt "" " \n" "\n"
+test_fmt "" "a \n" "a\n"
+test_fmt "" "a\t\n" "a\n"
+
+exit 0