aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-03-11 03:44:10 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-03-11 03:44:17 +0000
commit67728a18b9c18e55cc60e063380825b80f25b1b9 (patch)
treeb01bed941d1fa482309ea744e8da56e5dd4376e0
parent96294c22f7e54a48df44c86a4ee5848e71ac4470 (diff)
yes: Add tests
MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55802
-rw-r--r--etc/mtree/BSD.tests.dist2
-rw-r--r--usr.bin/yes/Makefile4
-rw-r--r--usr.bin/yes/tests/Makefile4
-rw-r--r--usr.bin/yes/tests/yes_test.sh85
4 files changed, 95 insertions, 0 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 770f3434ac11..4fa35d1a17d0 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -1265,6 +1265,8 @@
yacc
..
..
+ yes
+ ..
..
usr.sbin
certctl
diff --git a/usr.bin/yes/Makefile b/usr.bin/yes/Makefile
index b1d4075b5917..545c95d00624 100644
--- a/usr.bin/yes/Makefile
+++ b/usr.bin/yes/Makefile
@@ -1,3 +1,7 @@
+.include <src.opts.mk>
+
PROG= yes
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
.include <bsd.prog.mk>
diff --git a/usr.bin/yes/tests/Makefile b/usr.bin/yes/tests/Makefile
new file mode 100644
index 000000000000..874a1bc21751
--- /dev/null
+++ b/usr.bin/yes/tests/Makefile
@@ -0,0 +1,4 @@
+PACKAGE= tests
+ATF_TESTS_SH= yes_test
+
+.include <bsd.test.mk>
diff --git a/usr.bin/yes/tests/yes_test.sh b/usr.bin/yes/tests/yes_test.sh
new file mode 100644
index 000000000000..f4c04e186536
--- /dev/null
+++ b/usr.bin/yes/tests/yes_test.sh
@@ -0,0 +1,85 @@
+#
+# Copyright (c) 2026 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_test_case none
+none_head()
+{
+ atf_set "descr" "No arguments"
+}
+none_body()
+{
+ atf_check \
+ -o inline:"y\ny\ny\ny\ny\n" \
+ -x "yes | head -5"
+}
+
+atf_test_case one
+one_head()
+{
+ atf_set "descr" "One argument"
+}
+one_body()
+{
+ local y="Hello, world!"
+ atf_check \
+ -o inline:"${y}\n${y}\n${y}\n${y}\n${y}\n" \
+ -x "yes '${y}' | head -5"
+}
+
+atf_test_case multi
+multi_head()
+{
+ atf_set "descr" "Multiple arguments"
+}
+multi_body()
+{
+ set -- The Magic Words are Squeamish Ossifrage
+ local y="$*"
+ atf_check \
+ -o inline:"${y}\n${y}\n${y}\n${y}\n${y}\n" \
+ -x "yes $* | head -5"
+}
+
+atf_test_case argv
+argv_head()
+{
+ atf_set "descr" "Verify that argv is unmolested"
+}
+argv_body()
+{
+ yes y >/dev/null &
+ local pid=$!
+ atf_check -o inline:"yes y\n" ps -o args= $pid
+ kill $pid
+ wait
+}
+
+atf_test_case stdout
+stdout_head()
+{
+ atf_set descr "Error writing to stdout"
+}
+stdout_body()
+{
+ (
+ trap "" PIPE
+ # Give true(1) some time to exit.
+ sleep 1
+ yes 2>stderr
+ echo $? >result
+ ) | true
+ atf_check -o inline:"1\n" cat result
+ atf_check -o match:"stdout" cat stderr
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case none
+ atf_add_test_case one
+ atf_add_test_case multi
+ atf_add_test_case argv
+ atf_add_test_case stdout
+}