xref: /freebsd/usr.bin/lorder/tests/lorder_test.sh (revision 96da41b6dbf383436018f11ad8a672faab2d3789)
1#
2# Copyright (c) 2024 Klara, Inc.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7atf_test_case noargs
8noargs_head() {
9	atf_set descr "No arguments"
10}
11noargs_body() {
12	atf_check -s exit:1 -e match:"^usage:" \
13		  lorder
14}
15
16atf_test_case onearg
17onearg_head() {
18	atf_set descr "One argument"
19}
20onearg_body() {
21	echo "void a(void) { }" >a.c
22	cc -o a.o -c a.c
23	echo "a.o a.o" >output
24	atf_check -o file:output \
25		  lorder *.o
26}
27
28atf_test_case dashdash
29dashdash_head() {
30	atf_set descr "One argument"
31}
32dashdash_body() {
33	echo "void a(void) { }" >a.c
34	cc -o a.o -c a.c
35	echo "a.o a.o" >output
36	atf_check -o file:output \
37		  lorder -- *.o
38}
39
40atf_test_case nonexistent
41nonexistent_head() {
42	atf_set descr "Nonexistent file"
43}
44nonexistent_body() {
45	atf_check -s not-exit:0 -e match:"No such file" -o empty \
46		  lorder nonexistent.o
47}
48
49atf_test_case invalid
50invalid_head() {
51	atf_set descr "Invalid file"
52}
53invalid_body() {
54	echo "not an object file" >invalid.o
55	atf_check -s not-exit:0 -e match:"File format not" -o empty \
56		  lorder invalid.o
57}
58
59atf_test_case objects
60objects_head() {
61	atf_set descr "Order objects"
62}
63objects_body() {
64	echo "void a(void) { }" >a.c
65	echo "void a(void); void b(void) { a(); }" >b.c
66	echo "void b(void); void c(void) { b(); }" >c.c
67	for n in a b c ; do
68		cc -o $n.o -c $n.c
69		echo "$n.o $n.o"
70	done >output
71	echo "b.o a.o" >>output
72	echo "c.o b.o" >>output
73	atf_check -o file:output \
74		  lorder *.o
75}
76
77atf_test_case archives
78archives_head() {
79	atf_set descr "Order archives"
80}
81archives_body() {
82	echo "void a(void) { }" >a.c
83	echo "void a(void); void b(void) { a(); }" >b.c
84	echo "void b(void); void c(void) { b(); }" >c.c
85	echo "void e(void); void d(void) { e(); }" >d.c
86	echo "void d(void); void e(void) { d(); }" >e.c
87	for n in a b c d e ; do
88		cc -o $n.o -c $n.c
89	done
90	for n in a b c ; do
91		ar -crs $n.a $n.o
92		echo "$n.a $n.a"
93	done >output
94	ar -crs z.a d.o e.o
95	echo "z.a z.a" >>output
96	echo "b.a a.a" >>output
97	echo "c.a b.a" >>output
98	atf_check -o file:output \
99		  lorder *.a
100}
101
102atf_init_test_cases()
103{
104	atf_add_test_case noargs
105	atf_add_test_case onearg
106	atf_add_test_case dashdash
107	atf_add_test_case nonexistent
108	atf_add_test_case invalid
109	atf_add_test_case objects
110	atf_add_test_case archives
111}
112