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
This commit is contained in:
Dag-Erling Smørgrav 2024-01-12 16:40:26 +01:00
parent a3d80dd8aa
commit e762fd81e2
3 changed files with 158 additions and 12 deletions

View File

@ -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

View File

@ -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>

149
usr.bin/uniq/tests/uniq_test.sh Executable file
View File

@ -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
}