]> code.delx.au - gnu-emacs/blob - test/automated/flymake-tests.el
Update copyright year to 2016
[gnu-emacs] / test / automated / flymake-tests.el
1 ;;; flymake-tests.el --- Test suite for flymake
2
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5 ;; Author: Eduard Wiebe <usenet@pusto.de>
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;;; Code:
25 (require 'ert)
26 (require 'flymake)
27
28 (defvar flymake-tests-data-directory
29 (expand-file-name "data/flymake" (getenv "EMACS_TEST_DIRECTORY"))
30 "Directory containing flymake test data.")
31
32 \f
33 ;; Warning predicate
34 (defun flymake-tests--current-face (file predicate)
35 (let ((buffer (find-file-noselect
36 (expand-file-name file flymake-tests-data-directory)))
37 (process-environment (cons "LC_ALL=C" process-environment))
38 (i 0))
39 (unwind-protect
40 (with-current-buffer buffer
41 (setq-local flymake-warning-predicate predicate)
42 (goto-char (point-min))
43 (flymake-mode 1)
44 ;; Weirdness here... http://debbugs.gnu.org/17647#25
45 (while (and flymake-is-running (< (setq i (1+ i)) 10))
46 (sleep-for (+ 0.5 flymake-no-changes-timeout)))
47 (flymake-goto-next-error)
48 (face-at-point))
49 (and buffer (let (kill-buffer-query-functions) (kill-buffer buffer))))))
50
51 (ert-deftest warning-predicate-rx-gcc ()
52 "Test GCC warning via regexp predicate."
53 (skip-unless (and (executable-find "gcc") (executable-find "make")))
54 (should (eq 'flymake-warnline
55 (flymake-tests--current-face "test.c" "^[Ww]arning"))))
56
57 (ert-deftest warning-predicate-function-gcc ()
58 "Test GCC warning via function predicate."
59 (skip-unless (and (executable-find "gcc") (executable-find "make")))
60 (should (eq 'flymake-warnline
61 (flymake-tests--current-face "test.c"
62 (lambda (msg) (string-match "^[Ww]arning" msg))))))
63
64 (ert-deftest warning-predicate-rx-perl ()
65 "Test perl warning via regular expression predicate."
66 (skip-unless (executable-find "perl"))
67 (should (eq 'flymake-warnline
68 (flymake-tests--current-face "test.pl" "^Scalar value"))))
69
70 (ert-deftest warning-predicate-function-perl ()
71 "Test perl warning via function predicate."
72 (skip-unless (executable-find "perl"))
73 (should (eq 'flymake-warnline
74 (flymake-tests--current-face
75 "test.pl"
76 (lambda (msg) (string-match "^Scalar value" msg))))))
77
78 (provide 'flymake-tests)
79
80 ;;; flymake.el ends here