1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
;;; test-error-filters.el --- Flycheck Specs: Error Filters -*- 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 error filters.
;;; Code:
(require 'flycheck-buttercup)
(describe "Error filters"
(describe "flycheck-sanitize-errors"
(it "removes trailing whitespace"
(let ((err (flycheck-error-new-at 1 1 'error " foo ")))
(expect (flycheck-sanitize-errors (list err))
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 1 'error "foo")))))
(it "removes empty error IDs"
(let ((err (flycheck-error-new-at 1 1 'error "foo" :id "")))
(expect (flycheck-sanitize-errors (list err))
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 1 'error "foo")))))
(it "removes zero columns"
(let ((err (flycheck-error-new-at 1 0 'error "foo")))
(expect (flycheck-sanitize-errors (list err))
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 nil 'error "foo"))))))
(describe "flycheck-remove-error-file-names"
(it "removes the given filename from errors"
(let ((errors
(list
(flycheck-error-new-at 1 1 'error "foo" :filename "hello")
(flycheck-error-new-at 2 2 'warning "bar" :filename "world")
(flycheck-error-new-at 3 3 'info "spam"))))
(expect (flycheck-remove-error-file-names "world" errors)
:to-be-equal-flycheck-errors
(list
(flycheck-error-new-at 1 1 'error "foo" :filename "hello")
(flycheck-error-new-at 2 2 'warning "bar")
(flycheck-error-new-at 3 3 'info "spam"))))))
(describe "flycheck-increment-error-columns"
(it "ignores nil columns"
(let ((errors (list (flycheck-error-new-at 4 nil))))
(expect (flycheck-increment-error-columns errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 4 nil)))))
(it "increments with the default offset"
(let ((errors (list (flycheck-error-new-at 4 6)
(flycheck-error-new-at 7 9))))
(expect (flycheck-increment-error-columns errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 4 7)
(flycheck-error-new-at 7 10)))))
(it "increments with a custom offset"
(let ((errors (list (flycheck-error-new-at 4 6)
(flycheck-error-new-at 7 9))))
(expect (flycheck-increment-error-columns errors 10)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 4 16)
(flycheck-error-new-at 7 19))))))
(describe "flycheck-fold-include-levels"
(it "skips over intermittent errors"
;; See https://github.com/flycheck/flycheck/pull/783
(let ((errors
(list (flycheck-error-new-at 1 0 'error "In file included from"
:filename "foo.cpp")
(flycheck-error-new-at 6 11 'error "b is not a member of hi"
:filename "foo.cpp")
(flycheck-error-new-at 5 20 'note
"in definition of macro CHECK"
:filename "foo.h")
(flycheck-error-new-at 8 5 'error
"xx was not declared in this scope"
:filename "foo.cpp"))))
(expect
(flycheck-fold-include-levels errors "In file included from")
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 0 'error "In include foo.h"
:filename "foo.cpp")
(flycheck-error-new-at 6 11 'error "b is not a member of hi"
:filename "foo.cpp")
(flycheck-error-new-at 5 20 'note "in definition of macro CHECK"
:filename "foo.h")
(flycheck-error-new-at 8 5 'error
"xx was not declared in this scope"
:filename "foo.cpp"))))))
(describe "flycheck-collapse-error-message-whitespace"
(it "collapses all whitespace in error messages"
(let ((err (flycheck-error-new-at 1 1 'error
"spam \nwith\t eggs")))
(expect (flycheck-collapse-error-message-whitespace (list err))
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 1 'error
"spam with eggs"))))))
(describe "flycheck-dequalify-error-ids"
(it "removes all nested qualifiers"
(let ((errors
(list (flycheck-error-new-at 1 2 nil nil :id "foo.bar")
(flycheck-error-new-at 1 2 nil nil :id "Spam.With.Eggs"))))
(expect (flycheck-dequalify-error-ids errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 2 nil nil :id "bar")
(flycheck-error-new-at 1 2 nil nil :id "Eggs")))))
(it "leaves unqualified IDs alone"
(let ((errors (list (flycheck-error-new-at 1 2 nil nil :id "foobar"))))
(expect (flycheck-dequalify-error-ids errors)
:to-be-equal-flycheck-errors errors)))
(it "ignores errors without IDs"
(let ((errors (list (flycheck-error-new-at 3 4))))
(expect (flycheck-dequalify-error-ids errors)
:to-be-equal-flycheck-errors errors))))
(describe "flycheck-remove-error-ids"
(it "ignores errors without IDs"
(let ((errors (list (flycheck-error-new-at 1 2))))
(expect (flycheck-remove-error-ids errors)
:to-be-equal-flycheck-errors errors)))
(it "removes error IDs"
(let ((errors (list (flycheck-error-new-at 1 2 nil nil :id "Foo.Bar"))))
(expect (flycheck-remove-error-ids errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 1 2))))))
(describe "flycheck-fill-empty-line-numbers"
(it "ignores errors with line numbers"
(let ((errors (list (flycheck-error-new-at 1 2))))
(expect (flycheck-fill-empty-line-numbers errors)
:to-be-equal-flycheck-errors errors)))
(it "sets errors missing line numbers to line 0"
(let ((errors (list (flycheck-error-new-at nil nil))))
(expect (flycheck-fill-empty-line-numbers errors)
:to-be-equal-flycheck-errors
(list (flycheck-error-new-at 0 nil)))))))
;;; test-error-filters.el ends here
|