yes: Add tests

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D55802
This commit is contained in:
Dag-Erling Smørgrav
2026-03-11 04:44:10 +01:00
parent 96294c22f7
commit 67728a18b9
4 changed files with 95 additions and 0 deletions
+2
View File
@@ -1265,6 +1265,8 @@
yacc
..
..
yes
..
..
usr.sbin
certctl
+4
View File
@@ -1,3 +1,7 @@
.include <src.opts.mk>
PROG= yes
HAS_TESTS=
SUBDIR.${MK_TESTS}= tests
.include <bsd.prog.mk>
+4
View File
@@ -0,0 +1,4 @@
PACKAGE= tests
ATF_TESTS_SH= yes_test
.include <bsd.test.mk>
+85
View File
@@ -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
}