aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2023-05-10 13:45:44 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2023-05-10 13:45:44 +0000
commit09aee570980b7eca6e3c902a66f6db129b8c7376 (patch)
treeb41202c72689c71c6c96e54c55924ac53092fbc1
parentb55bc49e8694d9226a82041ff23ad61a5c7a6a76 (diff)
downloadsrc-09aee570980b7eca6e3c902a66f6db129b8c7376.tar.gz
src-09aee570980b7eca6e3c902a66f6db129b8c7376.zip
tsort: Add unit tests.
MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D40043
-rw-r--r--etc/mtree/BSD.tests.dist2
-rw-r--r--usr.bin/tsort/Makefile5
-rw-r--r--usr.bin/tsort/tests/Makefile6
-rwxr-xr-xusr.bin/tsort/tests/tsort_test.sh66
4 files changed, 79 insertions, 0 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index c9a13cec193e..5d99653100df 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -1116,6 +1116,8 @@
..
truncate
..
+ tsort
+ ..
units
..
unifdef
diff --git a/usr.bin/tsort/Makefile b/usr.bin/tsort/Makefile
index b0d353e4d8f7..c0933dac2de1 100644
--- a/usr.bin/tsort/Makefile
+++ b/usr.bin/tsort/Makefile
@@ -1,6 +1,11 @@
# @(#)Makefile 8.1 (Berkeley) 6/9/93
# $FreeBSD$
+.include <src.opts.mk>
+
PROG= tsort
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
+
.include <bsd.prog.mk>
diff --git a/usr.bin/tsort/tests/Makefile b/usr.bin/tsort/tests/Makefile
new file mode 100644
index 000000000000..ab16c2842dd0
--- /dev/null
+++ b/usr.bin/tsort/tests/Makefile
@@ -0,0 +1,6 @@
+PACKAGE= tests
+
+ATF_TESTS_SH= tsort_test
+BINDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/usr.bin/tsort/tests/tsort_test.sh b/usr.bin/tsort/tests/tsort_test.sh
new file mode 100755
index 000000000000..88d4efaf2b9f
--- /dev/null
+++ b/usr.bin/tsort/tests/tsort_test.sh
@@ -0,0 +1,66 @@
+#
+# Copyright (c) 2023 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_test_case basic
+basic_head()
+{
+ atf_set "descr" "Sort a basic graph"
+}
+basic_body()
+{
+ cat >input <<EOF
+A B
+A F
+B C
+B D
+D E
+EOF
+ cat >output <<EOF
+A
+F
+B
+D
+C
+E
+EOF
+ atf_check -o file:output tsort input
+ atf_check -o file:output tsort <input
+}
+
+atf_test_case cycle
+cycle_head()
+{
+ atf_set "descr" "Sort a graph with a cycle"
+}
+cycle_body()
+{
+ cat >input <<EOF
+A B
+A F
+B C
+B D
+D E
+D A
+EOF
+ cat >output<<EOF
+D
+E
+A
+F
+B
+C
+EOF
+ atf_check -e match:cycle -o file:output tsort input
+ atf_check -e match:cycle -o file:output tsort <input
+ atf_check -o file:output tsort -q input
+ atf_check -o file:output tsort -q <input
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic
+ atf_add_test_case cycle
+}