extensions/spellcheck/hunspell/tests/unit/data/test.sh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/spellcheck/hunspell/tests/unit/data/test.sh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +#!/bin/bash
     1.5 +export LC_ALL="C"
     1.6 +
     1.7 +function check_valgrind_log () {
     1.8 +if [ "$VALGRIND" != "" ]; then
     1.9 +  if [ -f $TEMPDIR/test.pid* ]; then
    1.10 +    log=`ls $TEMPDIR/test.pid*`
    1.11 +    if ! grep -q 'ERROR SUMMARY: 0 error' $log; then
    1.12 +        echo "Fail in $NAME $1 checking detected by Valgrind"
    1.13 +        echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
    1.14 +        mv $log $TEMPDIR/badlogs
    1.15 +        exit 1
    1.16 +    fi
    1.17 +    if grep -q 'LEAK SUMMARY' $log; then
    1.18 +        echo "Memory leak in $NAME $1 checking detected by Valgrind"
    1.19 +        echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
    1.20 +        mv $log $TEMPDIR/badlogs
    1.21 +        exit 1
    1.22 +    fi    
    1.23 +    rm -f $log
    1.24 +  fi
    1.25 +fi
    1.26 +}
    1.27 +
    1.28 +TESTDIR=.
    1.29 +TEMPDIR=$TESTDIR/testSubDir
    1.30 +NAME="$1"
    1.31 +shift
    1.32 +
    1.33 +if [ ! -d $TEMPDIR ]; then
    1.34 +  mkdir $TEMPDIR
    1.35 +fi
    1.36 +
    1.37 +shopt -s expand_aliases
    1.38 +
    1.39 +alias hunspell='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/hunspell'
    1.40 +alias analyze='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/analyze'
    1.41 +
    1.42 +if [ "$VALGRIND" != "" ]; then
    1.43 +  rm -f $TEMPDIR/test.pid*
    1.44 +  if [ ! -d $TEMPDIR/badlogs ]; then
    1.45 +    mkdir $TEMPDIR/badlogs
    1.46 +  fi
    1.47 +
    1.48 +  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'
    1.49 +  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'
    1.50 +fi
    1.51 +
    1.52 +# Tests good words
    1.53 +if test -f $TESTDIR/$NAME.good; then
    1.54 +    hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
    1.55 +    if test -s $TEMPDIR/$NAME.good; then
    1.56 +        echo "============================================="
    1.57 +        echo "Fail in $NAME.good. Good words recognised as wrong:"
    1.58 +        cat $TEMPDIR/$NAME.good
    1.59 +        rm -f $TEMPDIR/$NAME.good
    1.60 +        exit 1
    1.61 +    fi
    1.62 +    rm -f $TEMPDIR/$NAME.good
    1.63 +fi
    1.64 +
    1.65 +check_valgrind_log "good words"
    1.66 +
    1.67 +# Tests bad words
    1.68 +if test -f $TESTDIR/$NAME.wrong; then
    1.69 +    hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong
    1.70 +    tr -d '	' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
    1.71 +    if ! cmp $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab >/dev/null; then
    1.72 +        echo "============================================="
    1.73 +        echo "Fail in $NAME.wrong. Bad words recognised as good:"
    1.74 +        tr -d '	' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
    1.75 +        diff $TEMPDIR/$NAME.wrong.detab $TEMPDIR/$NAME.wrong | grep '^<' | sed 's/^..//'
    1.76 +        rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
    1.77 +        exit 1
    1.78 +    fi
    1.79 +    rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
    1.80 +fi
    1.81 +
    1.82 +check_valgrind_log "bad words"
    1.83 +
    1.84 +# Tests morphological analysis
    1.85 +if test -f $TESTDIR/$NAME.morph; then
    1.86 +    sed 's/	$//' $TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
    1.87 +    analyze $TESTDIR/$NAME.aff $TESTDIR/$NAME.dic $TEMPDIR/$NAME.good >$TEMPDIR/$NAME.morph
    1.88 +    if ! cmp $TEMPDIR/$NAME.morph $TESTDIR/$NAME.morph >/dev/null; then
    1.89 +        echo "============================================="
    1.90 +        echo "Fail in $NAME.morph. Bad analysis?"
    1.91 +        diff $TESTDIR/$NAME.morph $TEMPDIR/$NAME.morph | grep '^<' | sed 's/^..//'
    1.92 +        rm -f $TEMPDIR/$NAME.morph
    1.93 +        exit 1
    1.94 +    fi
    1.95 +    rm -f $TEMPDIR/$NAME.{morph,good}
    1.96 +fi
    1.97 +
    1.98 +check_valgrind_log "morphological analysis"
    1.99 +
   1.100 +# Tests suggestions
   1.101 +if test -f $TESTDIR/$NAME.sug; then
   1.102 +    hunspell $* -a -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong | grep '^&' | \
   1.103 +        sed 's/^[^:]*: //' >$TEMPDIR/$NAME.sug 
   1.104 +    if ! cmp $TEMPDIR/$NAME.sug $TESTDIR/$NAME.sug >/dev/null; then
   1.105 +        echo "============================================="
   1.106 +        echo "Fail in $NAME.sug. Bad suggestion?"
   1.107 +        diff $TESTDIR/$NAME.sug $TEMPDIR/$NAME.sug
   1.108 +        rm -f $TEMPDIR/$NAME.sug
   1.109 +        exit 1
   1.110 +    fi
   1.111 +    rm -f $TEMPDIR/$NAME.sug
   1.112 +fi
   1.113 +
   1.114 +check_valgrind_log "suggestion"

mercurial