aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2024-01-12 15:40:26 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2024-01-12 15:43:49 +0000
commite762fd81e253d4ae9b9f7d2e65cf448633bbe527 (patch)
tree43b16fe2d7e760e9d1b687e0597268b9a3e88204
parenta3d80dd8aa6ac15877e00102ab174b417ac81d79 (diff)
downloadsrc-e762fd81e253d4ae9b9f7d2e65cf448633bbe527.tar.gz
src-e762fd81e253d4ae9b9f7d2e65cf448633bbe527.zip
uniq: Replace NetBSD's unit tests with our own.
These new tests cover more functionality and are easier to extend. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D43381
-rw-r--r--ObsoleteFiles.inc8
-rw-r--r--usr.bin/uniq/tests/Makefile13
-rwxr-xr-xusr.bin/uniq/tests/uniq_test.sh149
3 files changed, 158 insertions, 12 deletions
diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index da7e3d432bfb..ac936aebb574 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -51,6 +51,14 @@
# xargs -n1 | sort | uniq -d;
# done
+# 20240112: replaced NetBSD tests for uniq with our own
+OLD_FILES+=usr/tests/usr.bin/uniq/d_basic.in
+OLD_FILES+=usr/tests/usr.bin/uniq/d_basic.out
+OLD_FILES+=usr/tests/usr.bin/uniq/d_counts.out
+OLD_FILES+=usr/tests/usr.bin/uniq/d_input.in
+OLD_FILES+=usr/tests/usr.bin/uniq/d_show_duplicates.out
+OLD_FILES+=usr/tests/usr.bin/uniq/d_show_uniques.out
+
# 20231208: new clang import which bumps version from 16 to 17
OLD_FILES+=usr/lib/clang/16/include/__clang_cuda_builtin_vars.h
OLD_FILES+=usr/lib/clang/16/include/__clang_cuda_cmath.h
diff --git a/usr.bin/uniq/tests/Makefile b/usr.bin/uniq/tests/Makefile
index d9c839aa35b6..55bb98e98c34 100644
--- a/usr.bin/uniq/tests/Makefile
+++ b/usr.bin/uniq/tests/Makefile
@@ -1,15 +1,4 @@
-
PACKAGE= tests
-
-NETBSD_ATF_TESTS_SH= uniq_test
-
-${PACKAGE}FILES+= d_basic.in
-${PACKAGE}FILES+= d_basic.out
-${PACKAGE}FILES+= d_counts.out
-${PACKAGE}FILES+= d_input.in
-${PACKAGE}FILES+= d_show_duplicates.out
-${PACKAGE}FILES+= d_show_uniques.out
-
-.include <netbsd-tests.test.mk>
+ATF_TESTS_SH= uniq_test
.include <bsd.test.mk>
diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh
new file mode 100755
index 000000000000..ddd9ec9881dd
--- /dev/null
+++ b/usr.bin/uniq/tests/uniq_test.sh
@@ -0,0 +1,149 @@
+#
+# Copyright (c) 2024 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_check_uniq() {
+ atf_check uniq "$@" input actual
+ atf_check diff -u actual expected
+ atf_check uniq "$@" - actual <input
+ atf_check diff -u actual expected
+ atf_check -o file:expected uniq "$@" input
+ atf_check -o file:expected uniq "$@" <input
+ atf_check -o file:expected uniq "$@" - <input
+}
+
+atf_test_case basic
+basic_head() {
+ atf_set descr "basic test without options"
+}
+basic_body() {
+ printf "a\na\nb\nb\na\na\n" >input
+ printf "a\nb\na\n" >expected
+ atf_check_uniq
+}
+
+atf_test_case count
+count_head() {
+ atf_set descr "basic test showing counts"
+}
+count_body() {
+ printf "a\na\nb\nb\nb\na\na\na\na\n" >input
+ printf " 2 a\n 3 b\n 4 a\n" >expected
+ atf_check_uniq -c
+ atf_check_uniq --count
+}
+
+atf_test_case repeated
+repeated_head() {
+ atf_set descr "print repeated lines only"
+}
+repeated_body() {
+ printf "a\na\nb\na\na\n" >input
+ printf "a\na\n" >expected
+ atf_check_uniq -d
+ atf_check_uniq --repeated
+}
+
+atf_test_case count_repeated
+count_repeated_head() {
+ atf_set descr "count and print repeated lines only"
+}
+count_repeated_body() {
+ printf "a\na\nb\nb\na\n" >input
+ printf " 2 a\n 2 b\n" >expected
+ atf_check_uniq --count --repeated
+}
+
+atf_test_case all_repeated
+all_repeated_head() {
+ atf_set descr "print every instance of repeated lines"
+}
+all_repeated_body() {
+ printf "a\na\nb\na\na\n" >input
+ printf "a\na\na\na\n" >expected
+ atf_check_uniq -D
+ atf_check_uniq --all-repeated
+}
+
+atf_test_case skip_fields
+skip_fields_head() {
+ atf_set descr "skip fields"
+}
+skip_fields_body() {
+ printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
+ printf "1 a\n3 b\n5 a\n" >expected
+ atf_check_uniq -f 1
+ atf_check_uniq --skip-fields 1
+}
+
+atf_test_case skip_fields_tab
+skip_fields_tab_head() {
+ atf_set descr "skip fields (with tabs)"
+}
+skip_fields_tab_body() {
+ printf "1\ta\n2\ta\n3\tb\n4\tb\n5\ta\n6\ta\n" >input
+ printf "1\ta\n3\tb\n5\ta\n" >expected
+ atf_check_uniq -f 1
+ atf_check_uniq --skip-fields 1
+}
+
+atf_test_case ignore_case
+ignore_case_head() {
+ atf_set descr "ignore case"
+}
+ignore_case_body() {
+ printf "a\nA\nb\nB\na\nA\n" >input
+ printf "a\nb\na\n" >expected
+ atf_check_uniq -i
+ atf_check_uniq --ignore-case
+}
+
+atf_test_case skip_chars
+skip_chars_head() {
+ atf_set descr "skip chars"
+}
+skip_chars_body() {
+ printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
+ printf "1 a\n3 b\n5 a\n" >expected
+ atf_check_uniq -s 2
+ atf_check_uniq --skip-chars 2
+}
+
+atf_test_case unique
+unique_head() {
+ atf_set descr "print non-repeated lines only"
+}
+unique_body() {
+ printf "a\na\nb\na\na\n" >input
+ printf "b\n" >expected
+ atf_check_uniq -u
+ atf_check_uniq --unique
+}
+
+atf_test_case count_unique
+count_unique_head() {
+ atf_set descr "print non-repeated lines with count"
+}
+count_unique_body() {
+ printf "a\na\nb\n" >input
+ printf " 1 b\n" >expected
+ atf_check_uniq --unique --count
+ atf_check_uniq --count --unique
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic
+ atf_add_test_case count
+ atf_add_test_case repeated
+ atf_add_test_case count_repeated
+ atf_add_test_case all_repeated
+ atf_add_test_case skip_fields
+ atf_add_test_case skip_fields_tab
+ atf_add_test_case ignore_case
+ atf_add_test_case skip_chars
+ atf_add_test_case unique
+ atf_add_test_case count_unique
+}