diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-05-10 13:45:44 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-05-10 13:45:44 +0000 |
commit | 09aee570980b7eca6e3c902a66f6db129b8c7376 (patch) | |
tree | b41202c72689c71c6c96e54c55924ac53092fbc1 /usr.bin/tsort | |
parent | b55bc49e8694d9226a82041ff23ad61a5c7a6a76 (diff) | |
download | src-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
Diffstat (limited to 'usr.bin/tsort')
-rw-r--r-- | usr.bin/tsort/Makefile | 5 | ||||
-rw-r--r-- | usr.bin/tsort/tests/Makefile | 6 | ||||
-rwxr-xr-x | usr.bin/tsort/tests/tsort_test.sh | 66 |
3 files changed, 77 insertions, 0 deletions
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 +} |