git: 85ff0b08ee69 - main - tee: add some basic tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 20 Apr 2025 16:35:46 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=85ff0b08ee699ff323404727998993275b4d2e2a
commit 85ff0b08ee699ff323404727998993275b4d2e2a
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-04-20 16:34:50 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-04-20 16:35:32 +0000
tee: add some basic tests
The cases are ordered in such a way that we naturally progress through
the functionality, with the earliest failures perhaps shedding light on
any later failures.
sysutils/porch is used for one test if it's available, just to cleanly
check that SIGINT is being ignored properly.
Reviewed by: des, emaste
Differential Revision: https://reviews.freebsd.org/D48195
---
etc/mtree/BSD.tests.dist | 2 ++
usr.bin/tee/Makefile | 5 +++
usr.bin/tee/tests/Makefile | 6 ++++
usr.bin/tee/tests/sigint.orch | 14 ++++++++
usr.bin/tee/tests/tee_test.sh | 74 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 101 insertions(+)
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index f197021bd4e9..20744e7b944a 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -1207,6 +1207,8 @@
..
tar
..
+ tee
+ ..
tftp
..
touch
diff --git a/usr.bin/tee/Makefile b/usr.bin/tee/Makefile
index ab7b93575967..1e5781bef4da 100644
--- a/usr.bin/tee/Makefile
+++ b/usr.bin/tee/Makefile
@@ -1,3 +1,8 @@
+.include <src.opts.mk>
+
PROG= tee
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
.include <bsd.prog.mk>
diff --git a/usr.bin/tee/tests/Makefile b/usr.bin/tee/tests/Makefile
new file mode 100644
index 000000000000..acb78e671a8c
--- /dev/null
+++ b/usr.bin/tee/tests/Makefile
@@ -0,0 +1,6 @@
+PACKAGE= tests
+
+ATF_TESTS_SH+= tee_test
+${PACKAGE}FILES+= sigint.orch
+
+.include <bsd.test.mk>
diff --git a/usr.bin/tee/tests/sigint.orch b/usr.bin/tee/tests/sigint.orch
new file mode 100644
index 000000000000..2fc0b32c61fb
--- /dev/null
+++ b/usr.bin/tee/tests/sigint.orch
@@ -0,0 +1,14 @@
+-- We expect the caller to have spawned the appropriate application
+write "text\r"
+match "text"
+
+write "^C"
+
+-- If SIGINT isn't being ignored, we'll bail out somewhere in the process of
+-- writing to the pty or trying to read from it to perform the following match.
+write "text\r"
+match "text"
+
+-- Finally, just close it out cleanly.
+write "^D"
+eof()
diff --git a/usr.bin/tee/tests/tee_test.sh b/usr.bin/tee/tests/tee_test.sh
new file mode 100644
index 000000000000..6ac733f2e58f
--- /dev/null
+++ b/usr.bin/tee/tests/tee_test.sh
@@ -0,0 +1,74 @@
+#
+# Copyright (c) 2024 Kyle Evans <kevans@FreeBSD.org>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_test_case single_file
+single_file_body()
+{
+ atf_check -o inline:"text\n" -x "echo text | tee file"
+ atf_check -o inline:"text\n" cat file
+}
+
+atf_test_case device
+device_body()
+{
+ atf_check -e inline:"text\n" -o inline:"text\n" -x \
+ "echo text | tee /dev/stderr"
+}
+
+atf_test_case multiple_file
+multiple_file_body()
+{
+ atf_check -o inline:"text\n" -x "echo text | tee file1 file2"
+ atf_check -o inline:"text\n" cat file1
+ atf_check -o inline:"text\n" cat file2
+}
+
+atf_test_case append
+append_body()
+{
+ atf_check -o ignore -x "echo text | tee file"
+ atf_check -o inline:"text\n" cat file
+
+ # Should overwrite if done again
+ atf_check -o ignore -x "echo text | tee file"
+ atf_check -o inline:"text\n" cat file
+
+ # Should duplicate if we use -a
+ atf_check -o ignore -x "echo text | tee -a file"
+ atf_check -o inline:"text\ntext\n" cat file
+}
+
+atf_test_case sigint_ignored
+sigint_ignored_head()
+{
+ # This is most cleanly tested with interactive input, to avoid adding
+ # a lot of complexity in trying to manage an input and signal delivery
+ # dance purely in shell.
+ atf_set "require.progs" "porch"
+}
+sigint_ignored_body()
+{
+
+ # sigint.orch will write "text" to the file twice if we're properly
+ # ignoring SIGINT, so we'll do one test to confirm that SIGINT is not
+ # being ignored by porch(1), then another to confirm that tee(1) will
+ # ignore SIGINT when instructed to.
+ atf_check -s exit:1 -e ignore \
+ porch -f $(atf_get_srcdir)/sigint.orch tee file
+ atf_check -o inline:"text\n" cat file
+
+ atf_check porch -f $(atf_get_srcdir)/sigint.orch tee -i file
+ atf_check -o inline:"text\ntext\n" cat file
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case single_file
+ atf_add_test_case device
+ atf_add_test_case multiple_file
+ atf_add_test_case append
+ atf_add_test_case sigint_ignored
+}