Page MenuHomeFreeBSD

D55802.diff
No OneTemporary

D55802.diff

diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
--- 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
--- 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
--- /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
--- /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
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 16, 7:12 AM (18 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35128782
Default Alt Text
D55802.diff (2 KB)

Event Timeline