Date: Wed, 11 Mar 2026 03:44:44 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 67728a18b9c1 - main - yes: Add tests Message-ID: <69b0e52c.3a826.c9c4e07@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=67728a18b9c18e55cc60e063380825b80f25b1b9 commit 67728a18b9c18e55cc60e063380825b80f25b1b9 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-03-11 03:44:10 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-03-11 03:44:17 +0000 yes: Add tests MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55802 --- etc/mtree/BSD.tests.dist | 2 + usr.bin/yes/Makefile | 4 ++ usr.bin/yes/tests/Makefile | 4 ++ usr.bin/yes/tests/yes_test.sh | 85 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) 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 +}home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69b0e52c.3a826.c9c4e07>
