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 atf_set require.progs "cc" 20} 21onearg_body() { 22 echo "void a(void) { }" >a.c 23 cc -o a.o -c a.c 24 echo "a.o a.o" >output 25 atf_check -o file:output \ 26 lorder *.o 27} 28 29atf_test_case dashdash 30dashdash_head() { 31 atf_set descr "One argument with double dash" 32 atf_set require.progs "cc" 33} 34dashdash_body() { 35 echo "void a(void) { }" >a.c 36 cc -o a.o -c a.c 37 echo "a.o a.o" >output 38 atf_check -o file:output \ 39 lorder -- *.o 40} 41 42atf_test_case nonexistent 43nonexistent_head() { 44 atf_set descr "Nonexistent file" 45} 46nonexistent_body() { 47 atf_check -s not-exit:0 -e match:"No such file" -o empty \ 48 lorder nonexistent.o 49} 50 51atf_test_case invalid 52invalid_head() { 53 atf_set descr "Invalid file" 54} 55invalid_body() { 56 echo "not an object file" >invalid.o 57 atf_check -s not-exit:0 -e match:"not recognized" -o empty \ 58 lorder invalid.o 59} 60 61atf_test_case objects 62objects_head() { 63 atf_set descr "Order objects" 64 atf_set require.progs "cc" 65} 66objects_body() { 67 echo "void a(void) { }" >a.c 68 echo "void a(void); void b(void) { a(); }" >b.c 69 echo "void b(void); void c(void) { b(); }" >c.c 70 for n in a b c ; do 71 cc -o $n.o -c $n.c 72 echo "$n.o $n.o" 73 done >output 74 echo "b.o a.o" >>output 75 echo "c.o b.o" >>output 76 atf_check -o file:output \ 77 lorder *.o 78} 79 80atf_test_case archives 81archives_head() { 82 atf_set descr "Order archives" 83 atf_set require.progs "cc" 84} 85archives_body() { 86 echo "void a(void) { }" >a.c 87 echo "void a(void); void b(void) { a(); }" >b.c 88 echo "void b(void); void c(void) { b(); }" >c.c 89 echo "void e(void); void d(void) { e(); }" >d.c 90 echo "void d(void); void e(void) { d(); }" >e.c 91 for n in a b c d e ; do 92 cc -o $n.o -c $n.c 93 done 94 for n in a b c ; do 95 ar -crs $n.a $n.o 96 echo "$n.a $n.a" 97 done >output 98 ar -crs z.a d.o e.o 99 echo "z.a z.a" >>output 100 echo "b.a a.a" >>output 101 echo "c.a b.a" >>output 102 atf_check -o file:output \ 103 lorder *.a 104} 105 106atf_init_test_cases() 107{ 108 atf_add_test_case noargs 109 atf_add_test_case onearg 110 atf_add_test_case dashdash 111 atf_add_test_case nonexistent 112 atf_add_test_case invalid 113 atf_add_test_case objects 114 atf_add_test_case archives 115} 116