test.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/bash
  2. # ##### BEGIN LICENSE BLOCK #####
  3. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. #
  5. # Copyright (C) 2002-2022 Németh László
  6. #
  7. # The contents of this file are subject to the Mozilla Public License Version
  8. # 1.1 (the "License"); you may not use this file except in compliance with
  9. # the License. You may obtain a copy of the License at
  10. # http://www.mozilla.org/MPL/
  11. #
  12. # Software distributed under the License is distributed on an "AS IS" basis,
  13. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. # for the specific language governing rights and limitations under the
  15. # License.
  16. #
  17. # Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks.
  18. #
  19. # Alternatively, the contents of this file may be used under the terms of
  20. # either the GNU General Public License Version 2 or later (the "GPL"), or
  21. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  22. # in which case the provisions of the GPL or the LGPL are applicable instead
  23. # of those above. If you wish to allow use of your version of this file only
  24. # under the terms of either the GPL or the LGPL, and not to allow others to
  25. # use your version of this file under the terms of the MPL, indicate your
  26. # decision by deleting the provisions above and replace them with the notice
  27. # and other provisions required by the GPL or the LGPL. If you do not delete
  28. # the provisions above, a recipient may use your version of this file under
  29. # the terms of any one of the MPL, the GPL or the LGPL.
  30. # ##### END LICENSE BLOCK #####
  31. # set -x # uncomment for debugging
  32. set -o pipefail
  33. export LC_ALL="C"
  34. function check_valgrind_log () {
  35. if [[ "$VALGRIND" != "" && -f $TEMPDIR/test.pid* ]]; then
  36. log=$(ls $TEMPDIR/test.pid*)
  37. if ! grep -q 'ERROR SUMMARY: 0 error' $log; then
  38. echo "Fail in $NAME $1 checking detected by Valgrind"
  39. echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
  40. mv $log $TEMPDIR/badlogs
  41. exit 1
  42. fi
  43. if grep -q 'LEAK SUMMARY' $log; then
  44. echo "Memory leak in $NAME $1 checking detected by Valgrind"
  45. echo "$log Valgrind log file moved to $TEMPDIR/badlogs"
  46. mv $log $TEMPDIR/badlogs
  47. exit 1
  48. fi
  49. rm -f $log
  50. fi
  51. }
  52. TEMPDIR=./testSubDir
  53. NAME="${1%.dic}"
  54. shift
  55. ENCODING=UTF-8 #io encoding passed with -i
  56. if [[ "$1" == "-i" && -n "$2" ]]; then
  57. ENCODING="$2"
  58. shift 2
  59. fi
  60. shopt -s expand_aliases
  61. [[ "$HUNSPELL" = "" ]] && HUNSPELL="$(dirname $0)"/../src/tools/hunspell
  62. [[ "$ANALYZE" = "" ]] && ANALYZE="$(dirname $0)"/../src/tools/analyze
  63. [[ "$LIBTOOL" = "" ]] && LIBTOOL="$(dirname $0)"/../libtool
  64. alias hunspell='"$LIBTOOL" --mode=execute "$HUNSPELL"'
  65. alias analyze='"$LIBTOOL" --mode=execute "$ANALYZE"'
  66. if [[ "$VALGRIND" != "" ]]; then
  67. mkdir $TEMPDIR 2> /dev/null || :
  68. rm -f $TEMPDIR/test.pid* || :
  69. mkdir $TEMPDIR/badlogs 2> /dev/null || :
  70. alias hunspell='"$LIBTOOL" --mode=execute valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid "$HUNSPELL"'
  71. alias analyze='"$LIBTOOL" --mode=execute valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid "$ANALYZE"'
  72. fi
  73. CR=$(printf "\r")
  74. in_dict="$NAME"
  75. if [[ ! -f "$in_dict.dic" ]]; then
  76. echo "Dictionary $in_dict.dic does not exists"
  77. exit 3
  78. fi
  79. # Tests good words
  80. in_file="$in_dict.good"
  81. if [[ -f $in_file ]]; then
  82. out=$(hunspell -l -i "$ENCODING" "$@" -d "$in_dict" < "$in_file" \
  83. | tr -d "$CR")
  84. if [[ $? -ne 0 ]]; then exit 2; fi
  85. if [[ "$out" != "" ]]; then
  86. echo "============================================="
  87. echo "Fail in $NAME.good. Good words recognised as wrong:"
  88. echo "$out"
  89. exit 1
  90. fi
  91. fi
  92. check_valgrind_log "good words"
  93. # Tests bad words
  94. in_file="$in_dict.wrong"
  95. if [[ -f $in_file ]]; then
  96. out=$(hunspell -G -i "$ENCODING" "$@" -d "$in_dict" < "$in_file" \
  97. | tr -d "$CR") #strip carriage return for mingw builds
  98. if [[ $? -ne 0 ]]; then exit 2; fi
  99. if [[ "$out" != "" ]]; then
  100. echo "============================================="
  101. echo "Fail in $NAME.wrong. Bad words recognised as good:"
  102. echo "$out"
  103. exit 1
  104. fi
  105. fi
  106. check_valgrind_log "bad words"
  107. # Tests good words' root
  108. in_file="$in_dict.good"
  109. expected_file="$in_dict.root"
  110. if [[ -f $expected_file ]]; then
  111. # Extract the root words of the affixed words, after '+'
  112. out=$(hunspell -d "$in_dict" < "$in_file" | grep -a '^+ ' \
  113. | sed 's/^+ //')
  114. if [[ $? -ne 0 ]]; then exit 2; fi
  115. expected=$(<"$expected_file")
  116. if [[ "$out" != "$expected" ]]; then
  117. echo "============================================="
  118. echo "Fail in $NAME.root. Bad analysis?"
  119. diff "$expected_file" <(echo "$out") | grep '^<' | sed 's/^..//'
  120. exit 1
  121. fi
  122. fi
  123. check_valgrind_log "root"
  124. # Tests morphological analysis
  125. in_file="$in_dict.good"
  126. expected_file="$in_dict.morph"
  127. if [[ -f $expected_file ]]; then
  128. #in=$(sed 's/ $//' "$in_file") #passes without this.
  129. out=$(analyze "$in_dict.aff" "$in_dict.dic" "$in_file" \
  130. | tr -d "$CR") #strip carige return for mingw builds
  131. if [[ $? -ne 0 ]]; then exit 2; fi
  132. expected=$(<"$expected_file")
  133. if [[ "$out" != "$expected" ]]; then
  134. echo "============================================="
  135. echo "Fail in $NAME.morph. Bad analysis?"
  136. diff "$expected_file" <(echo "$out") | grep '^<' | sed 's/^..//'
  137. exit 1
  138. fi
  139. fi
  140. check_valgrind_log "morphological analysis"
  141. # Tests suggestions
  142. in_file=$in_dict.wrong
  143. expected_file=$in_dict.sug
  144. if [[ -f $expected_file ]]; then
  145. out=$(hunspell -i "$ENCODING" "$@" -a -d "$in_dict" <"$in_file" | \
  146. { grep -a '^&' || true; } | sed 's/^[^:]*: //')
  147. if [[ $? -ne 0 ]]; then exit 2; fi
  148. expected=$(<"$expected_file")
  149. if [[ "$out" != "$expected" ]]; then
  150. echo "============================================="
  151. echo "Fail in $NAME.sug. Bad suggestion?"
  152. diff "$expected_file" <(echo "$out")
  153. exit 1
  154. fi
  155. fi
  156. check_valgrind_log "suggestion"