1# $FreeBSD$
2
3: ${SH:="__SH__"}
4export SH
5
6# TODO(jmmv): The Kyua TAP interface should be passing us the value of
7# "srcdir" as an environment variable, just as it does with the ATF
8# interface in the form of a configuration variable.  For now, just try
9# to guess this.
10: ${TESTS_DATA:=$(dirname ${0})}
11
12COUNTER=1
13
14do_test() {
15	c=${COUNTER}
16	COUNTER=$((COUNTER+1))
17	${SH} $1 > tmp.stdout 2> tmp.stderr
18	if [ $? -ne $2 ]; then
19		echo "not ok ${c} - ${1} # wrong exit status"
20		rm tmp.stdout tmp.stderr
21		return
22	fi
23	sed -I '' -e "s|^${TESTS_DATA}|.|" tmp.stderr
24	for i in stdout stderr; do
25		if [ -f ${1}.${i} ]; then
26			if ! cmp -s tmp.${i} ${1}.${i}; then
27				echo "not ok ${c} - ${1} # wrong output on ${i}"
28				rm tmp.stdout tmp.stderr
29				return
30			fi
31		elif [ -s tmp.${i} ]; then
32			echo "not ok ${c} - ${1} # wrong output on ${i}"
33			rm tmp.stdout tmp.stderr
34			return
35		fi
36	done
37	echo "ok ${c} - ${1}"
38	rm tmp.stdout tmp.stderr
39}
40
41TESTS=$(find -Es ${TESTS_DATA} -regex ".*\.[0-9]+")
42printf "1..%d\n" $(echo ${TESTS} | wc -w)
43
44for i in ${TESTS} ; do
45	do_test ${i} ${i##*.}
46done
47