aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJoão Távora2017-09-26 00:45:46 +0100
committerJoão Távora2017-10-03 13:53:22 +0100
commit94a88c1ae98b1bf7ab80ae9cdd4d6e16b36597ef (patch)
treeb5b2be6eceaa527cc2b9cc93a83c40e82a4c0b25 /test
parentb2f8b8b47ad6fe1550a183c5e96896ff587cd5f0 (diff)
downloademacs-94a88c1ae98b1bf7ab80ae9cdd4d6e16b36597ef.tar.gz
emacs-94a88c1ae98b1bf7ab80ae9cdd4d6e16b36597ef.zip
New Flymake API variable flymake-diagnostic-functions
Lay groundwork for multiple active backends in the same buffer. Backends are lisp functions called when flymake-mode sees fit. They are responsible for examining the current buffer and telling flymake.el, via return value, if they can syntax check it. Backends should return quickly and inexpensively, but they are also passed a REPORT-FN argument which they may or may not call asynchronously after performing more expensive work. REPORT-FN's calling convention stipulates that a backend calls it with a list of diagnostics as argument, or, alternatively, with a symbol denoting an exceptional situation, usually some panic resulting from a misconfigured backend. In keeping with legacy behaviour, flymake.el's response to a panic is to disable the issuing backend. The flymake--diag object representing a diagnostic now also keeps information about its source backend. Among other uses, this allows flymake to selectively cleanup overlays based on which backend is updating its diagnostics. * lisp/progmodes/flymake-proc.el (flymake-proc--report-fn): New dynamic variable. (flymake-proc--process): New variable. (flymake-can-syntax-check-buffer): Remove. (flymake-proc--process-sentinel): Simplify. Use unwind-protect. Affect flymake-proc--processes here. Bind flymake-proc--report-fn. (flymake-proc--process-filter): Bind flymake-proc--report-fn. (flymake-proc--post-syntax-check): Delete (flymake-proc-start-syntax-check): Take mandatory report-fn. Rewrite. Bind flymake-proc--report-fn. (flymake-proc--process-sentinel): Rewrite and simplify. (flymake-proc--panic): New helper. (flymake-proc--start-syntax-check-process): Record report-fn in process. Use flymake-proc--panic. (flymake-proc-stop-all-syntax-checks): Use mapc. Don't affect flymake-proc--processes here. Record interruption reason. (flymake-proc--init-find-buildfile-dir) (flymake-proc--init-create-temp-source-and-master-buffer-copy): Use flymake-proc--panic. (flymake-diagnostic-functions): Add flymake-proc-start-syntax-check. (flymake-proc-compile): Call flymake-proc-stop-all-syntax-checks with a reason. * lisp/progmodes/flymake.el (flymake-backends): Delete. (flymake-check-was-interrupted): Delete. (flymake--diag): Add backend slot. (flymake-delete-own-overlays): Take optional filter arg. (flymake-diagnostic-functions): New user-visible variable. (flymake--running-backends, flymake--disabled-backends): New buffer-local variables. (flymake-is-running): Now a function, not a variable. (flymake-mode-line, flymake-mode-line-e-w) (flymake-mode-line-status): Delete. (flymake-lighter): flymake's minor-mode "lighter". (flymake-report): Delete. (flymake--backend): Delete. (flymake--can-syntax-check-buffer): Delete. (flymake--handle-report, flymake--disable-backend) (flymake--run-backend, flymake--run-backend): New helpers. (flymake-make-report-fn): Make a lambda. (flymake--start-syntax-check): Iterate flymake-diagnostic-functions. (flymake-mode): Use flymake-lighter. Simplify. Initialize flymake--running-backends and flymake--disabled-backends. (flymake-find-file-hook): Simplify. * test/lisp/progmodes/flymake-tests.el (flymake-tests--call-with-fixture): Use flymake-is-running the function. Check if flymake-mode already active before activating it. Add a thorough test for flymake multiple backends * lisp/progmodes/flymake.el (flymake--start-syntax-check): Don't use condition-case-unless-debug, use condition-case * test/lisp/progmodes/flymake-tests.el (flymake-tests--assert-set): New helper macro. (dummy-backends): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/flymake-tests.el121
1 files changed, 118 insertions, 3 deletions
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index 5ecc87fc7e6..c2deb1dc5c7 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -1,4 +1,4 @@
1;;; flymake-tests.el --- Test suite for flymake 1;;; flymake-tests.el --- Test suite for flymake -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 2011-2017 Free Software Foundation, Inc. 3;; Copyright (C) 2011-2017 Free Software Foundation, Inc.
4 4
@@ -53,7 +53,7 @@ SEVERITY-PREDICATE is used to setup
53 (when sev-pred-supplied-p 53 (when sev-pred-supplied-p
54 (setq-local flymake-proc-diagnostic-type-pred severity-predicate)) 54 (setq-local flymake-proc-diagnostic-type-pred severity-predicate))
55 (goto-char (point-min)) 55 (goto-char (point-min))
56 (flymake-mode 1) 56 (unless flymake-mode (flymake-mode 1))
57 ;; Weirdness here... http://debbugs.gnu.org/17647#25 57 ;; Weirdness here... http://debbugs.gnu.org/17647#25
58 ;; ... meaning `sleep-for', and even 58 ;; ... meaning `sleep-for', and even
59 ;; `accept-process-output', won't suffice as ways to get 59 ;; `accept-process-output', won't suffice as ways to get
@@ -63,7 +63,7 @@ SEVERITY-PREDICATE is used to setup
63 ;; reading an input event, so, as a workaround, use a dummy 63 ;; reading an input event, so, as a workaround, use a dummy
64 ;; `read-event' with a very short timeout. 64 ;; `read-event' with a very short timeout.
65 (unless noninteractive (read-event "" nil 0.1)) 65 (unless noninteractive (read-event "" nil 0.1))
66 (while (and flymake-is-running (< (setq i (1+ i)) 10)) 66 (while (and (flymake-is-running) (< (setq i (1+ i)) 10))
67 (unless noninteractive (read-event "" nil 0.1)) 67 (unless noninteractive (read-event "" nil 0.1))
68 (sleep-for (+ 0.5 flymake-no-changes-timeout))) 68 (sleep-for (+ 0.5 flymake-no-changes-timeout)))
69 (funcall fn))) 69 (funcall fn)))
@@ -130,6 +130,121 @@ SEVERITY-PREDICATE is used to setup
130 (should (eq 'flymake-error (face-at-point))) 130 (should (eq 'flymake-error (face-at-point)))
131 (should-error (flymake-goto-next-error nil t)) )) 131 (should-error (flymake-goto-next-error nil t)) ))
132 132
133(defmacro flymake-tests--assert-set (set
134 should
135 should-not)
136 (declare (indent 1))
137 `(progn
138 ,@(cl-loop
139 for s in should
140 collect `(should (memq ,s ,set)))
141 ,@(cl-loop
142 for s in should-not
143 collect `(should-not (memq ,s ,set)))))
144
145(ert-deftest dummy-backends ()
146 "Test GCC warning via function predicate."
147 (with-temp-buffer
148 (cl-labels
149 ((diagnose
150 (report-fn type words)
151 (funcall
152 report-fn
153 (cl-loop
154 for word in words
155 append
156 (save-excursion
157 (goto-char (point-min))
158 (cl-loop while (word-search-forward word nil t)
159 collect (flymake-make-diagnostic
160 (current-buffer)
161 (match-beginning 0)
162 (match-end 0)
163 type
164 (concat word " is wrong")))))))
165 (error-backend
166 (report-fn)
167 (run-with-timer
168 0.5 nil
169 #'diagnose report-fn :error '("manha" "prognata")))
170 (warning-backend
171 (report-fn)
172 (run-with-timer
173 0.5 nil
174 #'diagnose report-fn :warning '("ut" "dolor")))
175 (sync-backend
176 (report-fn)
177 (diagnose report-fn :note '("quis" "commodo")))
178 (refusing-backend
179 (_report-fn)
180 nil)
181 (panicking-backend
182 (report-fn)
183 (run-with-timer
184 0.5 nil
185 report-fn :panic :explanation "The spanish inquisition!"))
186 (crashing-backend
187 (_report-fn)
188 ;; HACK: Shoosh log during tests
189 (setq-local warning-minimum-log-level :emergency)
190 (error "crashed")))
191 (insert "Lorem ipsum dolor sit amet, consectetur adipiscing
192 elit, sed do eiusmod tempor incididunt ut labore et dolore
193 manha aliqua. Ut enim ad minim veniam, quis nostrud
194 exercitation ullamco laboris nisi ut aliquip ex ea commodo
195 consequat. Duis aute irure dolor in reprehenderit in
196 voluptate velit esse cillum dolore eu fugiat nulla
197 pariatur. Excepteur sint occaecat cupidatat non prognata
198 sunt in culpa qui officia deserunt mollit anim id est
199 laborum.")
200 (let ((flymake-diagnostic-functions
201 (list #'error-backend #'warning-backend #'sync-backend
202 #'refusing-backend #'panicking-backend
203 #'crashing-backend
204 )))
205 (flymake-mode)
206 ;; FIXME: accessing some flymake-ui's internals here...
207 (flymake-tests--assert-set flymake--running-backends
208 (#'error-backend #'warning-backend #'panicking-backend)
209 (#'sync-backend #'crashing-backend #'refusing-backend))
210
211 (flymake-tests--assert-set flymake--disabled-backends
212 (#'crashing-backend)
213 (#'error-backend #'warning-backend #'sync-backend
214 #'panicking-backend #'refusing-backend))
215
216 (cl-loop repeat 10 while (flymake-is-running)
217 unless noninteractive do (read-event "" nil 0.1)
218 do (sleep-for (+ 0.5 flymake-no-changes-timeout)))
219
220 (should (eq flymake--running-backends '()))
221
222 (flymake-tests--assert-set flymake--disabled-backends
223 (#'crashing-backend #'panicking-backend)
224 (#'error-backend #'warning-backend #'sync-backend
225 #'refusing-backend))
226
227 (goto-char (point-min))
228 (flymake-goto-next-error)
229 (should (eq 'flymake-warning (face-at-point))) ; dolor
230 (flymake-goto-next-error)
231 (should (eq 'flymake-warning (face-at-point))) ; ut
232 (flymake-goto-next-error)
233 (should (eq 'flymake-error (face-at-point))) ; manha
234 (flymake-goto-next-error)
235 (should (eq 'flymake-warning (face-at-point))) ; Ut
236 (flymake-goto-next-error)
237 (should (eq 'flymake-note (face-at-point))) ; quis
238 (flymake-goto-next-error)
239 (should (eq 'flymake-warning (face-at-point))) ; ut
240 (flymake-goto-next-error)
241 (should (eq 'flymake-note (face-at-point))) ; commodo
242 (flymake-goto-next-error)
243 (should (eq 'flymake-warning (face-at-point))) ; dolor
244 (flymake-goto-next-error)
245 (should (eq 'flymake-error (face-at-point))) ; prognata
246 (should-error (flymake-goto-next-error nil t))))))
247
133(provide 'flymake-tests) 248(provide 'flymake-tests)
134 249
135;;; flymake.el ends here 250;;; flymake.el ends here