#! /bin/sh

# Note:  When run via "make check", test output files are automatically deleted.
#	 When run from the command line, output files are left in directory
#	 robx.YYYYMMDD.  This is useful when something is different.
#
#	 ./inputs  - test inputs
#	 ./outputs - known correct outputs
#
#	 robx.YYYYMMDD:
#		directory containing individual output files

NODB=1 . ${srcdir=.}/t.frame

[ -d "$TMPDIR"/tests ] && rm -rf "$TMPDIR"/tests
mkdir -p "$TMPDIR"/tests

CFG="$TMPDIR/test.cf"

cat <<EOF > "$CFG"
robx=0.415
min_dev=0.0
spam_header_name=X-Bogosity
stats_in_header=Y
EOF

$BOGOFILTER -c "$CFG" -y 0 -s < "$SYSTEST/inputs/spam.mbx"
$BOGOFILTER -c "$CFG" -y 0 -n < "$SYSTEST/inputs/good.mbx"

if [ ! -z "$RUN_FROM_MAKE" ] ; then
    $BOGOUTIL -C -D -R "$TMPDIR"/wordlist.$DB_EXT
else
    for f in $BOGOFILTER_DIR/*.$DB_EXT ; do
	n="$(basename "$f" .$DB_EXT)"
	$BOGOUTIL -C -d $BOGOFILTER_DIR"/$n".$DB_EXT > "$TMPDIR/$n.txt"
    done
    $BOGOUTIL -C -vvvv -D -R "$TMPDIR"/wordlist.$DB_EXT > "$TMPDIR"/output.vvv
fi

if [ "$BF_SAVEDIR" ] ; then . ${srcdir}/t.save ; fi

RESULT=`$BOGOUTIL -C -w "$TMPDIR"/wordlist.$DB_EXT .ROBX | $AWK '/.ROBX/ { print $2; }'`

WANT="366405"

if [ "$RESULT" != "$WANT" ] ; then
    echo want: $WANT, have: $RESULT
fi

test "$RESULT" = "$WANT"
