#!/bin/sh

# This software is in the public domain and may be freely copied and
# distributed.
#
# THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTY. IN PARTICULAR, THE AUTHORS DO NOT MAKE ANY REPRESENTATION OR
# WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR
# ITS FITNESS FOR ANY PARTICULAR PURPOSE.

ok_failed=0
notok_failed=0

# test correct usage

echo "Running ok"
./ok
if [ $? -ne 0 ]; then
    echo "*** ok failed ***"
    ok_failed=1
else
    echo "--- ok succeeded" 
fi

# test incorrect usage

if [ ! -f notok.log ]; then
    echo "*** notok.log missing - can't test notok ***"
    exit 1
fi
rm -f notok.out

n=`./notok 2>&1 | awk '{print $3}' | awk -F- '{print $2}'`
echo "Running notok 1-$n (ignore 'core dumped' messages, if any)"

i=1
while :
do
    ./notok $i 2>&1 | grep "^exc" >>notok.out
    i=`expr $i + 1`
    [ $i -gt $n ] && break
done

diff notok.log notok.out >/dev/null
if [ $? -ne 0 ]; then
    echo "*** notok failed (compare notok.out with notok.log) ***"
    notok_failed=1
else
    echo "--- notok succeeded"
    rm -f notok.out
fi

rm -f core

exit `expr $ok_failed + $notok_failed` 
