Commit | Line | Data |
---|---|---|
c5b0993e EW |
1 | ;;; flymake-tests.el --- Test suite for flymake |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2011-2014 Free Software Foundation, Inc. |
c5b0993e EW |
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 | ||
d5112380 GM |
28 | (defvar flymake-tests-data-directory |
29 | (expand-file-name "flymake/warnpred" (getenv "EMACS_TEST_DIRECTORY")) | |
30 | "Directory containing flymake test data.") | |
31 | ||
c5b0993e EW |
32 | \f |
33 | ;; Warning predicate | |
34 | (defun flymake-tests--current-face (file predicate) | |
d5112380 | 35 | (let ((buffer (find-file-noselect |
f7586999 GM |
36 | (expand-file-name file flymake-tests-data-directory))) |
37 | (i 0)) | |
c5b0993e | 38 | (unwind-protect |
d5112380 | 39 | (with-current-buffer buffer |
c5b0993e EW |
40 | (setq-local flymake-warning-predicate predicate) |
41 | (goto-char (point-min)) | |
42 | (flymake-mode 1) | |
f7586999 GM |
43 | ;; Weirdness here... http://debbugs.gnu.org/17647#25 |
44 | (while (and flymake-is-running (< (setq i (1+ i)) 10)) | |
45 | (sleep-for (+ 0.5 flymake-no-changes-timeout))) | |
c5b0993e EW |
46 | (flymake-goto-next-error) |
47 | (face-at-point)) | |
7e58d673 | 48 | (and buffer (let (kill-buffer-query-functions) (kill-buffer buffer)))))) |
c5b0993e | 49 | |
adc5dbce | 50 | (ert-deftest warning-predicate-rx-gcc () |
c5b0993e | 51 | "Test GCC warning via regexp predicate." |
c76489d6 | 52 | (skip-unless (executable-find "gcc")) |
c5b0993e | 53 | (should (eq 'flymake-warnline |
d5112380 | 54 | (flymake-tests--current-face "test.c" "^[Ww]arning")))) |
c5b0993e EW |
55 | |
56 | (ert-deftest warning-predicate-function-gcc () | |
57 | "Test GCC warning via function predicate." | |
c76489d6 | 58 | (skip-unless (and (executable-find "gcc") (executable-find "make"))) |
c5b0993e | 59 | (should (eq 'flymake-warnline |
d5112380 | 60 | (flymake-tests--current-face "test.c" |
c5b0993e EW |
61 | (lambda (msg) (string-match "^[Ww]arning" msg)))))) |
62 | ||
63 | (ert-deftest warning-predicate-rx-perl () | |
64 | "Test perl warning via regular expression predicate." | |
c76489d6 | 65 | (skip-unless (executable-find "perl")) |
c5b0993e | 66 | (should (eq 'flymake-warnline |
d5112380 | 67 | (flymake-tests--current-face "test.pl" "^Scalar value")))) |
c5b0993e EW |
68 | |
69 | (ert-deftest warning-predicate-function-perl () | |
70 | "Test perl warning via function predicate." | |
c76489d6 | 71 | (skip-unless (executable-find "perl")) |
c5b0993e EW |
72 | (should (eq 'flymake-warnline |
73 | (flymake-tests--current-face | |
d5112380 | 74 | "test.pl" |
c5b0993e EW |
75 | (lambda (msg) (string-match "^Scalar value" msg)))))) |
76 | ||
77 | (provide 'flymake-tests) | |
78 | ||
79 | ;;; flymake.el ends here |