#!/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.

notok2_failed=0

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

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

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

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

rm -f core

exit $notok2_failed
