Files
emacs-gpu/test/lisp/textmodes/ispell-tests/ispell-international-ispell-tests.el
LockywolfandEli Zaretskii 1f3d417736 Fix detecting a working hunspell on systems without a dictionary
Fixes bug#79477 and bug#79514

* test/lisp/textmodes/ispell-tests/ispell-hunspell-tests.el
(ispell-tests-hunspell--hunspell-working): Implement checker.
(ispell/hunspell/ispell-word/russian/check-only): Add skip-check.
(ispell/hunspell/ispell-word/english/check-only): Add skip-check.
(ispell/hunspell/ispell-word/language-switch/check-only): Add
skip-check.
(ispell/hunspell/ispell-word/russian/check-only/wrong-language): Add
skip-check.
(ispell/hunspell/ispell-word/multilang): Add skip-check.
* test/lisp/textmodes/ispell-tests/ispell-tests-common.el
(fake-aspell-path): Improve checking that an engine works.
(ispell-tests--letopt): Make restoring variables more robust,
rename to a local name.  Add debug spec.
(ispell-tests--with-ispell-global-dictionary): Rename to a local name
Add debug spec.
(ispell-tests--some-valid-dictionary): Add a selector for a safe
dictionary.
(ispell/ispell-accept-buffer-local-defs/received-file): Add.
(ispell-tests--constants/english/correct-list): Add.
(ispell-tests--constants/english/correct-one): Add.
(ispell-tests--constants/english/wrong): Add.
(ispell-tests--constants/russian/correct): Add.
(ispell-tests--constants/russian/wrong): Add.
(ispell-tests--constants/completion): Add.
* test/lisp/textmodes/ispell-tests/ispell-tests.el
(ispell/ispell-buffer-local-words/ispell-buffer-session-localwords):
reverse letopt and with-ispell-dictionary.
(ispell/ispell-buffer-local-words/ispell-words-keyword):
reverse letopt and with-ispell-dictionary.
(ispell/ispell-complete-word-interior-frag/simple):
reverse letopt and with-ispell-dictionary.
(ispell/ispell-complete-word/ispell-completion-at-point):
reverse letopt and with-ispell-dictionary.
(ispell/ispell-init-process/works-with-home):
reverse letopt and with-ispell-dictionary.
(ispell/ispell-kill-ispell):
reverse letopt and with-ispell-dictionary.
* test/lisp/textmodes/ispell-resources/fake-aspell-new.bash:
Add comments on unused function.  Replace echo with printf.
2025-10-18 13:59:07 +03:00

223 lines
8.3 KiB
EmacsLisp

;;; ispell-international-ispell-tests.el --- Test ispell.el International Ispell backend. -*- lexical-binding: t; -*-
;; Copyright (C) 2025 Lockywolf
;; Author: Lockywolf <for_emacs_1@lockywolf.net>
;; Keywords: languages, text
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for ispell.el's cooperation with International Ispell.
;;; Code:
(require 'ispell)
(require 'ert)
(require 'ert-x)
(eval-and-compile
(let ((load-path (cons (file-name-directory
(or (macroexp-file-name) load-file-name))
load-path)))
(require 'ispell-tests-common)))
(ert-deftest ispell/international-ispell/ispell-word/russian/check-only ()
"This test checks that Russian spellchecking works for International Ispell with UTF-8."
(skip-unless (executable-find "ispell"))
(skip-unless (equal
0
(call-process "ispell" nil nil nil "-vv")))
(skip-unless (string-equal
"
*
привет
"
(with-temp-buffer
(insert ispell-tests--constants/russian/correct "\n")
(forward-line -1)
(call-process-region nil nil "ispell" nil t nil "-a" "-d" "russian")
(goto-char 1)
(kill-line)
(buffer-string))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt
((ispell-program-name "ispell")
(ispell-local-dictionary-alist
'((
"russian"
"[A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
"[^A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
""
nil
nil
nil
nil
))))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
ispell-tests--constants/russian/correct "\n")
(goto-char 1)
(ispell-change-dictionary "russian")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is correct" lres))))
(with-temp-buffer
(insert
ispell-tests--constants/russian/correct "\n")
(goto-char 1)
(ispell-change-dictionary "russian")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is correct" lres))))
(with-temp-buffer
(insert
ispell-tests--constants/russian/wrong "\n"
)
(goto-char 1)
(ispell-change-dictionary "russian")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is incorrect" lres))))
)))
)
(ert-deftest ispell/international-ispell/ispell-word/language-switch/check-only ()
"This test checks that Russian spellchecking works for International Ispell with UTF-8 when switching the language."
(skip-unless (executable-find "ispell"))
(skip-unless (equal
0
(call-process "ispell" nil nil nil "-vv")))
(skip-unless (string-equal
"
*
привет
"
(with-temp-buffer
(insert ispell-tests--constants/russian/correct "\n")
(forward-line -1)
(call-process-region nil nil "ispell" nil t nil "-a" "-d" "russian")
(goto-char 1)
(kill-line)
(buffer-string))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt
((ispell-program-name "ispell")
(ispell-local-dictionary-alist
'((
"russian"
"[A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
"[^A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
""
nil
nil
nil
nil
))))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
ispell-tests--constants/russian/correct "\n")
(goto-char 1)
(ispell-change-dictionary "russian")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is correct" lres)))
(goto-char (buffer-end 1))
(insert
"\n" ispell-tests--constants/russian/wrong "\n"
)
(forward-line -1)
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is incorrect" lres)))
(goto-char (buffer-end 1))
(ispell-change-dictionary "english")
(insert
"\n" ispell-tests--constants/english/correct-one "\n"
)
(forward-line -1)
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is correct" lres)))
))))
)
(ert-deftest ispell/international-ispell/ispell-word/russian/check-only/wrong-language ()
"If we give Russian-checking Ispell an english word, it should still process it gracefully.
It will not say correct/incorrect, but it should at least not crash or something."
(skip-unless (executable-find "ispell"))
(skip-unless (equal
0
(call-process "ispell" nil nil nil "-vv")))
(skip-unless (string-equal
(seq-concatenate 'string
"
*
" ispell-tests--constants/russian/correct "
")
(with-temp-buffer
(insert ispell-tests--constants/russian/correct "\n")
(forward-line -1)
(call-process-region nil nil "ispell" nil t nil "-a" "-d" "russian")
(goto-char 1)
(kill-line)
(buffer-string))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt
((ispell-program-name "ispell")
(ispell-local-dictionary-alist
'((
"russian"
"[A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
"[^A-Za-zабвгдеёжзиклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]"
""
nil
nil
nil
nil
))))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
ispell-tests--constants/english/correct-one "\n")
(goto-char 1)
(ispell-change-dictionary "russian")
(let ((ispell-check-only t))
(ispell-word))
(insert "\n" ispell-tests--constants/russian/correct "\n")
(forward-line -1)
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is correct" lres)))))))
)
(provide 'ispell-international-ispell-tests)
;;; ispell-international-ispell-tests.el ends here