Sync /bin/sh regression tests with FreeBSD.
[dragonfly.git] / tools / regression / bin / sh / regress.sh
1 # $FreeBSD: src/tools/regression/bin/sh/regress.sh,v 1.5 2011/02/19 13:23:13 jilles Exp $
2
3 if [ -z "${SH}" ]; then
4         echo '${SH} is not set, please correct and re-run.'
5         exit 1
6 fi
7 export SH=${SH}
8
9 COUNTER=1
10
11 do_test() {
12         c=${COUNTER}
13         COUNTER=$((COUNTER+1))
14         ${SH} $1 > tmp.stdout 2> tmp.stderr
15         if [ $? -ne $2 ]; then
16                 echo "not ok ${c} - ${1} # wrong exit status"
17                 rm tmp.stdout tmp.stderr
18                 return
19         fi
20         for i in stdout stderr; do
21                 if [ -f ${1}.${i} ]; then
22                         if ! cmp -s tmp.${i} ${1}.${i}; then
23                                 echo "not ok ${c} - ${1} # wrong output on ${i}"
24                                 rm tmp.stdout tmp.stderr
25                                 return
26                         fi
27                 elif [ -s tmp.${i} ]; then
28                         echo "not ok ${c} - ${1} # wrong output on ${i}"
29                         rm tmp.stdout tmp.stderr
30                         return
31                 fi
32         done
33         echo "ok ${c} - ${1}"
34         rm tmp.stdout tmp.stderr
35 }
36
37 TESTS=$(find -Es . -regex ".*\.[0-9]+")
38 printf "1..%d\n" $(echo ${TESTS} | wc -w)
39
40 for i in ${TESTS} ; do
41         do_test ${i} ${i##*.}
42 done