Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F102058671
D46996.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D46996.diff
View Options
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
@@ -1097,6 +1097,8 @@
..
du
..
+ env
+ ..
factor
..
file
diff --git a/usr.bin/env/Makefile b/usr.bin/env/Makefile
--- a/usr.bin/env/Makefile
+++ b/usr.bin/env/Makefile
@@ -1,7 +1,12 @@
+.include <src.opts.mk>
+
PACKAGE= runtime
PROG= env
SRCS= env.c envopts.c
LIBADD= util
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
+
.include <bsd.prog.mk>
diff --git a/usr.bin/env/tests/Makefile b/usr.bin/env/tests/Makefile
new file mode 100644
--- /dev/null
+++ b/usr.bin/env/tests/Makefile
@@ -0,0 +1,6 @@
+PACKAGE= tests
+
+ATF_TESTS_SH= env_test
+BINDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/usr.bin/env/tests/env_test.sh b/usr.bin/env/tests/env_test.sh
new file mode 100644
--- /dev/null
+++ b/usr.bin/env/tests/env_test.sh
@@ -0,0 +1,100 @@
+#
+# Copyright (c) 2024 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+magic_words="Squeamish $$ Ossifrage"
+
+atf_test_case basic
+basic_head()
+{
+ atf_set "descr" "Basic test case"
+}
+basic_body()
+{
+ atf_check -o match:"^magic_words=${magic_words}\$" \
+ env magic_words="${magic_words}"
+ export MAGIC_WORDS="${magic_words}"
+ atf_check -o match:"^MAGIC_WORDS=${magic_words}\$" \
+ env
+ unset MAGIC_WORDS
+}
+
+atf_test_case unset
+unset_head()
+{
+ atf_set "descr" "Unset a variable"
+}
+unset_body()
+{
+ export MAGIC_WORDS="${magic_words}"
+ atf_check -o not-match:"^MAGIC_WORDS=" \
+ env -u MAGIC_WORDS
+ unset MAGIC_WORDS
+}
+
+atf_test_case empty
+empty_head()
+{
+ atf_set "descr" "Empty environment"
+}
+empty_body()
+{
+ atf_check env -i
+}
+
+atf_test_case true
+true_head()
+{
+ atf_set "descr" "Run true"
+}
+true_body()
+{
+ atf_check env true
+}
+
+atf_test_case false
+false_head()
+{
+ atf_set "descr" "Run false"
+}
+false_body()
+{
+ atf_check -s exit:1 env false
+}
+
+atf_test_case false
+false_head()
+{
+ atf_set "descr" "Run false"
+}
+false_body()
+{
+ atf_check -s exit:1 env false
+}
+
+atf_test_case altpath
+altpath_head()
+{
+ atf_set "descr" "Use alternate path"
+}
+altpath_body()
+{
+ echo "echo ${magic_words}" >magic_words
+ chmod 0755 magic_words
+ atf_check -s exit:127 -e match:"No such file" \
+ env magic_words
+ atf_check -o inline:"${magic_words}\n" \
+ env -P "${PWD}" magic_words
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic
+ atf_add_test_case unset
+ atf_add_test_case empty
+ atf_add_test_case true
+ atf_add_test_case false
+ atf_add_test_case altpath
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 8, 2:42 AM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14525963
Default Alt Text
D46996.diff (2 KB)
Attached To
Mode
D46996: env: Add a handful of test cases.
Attached
Detach File
Event Timeline
Log In to Comment