Skip to content

Commit

Permalink
Merge pull request #1433 from flycheck/test-error-groups
Browse files Browse the repository at this point in the history
Update integration tests for Rust and error groups
  • Loading branch information
cpitclaudel committed Mar 26, 2018
2 parents 95bcf0a + c5df6f7 commit 0a588ed
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 82 deletions.
36 changes: 30 additions & 6 deletions flycheck-ert.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; flycheck-ert.el --- Flycheck: ERT extensions -*- lexical-binding: t; -*-

;; Copyright (C) 2017 Flycheck contributors
;; Copyright (C) 2017-2018 Flycheck contributors
;; Copyright (C) 2013-2016 Sebastian Wiesner and Flycheck contributors

;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
Expand Down Expand Up @@ -332,14 +332,27 @@ Raise an assertion error if the buffer is not clear afterwards."

;;; Test assertions

(defun flycheck-error-without-group (err)
"Return a copy ERR with the `group' property set to nil."
(let ((copy (copy-flycheck-error err)))
(setf (flycheck-error-group copy) nil)
copy))

(defun flycheck-ert-should-overlay (error)
"Test that ERROR has a proper overlay in the current buffer.
ERROR is a Flycheck error object."
(let* ((overlay (-first (lambda (ov) (equal (overlay-get ov 'flycheck-error)
error))
(let* ((overlay (-first (lambda (ov)
(equal (flycheck-error-without-group
(overlay-get ov 'flycheck-error))
(flycheck-error-without-group error)))
(flycheck-overlays-in 0 (+ 1 (buffer-size)))))
(region (flycheck-error-region-for-mode error 'symbols))
(region
;; Overlays of errors from other files are on the first line
(if (flycheck-relevant-error-other-file-p error)
(cons (point-min)
(save-excursion (goto-char (point-min)) (point-at-eol)))
(flycheck-error-region-for-mode error 'symbols)))
(level (flycheck-error-level error))
(category (flycheck-error-level-overlay-category level))
(face (get category 'face))
Expand All @@ -355,7 +368,9 @@ ERROR is a Flycheck error object."
(overlay-get overlay 'before-string))
fringe-icon))
(should (eq (overlay-get overlay 'category) category))
(should (equal (overlay-get overlay 'flycheck-error) error))))
(should (equal (flycheck-error-without-group (overlay-get overlay
'flycheck-error))
(flycheck-error-without-group error)))))

(defun flycheck-ert-should-errors (&rest errors)
"Test that the current buffers has ERRORS.
Expand All @@ -373,7 +388,16 @@ buffer is equal to the number of given ERRORS. In other words,
check that the buffer has all ERRORS, and no other errors."
(let ((expected (mapcar (apply-partially #'apply #'flycheck-error-new-at)
errors)))
(should (equal expected flycheck-current-errors))
(should (equal (mapcar #'flycheck-error-without-group expected)
(mapcar #'flycheck-error-without-group
flycheck-current-errors)))
;; Check that related errors are the same
(cl-mapcar (lambda (err1 err2)
(should (equal (mapcar #'flycheck-error-without-group
(flycheck-related-errors err1 expected))
(mapcar #'flycheck-error-without-group
(flycheck-related-errors err2)))))
expected flycheck-current-errors)
(mapc #'flycheck-ert-should-overlay expected))
(should (= (length errors)
(length (flycheck-overlays-in (point-min) (point-max))))))
Expand Down
37 changes: 24 additions & 13 deletions flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -3233,17 +3233,21 @@ Return a list of all errors that are relevant for their
corresponding buffer."
(seq-filter #'flycheck-relevant-error-p errors))

(defun flycheck-related-errors (err)
(defun flycheck-related-errors (err &optional error-set)
"Get all the errors that are in the same group as ERR.

Return a list of all errors (in `flycheck-current-errors') that
have the same `flycheck-error-group' as ERR, including ERR
itself."
(-if-let (group (flycheck-error-group err))
(seq-filter (lambda (e)
(eq (flycheck-error-group e) group))
flycheck-current-errors)
(list err)))
Return a list of all errors (from ERROR-SET) that have the same
`flycheck-error-group' as ERR, including ERR itself.

If ERROR-SET is nil, `flycheck-current-errors' is used instead."
(let ((group (flycheck-error-group err))
(checker (flycheck-error-checker err)))
(if group
(seq-filter (lambda (e)
(and (eq (flycheck-error-checker e) checker)
(eq (flycheck-error-group e) group)))
(or error-set flycheck-current-errors))
(list err))))


;;; Status reporting for the current buffer
Expand Down Expand Up @@ -9512,10 +9516,17 @@ Relative paths are relative to the file being checked."
(defun flycheck-rust-error-filter (errors)
"Filter ERRORS from rustc output that have no explanatory value."
(seq-remove (lambda (err)
(string-match-p
(rx "aborting due to " (optional (one-or-more num) " ")
"previous error")
(flycheck-error-message err)))
(or
;; Macro errors emit a diagnostic in a phony file,
;; e.g. "<println macros>".
(string-match-p
(rx "macros>" line-end)
(flycheck-error-filename err))
;; Redundant message giving the number of failed errors
(string-match-p
(rx "aborting due to " (optional (one-or-more num) " ")
"previous error")
(flycheck-error-message err))))
errors))

(defun flycheck-rust-manifest-directory ()
Expand Down
Loading

0 comments on commit 0a588ed

Please sign in to comment.