cde841e6606bdcdd486c0211a865d2300072aff9
[oweals/busybox.git] / shell / hush_test / run-all
1 #!/bin/sh
2
3 unset LANG LANGUAGE
4 unset LC_COLLATE
5 unset LC_CTYPE
6 unset LC_MONETARY
7 unset LC_MESSAGES
8 unset LC_NUMERIC
9 unset LC_TIME
10 unset LC_ALL
11
12 test -x hush || {
13         echo "No ./hush - creating a link to ../../busybox"
14         ln -s ../../busybox hush
15 }
16 if test ! -e .config; then
17         if test -f ../../.config; then
18                 cp ../../.config . || exit 1
19         else
20                 echo "Missing .config file"
21                 exit 1
22         fi
23 fi
24 eval $(sed -e '/^#/d' -e '/^$/d' -e 's:^:export :' .config)
25
26 PATH="`pwd`:$PATH" # for hush and recho/zecho/printenv
27 export PATH
28
29 THIS_SH="`pwd`/hush"
30 export THIS_SH
31
32 do_test()
33 {
34         test -d "$1" || return 0
35         d=${d%/}
36 #       echo Running tests in directory "$1"
37         (
38         tret=0
39         cd "$1" || { echo "cannot cd $1!"; exit 1; }
40         for x in run-*; do
41         test -f "$x" || continue
42         case "$x" in
43                 "$0"|run-minimal|run-gprof) ;;
44                 *.orig|*~) ;;
45                 #*) echo $x ; sh $x ;;
46                 *)
47                 sh "$x" >"../$1-$x.fail" 2>&1 && \
48                 { echo "$1/$x: ok"; rm "../$1-$x.fail"; } || echo "$1/$x: fail";
49                 ;;
50         esac
51         done
52         # Many bash run-XXX scripts just do this,
53         # no point in duplication it all over the place
54         for x in *.tests; do
55         test -x "$x" || continue
56         name="${x%%.tests}"
57         test -f "$name.right" || continue
58 #       echo Running test: "$x"
59         (
60                 "$THIS_SH" "./$x" >"$name.xx" 2>&1
61                 # filter C library differences
62                 sed -i \
63                         -e "/: invalid option /s:'::g" \
64                         "$name.xx"
65                 test $? -eq 77 && rm -f "../$1-$x.fail" && exit 77
66                 diff -u "$name.xx" "$name.right" >"../$1-$x.fail" && rm -f "$name.xx" "../$1-$x.fail"
67         )
68         case $? in
69                 0)  echo "$1/$x: ok";;
70                 77) echo "$1/$x: skip (feature disabled)";;
71                 *)  echo "$1/$x: fail"; tret=1;;
72         esac
73         done
74         exit ${tret}
75         )
76 }
77
78 # Main part of this script
79 # Usage: run-all [directories]
80
81 ret=0
82
83 if [ $# -lt 1 ]; then
84         # All sub directories
85         modules=`ls -d hush-*`
86
87         for module in $modules; do
88         do_test $module || ret=1
89         done
90 else
91         while [ $# -ge 1 ]; do
92         if [ -d $1 ]; then
93                 do_test $1 || ret=1
94         fi
95         shift
96         done
97 fi
98
99 exit ${ret}