1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/bin/sh
set -e || exit "$?"
DIFF='diff -a -u'
$DIFF $0 $0 >/dev/null 2>&1 || DIFF='diff'
t=$0.tmp.$$
echo "Creating temporary directory $t"
mkdir $t
trap 'echo "Cleaning up $t"; rm -r $t' EXIT
do_test() {
echo "Testing $1"
rm -f $t/*
sed -e 's/-o ${base}.o//' compile | \
sh -s $1 -DSELFTEST_MAIN -o $t/test.o -include selftest.c || {
echo "=====> Compile failed! <====="
return 1
}
./load $t/test .libs/libbg.a || {
echo "=====> Load failed! <====="
return 1
}
( cd $t && ./test >./test.out 2>&1; ) || {
echo "=====> Test output <====="
cat -v $t/test.out
echo "=====> Test failed! <====="
return 1
}
./selftest-cmp $1 $t/test.out || {
echo "=====> Expected output <====="
sed -e '1,/^#ifdef SELFTEST_EXP/d' -e '/^#endif/,$d' $1
echo "=====> Test output <====="
cat -v $t/test.out
echo "=====> Output failed! <====="
return 1
}
return 0
}
exitcode=true
if [ $# -gt 0 ]; then
for c in "$@"; do
do_test $c || exitcode=false
done
else
for c in `fgrep -l '#ifdef SELFTEST_MAIN' */*.c`
do
[ $(dirname "$c") != net ] || continue
do_test $c || exitcode=false
done
fi
$exitcode
|