Skip to content

Commit

Permalink
Write specs for error list
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Jan 10, 2016
1 parent f7a3b15 commit 114aa04
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 178 deletions.
178 changes: 0 additions & 178 deletions test/flycheck-test.el
Expand Up @@ -2814,184 +2814,6 @@ evaluating BODY."
(flycheck-first-error 2)
(should (flycheck-ert-at-nth-error 2))))


;;; Listing errors in buffers
(ert-deftest flycheck-error-list-buffer/name ()
:tags '(error-list)
(should (string= flycheck-error-list-buffer "*Flycheck errors*")))

(ert-deftest flycheck-error-list-mode/derived-from-tabulated-list-mode ()
:tags '(error-list)
(with-temp-buffer
(flycheck-error-list-mode)
(derived-mode-p 'tabulated-list)))

(ert-deftest flycheck-error-list-mode/tabulated-list-format ()
:tags '(error-list)
(with-temp-buffer
(flycheck-error-list-mode)
(should (equal tabulated-list-format
[("Line" 4 flycheck-error-list-entry-< :right-align t)
("Col" 3 nil :right-align t)
("Level" 8 flycheck-error-list-entry-level-<)
("ID" 6 t)
("Message" 0 t)
(" (Checker)" 8 t)]))
(should (local-variable-p 'tabulated-list-format))))

(ert-deftest flycheck-error-list-mode/tabulated-list-padding ()
:tags '(error-list)
(with-temp-buffer
(flycheck-error-list-mode)
(should (equal tabulated-list-padding 1))
(should (local-variable-p 'tabulated-list-padding))))

(ert-deftest flycheck-error-list-mode/tabulated-list-entries ()
:tags '(error-list)
(with-temp-buffer
(flycheck-error-list-mode)
(should (eq tabulated-list-entries 'flycheck-error-list-entries))
(should (local-variable-p 'tabulated-list-entries))))

(ert-deftest flycheck-error-list-mode/initializes-header ()
:tags '(error-list)
(with-temp-buffer
(should-not header-line-format)
(flycheck-error-list-mode)
(should (string= header-line-format " Line Col Level ID Message (Checker) "))))

(ert-deftest flycheck-error-list-source-buffer/is-permanently-local ()
:tags '(error-list)
(should (get 'flycheck-error-list-source-buffer 'permanent-local)))

(ert-deftest flycheck-error-list-make-entry/line-and-column ()
:tags '(error-list)
(let* ((error (flycheck-error-new-at 10 12 'warning "A foo warning"
:checker 'emacs-lisp-checkdoc
:id "W1"))
(entry (flycheck-error-list-make-entry error))
(cells (cadr entry)))
(should (eq (car entry) error))
(should (equal (aref cells 0)
(list "10"
'type 'flycheck-error-list
'face 'flycheck-error-list-line-number)))
(should (equal (aref cells 1)
(list "12"
'type 'flycheck-error-list
'face 'flycheck-error-list-column-number)))
(let ((face (flycheck-error-level-error-list-face 'warning)))
(should (equal (aref cells 2)
(list "warning"
'type 'flycheck-error-list
'face face))))
(should (equal (aref cells 3)
(list "W1"
'type 'flycheck-error-list
'face 'flycheck-error-list-id)))
(should (equal (aref cells 4)
(list "A foo warning"
'type 'flycheck-error-list
'face 'default)))
(should (equal (aref cells 5)
(list "(emacs-lisp-checkdoc)"
'type 'flycheck-error-list
'face 'flycheck-error-list-checker-name)))))

(ert-deftest flycheck-error-list-make-entry/no-column ()
:tags '(error-list)
(let* ((error (flycheck-error-new-at 10 nil 'error "A foo error"
:checker 'emacs-lisp-checkdoc))
(entry (flycheck-error-list-make-entry error))
(cells (cadr entry)))
(should (eq (car entry) error))
(should (equal (aref cells 0)
(list "10"
'type 'flycheck-error-list
'face 'flycheck-error-list-line-number)))
(should (equal (aref cells 1)
(list ""
'type 'flycheck-error-list
'face 'flycheck-error-list-column-number)))
(let ((face (flycheck-error-level-error-list-face 'error)))
(should (equal (aref cells 2)
(list "error"
'type 'flycheck-error-list
'face face))))
(should (equal (aref cells 3)
(list ""
'type 'flycheck-error-list
'face 'flycheck-error-list-id)))
(should (equal (aref cells 4)
(list "A foo error"
'type 'flycheck-error-list
'face 'default)))
(should (equal (aref cells 5)
(list "(emacs-lisp-checkdoc)"
'type 'flycheck-error-list
'face 'flycheck-error-list-checker-name)))))

(ert-deftest flycheck-error-list-make-entry/no-message ()
:tags '(error-list)
(let* ((error (flycheck-error-new-at 10 nil 'info nil :checker 'coq))
(entry (flycheck-error-list-make-entry error))
(cells (cadr entry)))
(should (eq (car entry) error))
(should (equal (aref cells 0)
(list "10"
'type 'flycheck-error-list
'face 'flycheck-error-list-line-number)))
(should (equal (aref cells 1)
(list ""
'type 'flycheck-error-list
'face 'flycheck-error-list-column-number)))
(let ((face (flycheck-error-level-error-list-face 'info)))
(should (equal (aref cells 2)
(list "info"
'type 'flycheck-error-list
'face face))))
(should (equal (aref cells 3)
(list ""
'type 'flycheck-error-list
'face 'flycheck-error-list-id)))
(should (equal (aref cells 4)
(list "Unknown info"
'type 'flycheck-error-list
'face 'default)))
(should (equal (aref cells 5)
(list "(coq)"
'type 'flycheck-error-list
'face 'flycheck-error-list-checker-name)))))

(ert-deftest flycheck-error-list-mode-line-filter-indicator/no-filter ()
:tags '(error-list)
(let ((flycheck-error-list-minimum-level nil))
(should (string= (flycheck-error-list-mode-line-filter-indicator) ""))))

(ert-deftest flycheck-error-list-mode-line-filter-indicator/with-filter ()
:tags '(error-list)
(let ((flycheck-error-list-minimum-level 'error))
(should (string= (flycheck-error-list-mode-line-filter-indicator)
" [>= error]"))))

(ert-deftest flycheck-error-list-reset-filter/kills-local-variable ()
:tags '(error-list)
(with-temp-buffer
(setq-local flycheck-error-list-minimum-level 'error)
(should (local-variable-p 'flycheck-error-list-minimum-level))
(flycheck-error-list-reset-filter)
(should-not (local-variable-p 'flycheck-error-list-minimum-level))))

(ert-deftest flycheck-error-list-apply-filter/filters-lower-levels ()
:tags '(error-list)
(let ((flycheck-error-list-minimum-level 'warning)
(errors (list (flycheck-error-new-at 10 10 'error)
(flycheck-error-new-at 20 20 'warning)
(flycheck-error-new-at 30 30 'info))))
(should (equal (flycheck-error-list-apply-filter errors)
(list (flycheck-error-new-at 10 10 'error)
(flycheck-error-new-at 20 20 'warning))))))


;;; Displaying errors in buffers
(ert-deftest flycheck-display-errors/no-display-function-set ()
Expand Down
198 changes: 198 additions & 0 deletions test/specs/test-error-list.el
@@ -0,0 +1,198 @@
;;; test-error-list.el --- Flycheck Specs: Error List -*- lexical-binding: t; -*-

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

;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>

;; This file is not part of GNU Emacs.

;; This program 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.

;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Specs for the error list.

;;; Code:

(require 'flycheck-buttercup)

(defmacro flycheck/with-error-list-buffer (&rest body)
"Run BODY in a temporary error list buffer."
(declare (indent 0))
`(with-temp-buffer
(delay-mode-hooks (flycheck-error-list-mode))
(setq delayed-mode-hooks nil)
,@body))

(describe "Error List"
(it "has the correct buffer name"
(expect flycheck-error-list-buffer :to-equal "*Flycheck errors*"))

(it "has a permanently local source buffer"
(flycheck/with-error-list-buffer
(expect (get 'flycheck-error-list-source-buffer 'permanent-local)
:to-be-truthy)))

(it "derives from Tabulated List Mode"
(flycheck/with-error-list-buffer
(expect (derived-mode-p 'tabulated-list-mode) :to-be-truthy)))

(describe "Format"
(it "sets the error list format locally"
(flycheck/with-error-list-buffer
(expect tabulated-list-format :not :to-equal nil)
(expect 'tabulated-list-format :to-be-local)))

(it "sets a proper padding locally"
(flycheck/with-error-list-buffer
(expect tabulated-list-padding :to-equal 1)
(expect 'tabulated-list-padding :to-be-local)))

(it "sets the list entries locally"
(flycheck/with-error-list-buffer
(expect tabulated-list-entries :to-equal 'flycheck-error-list-entries)
(expect 'tabulated-list-entries :to-be-local)))

(it "has a local header line"
(flycheck/with-error-list-buffer
(expect header-line-format
:to-equal " Line Col Level ID Message (Checker) ")
(expect 'header-line-format :to-be-local))))

(describe "Columns"
(it "has the line number in the 1st column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 0)
:to-equal
'("Line" 4 flycheck-error-list-entry-< :right-align t))))

(it "has the column number in the 2nd column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 1)
:to-equal '("Col" 3 nil :right-align t))))

(it "has the error level in the 3rd column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 2)
:to-equal '("Level" 8 flycheck-error-list-entry-level-<))))

(it "has the error ID in the 4th column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 3)
:to-equal '("ID" 6 t))))

(it "has the error message in the 5th column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 4)
:to-equal '("Message" 0 t))))

(it "has the syntax checker in the 6th column"
(flycheck/with-error-list-buffer
(expect (aref tabulated-list-format 5)
:to-equal '(" (Checker)" 8 t)))))

(describe "Entry"
(let* ((warning (flycheck-error-new-at 10 12 'warning "A foo warning"
:checker 'emacs-lisp-checkdoc
:id "W1"))
(entry (flycheck-error-list-make-entry warning))
(cells (cadr entry)))

(it "has the error object as ID"
(expect (car entry) :to-be warning))

(it "has the line number in the 1st cell"
(expect (aref cells 0) :to-equal
(list "10"
'type 'flycheck-error-list
'face 'flycheck-error-list-line-number)))

(it "has the column number in the 2nd cell"
(expect (aref cells 1) :to-equal
(list "12"
'type 'flycheck-error-list
'face 'flycheck-error-list-column-number)))

(it "has an empty 2nd cell if there is no column number"
(cl-letf* (((flycheck-error-column warning) nil)
(entry (flycheck-error-list-make-entry warning))
(cells (cadr entry)))
(expect (aref cells 1) :to-equal
(list ""
'type 'flycheck-error-list
'face 'flycheck-error-list-column-number))))

(it "has the error level in the 3rd cell"
(expect (aref cells 2) :to-equal
(list "warning"
'type 'flycheck-error-list
'face (flycheck-error-level-error-list-face 'warning))))

(it "has the error ID in the 4th cell"
(expect (aref cells 3) :to-equal
(list "W1"
'type 'flycheck-error-list
'face 'flycheck-error-list-id)))

(it "has the error message in the 5th cell"
(expect (aref cells 4) :to-equal
(list "A foo warning"
'type 'flycheck-error-list
'face 'default)))

(it "has a default message in the 5th cell if there is no message"
(cl-letf* (((flycheck-error-message warning) nil)
(entry (flycheck-error-list-make-entry warning))
(cells (cadr entry)))
(expect (aref cells 4) :to-equal
(list "Unknown warning"
'type 'flycheck-error-list
'face 'default))))

(it "has the syntax checker in the 6th cell"
(expect (aref cells 5) :to-equal
(list "(emacs-lisp-checkdoc)"
'type 'flycheck-error-list
'face 'flycheck-error-list-checker-name)))))

(describe "Filter"
(it "kills the filter variable when resetting the filter"
(flycheck/with-error-list-buffer
(setq-local flycheck-error-list-minimum-level 'error)
(expect 'flycheck-error-list-minimum-level :to-be-local)
(flycheck-error-list-reset-filter)
(expect 'flycheck-error-list-minimum-level :not :to-be-local)))

(it "filters errors with lower levels"
(let ((flycheck-error-list-minimum-level 'warning)
(errors (list (flycheck-error-new-at 10 10 'error)
(flycheck-error-new-at 20 20 'warning)
(flycheck-error-new-at 30 30 'info))))
(expect (flycheck-error-list-apply-filter errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 10 10 'error)
(flycheck-error-new-at 20 20 'warning)))))

(describe "Mode Line"
(it "shows no mode line indicator if no filter is set"
(let ((flycheck-error-list-minimum-level nil))
(expect (flycheck-error-list-mode-line-filter-indicator)
:to-be-empty-string)))

(it "shows the level filter in the mode line if set"
(let ((flycheck-error-list-minimum-level 'warning))
(expect (flycheck-error-list-mode-line-filter-indicator)
:to-equal " [>= warning]"))))))

;;; test-error-list.el ends here

0 comments on commit 114aa04

Please sign in to comment.