tr: more of code shrink (getopt32-ification)
[people/mcb30/busybox.git] / testsuite / runtest
1 #!/bin/sh
2
3 # Run old-style test.
4
5 run_applet_testcase()
6 {
7         local applet=$1
8         local testcase=$2
9
10         local status=0
11         local RES=
12
13         local uc_applet=$(echo $applet | tr a-z A-Z)
14         local testname=$(basename $testcase)
15
16         if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
17                 echo UNTESTED: $testname
18                 return 0
19         fi
20
21         if grep -q "^# FEATURE: " $testcase; then
22                 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
23
24                 if grep -q "^# ${feature} is not set$" $bindir/.config; then
25                         echo UNTESTED: $testname
26                         return 0
27                 fi
28         fi
29
30         rm -rf tmp
31         mkdir -p tmp
32         pushd tmp > /dev/null
33
34         d=$tsdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$?
35
36         if [ $status -ne 0 ]; then
37                 echo FAIL: $testname
38                 if [ $verbose -gt 0 ]; then
39                         cat .logfile.txt
40                 fi
41                 status=$?
42         else
43                 echo PASS: $testname
44                 rm -f .logfile.txt
45                 status=$?
46         fi
47
48         popd > /dev/null
49         rm -rf tmp
50
51         return $status
52 }
53
54 run_applet_tests()
55 {
56         local applet=$1
57
58         local status=0
59
60         for testcase in $tsdir/$applet/*; do
61                 if [ "$testcase" = "$tsdir/$applet/CVS" ]; then
62                         continue
63                 fi
64                 if ! run_applet_testcase $applet $testcase; then
65                         status=1
66                 fi
67         done
68
69         return $status
70 }
71
72
73 status=0
74 verbose=0
75
76 [ -n "$tsdir" ] || tsdir=$(pwd)
77 [ -n "$bindir" ] || bindir=$(dirname $(pwd))
78 PATH="$bindir:$PATH"
79
80 if [ x"$1" = x"-v" ]; then
81         verbose=1
82         export VERBOSE=$verbose
83         shift
84 fi
85
86 implemented=$(
87         $bindir/busybox 2>&1 |
88         while read line; do
89                 if test x"$line" = x"Currently defined functions:"; then
90                         xargs | sed 's/,//g'
91                         break
92                 fi
93         done
94         )
95
96 applets="$implemented"
97 if [ $# -ne 0 ]; then
98         applets="$@"
99 fi
100
101 # Populate a directory with links to all busybox applets
102
103 LINKSDIR="$bindir/runtest-tempdir-links"
104 rm -rf "$LINKSDIR" 2>/dev/null
105 mkdir "$LINKSDIR"
106 for i in $implemented; do
107         ln -s $bindir/busybox "$LINKSDIR"/$i
108 done
109
110 # Set up option flags so tests can be selective.
111
112 configfile=${bindir}/.config
113 export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile | xargs | sed 's/ /:/g')
114
115 for applet in $applets; do
116         if [ "$applet" = "links" ]; then continue; fi
117         if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
118                 if ! run_applet_tests $applet; then
119                         status=1
120                 fi
121         fi
122
123         # Is this a new-style test?
124         if [ -f ${applet}.tests ]; then
125                 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then
126                         echo "SKIPPED: $applet (not built)"
127                         continue
128                 fi
129                 if PATH="$LINKSDIR":$tsdir:$bindir:$PATH \
130                                 "${tsdir:-.}/$applet".tests
131                 then
132                         :
133                 else
134                         status=1
135                 fi
136         fi
137
138 done
139 rm -rf "$LINKSDIR"
140 exit $status