#! /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
#	 split.YYYYMMDD.  This is useful when something is different.
#
#	 ./inputs  - test inputs
#	 ./outputs - known correct outputs
#
#	 split.YYYYMMDD:
#		directory containing individual output files

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

map_rc()
{
    (
	set +e
	eval "$@"
	a=$?
	[ $a -eq 0 ] && exit 0
	[ $a -eq 1 ] && exit 0
	[ $a -eq 2 ] && exit 0
	exit $a
    )
}

$BOGOFILTER -C -s < "$srcdir/inputs/spam.mbx"
$BOGOFILTER -C -n < "$srcdir/inputs/good.mbx"

OUT="split.out"

files=`ls "${srcdir}"/inputs/msg.split.*`
for msg in $files ; do
    nam=`basename "$msg"`
    out="$TMPDIR"/$nam
    map_rc $BOGOLEXER -C -p $v -I "$msg" > "$out.l"
    map_rc $BOGOFILTER -C -vvv -I "$msg" > "$out.f"
    printf "%-24s %s\n" "$nam" `head -1 "$out.f" | sed s@spamicity=@@ \
    | tr -d "," | $AWK '{print $4}'` >> "$TMPDIR/$OUT"
done

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

test $verbose -eq 0 && cmp "$OUTPUTS/$OUT" "$TMPDIR"/$OUT \
|| diff $DIFF_BRIEF "$OUTPUTS/$OUT" "$TMPDIR/$OUT"
