From 2c817f1b9fc7e2aa54d954f5cb694005d6d12b75 Mon Sep 17 00:00:00 2001
From: Mattias Andrée <maandree@kth.se>
Date: Sun, 27 Mar 2016 20:05:33 +0200
Subject: Add uniq test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Mattias Andrée <maandree@kth.se>
---
 test-all                   |   2 +-
 uniq-test/1.in             |   0
 uniq-test/1.out            |   0
 uniq-test/2.in             |   1 +
 uniq-test/2.out            |   1 +
 uniq-test/3.in             |   3 +
 uniq-test/3.out            |   3 +
 uniq-test/4.in             |   3 +
 uniq-test/4.out            |   3 +
 uniq-test/5.in             |   3 +
 uniq-test/5.out            |   3 +
 uniq-test/6.in             |   6 ++
 uniq-test/6.out            |   3 +
 uniq-test/7.in             | Bin 0 -> 9 bytes
 uniq-test/7.out            | Bin 0 -> 9 bytes
 uniq-test/cflag.in         |   9 +++
 uniq-test/cflag.out        |   5 ++
 uniq-test/dflag.in         |   6 ++
 uniq-test/dflag.out        |   2 +
 uniq-test/fflag.in         |   4 ++
 uniq-test/fflag.out        |   2 +
 uniq-test/fsflag.in        |   7 +++
 uniq-test/fsflag.out       |   4 ++
 uniq-test/sflag.in         |   4 ++
 uniq-test/sflag.out        |   2 +
 uniq-test/sflag_excess.in  |   5 ++
 uniq-test/sflag_excess.out |   1 +
 uniq-test/test             | 147 +++++++++++++++++++++++++++++++++++++++++++++
 uniq-test/uflag.in         |   6 ++
 uniq-test/uflag.out        |   2 +
 30 files changed, 236 insertions(+), 1 deletion(-)
 create mode 100644 uniq-test/1.in
 create mode 100644 uniq-test/1.out
 create mode 100644 uniq-test/2.in
 create mode 100644 uniq-test/2.out
 create mode 100644 uniq-test/3.in
 create mode 100644 uniq-test/3.out
 create mode 100644 uniq-test/4.in
 create mode 100644 uniq-test/4.out
 create mode 100644 uniq-test/5.in
 create mode 100644 uniq-test/5.out
 create mode 100644 uniq-test/6.in
 create mode 100644 uniq-test/6.out
 create mode 100644 uniq-test/7.in
 create mode 100644 uniq-test/7.out
 create mode 100644 uniq-test/cflag.in
 create mode 100644 uniq-test/cflag.out
 create mode 100644 uniq-test/dflag.in
 create mode 100644 uniq-test/dflag.out
 create mode 100644 uniq-test/fflag.in
 create mode 100644 uniq-test/fflag.out
 create mode 100644 uniq-test/fsflag.in
 create mode 100644 uniq-test/fsflag.out
 create mode 100644 uniq-test/sflag.in
 create mode 100644 uniq-test/sflag.out
 create mode 100644 uniq-test/sflag_excess.in
 create mode 100644 uniq-test/sflag_excess.out
 create mode 100755 uniq-test/test
 create mode 100644 uniq-test/uflag.in
 create mode 100644 uniq-test/uflag.out

diff --git a/test-all b/test-all
index 0e7227e..34ce139 100755
--- a/test-all
+++ b/test-all
@@ -6,7 +6,7 @@ function all()
 {
 	echo patch md5sum rawshake256sum rawshake512sum sha1sum sha224sum sha256sum sha3-224sum \
 	     sha3-256sum sha3-384sum sha3-512sum sha384sum sha512-224sum sha512-256sum sha512sum \
-	     shake256sum shake512sum cksum true false echo test basename dirname
+	     shake256sum shake512sum cksum true false echo test basename dirname uniq
 }
 
 exec 99>&2
diff --git a/uniq-test/1.in b/uniq-test/1.in
new file mode 100644
index 0000000..e69de29
diff --git a/uniq-test/1.out b/uniq-test/1.out
new file mode 100644
index 0000000..e69de29
diff --git a/uniq-test/2.in b/uniq-test/2.in
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/uniq-test/2.in
@@ -0,0 +1 @@
+
diff --git a/uniq-test/2.out b/uniq-test/2.out
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/uniq-test/2.out
@@ -0,0 +1 @@
+
diff --git a/uniq-test/3.in b/uniq-test/3.in
new file mode 100644
index 0000000..de98044
--- /dev/null
+++ b/uniq-test/3.in
@@ -0,0 +1,3 @@
+a
+b
+c
diff --git a/uniq-test/3.out b/uniq-test/3.out
new file mode 100644
index 0000000..de98044
--- /dev/null
+++ b/uniq-test/3.out
@@ -0,0 +1,3 @@
+a
+b
+c
diff --git a/uniq-test/4.in b/uniq-test/4.in
new file mode 100644
index 0000000..bfdaa0f
--- /dev/null
+++ b/uniq-test/4.in
@@ -0,0 +1,3 @@
+a
+b
+
diff --git a/uniq-test/4.out b/uniq-test/4.out
new file mode 100644
index 0000000..bfdaa0f
--- /dev/null
+++ b/uniq-test/4.out
@@ -0,0 +1,3 @@
+a
+b
+
diff --git a/uniq-test/5.in b/uniq-test/5.in
new file mode 100644
index 0000000..8f468ef
--- /dev/null
+++ b/uniq-test/5.in
@@ -0,0 +1,3 @@
+a
+b
+a
diff --git a/uniq-test/5.out b/uniq-test/5.out
new file mode 100644
index 0000000..8f468ef
--- /dev/null
+++ b/uniq-test/5.out
@@ -0,0 +1,3 @@
+a
+b
+a
diff --git a/uniq-test/6.in b/uniq-test/6.in
new file mode 100644
index 0000000..a97cece
--- /dev/null
+++ b/uniq-test/6.in
@@ -0,0 +1,6 @@
+a
+a
+b
+b
+c
+c
diff --git a/uniq-test/6.out b/uniq-test/6.out
new file mode 100644
index 0000000..de98044
--- /dev/null
+++ b/uniq-test/6.out
@@ -0,0 +1,3 @@
+a
+b
+c
diff --git a/uniq-test/7.in b/uniq-test/7.in
new file mode 100644
index 0000000..ed1ccaf
Binary files /dev/null and b/uniq-test/7.in differ
diff --git a/uniq-test/7.out b/uniq-test/7.out
new file mode 100644
index 0000000..ed1ccaf
Binary files /dev/null and b/uniq-test/7.out differ
diff --git a/uniq-test/cflag.in b/uniq-test/cflag.in
new file mode 100644
index 0000000..7f2efd0
--- /dev/null
+++ b/uniq-test/cflag.in
@@ -0,0 +1,9 @@
+a
+b
+b
+c
+c
+c
+b
+b
+a
diff --git a/uniq-test/cflag.out b/uniq-test/cflag.out
new file mode 100644
index 0000000..6a137de
--- /dev/null
+++ b/uniq-test/cflag.out
@@ -0,0 +1,5 @@
+1 a
+2 b
+3 c
+2 b
+1 a
diff --git a/uniq-test/dflag.in b/uniq-test/dflag.in
new file mode 100644
index 0000000..b3040d6
--- /dev/null
+++ b/uniq-test/dflag.in
@@ -0,0 +1,6 @@
+1
+2
+2
+a
+b
+b
diff --git a/uniq-test/dflag.out b/uniq-test/dflag.out
new file mode 100644
index 0000000..bdaf90f
--- /dev/null
+++ b/uniq-test/dflag.out
@@ -0,0 +1,2 @@
+2
+b
diff --git a/uniq-test/fflag.in b/uniq-test/fflag.in
new file mode 100644
index 0000000..aa9c83e
--- /dev/null
+++ b/uniq-test/fflag.in
@@ -0,0 +1,4 @@
+a b c d e f
+A   b c d e f
+A	B c d e f
+A B C d e f
diff --git a/uniq-test/fflag.out b/uniq-test/fflag.out
new file mode 100644
index 0000000..cb9fb63
--- /dev/null
+++ b/uniq-test/fflag.out
@@ -0,0 +1,2 @@
+a b c d e f
+A B C d e f
diff --git a/uniq-test/fsflag.in b/uniq-test/fsflag.in
new file mode 100644
index 0000000..7bed3cd
--- /dev/null
+++ b/uniq-test/fsflag.in
@@ -0,0 +1,7 @@
+a b c d e f
+A b c d e f
+A B c d e f
+A B C d e f
+A B C D e f
+A B C D E f
+A B C D E F
diff --git a/uniq-test/fsflag.out b/uniq-test/fsflag.out
new file mode 100644
index 0000000..eb7f382
--- /dev/null
+++ b/uniq-test/fsflag.out
@@ -0,0 +1,4 @@
+a b c d e f
+A B C D e f
+A B C D E f
+A B C D E F
diff --git a/uniq-test/sflag.in b/uniq-test/sflag.in
new file mode 100644
index 0000000..577a22d
--- /dev/null
+++ b/uniq-test/sflag.in
@@ -0,0 +1,4 @@
+aa
+ba
+bb
+ab
diff --git a/uniq-test/sflag.out b/uniq-test/sflag.out
new file mode 100644
index 0000000..6ad4673
--- /dev/null
+++ b/uniq-test/sflag.out
@@ -0,0 +1,2 @@
+aa
+bb
diff --git a/uniq-test/sflag_excess.in b/uniq-test/sflag_excess.in
new file mode 100644
index 0000000..9405325
--- /dev/null
+++ b/uniq-test/sflag_excess.in
@@ -0,0 +1,5 @@
+a
+b
+c
+d
+e
diff --git a/uniq-test/sflag_excess.out b/uniq-test/sflag_excess.out
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/uniq-test/sflag_excess.out
@@ -0,0 +1 @@
+a
diff --git a/uniq-test/test b/uniq-test/test
new file mode 100755
index 0000000..f5393a0
--- /dev/null
+++ b/uniq-test/test
@@ -0,0 +1,147 @@
+#!/bin/bash
+
+cd -- "$(dirname "$0")"
+if test -z "$UNIQ"; then
+	UNIQ=../uniq
+fi
+N=7
+u="$PREFIX $UNIQ"
+
+report ()
+{
+	if test $1 = 0; then
+		printf "\033[1;32mTest %s OK\033[m\n" "$2"
+	else
+		printf "\033[1;31mTest %s FAILED\033[m\n" "$2"
+	fi
+}
+
+report_np ()
+{
+	if test $1 = 0; then
+		printf "\033[1;32mTest %s OK (NON-POSIX)\033[m\n" "$2"
+	else
+		printf "\033[1;31mTest %s FAILED (NON-POSIX)\033[m\n" "$2"
+	fi
+}
+
+test_file ()
+{
+	diff <($u < $1.in) $1.out > /dev/null
+	report $? "file_$1"
+}
+
+
+file_1 () { test_file 1; }
+file_2 () { test_file 2; }
+file_3 () { test_file 3; }
+file_4 () { test_file 4; }
+file_5 () { test_file 5; }
+file_6 () { test_file 6; }
+file_7 () { test_file 7; }
+
+dflag ()
+{
+	diff <($u -d < dflag.in) dflag.out > /dev/null
+	report $? "dflag"
+}
+
+uflag ()
+{
+	diff <($u -u < uflag.in) uflag.out > /dev/null
+	report $? "uflag"
+}
+
+cflag ()
+{
+	diff <($u -c < cflag.in | sed 's/^ *//') cflag.out > /dev/null
+	# The `sed` is due to conflicting specifications in uniq(1p).
+	report $? "cflag"
+}
+
+sflag_excess ()
+{
+	diff <($u -s10 < sflag_excess.in) sflag_excess.out > /dev/null
+	report $? "sflag_excess"
+}
+
+sflag ()
+{
+	diff <($u -s1 < sflag.in) sflag.out > /dev/null
+	report $? "sflag"
+}
+
+f0flag ()
+{
+	diff <($u -f0 < 5.in) 5.out > /dev/null
+	report_np $? "f0flag"
+}
+
+fflag_excess ()
+{
+	diff <($u -f10 < 5.in) <(head -n 1 < 5.out) > /dev/null
+	report $? "fflag_excess"
+}
+
+fflag ()
+{
+	diff <($u -f2 < fflag.in) fflag.out > /dev/null
+	report $? "fflag"
+}
+
+fsflag ()
+{
+	diff <($u -f2 -s2 < fsflag.in) fsflag.out > /dev/null
+	report $? "fsflag"
+}
+
+file_in ()
+{
+	diff <($u 5.in) 5.out > /dev/null
+	report $? "file_in"
+}
+
+dash_in ()
+{
+	diff <($u - < 5.in) 5.out > /dev/null
+	report $? "dash_in"
+}
+
+file_out ()
+{
+	$u - tmp < 5.in && diff tmp 5.out > /dev/null
+	report $? "file_out"
+}
+
+dash_out ()
+{
+	touch tmp; rm tmp;
+	$u - - < 5.in > tmp && diff tmp 5.out > /dev/null
+	report_np $? "dash_out"
+	if test -f ./-; then
+		rm ./-
+	fi
+}
+
+
+if test $# = 0; then
+	set $(printf 'file_%i\n' $(seq 1 $N)) dflag uflag cflag sflag_excess \
+	    sflag f0flag fflag_excess fflag fsflag file_in dash_in file_out \
+	    dash_out
+fi
+(
+for f in $@; do
+	$f
+done
+) | tee result
+! grep FAILED < result > /dev/null
+ret=$?
+if test $ret != 0; then
+	if test $(grep FAILED < result | grep -v NON-POSIX | wc -l) = 0; then
+		ret=1
+	else
+		ret=2
+	fi
+fi
+rm result
+exit $ret
diff --git a/uniq-test/uflag.in b/uniq-test/uflag.in
new file mode 100644
index 0000000..b3040d6
--- /dev/null
+++ b/uniq-test/uflag.in
@@ -0,0 +1,6 @@
+1
+2
+2
+a
+b
+b
diff --git a/uniq-test/uflag.out b/uniq-test/uflag.out
new file mode 100644
index 0000000..e439850
--- /dev/null
+++ b/uniq-test/uflag.out
@@ -0,0 +1,2 @@
+1
+a
-- 
cgit v1.2.3-70-g09d2