#!/bin/sh

#Test database maintenance using bogoutil's dump/load capabilities.
#    The building of wordlist.db also tests bogofilter's lexer

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

OUT="$TMPDIR/maint.out"

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

filter="egrep -v ^\\.ENCODING"

CORRECT="$TMPDIR"/ref.txt
cat >> "$CORRECT" <<EOF
initial: 5303
count 0 -> 5303
count 1 -> 1847
count 2 -> 949
count 3 -> 610
EOF

echo "initial:" $($BOGOUTIL -d "$WORDLIST" | $filter | wc -l) > "$OUT"

for cnt in 0 1 2 3 ; do
    $BOGOUTIL -C -c $cnt -m "$WORDLIST"
    echo "count $cnt ->" $($BOGOUTIL -C -d "$WORDLIST" | $filter | wc -l) >> "$OUT"
    if  [ $verbose -ne 0 ]; then
	$BOGOUTIL -C -d "$WORDLIST" > "$OUT".$cnt
    fi
done

if  [ $verbose -eq 0 ]; then
    cmp "$CORRECT" "$OUT" \
    ||  diff $DIFF_BRIEF "$CORRECT" "$OUT"
else
    diff $DIFF_BRIEF "$CORRECT" "$OUT"
fi
