Check-in hunspell source code.
[chromium-blink-merge.git] / third_party / hunspell_new / tests / test.sh
blobc89ca9bf75dd31f05cb46676c76a31f739cb5137
1 #!/bin/bash
2 export LC_ALL="C"
4 function check_valgrind_log () {
5 if [ "$VALGRIND" != "" ]; then
6 if [ -f $TEMPDIR/test.pid* ]; then
7 log=`ls $TEMPDIR/test.pid*`
8 if ! grep -q 'ERROR SUMMARY: 0 error' $log; then
9 echo "Fail in $NAME $1 checking detected by Valgrind"
10 echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
11 mv $log $TEMPDIR/badlogs
12 exit 1
14 if grep -q 'LEAK SUMMARY' $log; then
15 echo "Memory leak in $NAME $1 checking detected by Valgrind"
16 echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
17 mv $log $TEMPDIR/badlogs
18 exit 1
19 fi
20 rm -f $log
25 TESTDIR=.
26 TEMPDIR=$TESTDIR/testSubDir
27 NAME="$1"
28 shift
30 if [ ! -d $TEMPDIR ]; then
31 mkdir $TEMPDIR
34 shopt -s expand_aliases
36 alias hunspell='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/hunspell'
37 alias analyze='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/analyze'
39 if [ "$VALGRIND" != "" ]; then
40 rm -f $TEMPDIR/test.pid*
41 if [ ! -d $TEMPDIR/badlogs ]; then
42 mkdir $TEMPDIR/badlogs
45 alias hunspell='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid ../src/tools/hunspell'
46 alias analyze='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid ../src/tools/analyze'
49 # Tests good words
50 if test -f $TESTDIR/$NAME.good; then
51 hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
52 if test -s $TEMPDIR/$NAME.good; then
53 echo "============================================="
54 echo "Fail in $NAME.good. Good words recognised as wrong:"
55 cat $TEMPDIR/$NAME.good
56 rm -f $TEMPDIR/$NAME.good
57 exit 1
59 rm -f $TEMPDIR/$NAME.good
62 check_valgrind_log "good words"
64 # Tests bad words
65 if test -f $TESTDIR/$NAME.wrong; then
66 hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong
67 tr -d ' ' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
68 if ! cmp $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab >/dev/null; then
69 echo "============================================="
70 echo "Fail in $NAME.wrong. Bad words recognised as good:"
71 tr -d ' ' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
72 diff $TEMPDIR/$NAME.wrong.detab $TEMPDIR/$NAME.wrong | grep '^<' | sed 's/^..//'
73 rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
74 exit 1
76 rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
79 check_valgrind_log "bad words"
81 # Tests morphological analysis
82 if test -f $TESTDIR/$NAME.morph; then
83 sed 's/ $//' $TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
84 analyze $TESTDIR/$NAME.aff $TESTDIR/$NAME.dic $TEMPDIR/$NAME.good >$TEMPDIR/$NAME.morph
85 if ! cmp $TEMPDIR/$NAME.morph $TESTDIR/$NAME.morph >/dev/null; then
86 echo "============================================="
87 echo "Fail in $NAME.morph. Bad analysis?"
88 diff $TESTDIR/$NAME.morph $TEMPDIR/$NAME.morph | grep '^<' | sed 's/^..//'
89 rm -f $TEMPDIR/$NAME.morph
90 exit 1
92 rm -f $TEMPDIR/$NAME.{morph,good}
95 check_valgrind_log "morphological analysis"
97 # Tests suggestions
98 if test -f $TESTDIR/$NAME.sug; then
99 hunspell $* -a -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong | grep '^&' | \
100 sed 's/^[^:]*: //' >$TEMPDIR/$NAME.sug
101 if ! cmp $TEMPDIR/$NAME.sug $TESTDIR/$NAME.sug >/dev/null; then
102 echo "============================================="
103 echo "Fail in $NAME.sug. Bad suggestion?"
104 diff $TESTDIR/$NAME.sug $TEMPDIR/$NAME.sug
105 rm -f $TEMPDIR/$NAME.sug
106 exit 1
108 rm -f $TEMPDIR/$NAME.sug
111 check_valgrind_log "suggestion"