From c5b0993e5f54a664d7edbdf9caffb43555618c51 Mon Sep 17 00:00:00 2001 From: Eduard Wiebe Date: Fri, 21 Jun 2013 10:36:13 -0400 Subject: [PATCH] Extend flymake's warning predicate to be a function. Test suite for flymake. * lisp/progmodes/flymake.el (flymake-warning-predicate): New. (flymake-parse-line): Use it. (flymake-warning-re): Make obsolete alias to `flymake-warning-predicate'. * doc/misc/flymake.texi (Parsing the output, Customizable variables): Add reference to `flymake-warning-predicate'. * test/automated/flymake-tests.el: * test/automated/flymake/warnpred/Makefile * test/automated/flymake/warnpred/test.c * test/automated/flymake/warnpred/test.pl: New files. Fixes: debbugs:14217 --- doc/misc/ChangeLog | 115 ++++++++++++----------- doc/misc/flymake.texi | 3 + lisp/ChangeLog | 8 ++ lisp/progmodes/flymake.el | 30 ++++-- test/ChangeLog | 8 ++ test/automated/flymake-tests.el | 82 ++++++++++++++++ test/automated/flymake/warnpred/Makefile | 8 ++ test/automated/flymake/warnpred/test.c | 5 + test/automated/flymake/warnpred/test.pl | 2 + 9 files changed, 196 insertions(+), 65 deletions(-) create mode 100644 test/automated/flymake-tests.el create mode 100644 test/automated/flymake/warnpred/Makefile create mode 100644 test/automated/flymake/warnpred/test.c create mode 100644 test/automated/flymake/warnpred/test.pl diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 2368c351ab1..e167c73f7f1 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -1,3 +1,8 @@ +2013-06-21 Eduard Wiebe + + * flymake.texi (Parsing the output, Customizable variables): + Add reference to `flymake-warning-predicate'. + 2013-06-19 Michael Albinus * tramp.texi (Top, Configuration): Insert section `Predefined @@ -101,8 +106,8 @@ 2013-03-08 Jay Belanger - * calc.texi (Basic Operations on Units): Fix - cross-reference. + * calc.texi (Basic Operations on Units): + Fix cross-reference. 2013-03-07 Katsumi Yamaoka @@ -140,8 +145,8 @@ * tramp.texi (Inline methods): Remove "ssh1", "ssh2", "plink1" and "plink2" entries. "plink2" is obsolete for a long time. - (External methods): Remove "scp1" and "scp2" entries. Explain - user name and host name specification for "adb". + (External methods): Remove "scp1" and "scp2" entries. + Explain user name and host name specification for "adb". 2013-02-28 Michael Albinus @@ -221,8 +226,8 @@ from ede new. (Simple projects): Re-write to not talk about ede-simple-project which is deprecated, and instead use the term to mean projects - that don't do much management, just project wrapping. Add - ede-generic-project link. + that don't do much management, just project wrapping. + Add ede-generic-project link. (ede-generic-project): New node (bug#11441). 2013-02-07 Glenn Morris @@ -361,8 +366,8 @@ 2012-12-24 Lars Ingebrigtsen - * gnus.texi (Browse Foreign Server): Document - `gnus-browse-delete-group'. + * gnus.texi (Browse Foreign Server): + Document `gnus-browse-delete-group'. 2012-12-22 Glenn Morris @@ -599,8 +604,8 @@ Improve docs for url-queue-*. (Supported URL Types): Copyedits. Delete empty subnodes. - * url.texi (Introduction): Rename from Getting Started. Rewrite - the introduction. + * url.texi (Introduction): Rename from Getting Started. + Rewrite the introduction. (URI Parsing): Rewrite. Omit the obsolete attributes slot. 2012-11-10 Glenn Morris @@ -700,14 +705,14 @@ 2012-10-26 Bastien Guerry - * org.texi (Installation): Update the link to Org's ELPA. Also - don't mention org-install.el anymore as the replacement file + * org.texi (Installation): Update the link to Org's ELPA. + Also don't mention org-install.el anymore as the replacement file org-loaddefs.el is now loaded by org.el. 2012-10-25 Michael Albinus - * tramp.texi (Frequently Asked Questions): Mention - `tramp-completion-reread-directory-timeout' for performance + * tramp.texi (Frequently Asked Questions): + Mention `tramp-completion-reread-directory-timeout' for performance improvement. 2012-10-25 Glenn Morris @@ -830,8 +835,8 @@ (Referencing Labels): Update regarding reference styles. (Citation Styles): Mention support for ConTeXt. (Options (Defining Label Environments)): Fix typo. - (Options (Creating Citations)): Document - `reftex-cite-key-separator'. + (Options (Creating Citations)): + Document `reftex-cite-key-separator'. 2012-09-30 Achim Gratz @@ -863,8 +868,8 @@ 2012-09-30 Bastien Guerry - * org.texi (Installation, Feedback, Batch execution): Use - (add-to-list 'load-path ... t) for the contrib dir. + * org.texi (Installation, Feedback, Batch execution): + Use (add-to-list 'load-path ... t) for the contrib dir. * org.texi (results): Update documentation for ":results drawer" and ":results org". @@ -891,8 +896,8 @@ (Agenda commands): Reorder. Document `*' to toggle persistent marks. - * org.texi (Agenda dispatcher): Mention - `org-toggle-agenda-sticky'. + * org.texi (Agenda dispatcher): + Mention `org-toggle-agenda-sticky'. (Agenda commands, Exporting Agenda Views): Fix typo. * org.texi (Templates in contexts, Setting Options): Update to @@ -1067,8 +1072,8 @@ (Unsafe Simplifications): Mention `m E'. (Simplification of Units): Mention `m U'. (Trigonometric/Hyperbolic Functions, Reducing and Mapping) - (Kinds of Declarations, Functions for Declarations): Mention - "algebraic simplifications" instead of `a s'. + (Kinds of Declarations, Functions for Declarations): + Mention "algebraic simplifications" instead of `a s'. (Algebraic Entry): Remove mention of default simplifications. 2012-07-30 Jay Belanger @@ -1100,8 +1105,8 @@ 2012-07-06 Michael Albinus - * tramp.texi (Multi-hops): Introduce - `tramp-restricted-shell-hosts-alist'. + * tramp.texi (Multi-hops): + Introduce `tramp-restricted-shell-hosts-alist'. 2012-06-26 Lars Magne Ingebrigtsen @@ -1293,8 +1298,8 @@ (Synchronous Methods): Remove obsolete dbus-call-method-non-blocking. (Asynchronous Methods): Fix description of dbus-call-method-asynchronously. - (Receiving Method Calls): Fix some minor errors. Add - dbus-interface-emacs. + (Receiving Method Calls): Fix some minor errors. + Add dbus-interface-emacs. (Signals): Describe unicast signals and the new match rules. (Alternative Buses): Add the PRIVATE optional argument to dbus-init-bus. Describe its new return value. Add dbus-setenv. @@ -1327,8 +1332,8 @@ 2012-04-09 Eli Zaretskii - * makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): Add - emacs-gnutls. + * makefile.w32-in (INFO_TARGETS, DVI_TARGETS, clean): + Add emacs-gnutls. ($(infodir)/emacs-gnutls, emacs-gnutls.dvi): New targets. 2012-04-09 Teodor Zlatanov @@ -1431,7 +1436,7 @@ 2012-04-01 Eric Schulte - * org.texi (Key bindings and useful functions): Updated babel key + * org.texi (Key bindings and useful functions): Update babel key binding documentation in manual. 2012-04-01 Eric Schulte @@ -1532,8 +1537,8 @@ 2012-02-13 Lars Ingebrigtsen - * gnus.texi (Customizing the IMAP Connection): Mention - nnimap-record-commands. + * gnus.texi (Customizing the IMAP Connection): + Mention nnimap-record-commands. 2012-02-10 Glenn Morris @@ -1604,8 +1609,8 @@ 2012-01-03 Bernt Hansen - * org.texi (Agenda commands): Document - `org-clock-report-include-clocking-task'. + * org.texi (Agenda commands): + Document `org-clock-report-include-clocking-task'. 2012-01-03 Bastien Guerry @@ -1690,8 +1695,8 @@ 2012-01-03 Eric Schulte - * org.texi (Buffer-wide header arguments): Update - documentation to reflect removal of #+PROPERTIES. + * org.texi (Buffer-wide header arguments): + Update documentation to reflect removal of #+PROPERTIES. 2012-01-03 Carsten Dominik @@ -1852,7 +1857,7 @@ * mh-e.texi (VERSION, EDITION, UPDATED, UPDATE-MONTH): Update for release 8.3. - (Preface): Updated support information. + (Preface): Update support information. (From Bill Wohler): Reset text to original version. As a historical quote, the tense should be correct in the time that it was written. @@ -2054,8 +2059,8 @@ 2011-08-15 Bastien Guerry - * org.texi (Dynamic blocks, Structure editing): Mention - the function `org-narrow-to-block'. + * org.texi (Dynamic blocks, Structure editing): + Mention the function `org-narrow-to-block'. 2011-08-15 Eric Schulte @@ -2082,15 +2087,15 @@ 2011-08-15 Eric Schulte - * org.texi (Conflicts): Changed "yasnippets" to "yasnippet" and + * org.texi (Conflicts): Change "yasnippets" to "yasnippet" and added extra whitespace around functions to be consistent with the rest of the section. 2011-08-15 Eric Schulte - * org.texi (Evaluating code blocks): Expanded discussion of + * org.texi (Evaluating code blocks): Expand discussion of #+call: line syntax. - (Header arguments in function calls): Expanded discussion of + (Header arguments in function calls): Expand discussion of #+call: line syntax. 2011-08-15 Eric Schulte @@ -2120,12 +2125,12 @@ 2011-08-15 Tom Dye - * org.texi (cache): Improved documentation of code block caches. + * org.texi (cache): Improve documentation of code block caches. 2011-08-15 Tom Dye - * org.texi (Code block specific header arguments): Documentation - of multi-line header arguments. + * org.texi (Code block specific header arguments): + Documentation of multi-line header arguments. 2011-08-15 Eric Schulte @@ -2181,15 +2186,15 @@ 2011-07-04 Michael Albinus - * tramp.texi (Cleanup remote connections): Add - `tramp-cleanup-this-connection'. + * tramp.texi (Cleanup remote connections): + Add `tramp-cleanup-this-connection'. 2011-07-03 Lars Magne Ingebrigtsen * gnus.texi (Subscription Methods): Link to "Group Levels" to explain zombies. (Checking New Groups): Ditto (bug#8974). - (Checking New Groups): Moved the reference to the right place. + (Checking New Groups): Move the reference to the right place. 2011-07-03 Dave Abrahams (tiny change) @@ -2216,8 +2221,8 @@ 2011-06-26 Lars Magne Ingebrigtsen - * gnus.texi (Summary Mail Commands): Document - `gnus-summary-reply-to-list-with-original'. + * gnus.texi (Summary Mail Commands): + Document `gnus-summary-reply-to-list-with-original'. 2011-06-20 Stefan Monnier @@ -2280,7 +2285,7 @@ * gnus.texi (nnmairix caveats, Setup, Registry Article Refer Method) (Fancy splitting to parent, Store arbitrary data): - Updated gnus-registry docs. + Update gnus-registry docs. 2011-04-13 Juanma Barranquero @@ -3401,8 +3406,8 @@ Sync with Tramp 2.1.19. - * tramp.texi (Inline methods, Default Method): Mention - `tramp-inline-compress-start-size'. Remove "kludgy" phrase. + * tramp.texi (Inline methods, Default Method): + Mention `tramp-inline-compress-start-size'. Remove "kludgy" phrase. Remove remark about doubled "-t" argument. (Auto-save and Backup): Remove reference to Emacs 21. (Filename Syntax): Describe port numbers. @@ -6056,7 +6061,7 @@ 2007-10-28 Kevin Greiner * gnus.texi (nntp-open-via-telnet-and-telnet): Fix grammar. - (Agent Parameters): Updated parameter names to match code. + (Agent Parameters): Update parameter names to match code. (Group Agent Commands): Corrected 'gnus-agent-fetch-series' as 'gnus-agent-summary-fetch-series'. (Agent and flags): New section providing a generalized discussion @@ -6860,7 +6865,7 @@ (Tag searches): Document regular expression search for tags. (Stuck projects): New section. (In-buffer settings): New keywords. - (History and Acknowledgments): Updated description. + (History and Acknowledgments): Update description. 2007-02-24 Alan Mackenzie @@ -7092,7 +7097,7 @@ (Custom agenda views): Section completely rewritten. (Summary): Compare with Planner. (Feedback): More info about creating backtraces. - (Plain lists): Modified example. + (Plain lists): Modify example. (Breaking down tasks): New section. (Custom time format): New section. (Time stamps): Document inactive timestamps. diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index f88bd95008c..d1f3e21c20e 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -311,6 +311,9 @@ Used when looking for a master file. @xref{Locating a master file}. Patterns for error/warning messages in the form @code{(regexp file-idx line-idx col-idx err-text-idx)}. @xref{Parsing the output}. +@item flymake-warning-predicate +Predicate to classify error text as warning. @xref{Parsing the output}. + @item flymake-compilation-prevents-syntax-check A flag indicating whether compilation and syntax check of the same file cannot be run simultaneously. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 414650b0656..ebed2e2de1c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-06-21 Eduard Wiebe + + Extend flymake's warning predicate to be a function (bug#14217). + * progmodes/flymake.el (flymake-warning-predicate): New. + (flymake-parse-line): Use it. + (flymake-warning-re): Make obsolete alias to + `flymake-warning-predicate'. + 2013-06-21 Stefan Monnier * emacs-lisp/package.el (package-alist): Include obsolete packages. diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 99b48e8d0db..2ead734d163 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1049,8 +1049,12 @@ from compile.el") ;; :type '(repeat (string number number number)) ;;) -(defvar flymake-warning-re "^[wW]arning" - "Regexp matching against err-text to detect a warning.") +(define-obsolete-variable-alias 'flymake-warning-re 'flymake-warning-predicate "24.4") +(defvar flymake-warning-predicate "^[wW]arning" + "Predicate matching against error text to detect a warning. +Takes a single argument, the error's text and should return non-nil +if it's a warning. +Instead of a function, it can also be a regular expression.") (defun flymake-parse-line (line) "Parse LINE to see if it is an error or warning. @@ -1067,16 +1071,22 @@ Return its components if so, nil otherwise." (line-idx (nth 2 (car patterns)))) (setq raw-file-name (if file-idx (match-string file-idx line) nil)) - (setq line-no (if line-idx (string-to-number (match-string line-idx line)) 0)) + (setq line-no (if line-idx (string-to-number + (match-string line-idx line)) 0)) (setq err-text (if (> (length (car patterns)) 4) (match-string (nth 4 (car patterns)) line) - (flymake-patch-err-text (substring line (match-end 0))))) - (or err-text (setq err-text "")) - (if (and err-text (string-match flymake-warning-re err-text)) - (setq err-type "w") - ) - (flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx - raw-file-name line-no err-text) + (flymake-patch-err-text + (substring line (match-end 0))))) + (if (null err-text) + (setq err-text "") + (when (cond ((stringp flymake-warning-predicate) + (string-match flymake-warning-predicate err-text)) + ((functionp flymake-warning-predicate) + (funcall flymake-warning-predicate err-text))) + (setq err-type "w"))) + (flymake-log + 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" + file-idx line-idx raw-file-name line-no err-text) (setq matched t))) (setq patterns (cdr patterns))) (if matched diff --git a/test/ChangeLog b/test/ChangeLog index 90ea593a012..73ce74a02ae 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,11 @@ +2013-06-21 Eduard Wiebe + + Test suite for flymake. + * automated/flymake-tests.el: + * automated/flymake/warnpred/Makefile + * automated/flymake/warnpred/test.c + * automated/flymake/warnpred/test.pl: New files. + 2013-06-12 Rüdiger Sonderfeld * automated/reftex-tests.el (reftex-parse-from-file-test): Fix test. diff --git a/test/automated/flymake-tests.el b/test/automated/flymake-tests.el new file mode 100644 index 00000000000..6b68a956db8 --- /dev/null +++ b/test/automated/flymake-tests.el @@ -0,0 +1,82 @@ +;;; flymake-tests.el --- Test suite for flymake + +;; Copyright (C) 2011-2013 Free Software Foundation, Inc. + +;; Author: Eduard Wiebe + +;; 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 +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: +(require 'ert) +(require 'flymake) + +(defgroup flymake-tests nil + "Test suite for flymake.") + + +;; Warning predicate +(defun flymake-tests--current-face (file predicate) + (let ((buffer (find-file-noselect file))) + (unwind-protect + (with-current-buffer (find-file-noselect file) + (setq-local flymake-warning-predicate predicate) + (goto-char (point-min)) + (flymake-mode 1) + ;; XXX: is this reliable enough? + (sleep-for (+ 0.5 flymake-no-changes-timeout)) + (flymake-goto-next-error) + (face-at-point)) + (and buffer (kill-buffer buffer))))) + +(ert-deftest warnining-predicate-rx-gcc () + "Test GCC warning via regexp predicate." + :expected-result (if (executable-find "gcc") :passed :failed) + (should (eq 'flymake-warnline + (flymake-tests--current-face + "flymake/warnpred/test.c" + "^[Ww]arning")))) + +(ert-deftest warning-predicate-function-gcc () + "Test GCC warning via function predicate." + :expected-result (if (and (executable-find "gcc") (executable-find "make")) + :passed + :failed) + (should (eq 'flymake-warnline + (flymake-tests--current-face + "flymake/warnpred/test.c" + (lambda (msg) (string-match "^[Ww]arning" msg)))))) + +(ert-deftest warning-predicate-rx-perl () + "Test perl warning via regular expression predicate." + :expected-result (if (executable-find "perl") :passed :failed) + (should (eq 'flymake-warnline + (flymake-tests--current-face + "flymake/warnpred/test.pl" + "^Scalar value")))) + +(ert-deftest warning-predicate-function-perl () + "Test perl warning via function predicate." + :expected-result (if (executable-find "perl") :passed :failed) + (should (eq 'flymake-warnline + (flymake-tests--current-face + "flymake/warnpred/test.pl" + (lambda (msg) (string-match "^Scalar value" msg)))))) + +(provide 'flymake-tests) + +;;; flymake.el ends here diff --git a/test/automated/flymake/warnpred/Makefile b/test/automated/flymake/warnpred/Makefile new file mode 100644 index 00000000000..33af51c3337 --- /dev/null +++ b/test/automated/flymake/warnpred/Makefile @@ -0,0 +1,8 @@ +# Makefile for flymake tests + +CC_OPTS = -Wall + +check-syntax: + $(CC) $(CC_OPTS) ${CHK_SOURCES} + +# eof diff --git a/test/automated/flymake/warnpred/test.c b/test/automated/flymake/warnpred/test.c new file mode 100644 index 00000000000..3a3926131f5 --- /dev/null +++ b/test/automated/flymake/warnpred/test.c @@ -0,0 +1,5 @@ +int main() +{ + char c = 1000; + return c; +} diff --git a/test/automated/flymake/warnpred/test.pl b/test/automated/flymake/warnpred/test.pl new file mode 100644 index 00000000000..2013b2e4434 --- /dev/null +++ b/test/automated/flymake/warnpred/test.pl @@ -0,0 +1,2 @@ +@arr = [1,2,3,4]; +@arr[1] = -1; -- 2.39.2