2013-06-21 10:36:13 -04:00
|
|
|
|
;;; flymake-tests.el --- Test suite for flymake
|
|
|
|
|
|
2017-01-01 03:14:01 +00:00
|
|
|
|
;; Copyright (C) 2011-2017 Free Software Foundation, Inc.
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
|
|
|
|
;; Author: Eduard Wiebe <usenet@pusto.de>
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
(require 'ert)
|
|
|
|
|
(require 'flymake)
|
|
|
|
|
|
2013-11-04 21:54:38 -05:00
|
|
|
|
(defvar flymake-tests-data-directory
|
2017-08-20 12:19:45 +01:00
|
|
|
|
(expand-file-name "lisp/progmodes/flymake-resources"
|
|
|
|
|
(or (getenv "EMACS_TEST_DIRECTORY")
|
|
|
|
|
(expand-file-name "../../.."
|
|
|
|
|
(or load-file-name
|
|
|
|
|
buffer-file-name))))
|
2013-11-04 21:54:38 -05:00
|
|
|
|
"Directory containing flymake test data.")
|
|
|
|
|
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
2017-09-07 14:19:33 +01:00
|
|
|
|
;;
|
|
|
|
|
;;
|
|
|
|
|
(cl-defun flymake-tests--call-with-fixture (fn file
|
|
|
|
|
&key (severity-predicate
|
|
|
|
|
nil sev-pred-supplied-p))
|
|
|
|
|
"Call FN after flymake setup in FILE, using `flymake-proc`.
|
|
|
|
|
SEVERITY-PREDICATE is used to setup
|
|
|
|
|
`flymake-proc-warning-predicate'."
|
|
|
|
|
(let* ((file (expand-file-name file flymake-tests-data-directory))
|
|
|
|
|
(visiting (find-buffer-visiting file))
|
|
|
|
|
(buffer (or visiting (find-file-noselect file)))
|
|
|
|
|
(process-environment (cons "LC_ALL=C" process-environment))
|
|
|
|
|
(i 0))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
(unwind-protect
|
2013-11-04 21:54:38 -05:00
|
|
|
|
(with-current-buffer buffer
|
2017-09-21 14:57:20 +01:00
|
|
|
|
(save-excursion
|
|
|
|
|
(when sev-pred-supplied-p
|
|
|
|
|
(setq-local flymake-proc-warning-predicate severity-predicate))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(flymake-mode 1)
|
|
|
|
|
;; Weirdness here... http://debbugs.gnu.org/17647#25
|
|
|
|
|
;; ... meaning `sleep-for', and even
|
|
|
|
|
;; `accept-process-output', won't suffice as ways to get
|
|
|
|
|
;; process filters and sentinels to run, though they do work
|
|
|
|
|
;; fine in a non-interactive batch session. The only thing
|
|
|
|
|
;; that will indeed unblock pending process output is
|
|
|
|
|
;; reading an input event, so, as a workaround, use a dummy
|
|
|
|
|
;; `read-event' with a very short timeout.
|
2017-08-20 12:19:45 +01:00
|
|
|
|
(unless noninteractive (read-event "" nil 0.1))
|
2017-09-21 14:57:20 +01:00
|
|
|
|
(while (and flymake-is-running (< (setq i (1+ i)) 10))
|
|
|
|
|
(unless noninteractive (read-event "" nil 0.1))
|
|
|
|
|
(sleep-for (+ 0.5 flymake-no-changes-timeout)))
|
|
|
|
|
(funcall fn)))
|
2017-09-07 14:19:33 +01:00
|
|
|
|
(and buffer
|
|
|
|
|
(not visiting)
|
|
|
|
|
(let (kill-buffer-query-functions) (kill-buffer buffer))))))
|
|
|
|
|
|
|
|
|
|
(cl-defmacro flymake-tests--with-flymake ((file &rest args)
|
|
|
|
|
&body body)
|
|
|
|
|
(declare (indent 1)
|
|
|
|
|
(debug (sexp &rest form)))
|
|
|
|
|
`(flymake-tests--call-with-fixture (lambda () ,@body) ,file ,@args))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
2013-06-30 08:10:33 -07:00
|
|
|
|
(ert-deftest warning-predicate-rx-gcc ()
|
2013-06-21 10:36:13 -04:00
|
|
|
|
"Test GCC warning via regexp predicate."
|
2015-11-02 18:08:52 +01:00
|
|
|
|
(skip-unless (and (executable-find "gcc") (executable-find "make")))
|
2017-09-07 14:19:33 +01:00
|
|
|
|
(flymake-tests--with-flymake
|
|
|
|
|
("test.c" :severity-predicate "^[Ww]arning")
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning
|
|
|
|
|
(face-at-point)))))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
|
|
|
|
(ert-deftest warning-predicate-function-gcc ()
|
|
|
|
|
"Test GCC warning via function predicate."
|
2013-11-05 23:50:18 -08:00
|
|
|
|
(skip-unless (and (executable-find "gcc") (executable-find "make")))
|
2017-09-07 14:19:33 +01:00
|
|
|
|
(flymake-tests--with-flymake
|
|
|
|
|
("test.c" :severity-predicate
|
|
|
|
|
(lambda (msg) (string-match "^[Ww]arning" msg)))
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning
|
|
|
|
|
(face-at-point)))))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
|
|
|
|
(ert-deftest warning-predicate-rx-perl ()
|
|
|
|
|
"Test perl warning via regular expression predicate."
|
2013-11-05 23:50:18 -08:00
|
|
|
|
(skip-unless (executable-find "perl"))
|
2017-09-07 14:19:33 +01:00
|
|
|
|
(flymake-tests--with-flymake
|
|
|
|
|
("test.pl" :severity-predicate "^Scalar value")
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning
|
|
|
|
|
(face-at-point)))))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
|
|
|
|
(ert-deftest warning-predicate-function-perl ()
|
|
|
|
|
"Test perl warning via function predicate."
|
2013-11-05 23:50:18 -08:00
|
|
|
|
(skip-unless (executable-find "perl"))
|
2017-09-07 14:19:33 +01:00
|
|
|
|
(flymake-tests--with-flymake
|
|
|
|
|
("test.pl" :severity-predicate
|
|
|
|
|
(lambda (msg) (string-match "^Scalar value" msg)))
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning
|
|
|
|
|
(face-at-point)))))
|
2013-06-21 10:36:13 -04:00
|
|
|
|
|
2017-09-21 14:57:20 +01:00
|
|
|
|
(ert-deftest errors-and-warnings ()
|
|
|
|
|
"Test GCC warning via function predicate."
|
|
|
|
|
(skip-unless (and (executable-find "gcc") (executable-find "make")))
|
|
|
|
|
(flymake-tests--with-flymake
|
|
|
|
|
("errors-and-warnings.c")
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-error (face-at-point)))
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning (face-at-point)))
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-warning (face-at-point)))
|
|
|
|
|
(flymake-goto-next-error)
|
|
|
|
|
(should (eq 'flymake-error (face-at-point)))
|
|
|
|
|
(should-error (flymake-goto-next-error nil t)) ))
|
|
|
|
|
|
2013-06-21 10:36:13 -04:00
|
|
|
|
(provide 'flymake-tests)
|
|
|
|
|
|
|
|
|
|
;;; flymake.el ends here
|