Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / test / automated / flymake-tests.el
blobc9761050f738b1490a48caa6bf542f906da03615
1 ;;; flymake-tests.el --- Test suite for flymake
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Eduard Wiebe <usenet@pusto.de>
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
22 ;;; Commentary:
24 ;;; Code:
25 (require 'ert)
26 (require 'flymake)
28 (defvar flymake-tests-data-directory
29 (expand-file-name "flymake/warnpred" (getenv "EMACS_TEST_DIRECTORY"))
30 "Directory containing flymake test data.")
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 (unwind-protect
38 (with-current-buffer buffer
39 (setq-local flymake-warning-predicate predicate)
40 (goto-char (point-min))
41 (flymake-mode 1)
42 ;; XXX: is this reliable enough?
43 (sleep-for (+ 0.5 flymake-no-changes-timeout))
44 (flymake-goto-next-error)
45 (face-at-point))
46 (and buffer (kill-buffer buffer)))))
48 (ert-deftest warning-predicate-rx-gcc ()
49 "Test GCC warning via regexp predicate."
50 (skip-unless (executable-find "gcc"))
51 (should (eq 'flymake-warnline
52 (flymake-tests--current-face "test.c" "^[Ww]arning"))))
54 (ert-deftest warning-predicate-function-gcc ()
55 "Test GCC warning via function predicate."
56 (skip-unless (and (executable-find "gcc") (executable-find "make")))
57 (should (eq 'flymake-warnline
58 (flymake-tests--current-face "test.c"
59 (lambda (msg) (string-match "^[Ww]arning" msg))))))
61 (ert-deftest warning-predicate-rx-perl ()
62 "Test perl warning via regular expression predicate."
63 (skip-unless (executable-find "perl"))
64 (should (eq 'flymake-warnline
65 (flymake-tests--current-face "test.pl" "^Scalar value"))))
67 (ert-deftest warning-predicate-function-perl ()
68 "Test perl warning via function predicate."
69 (skip-unless (executable-find "perl"))
70 (should (eq 'flymake-warnline
71 (flymake-tests--current-face
72 "test.pl"
73 (lambda (msg) (string-match "^Scalar value" msg))))))
75 (provide 'flymake-tests)
77 ;;; flymake.el ends here