Use lexical-binding in warnings.el and add tests
* lisp/warnings.el: Use lexical-binding. Remove redundant :group args. * test/lisp/warnings-tests.el: New file.
This commit is contained in:
parent
7974422dfc
commit
766cd0c7c3
2 changed files with 61 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
|||
;;; warnings.el --- log and display warnings
|
||||
;;; warnings.el --- log and display warnings -*- lexical-binding:t -*-
|
||||
|
||||
;; Copyright (C) 2002-2020 Free Software Foundation, Inc.
|
||||
|
||||
|
@ -74,7 +74,6 @@ it may not itself be an alias.")
|
|||
If a warning's severity level is lower than this,
|
||||
the warning is logged in the warnings buffer, but the buffer
|
||||
is not immediately displayed. See also `warning-minimum-log-level'."
|
||||
:group 'warnings
|
||||
:type '(choice (const :emergency) (const :error)
|
||||
(const :warning) (const :debug))
|
||||
:version "22.1")
|
||||
|
@ -86,7 +85,6 @@ If a warning severity level is lower than this,
|
|||
the warning is completely ignored.
|
||||
Value must be lower or equal than `warning-minimum-level',
|
||||
because warnings not logged aren't displayed either."
|
||||
:group 'warnings
|
||||
:type '(choice (const :emergency) (const :error)
|
||||
(const :warning) (const :debug))
|
||||
:version "22.1")
|
||||
|
@ -100,7 +98,6 @@ Thus, (foo bar) as an element matches (foo bar)
|
|||
or (foo bar ANYTHING...) as TYPE.
|
||||
If TYPE is a symbol FOO, that is equivalent to the list (FOO),
|
||||
so only the element (FOO) will match it."
|
||||
:group 'warnings
|
||||
:type '(repeat (repeat symbol))
|
||||
:version "22.1")
|
||||
|
||||
|
@ -115,7 +112,6 @@ or (foo bar ANYTHING...) as TYPE.
|
|||
If TYPE is a symbol FOO, that is equivalent to the list (FOO),
|
||||
so only the element (FOO) will match it.
|
||||
See also `warning-suppress-log-types'."
|
||||
:group 'warnings
|
||||
:type '(repeat (repeat symbol))
|
||||
:version "22.1")
|
||||
|
||||
|
|
60
test/lisp/emacs-lisp/warnings-tests.el
Normal file
60
test/lisp/emacs-lisp/warnings-tests.el
Normal file
|
@ -0,0 +1,60 @@
|
|||
;;; warnings-tests.el --- tests for warnings.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; Author: Stefan Kangas <stefankangas@gmail.com>
|
||||
|
||||
;; Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
;; 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'warnings)
|
||||
|
||||
(ert-deftest test-warning-suppress-p ()
|
||||
(should (warning-suppress-p 'foo '((foo))))
|
||||
(should (warning-suppress-p '(foo bar) '((foo bar))))
|
||||
(should (warning-suppress-p '(foo bar baz) '((foo bar))))
|
||||
(should-not (warning-suppress-p '(foo bar baz) '((foo bax))))
|
||||
(should-not (warning-suppress-p 'foobar nil)))
|
||||
|
||||
(ert-deftest test-display-warning ()
|
||||
(dolist (level '(:emergency :error :warning))
|
||||
(with-temp-buffer
|
||||
(display-warning '(foo) "Hello123" level (current-buffer))
|
||||
(should (string-match "foo" (buffer-string)))
|
||||
(should (string-match "Hello123" (buffer-string))))
|
||||
(with-current-buffer "*Messages*"
|
||||
(should (string-match "Hello123" (buffer-string))))))
|
||||
|
||||
(ert-deftest test-display-warning/warning-minimum-level ()
|
||||
;; This test only works interactively:
|
||||
:expected-result :failed
|
||||
(let ((warning-minimum-level :emergency))
|
||||
(with-temp-buffer
|
||||
(display-warning '(foo) "baz" :warning (current-buffer)))
|
||||
(with-current-buffer "*Messages*"
|
||||
(should-not (string-match "baz" (buffer-string))))))
|
||||
|
||||
(ert-deftest test-display-warning/warning-minimum-log-level ()
|
||||
(let ((warning-minimum-log-level :error))
|
||||
(with-temp-buffer
|
||||
(display-warning '(foo) "hello" :warning (current-buffer))
|
||||
(should-not (string-match "hello" (buffer-string))))))
|
||||
|
||||
(provide 'warnings-tests)
|
||||
|
||||
;;; warnings-tests.el ends here
|
Loading…
Add table
Reference in a new issue