blob: d843dd245ba28cffdfcb0f95d9b6bb90f107901e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
;;; ispell-aspell-tests.el --- Test ispell.el aspell 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 aspell integration.
;;; 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/aspell/ispell-check-version/works ()
"Test that aspell is correctly detected."
(skip-unless (and (executable-find "aspell")
(with-temp-buffer
(call-process "aspell" nil t nil "-vv")
(search-backward "but really Aspell"))))
(ispell-tests--letopt ((ispell-program-name "aspell"))
(setq ispell-last-program-name (time-to-seconds))
(setf ispell-program-name "aspell")
(should (stringp ispell-really-aspell)))
'passed)
(ert-deftest ispell/aspell/ispell-check-version/version-lowlow ()
"Test that low-version aspell is correctly detected and rejected."
(skip-unless (progn
(let ((fake-aspell-path (expand-file-name
"./fake-aspell.bash"
ispell-tests--data-directory)))
(chmod fake-aspell-path #o770)
(call-process fake-aspell-path nil nil nil))))
(let ((fake-aspell-path (expand-file-name
"./fake-aspell.bash"
ispell-tests--data-directory)))
(ispell-tests--letopt ((ispell-program-name "aspell"))
(setq ispell-last-program-name (time-to-seconds))
(should-error
(progn
(setopt ispell-program-name fake-aspell-path)
(ispell-check-version t))))
'passed)
)
(ert-deftest ispell/aspell/ispell-word/english/correct ()
"This test checks that Russian spellchecking works for Aspell."
(skip-unless (executable-find "aspell"))
(skip-unless (equal
0
(call-process "aspell" nil nil nil "-vv")))
(skip-unless (equal
0
(with-temp-buffer
(insert "test")
(call-process-region
nil
nil
"aspell" nil t nil "-a" "-denglish"))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt ((ispell-program-name "aspell")
(ispell-dictionary "english"))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
ispell-tests--constants/english/correct-one "\n")
(goto-char 1)
(ispell-change-dictionary "english")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word)
(should (string-match "is correct" lres))
)))))
'passed)
)
(ert-deftest ispell/aspell/ispell-word/english/incorrect ()
"This test checks that English spellchecking works for Aspell."
(skip-unless (executable-find "aspell"))
(skip-unless (equal
0
(call-process "aspell" nil nil nil "-vv")))
(skip-unless (equal
0
(with-temp-buffer
(insert ispell-tests--constants/english/correct-one)
(call-process-region
nil
nil
"aspell" nil t nil "-a" "-denglish"))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt ((ispell-program-name "aspell")
(ispell-dictionary "english"))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
;; there is no such a word in English, I swear.
ispell-tests--constants/english/wrong"\n"
)
(goto-char 1)
(ispell-change-dictionary "english")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (string-match "is incorrect" lres))))
'passed
)))
)
(ert-deftest ispell/aspell/ispell-word/english/wrong-language ()
"This test checks that English spellchecking works for Aspell."
:expected-result :failed
(skip-unless (executable-find "aspell"))
(skip-unless (equal
0
(call-process "aspell" nil nil nil "-vv")))
(skip-unless (equal
0
(with-temp-buffer
(insert ispell-tests--constants/english/correct-one)
(call-process-region nil nil "aspell" nil '("*scratch*" t) nil "-a" "-denglish"))))
(with-environment-variables (("HOME" temporary-file-directory))
(let ((default-directory temporary-file-directory))
(ispell-tests--letopt
((ispell-program-name "aspell"))
(ignore-errors (ispell-kill-ispell t t))
(with-temp-buffer
(insert
;; giving Aspell a wrong language should not fail
ispell-tests--constants/russian/correct "\n"
)
(goto-char 1)
(ispell-change-dictionary "english")
(ert-with-message-capture lres
(let ((ispell-check-only t))
(ispell-word))
(should (not (string-match "Error" lres)))))
'passed)))
)
(provide 'ispell-aspell-tests)
;;; ispell-aspell-tests.el ends here
|