xref: /freebsd/usr.bin/tsort/tests/tsort_test.sh (revision fd45b686f9d92f583366c75b22c04c7ee49709c0)
1#
2# Copyright (c) 2023 Klara, Inc.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7atf_test_case basic
8basic_head()
9{
10	atf_set "descr" "Sort a basic graph"
11}
12basic_body()
13{
14	cat >input <<EOF
15A B
16A F
17B C
18B D
19D E
20EOF
21	cat >output <<EOF
22A
23F
24B
25D
26C
27E
28EOF
29	atf_check -o file:output tsort input
30	atf_check -o file:output tsort <input
31}
32
33atf_test_case cycle
34cycle_head()
35{
36	atf_set "descr" "Sort a graph with a cycle"
37}
38cycle_body()
39{
40	cat >input <<EOF
41A B
42A F
43B C
44B D
45D E
46D A
47EOF
48	cat >output<<EOF
49D
50E
51A
52F
53B
54C
55EOF
56	atf_check -e match:cycle -o file:output tsort input
57	atf_check -e match:cycle -o file:output tsort <input
58	atf_check -o file:output tsort -q input
59	atf_check -o file:output tsort -q <input
60}
61
62atf_init_test_cases()
63{
64	atf_add_test_case basic
65	atf_add_test_case cycle
66}
67