summaryrefslogtreecommitdiff
path: root/test/lisp/progmodes
diff options
context:
space:
mode:
authorJoão Távora <joaotavora@gmail.com>2017-09-28 12:06:56 +0100
committerJoão Távora <joaotavora@gmail.com>2017-10-03 14:18:55 +0100
commit8118f0f95f993f64f30ab1d48d9e988ab6f58019 (patch)
tree18ec49524249a9673e129084a37e8f550b879f3a /test/lisp/progmodes
parent9a629a73e0eb10589f5befaf0a1a3290d9ba6a47 (diff)
downloademacs-8118f0f95f993f64f30ab1d48d9e988ab6f58019.tar.gz
Fix three Flymake bugs when checking C header files
The first of these problems is longstanding: if an error-less B.h is included from error-ridden A.h, flymake's legacy parser will panic (and disable itself) since it sees a non-zero exit for a clean file. To fix this, recommend returning 'true' in the documentation for the check-syntax target. Another problem was introduced by the parser rewrite. For error patterns spanning more than one line, point may be left in the middle of a line and thus render other patterns useless. Those patterns were written for the old line-by-line parser. To make them useful again, move to the beginning of line in those situations. The third problem was also longstanding and happened on newer GCC's: The "In file included from" prefix confused flymake-proc-get-real-file-name. Fix this. Also updated flymake--diag-region to fallback to highlighting a full line less often. Add automatic tests to check this. * lisp/progmodes/flymake-proc.el (flymake-proc--diagnostics-for-pattern): Fix bug when patterns accidentally spans more than one line. Don't create diagnostics without error messages. (flymake-proc-real-file-name-considering-includes): New helper. (flymake-proc-allowed-file-name-masks): Use it. * lisp/progmodes/flymake.el (flymake-diag-region): Make COL argument explicitly optional. Only fall back to full line in extreme cases. * test/lisp/progmodes/flymake-tests.el (included-c-header-files): New test. (different-diagnostic-types): Update. * test/lisp/progmodes/flymake-resources/Makefile (check-syntax): Always return success (0) error code. (CC_OPTS): Add -Wextra * test/lisp/progmodes/flymake-resources/errors-and-warnings.c (main): Rewrite comments. * test/lisp/progmodes/flymake-resources/errors-and-warnings.c: Include some dummy header files. * test/lisp/progmodes/flymake-resources/no-problems.h: New file. * test/lisp/progmodes/flymake-resources/some-problems.h: New file. * doc/misc/flymake.texi (Example---Configuring a tool called via make): Recommend adding "|| true" to the check-syntax target.
Diffstat (limited to 'test/lisp/progmodes')
-rw-r--r--test/lisp/progmodes/flymake-resources/Makefile4
-rw-r--r--test/lisp/progmodes/flymake-resources/errors-and-warnings.c15
-rw-r--r--test/lisp/progmodes/flymake-resources/no-problems.h1
-rw-r--r--test/lisp/progmodes/flymake-resources/some-problems.h5
-rw-r--r--test/lisp/progmodes/flymake-tests.el20
5 files changed, 37 insertions, 8 deletions
diff --git a/test/lisp/progmodes/flymake-resources/Makefile b/test/lisp/progmodes/flymake-resources/Makefile
index 0f3f39791c8..494407567f2 100644
--- a/test/lisp/progmodes/flymake-resources/Makefile
+++ b/test/lisp/progmodes/flymake-resources/Makefile
@@ -1,6 +1,6 @@
# Makefile for flymake tests
-CC_OPTS = -Wall
+CC_OPTS = -Wall -Wextra
## Recent gcc (e.g. 4.8.2 on RHEL7) can automatically colorize their output,
## which can confuse flymake. Set GCC_COLORS to disable that.
@@ -8,6 +8,6 @@ CC_OPTS = -Wall
## normally use flymake, so it seems like just avoiding the issue
## in this test is fine. Set flymake-log-level to 3 to investigate.
check-syntax:
- GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES}
+ GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES} || true
# eof
diff --git a/test/lisp/progmodes/flymake-resources/errors-and-warnings.c b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
index 6454dd20236..1d38bd6bd27 100644
--- a/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
+++ b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
@@ -1,10 +1,13 @@
- int main()
+/* Flymake should notice an error on the next line, since
+ that file has at least one warning.*/
+#include "some-problems.h"
+/* But not this one */
+#include "no-problems.h"
+
+int main()
{
- char c = 1000;
+ char c = 1000; /* a note and a warning */
int bla;
- /* The following line should have one warning and one error. The
- warning spans the full line because gcc (at least 6.3.0) points
- places the error at the =, which isn't a sexp.*/
- char c; if (bla == (void*)3);
+ char c; if (bla == (void*)3); /* an error, and two warnings */
return c;
}
diff --git a/test/lisp/progmodes/flymake-resources/no-problems.h b/test/lisp/progmodes/flymake-resources/no-problems.h
new file mode 100644
index 00000000000..19ddc615b32
--- /dev/null
+++ b/test/lisp/progmodes/flymake-resources/no-problems.h
@@ -0,0 +1 @@
+typedef int no_problems;
diff --git a/test/lisp/progmodes/flymake-resources/some-problems.h b/test/lisp/progmodes/flymake-resources/some-problems.h
new file mode 100644
index 00000000000..165d8dd525e
--- /dev/null
+++ b/test/lisp/progmodes/flymake-resources/some-problems.h
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+strange;
+
+sint main();
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index fa77a9a8ae6..222c8f11848 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -122,14 +122,34 @@ SEVERITY-PREDICATE is used to setup
(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-note (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)))
+ (flymake-goto-next-error)
+ (should (eq 'flymake-warning (face-at-point)))
+ (flymake-goto-next-error)
+ (should (eq 'flymake-warning (face-at-point)))
+ (let ((flymake-wrap-around nil))
+ (should-error (flymake-goto-next-error nil nil t))) ))
+
+(ert-deftest included-c-header-files ()
+ "Test inclusion of .h header files."
+ (skip-unless (and (executable-find "gcc") (executable-find "make")))
+ (flymake-tests--with-flymake
+ ("some-problems.h")
+ (flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point)))
(flymake-goto-next-error)
(should (eq 'flymake-error (face-at-point)))
(let ((flymake-wrap-around nil))
+ (should-error (flymake-goto-next-error nil nil t))) )
+ (flymake-tests--with-flymake
+ ("no-problems.h")
+ (let ((flymake-wrap-around nil))
(should-error (flymake-goto-next-error nil nil t))) ))
(defmacro flymake-tests--assert-set (set