#! /bin/sh
##
## Test all games 
##

. sh/tmp.sh
. sh/verbose.sh
. sh/echo-n.sh

tmp_book=$TMP/$$.book
tmp_pgn=$TMP/$$.pgn

error ()
{
    echo >&2 "*** error:  $1"
    exit 1
}

[ "$verbose" = 1 ] && >&4 $echo_n "Testing games$echo_c"

for file in share/test_game/*.pgn 
do
    [ "$verbose" = 1 ] && >&4 $echo_n ".$echo_c"
    echo >&5 "Testing $file"
    if bin/babychess-book -c $tmp_book -m $file ; then : ; else
	error "reading $file"
    fi
    if >$tmp_pgn bin/babychess-book -r $tmp_book -D ; then : ; else
	error "recreating $file"
    fi
    if cmp $file.export $tmp_pgn ; then : ; else
	error "normalized file $file.export doesn't match"
    fi
done

[ "$verbose" = 1 ] && echo >&4

exit 0

