ash: builtin: Mark more regular built-ins
[oweals/busybox.git] / shell / ash_test / run-all
1 #!/bin/sh
2
3 TOPDIR=`pwd`
4
5 if test ! -x ash; then
6         if test ! -x ../../busybox; then
7                 echo "Can't run tests. Put ash binary into this directory (`pwd`)"
8                 exit 1
9         fi
10         echo "No ./ash - creating a link to ../../busybox"
11         ln -s ../../busybox ash
12 fi
13 if test ! -f .config; then
14         if test ! -f ../../.config; then
15                 echo "Missing .config file"
16                 exit 1
17         fi
18         cp ../../.config . || exit 1
19 fi
20
21 eval $(sed -e '/^#/d' -e '/^$/d' -e 's:^:export :' .config)
22
23 test -x printenv || gcc -O2 -o printenv printenv.c || exit $?
24 test -x recho    || gcc -O2 -o recho    recho.c    || exit $?
25 test -x zecho    || gcc -O2 -o zecho    zecho.c    || exit $?
26
27 PATH="`pwd`:$PATH" # for ash and recho/zecho/printenv
28 export PATH
29
30 THIS_SH="`pwd`/ash"
31 export THIS_SH
32
33 do_test()
34 {
35         test -d "$1" || return 0
36         d=${d%/}
37 #       echo Running tests in directory "$1"
38         # $1 but with / replaced by # so that it can be used as filename part
39         noslash=`echo "$1" | sed 's:/:#:g'`
40         (
41         cd "$1" || { echo "cannot cd $1!"; exit 1; }
42         for x in run-*; do
43                 test -f "$x" || continue
44                 case "$x" in
45                         "$0"|run-minimal|run-gprof) ;;
46                         *.orig|*~) ;;
47                         #*) echo $x ; sh $x ;;
48                         *)
49                         echo -n "$1/$x:"
50                         sh "$x" >"$TOPDIR/$noslash-$x.fail" 2>&1 && \
51                         { { echo " ok"; rm "$TOPDIR/$noslash-$x.fail"; } || echo " fail"; }
52                         ;;
53                 esac
54         done
55         # Many bash run-XXX scripts just do this,
56         # no point in duplication it all over the place
57         for x in *.tests; do
58                 test -x "$x" || continue
59                 name="${x%%.tests}"
60                 test -f "$name.right" || continue
61 #               echo Running test: "$x"
62                 echo -n "$1/$x:"
63                 {
64                         "$THIS_SH" "./$x" >"$name.xx" 2>&1
65                         diff -u "$name.xx" "$name.right" >"$TOPDIR/$noslash-$x.fail" \
66                         && rm -f "$name.xx" "$TOPDIR/$noslash-$x.fail"
67                 } && echo " ok" || echo " fail"
68                 done
69         )
70 }
71
72 # Main part of this script
73 # Usage: run-all [directories]
74
75 ret=0
76
77 if [ $# -lt 1 ]; then
78         # All sub directories
79         modules=`ls -d ash-*`
80         # If you want to test ash against hush testsuite
81         # (have to copy hush_test dir to current dir first):
82         #modules=`ls -d ash-* hush_test/hush-*`
83
84         for module in $modules; do
85                 do_test $module || ret=1
86         done
87 else
88         while [ $# -ge 1 ]; do
89         if [ -d $1 ]; then
90                 do_test $1 || ret=1
91         fi
92         shift
93         done
94 fi
95
96 exit ${ret}