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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/bin/bash
michael@0 2 export LC_ALL="C"
michael@0 3
michael@0 4 function check_valgrind_log () {
michael@0 5 if [ "$VALGRIND" != "" ]; then
michael@0 6 if [ -f $TEMPDIR/test.pid* ]; then
michael@0 7 log=`ls $TEMPDIR/test.pid*`
michael@0 8 if ! grep -q 'ERROR SUMMARY: 0 error' $log; then
michael@0 9 echo "Fail in $NAME $1 checking detected by Valgrind"
michael@0 10 echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
michael@0 11 mv $log $TEMPDIR/badlogs
michael@0 12 exit 1
michael@0 13 fi
michael@0 14 if grep -q 'LEAK SUMMARY' $log; then
michael@0 15 echo "Memory leak in $NAME $1 checking detected by Valgrind"
michael@0 16 echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
michael@0 17 mv $log $TEMPDIR/badlogs
michael@0 18 exit 1
michael@0 19 fi
michael@0 20 rm -f $log
michael@0 21 fi
michael@0 22 fi
michael@0 23 }
michael@0 24
michael@0 25 TESTDIR=.
michael@0 26 TEMPDIR=$TESTDIR/testSubDir
michael@0 27 NAME="$1"
michael@0 28 shift
michael@0 29
michael@0 30 if [ ! -d $TEMPDIR ]; then
michael@0 31 mkdir $TEMPDIR
michael@0 32 fi
michael@0 33
michael@0 34 shopt -s expand_aliases
michael@0 35
michael@0 36 alias hunspell='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/hunspell'
michael@0 37 alias analyze='../libtool --mode=execute -dlopen ../src/hunspell/.libs/libhunspell*.la ../src/tools/analyze'
michael@0 38
michael@0 39 if [ "$VALGRIND" != "" ]; then
michael@0 40 rm -f $TEMPDIR/test.pid*
michael@0 41 if [ ! -d $TEMPDIR/badlogs ]; then
michael@0 42 mkdir $TEMPDIR/badlogs
michael@0 43 fi
michael@0 44
michael@0 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'
michael@0 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'
michael@0 47 fi
michael@0 48
michael@0 49 # Tests good words
michael@0 50 if test -f $TESTDIR/$NAME.good; then
michael@0 51 hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
michael@0 52 if test -s $TEMPDIR/$NAME.good; then
michael@0 53 echo "============================================="
michael@0 54 echo "Fail in $NAME.good. Good words recognised as wrong:"
michael@0 55 cat $TEMPDIR/$NAME.good
michael@0 56 rm -f $TEMPDIR/$NAME.good
michael@0 57 exit 1
michael@0 58 fi
michael@0 59 rm -f $TEMPDIR/$NAME.good
michael@0 60 fi
michael@0 61
michael@0 62 check_valgrind_log "good words"
michael@0 63
michael@0 64 # Tests bad words
michael@0 65 if test -f $TESTDIR/$NAME.wrong; then
michael@0 66 hunspell -l $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong
michael@0 67 tr -d ' ' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
michael@0 68 if ! cmp $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab >/dev/null; then
michael@0 69 echo "============================================="
michael@0 70 echo "Fail in $NAME.wrong. Bad words recognised as good:"
michael@0 71 tr -d ' ' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
michael@0 72 diff $TEMPDIR/$NAME.wrong.detab $TEMPDIR/$NAME.wrong | grep '^<' | sed 's/^..//'
michael@0 73 rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
michael@0 74 exit 1
michael@0 75 fi
michael@0 76 rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
michael@0 77 fi
michael@0 78
michael@0 79 check_valgrind_log "bad words"
michael@0 80
michael@0 81 # Tests morphological analysis
michael@0 82 if test -f $TESTDIR/$NAME.morph; then
michael@0 83 sed 's/ $//' $TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
michael@0 84 analyze $TESTDIR/$NAME.aff $TESTDIR/$NAME.dic $TEMPDIR/$NAME.good >$TEMPDIR/$NAME.morph
michael@0 85 if ! cmp $TEMPDIR/$NAME.morph $TESTDIR/$NAME.morph >/dev/null; then
michael@0 86 echo "============================================="
michael@0 87 echo "Fail in $NAME.morph. Bad analysis?"
michael@0 88 diff $TESTDIR/$NAME.morph $TEMPDIR/$NAME.morph | grep '^<' | sed 's/^..//'
michael@0 89 rm -f $TEMPDIR/$NAME.morph
michael@0 90 exit 1
michael@0 91 fi
michael@0 92 rm -f $TEMPDIR/$NAME.{morph,good}
michael@0 93 fi
michael@0 94
michael@0 95 check_valgrind_log "morphological analysis"
michael@0 96
michael@0 97 # Tests suggestions
michael@0 98 if test -f $TESTDIR/$NAME.sug; then
michael@0 99 hunspell $* -a -d $TESTDIR/$NAME <$TESTDIR/$NAME.wrong | grep '^&' | \
michael@0 100 sed 's/^[^:]*: //' >$TEMPDIR/$NAME.sug
michael@0 101 if ! cmp $TEMPDIR/$NAME.sug $TESTDIR/$NAME.sug >/dev/null; then
michael@0 102 echo "============================================="
michael@0 103 echo "Fail in $NAME.sug. Bad suggestion?"
michael@0 104 diff $TESTDIR/$NAME.sug $TEMPDIR/$NAME.sug
michael@0 105 rm -f $TEMPDIR/$NAME.sug
michael@0 106 exit 1
michael@0 107 fi
michael@0 108 rm -f $TEMPDIR/$NAME.sug
michael@0 109 fi
michael@0 110
michael@0 111 check_valgrind_log "suggestion"

mercurial